Skip to content

Commit

Permalink
added support for node arguments, via nodeargs (like --harmony)
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
Bartvds committed Jul 1, 2014
1 parent d22b8b9 commit b42bee6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
7 changes: 7 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ module.exports = function (grunt) {
},
src: ['test/fixtures/module.async.js']
},
harmony_on: {
options: {
nodeargs: ['--harmony']
},
src: ['test/fixtures/node.harmony.js']
},
call_sync: {
call: function (grunt, options, async) {
var ctx = help.getContext('call.sync.gruntfile.js');
Expand Down Expand Up @@ -167,6 +173,7 @@ module.exports = function (grunt) {
'execute:node_args',
'execute:node_async',
'execute:node_sync',
'execute:harmony_on',
'execute:zero',
'execute:module_sync',
'execute:module_async',
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ grunt.initConfig({
},
src: ['script.js']
},
simple_target_with_harmony: {
options: {
// pass arguments to node itself (eg: before script parameter)
nodeargs: ['--harmony']
},
src: ['script.js']
},
cwd_target: {
options: {
// overide code cwd (defaults to '.' for project main)
Expand Down Expand Up @@ -127,7 +134,8 @@ grunt.initConfig({

## Versions

* 0.2.1 - Non-zero exit code will fail grunt, add support for commandline arguments
* 0.2.2 - Add support for node arguments, via `nodeargs` (like `--harmony`)
* 0.2.1 - Non-zero exit code will fail grunt, add support for commandline arguments
* 0.1.5 - Added callback module & inline function support
* 0.1.4 - Ditched stdio option, show errors inline (even in webstorm)
* 0.1.3 - Basic version, colors disabled
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-execute",
"description": "Execute code in node",
"version": "0.2.1",
"version": "0.2.2",
"homepage": "https://github.com/Bartvds/grunt-execute",
"author": {
"name": "Bart van der Schoor",
Expand Down
7 changes: 6 additions & 1 deletion tasks/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ module.exports = function (grunt) {

var start = Date.now();

var args = context.options.args ? [src].concat(context.options.args) : [src];
if (context.options.nodeargs) {
args = context.options.nodeargs.concat(args);
}

//use spawn so we don't have to depend on process.exit();
var child = grunt.util.spawn(
{
cmd: 'node',
args: context.options.args ? [src].concat(context.options.args) : [src],
args: args,
opts: {
cwd: (context.options.cwd !== null) ? context.options.cwd : path.dirname(src)
}
Expand Down
10 changes: 8 additions & 2 deletions test/execute_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ exports.execute = {
test.done();
},
args: function (test) {
test.expect(1);
easyTestOutput(test, 'node.args.js', ' foo bar');
if (process.version.match(/^v\d+\.(\d+)\.\d+$/)[1] >= 11) {
test.expect(2);
easyTestOutput(test, 'node.args.js', ' foo bar');
easyTestOutput(test, 'node.harmony.js', ' true');
} else {
test.expect(1);
easyTestOutput(test, 'node.args.js', ' foo bar');
}
test.done();
},
module_sync: function (test) {
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/node.harmony.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var help = require('../helper.js');
var ctx = help.getContext(__filename);

var fs = require('fs');

setTimeout(function () {
fs.writeFile(ctx.dest, ctx.data + ' ' + ('function' === typeof Map), function (err) {
if(err) throw err;
});
}, 100);

0 comments on commit b42bee6

Please sign in to comment.