Is there a way to read grunt tasks via terminal? - gruntjs

I would like to get the registered Tasks from a gruntfile via terminal.
Example:
grunt.registerTask('test', ['clean', 'compass', 'uglify', 'cssmin', 'imagemin', 'copy:test', 'ftp-deploy:test', 'clean']);
then on the terminal I would type something like
$> grunt --listtasks
Even better if I could register each task with a description like so:
grunt.registerTask('test', 'this task deploys to testserver',['clean', 'compass', 'uglify', 'cssmin', 'imagemin', 'copy:test', 'ftp-deploy:test', 'clean']);
Then the output could be something like:
$> test: this task deploys to testserver (clean, compass, uglify, cssmin, imagemin, copy:test, ftp-deploy:test, clean)

Run grunt --help to get a list of all registered tasks. This shows the command and the task description. Example output:
$ grunt --help
Grunt: The JavaScript Task Runner (v0.4.1)
Usage
grunt [options] [task [task ...]]
Options
--help, -h Display this help text.
--base Specify an alternate base path. By default, all file paths
are relative to the Gruntfile. (grunt.file.setBase) *
--no-color Disable colored output.
--gruntfile Specify an alternate Gruntfile. By default, grunt looks in
the current or parent directories for the nearest
Gruntfile.js or Gruntfile.coffee file.
--debug, -d Enable debugging mode for tasks that support it.
--stack Print a stack trace when exiting with a warning or fatal
error.
--force, -f A way to force your way past warnings. Want a suggestion?
Don't use this option, fix your code.
--tasks Additional directory paths to scan for task and "extra"
files. (grunt.loadTasks) *
--npm Npm-installed grunt plugins to scan for task and "extra"
files. (grunt.loadNpmTasks) *
--no-write Disable writing files (dry run).
--verbose, -v Verbose mode. A lot more information output.
--version, -V Print the grunt version. Combine with --verbose for more
info.
--completion Output shell auto-completion rules. See the grunt-cli
documentation for more information.
Options marked with * have methods exposed via the grunt API and should instead
be specified inside the Gruntfile wherever possible.
Available tasks
rosetta Shared variables between JS and CSS. *
asciify Ascii awesomizer. A Grunt task for better banners and hot
logs. *
clear Clear your terminal window
clean Clean files and folders. *
concat Concatenate files. *
jshint Validate files with JSHint. *
sass Compile Sass to CSS *
watch Run predefined tasks whenever watched files change.
csso Minify CSS files with CSSO. *
lintspaces Checking spaces *
newer Run a task with only those source files that have been
modified since the last successful run.
any-newer Run a task with all source files if any have been modified
since the last successful run.
newer-timestamp Internal task.
svgmin Minify SVG *
trimtrailingspaces Removing the trailing spaces *
webfont Compile separate SVG files to webfont *
Tasks run in the order specified. Arguments may be passed to tasks that accept
them by using colons, like "lint:files". Tasks marked with * are "multi tasks"
and will iterate over all sub-targets if no argument is specified.
The list of available tasks may change based on tasks directories or grunt
plugins specified in the Gruntfile or via command-line options.
For more information, see http://gruntjs.com/

Or have a look at grunt-available-tasks:

Related

How can I have Deno's std http file_server watch files?

I'm running an example file-server with a simple index.html file, I want the script to re-run when changes are made within the directory, how can I do that?
deno run --allow-net --allow-read --watch https://deno.land/std#0.157.0/http/file_server.ts ./
You can provide one or more path values for the watch argument when using deno run in order watch additional files outside the module graph. For example, use
deno run —-watch=. module.ts
to watch all files recursively in the current working directory.
You can use the deno help command to get information about the command you want to use (in this case run). This is how I answered your question:
% deno --version
deno 1.26.2 (release, x86_64-apple-darwin)
v8 10.7.193.16
typescript 4.8.3
% deno help run
---snip---
USAGE:
deno run [OPTIONS] <SCRIPT_ARG>...
ARGS:
<SCRIPT_ARG>...
Script arg
OPTIONS:
---snip---
--watch[=<FILES>...]
Watch for file changes and restart process automatically.
Local files from entry point module graph are watched by default.
Additional paths might be watched by passing them as arguments to
this flag.
However in the case of the static file server module that you asked about, there's no real benefit to reloading the server process as it just serves static files: any time you request a static file, you always get the latest version.
Perhaps you're looking for "hot/live reload" behavior in the browser client. This is a different pattern: a coordinated effort between the JavaScript in the page and the server — and that’s not something that’s supported by the module you asked about.

How to have gruntjs skip eslint task if no files are found?

I'm using grunt with the grunt-eslint plugin. This is part of a larger grunt task that first finds changed files and does various tasks with them. If there aren't any JS files changed (for example if I just change a CSS file) the whole task aborts because eslint fails with a "could not find any files to validate" message.
$ grunt eslint:precommit
Running "eslint:precommit" (eslint) task
Could not find any files to validate.
Warning: Task "eslint:precommit" failed. Use --force to continue.
Aborted due to warnings.
I don't want the task to fail if there aren't any JS files found.
Is there a way to either:
A. Have the grunt task not even call eslint and not fail if no files are run?
B. Have eslint not fail if no files are run?
(Related, but specific to a different tool called from grunt: Can an assemble target be silenced if there are no matching files? (Without using --force))
Using Dynamic task is your solution, here the link for the docs: http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks
Related links:
How can I skip a grunt task if a directory is empty

Issue when I run "grunt build"

I am working with grunt and when I write "grunt build" my dist folder builds everything, except for the js files. I get the following message:
I'm guessing I have to edit my Gruntfile, but I'm not sure how to go about solving this.
My Gruntfile is long, but here is the uglify part:
What does it mean by the destination was not written because src files were empty
It means the files listed in dist: {src:"<%config.app%>*" were not created yet. Use the following process:
Run copy and uglify manually and verbosely
grunt copy:dist --verbose
grunt uglify:dist --verbose
If it works, reorganize the task in question in the registerTask method:
grunt registerTask("build", ['copy:dist','uglify:dist']);
Otherwise, dump the <%config.app%> path to make sure it is correct
grunt.registerTask('dump', 'Dump Output', function(){ console.log(grunt.config.get() ) });
References
Grunt API: grunt.config.get
Grunt Documentation: Using the CLI

How can I execute additional commands after changes detected by `compass watch`?

I've executed compass watch in a Zurb Foundation project.
It works great, my assets are compiled as I make settings changes.
However, I'd like to also run additional a few grunt commands each time I make changes.
How can I add to the actions that compass performs when changes are detected?
Specifically, I'd like to run two commands from another directory.
This is what I've got:
cd /dir_foundation/
bundle exec compasss watch
After each change, I want it to also call:
grunt sass:dist
grunt cssmin
These grunt tasks are defined in a gruntfile that is 2 directories "up" from the /dir_foundation/ where the compass watch command is monitoring changes.
I found an answer.
http://compass-style.org/help/documentation/configuration-reference/#callbacks
This is what I added to my config.rb file:
on_stylesheet_saved do |file|
system('../../../compile.bat')
end
Where "compile.bat" contains:
grunt sass:dist
grunt cssmin

Using Grunt to run modified scripts

I have an EXE, let's call it MyApp.exe
I then have a folder containing a a list of unit tests. Eg.
-MyTest1.txt
-MyTest2.txt
-MyTest3.txt
-MyTest4.txt
I'd like to run:
MyApp.exe --File=MyTest1.txt (obviously if it was MyTest2.txt that was modified I'd want to have that be the input).
any time MyTest1.txt or one of the other files are modified.
What's the simplest way to do this with Grunt?
Turned out to be pretty simple.
See: https://www.npmjs.org/package/grunt-contrib-watch
Search page for:
"A very common request is to only compile files as needed. Here is an example that will only lint changed files with the jshint task:"

Resources