Is there a way to send multiple values for grunt.option - gruntjs

I'd like start grunt with an option set with multiple vales. Is this possible?
i.e.
grunt doThis --ip 1.2.3.4 --ip 2.3.4.5
Is this possible?
grunt.registerTask('doThis', function () {
console.log(grunt.option('ip'));
});
grunt doThis --ip="192.168.1.1" --ip="192.169.1.10"
Running "doThis" task
192.169.1.10
Done, without errors.

Yes. Grunt uses nopt to parse the command line options and it supports multiple values. You'd pass them like this:
grunt doThis --ip=1.2.3.4 --ip=2.3.4.5
You'll need at least version v1.0.0-rc1 of Grunt for this to work.

Related

UNIX/vim - Verify syntax error

How can I verify if my code on vim (Unix) has syntax errors?
Is there any command to test the code?
Thank you in advance!
Use a plugin which checks your code.
The one I use, and I'm not alone, is syntactic: https://github.com/vim-syntastic/syntastic
This works for a tons of different languages and even has multiple "lint" engines to choose from for each language. For instance, I use python and can configure syntactic to use one of the following checkers: flake8, pyflakes, pylint and the native python checker. And, yes, it checks vim script as well.
If you can't use any plugins AND only want to debug your vim-scripts, then your best bet is to use vim's own debugger (help debug-scripts). To use this mode:
Start vim in debug mode: vim -D my_broken_script.vim
use :debug to switch into debug mode.
use Ex commands to inspect local variables, echo idx, or global ones: echo g:idx, where idx is the var.
set breakpoints with :breakadd on either functions or files. And delete them with :breakdel
Use profile to investigate performance issues (help :profile): :profile start func and :profile stop

How to pass an option to a Grunt task using WebStorm?

I have a Gruntfile.js in my project, which is parsed by WebStorm (JetBrains IDE for Javascript). The parsed tasks appear in the Grunt view.
Considering the following task (see http://gruntjs.com/frequently-asked-questions#options) :
grunt.registerTask('upload', 'Upload code to specified target.', function(n) {
var target = grunt.option('target');
// do something useful with target here
});
How can I run grunt upload --target=staging using WebStorm ? I can't find a way to pass the option.
to specify custom CMD options (retrieved via grunt.option()) passed to Grunt task, use Tasks field of Grunt Run configuration, like: 'print -–echo=Hello' (or 'upload --target=staging' in your case)

Grunt : argument with colon

I'd like to pass an url to a grunt task. Unfortunately the separator used by grunt is the colon which is also present in an url.
So how could I pass a url as argument to a grunt task ?
I went for the grunt.option('optionName') way.
from the command line it's called like following :
grunt myTask --optionName=httpmyUrl

How to run a command in child process in grunt tasks?

I want to write a grunt task, which will start a server, and run some tests based on that server:
grunt.initConfig({
shell: {
sbtRun: {
options: {
stdout: true
},
command: './sbt run'
}
}
});
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('run-test-only', ...);
grunt.registerTask('start-server-and-test', ['shell:sbtRun', 'run-test-only']);
But the problem is, the task ./sbt run is not running in daemon. When I run:
grunt start-server-and-test
It will blocking in the shell:sbtRun task forever.
Is there any way to start it in a child process? So the second task run-test-only will be called, and the server will be destroyed automatically after testing?
I was facing a similar issue. I wanted to connect to a database and store the result of a query in a .csv. I created a separate file to do all that work and I was successful in running that file through the command line using:
node filename.js
I used grunt-shell and grunt-exec to run this command but everytime I saw the same error:
const child = require('child_process').exec;
Then, I found another grunt plugin i.e grunt-execute which was able to create a child process and the task was completed successfully. You could find more about grunt-execute here, https://www.npmjs.com/package/grunt-execute.
Hope this helps.

How to pass command line arguments to a Meteor app?

I would like to pass command line arguments to my Meteor app on start up.
For example --dev, --test or --prod indicating whether or not it is running in dev, test or prod environments. It can then load different resources on start up, etc...
I tried something like this in a /server/server.js
var arguments = process.argv.splice(2);
console.log('cmd args: ' + JSON.stringify(arguments,0,4));
The I ran a test. And quite a few others with just random command line arguments.
meteor --dev
The output in the console is only this.
cmd args: [
"--keepalive"
]
What is the best way to get command line arguments into a Meteor app?
Or, is this even the correct way to solve the higher level problem? and if not, what is the correct way to solve this problem of distinguishing between running enviro?
Meteor doesn't forward command line args to your app, if it doesn't know them. You have multiple possibilities:
Rewrite parts of meteor.js to forward unrecognized args. This shouldn't be too hard, but it's not a pretty solution. And if updates occur you are in trouble. :D
You could write a small config file and change the behaviour of your app based on the configuration options in there. Take a look at this question.
The easiest thing to do is using environment variables. You can read env vars in node like this. After that you can start your app the "express.js" way: $ METEOR_ENV=production meteor
I hope I could help you! :)
The reason it doesn't work is because the meteor command starts a proxy (which gets the arguments you give) and then it starts the meteor app with --keepalive.
process.argv will have correct values if you build Meteor with meteor build --directory /my/build/path and run it.

Resources