Socket
Socket
Sign inDemoInstall

jake

Package Overview
Dependencies
0
Maintainers
1
Versions
166
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.19 to 0.2.20

32

lib/loader.js

@@ -31,17 +31,19 @@ /*

// Warning, recursive
, exists = function () {
var cwd = process.cwd();
if (path.existsSync(jakefile) || path.existsSync(jakefile + '.js') ||
path.existsSync(jakefile + '.coffee')) {
return true;
}
if (!fileSpecified) {
process.chdir("..");
if (cwd === process.cwd()) {
return false;
}
return exists();
}
};
, exists;
exists = function () {
var cwd = process.cwd();
if (path.existsSync(jakefile) || path.existsSync(jakefile + '.js') ||
path.existsSync(jakefile + '.coffee')) {
return true;
}
if (!fileSpecified) {
process.chdir("..");
if (cwd === process.cwd()) {
return false;
}
return exists();
}
};
if (!exists()) {

@@ -60,3 +62,3 @@ fail('No Jakefile. Specify a valid path with -f/--jakefile, or place one in the current directory.');

}
if (jakefile.indexOf('/') != 0) {
if (jakefile.indexOf('/') != 0 && !/^[A-Za-z]+:\\/.test(jakefile)) {
jakefile = path.join(process.cwd(), jakefile);

@@ -63,0 +65,0 @@ }

@@ -22,2 +22,4 @@ /*

, spawn = require('child_process').spawn
, fs = require('fs')
, path = require('path')
, utils;

@@ -65,4 +67,4 @@

, list = arr.slice()
, stdout = options.stdout
, stderr = options.stderr
, printStdout = options.stdout
, printStderr = options.stderr
, breakOnError = typeof options.breakOnError != 'undefined' ?

@@ -80,41 +82,56 @@ options.breakOnError : true

if (next) {
// Ganking part of Node's child_process.exec to get cmdline args parsed
// If you're on Windows, no streaming output for you,
// just use exec
if (process.platform == 'win32') {
cmd = 'cmd.exe';
args = ['/s', '/c', next];
exec(next, function (err, stdout, stderr) {
if (err && breakOnError) {
fail(err);
}
else {
if (printStderr) {
console.error(stderr);
}
if (printStdout) {
console.log(stdout);
}
run();
}
});
}
// POSIX platform get streaming output for shell-commands
// Ganking part of Node's child_process.exec to get cmdline args parsed
else {
cmd = '/bin/sh';
args = ['-c', next];
}
// Spawn a child-process, set up output
sh = spawn(cmd, args);
// Out
if (stdout) {
sh.stdout.on('data', function (data) {
console.log(_truncate(data.toString()));
// Spawn a child-process, set up output
sh = spawn(cmd, args);
// Out
if (printStdout) {
sh.stdout.on('data', function (data) {
console.log(_truncate(data.toString()));
});
}
// Err
sh.stderr.on('data', function (data) {
var d = data.toString();
if (printStderr) {
console.error(_truncate(d));
}
// Accumulate the error-data so we can use it as the
// stack if the process exits with an error
errData += d;
});
// Exit, handle err or run next
sh.on('exit', function (code) {
var msg = errData || 'Process exited with error.';
msg = _trim(msg);
if (breakOnError && code != 0) {
fail(msg, code);
}
else {
run();
}
});
}
// Err
sh.stderr.on('data', function (data) {
var d = data.toString();
if (stderr) {
console.error(_truncate(d));
}
// Accumulate the error-data so we can use it as the
// stack if the process exits with an error
errData += d;
});
// Exit, handle err or run next
sh.on('exit', function (code) {
var msg = errData || 'Process exited with error.';
msg = _trim(msg);
if (breakOnError && code != 0) {
fail(msg, code);
}
else {
run();
}
});
}

@@ -187,4 +204,121 @@ else {

var _copyFile = function(fromPath, toPath, opts) {
var from = path.normalize(fromPath)
, to = path.normalize(toPath)
, fromStat
, toStat
, destExists
, destDoesNotExistErr
, content
, createDir = opts.createDir
, recurse = opts.recurse;
if (fromPath == toPath) {
throw new Error('Cannot copy ' + from + ' to itself.');
}
fromStat = fs.statSync(from);
try {
toStat = fs.statSync(to);
destExists = true;
//console.dir(to + ' destExists');
}
catch(e) {
destDoesNotExistErr = e;
destExists = false;
//console.dir(to + ' does not exist');
}
// Destination dir or file exists, copy in or overwrite
if (destExists || createDir) {
if (createDir) {
//console.log('creating dir ' + to);
try {
fs.mkdirSync(to);
}
catch(e) {
if (e.code != 'EEXIST') {
throw e;
}
}
}
// Copying a directory
if (fromStat.isDirectory()) {
var dirContents = fs.readdirSync(from)
, targetDir = path.join(to, path.basename(from));
// We don't care if the target dir already exists
try {
fs.mkdirSync(targetDir);
}
catch(e) {
if (e.code != 'EEXIST') {
throw e;
}
}
for (var i = 0, ii = dirContents.length; i < ii; i++) {
//console.log(dirContents[i]);
_copyFile(path.join(from, dirContents[i]), targetDir,
{createDir: true});
}
}
// Copying a file
else {
content = fs.readFileSync(from);
// Copy into dir
if (toStat.isDirectory()) {
//console.log('copy into dir ' + to);
fs.writeFileSync(path.join(to, path.basename(from)), content);
}
// Overwrite file
else {
console.log('overwriting ' + to);
fs.writeFileSync(to, content);
}
}
}
// Dest doesn't exist, can't create it
else {
throw destDoesNotExistErr;
}
}
, _copyDir = function (from, to, opts) {
var createDir = opts.createDir;
};
this.cpR = function (from, to) {
_copyFile.apply(this, [from, to, {recurse: true}]);
};
this.mkdirP = function (dir) {
var dirPath = path.normalize(dir)
, paths = dirPath.split(/\/|\\/)
, currPath
, next;
if (paths[0] == '' || /[A-Za-z]+:/.test(paths[0])) {
currPath = paths.shift() || '/';
currPath = path.join(currPath, paths.shift());
//console.log('basedir');
}
while ((next = paths.shift())) {
if (next == '..') {
currPath = path.join(currPath, next);
continue;
}
currPath = path.join(currPath, next);
try {
//console.log('making ' + currPath);
fs.mkdirSync(currPath);
}
catch(e) {
if (e.code != 'EEXIST') {
throw e;
}
}
}
};
})();
module.exports = utils;

@@ -10,3 +10,3 @@ {

],
"version": "0.2.19",
"version": "0.2.20",
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",

@@ -13,0 +13,0 @@ "bin": {

### Jake -- JavaScript build tool for Node.js
### Installing
### Installing with [NPM](http://npmjs.org/)
npm install -g jake
Note that Jake is a system-level tool, and wants to be installed globally.
### Installing from source
Prerequisites: Jake requires Node.js. (<http://nodejs.org/>)

@@ -25,10 +31,6 @@

### Installing with [NPM](http://npmjs.org/)
### Windows, installing from source
npm install -g jake
For Windows users installing from source, there are some additional steps.
Note that Jake is a system-level tool, and wants to be installed globally.
### Installing on Windows
*Assumed: current directory is the same directory where node.exe is present.*

@@ -40,5 +42,6 @@

Copy jake.bat to the same directory as node.exe
Copy jake.bat and jake to the same directory as node.exe
copy node_modules/jake/jake.bat jake.bat
copy node_modules/jake/jake jake

@@ -64,3 +67,3 @@ Add the directory of node.exe to the environment PATH variable.

-V
-V/v
--version Display the program version.

@@ -94,10 +97,15 @@

task(name, [prerequisites], action, [opts]);
```javascript
task(name, [prerequisites], action, [opts]);
```
The `name` argument is a String with the name of the task, and `prerequisites`
is an optional Array arg of the list of prerequisite tasks to perform first. The
`action` is a Function defininng the action to take for the task. (Note that
is an optional Array arg of the list of prerequisite tasks to perform first.
The `action` is a Function defininng the action to take for the task. (Note that
Object-literal syntax for name/prerequisites in a single argument a la Rake is
also supported, but JavaScript's lack of support for dynamic keys in Object
literals makes it not very useful.)
literals makes it not very useful.) The action is invoked with the Task object
itself as the execution context (i.e, "this" inside the action references the
Task object).

@@ -119,18 +127,22 @@ The `opts` argument is optional, and when it includes an `async` property set to

desc('This is the default task.');
task('default', function (params) {
console.log('This is the default task.');
});
```javascript
desc('This is the default task.');
task('default', function (params) {
console.log('This is the default task.');
});
desc('This task has prerequisites.');
task('hasPrereqs', ['foo', 'bar', 'baz'], function (params) {
console.log('Ran some prereqs first.');
});
desc('This task has prerequisites.');
task('hasPrereqs', ['foo', 'bar', 'baz'], function (params) {
console.log('Ran some prereqs first.');
});
```
And here's an example of an asynchronous task:
desc('This is an asynchronous task.');
task('asyncTask', function () {
setTimeout(complete, 1000);
}, {async: true});
```javascript
desc('This is an asynchronous task.');
task('asyncTask', function () {
setTimeout(complete, 1000);
}, {async: true});
```

@@ -152,6 +164,8 @@ A Task is also an EventEmitter which emits the 'complete' event when it is

desc('This builds a minified JS file for production.');
file('foo-minified.js', ['bar', 'foo-bar.js', 'foo-baz.js'], function () {
// Code to concat and minify goes here
});
```javascript
desc('This builds a minified JS file for production.');
file('foo-minified.js', ['bar', 'foo-bar.js', 'foo-baz.js'], function () {
// Code to concat and minify goes here
});
```

@@ -165,4 +179,6 @@ ### Directory-tasks

desc('This creates the bar directory for use with the foo-minified.js file-task.');
directory('bar');
```javascript
desc('This creates the bar directory for use with the foo-minified.js file-task.');
directory('bar');
```

@@ -176,3 +192,5 @@ This task will create the directory when used as a prerequisite for a file-task,

namespace(name, namespaceTasks);
```javascript
namespace(name, namespaceTasks);
```

@@ -185,19 +203,21 @@ Where is `name` is the name of the namespace, and `namespaceTasks` is a function

desc('This is the default task.');
task('default', function () {
console.log('This is the default task.');
});
```javascript
desc('This is the default task.');
task('default', function () {
console.log('This is the default task.');
});
namespace('foo', function () {
desc('This the foo:bar task');
task('bar', function () {
console.log('doing foo:bar task');
});
namespace('foo', function () {
desc('This the foo:bar task');
task('bar', function () {
console.log('doing foo:bar task');
});
desc('This the foo:baz task');
task('baz', ['default', 'foo:bar'], function () {
console.log('doing foo:baz task');
});
desc('This the foo:baz task');
task('baz', ['default', 'foo:bar'], function () {
console.log('doing foo:baz task');
});
});
});
```

@@ -215,6 +235,8 @@ In this example, the foo:baz task depends on the the default and foo:bar tasks.

desc('This is an awesome task.');
task('awesome', function (a, b, c) {
console.log(a, b, c);
});
```javascript
desc('This is an awesome task.');
task('awesome', function (a, b, c) {
console.log(a, b, c);
});
```

@@ -236,7 +258,9 @@ You could run `jake` like this:

desc('This is an awesome task.');
task('awesome', function (a, b, c) {
console.log(a, b, c);
console.log(process.env.qux, process.env.frang);
});
```javascript
desc('This is an awesome task.');
task('awesome', function (a, b, c) {
console.log(a, b, c);
console.log(process.env.qux, process.env.frang);
});
```

@@ -270,7 +294,9 @@ You could run `jake` like this:

desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
});
```javascript
desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
});
```

@@ -280,44 +306,52 @@ Tasks are EventEmitters. If the inner-task invoked is asynchronous, you can set

desc('Calls the async foo:baz task and its prerequisites.');
task('invokeFooBaz', function () {
var t = jake.Task['foo:baz'];
t.addListener('complete', function () {
console.log('Finished executing foo:baz');
// Maybe run some other code
// ...
// Complete the containing task
complete();
});
// Kick off foo:baz
t.invoke();
}, {async: true});
```javascript
desc('Calls the async foo:baz task and its prerequisites.');
task('invokeFooBaz', function () {
var t = jake.Task['foo:baz'];
t.addListener('complete', function () {
console.log('Finished executing foo:baz');
// Maybe run some other code
// ...
// Complete the containing task
complete();
});
// Kick off foo:baz
t.invoke();
}, {async: true});
```
The `invoke` method will only run the task once, even if you call it repeatedly.
desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
// Does nothing
jake.Task['foo:bar'].invoke();
});
```javascript
desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
// Does nothing
jake.Task['foo:bar'].invoke();
});
```
The `execute` method will run the desired task without its prerequisites:
desc('Calls the foo:bar task without its prerequisites.');
task('executeFooBar', function () {
// Calls foo:bar without its prereqs
jake.Task['foo:baz'].execute();
});
```javascript
desc('Calls the foo:bar task without its prerequisites.');
task('executeFooBar', function () {
// Calls foo:bar without its prereqs
jake.Task['foo:baz'].execute();
});
```
Calling `execute` repeatedly will run the desired task repeatedly.
desc('Calls the foo:bar task without its prerequisites.');
task('executeFooBar', function () {
// Calls foo:bar without its prereqs
jake.Task['foo:baz'].execute();
// Can keep running this over and over
jake.Task['foo:baz'].execute();
jake.Task['foo:baz'].execute();
});
```javascript
desc('Calls the foo:bar task without its prerequisites.');
task('executeFooBar', function () {
// Calls foo:bar without its prereqs
jake.Task['foo:baz'].execute();
// Can keep running this over and over
jake.Task['foo:baz'].execute();
jake.Task['foo:baz'].execute();
});
```

@@ -327,12 +361,14 @@ If you want to run the task and its prerequisites more than once, you can use

desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
// Does nothing
jake.Task['foo:bar'].invoke();
// Only re-runs foo:bar, but not its prerequisites
jake.Task['foo:bar'].reenable();
jake.Task['foo:bar'].invoke();
});
```javascript
desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
// Does nothing
jake.Task['foo:bar'].invoke();
// Only re-runs foo:bar, but not its prerequisites
jake.Task['foo:bar'].reenable();
jake.Task['foo:bar'].invoke();
});
```

@@ -342,21 +378,25 @@ The `reenable` method takes a single Boolean arg, a 'deep' flag, which reenables

desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
// Does nothing
jake.Task['foo:bar'].invoke();
// Only re-runs foo:bar, but not its prerequisites
jake.Task['foo:bar'].reenable(true);
jake.Task['foo:bar'].invoke();
});
```javascript
desc('Calls the foo:bar task and its prerequisites.');
task('invokeFooBar', function () {
// Calls foo:bar and its prereqs
jake.Task['foo:bar'].invoke();
// Does nothing
jake.Task['foo:bar'].invoke();
// Only re-runs foo:bar, but not its prerequisites
jake.Task['foo:bar'].reenable(true);
jake.Task['foo:bar'].invoke();
});
```
It's easy to pass params on to a sub-task run via `invoke` or `execute`:
desc('Passes params on to other tasks.');
task('passParams', function () {
var t = jake.Task['foo:bar'];
// Calls foo:bar, passing along current args
t.invoke.apply(t, arguments);
});
```javascript
desc('Passes params on to other tasks.');
task('passParams', function () {
var t = jake.Task['foo:bar'];
// Calls foo:bar, passing along current args
t.invoke.apply(t, arguments);
});
```

@@ -368,13 +408,17 @@ ### Aborting a task

desc('This task fails.');
task('failTask', function () {
fail('Yikes. Something back happened.');
});
```javascript
desc('This task fails.');
task('failTask', function () {
fail('Yikes. Something back happened.');
});
```
You can also pass an optional exit status-code to the fail command, like so:
desc('This task fails with an exit-status of 42.');
task('failTaskQuestionCustomStatus', function () {
fail('What is the answer?', 42);
});
```javascript
desc('This task fails with an exit-status of 42.');
task('failTaskQuestionCustomStatus', function () {
fail('What is the answer?', 42);
});
```

@@ -414,14 +458,16 @@ The process will exit with a status of 42.

desc('Runs the Jake tests.');
task('test', function () {
var cmds = [
'node ./tests/parseargs.js'
, 'node ./tests/task_base.js'
, 'node ./tests/file_task.js'
];
jake.exec(cmds, function () {
console.log('All tests passed.');
complete();
}, {stdout: true});
}, {async: true});
```javascript
desc('Runs the Jake tests.');
task('test', function () {
var cmds = [
'node ./tests/parseargs.js'
, 'node ./tests/task_base.js'
, 'node ./tests/file_task.js'
];
jake.exec(cmds, function () {
console.log('All tests passed.');
complete();
}, {stdout: true});
}, {async: true});
```

@@ -441,15 +487,17 @@ It also takes an optional options-object, where you can set `stdout` (print to

var t = new jake.PackageTask('fonebone', 'v0.1.2112', function () {
var fileList = [
'Jakefile'
, 'README.md'
, 'package.json'
, 'lib/*'
, 'bin/*'
, 'tests/*'
];
this.packageFiles.include(fileList);
this.needTarGz = true;
this.needTarBz2 = true;
});
```javascript
var t = new jake.PackageTask('fonebone', 'v0.1.2112', function () {
var fileList = [
'Jakefile'
, 'README.md'
, 'package.json'
, 'lib/*'
, 'bin/*'
, 'tests/*'
];
this.packageFiles.include(fileList);
this.needTarGz = true;
this.needTarBz2 = true;
});
```

@@ -485,9 +533,11 @@ This will automatically create a 'package' task that will assemble the specified

var list = new jake.FileList();
list.include('foo/*.txt');
list.include(['bar/*.txt', 'README.md']);
list.include('Makefile', 'package.json');
list.exclude('foo/zoobie.txt');
list.exclude(/foo\/src.*.txt/);
console.log(list.toArray());
```javascript
var list = new jake.FileList();
list.include('foo/*.txt');
list.include(['bar/*.txt', 'README.md']);
list.include('Makefile', 'package.json');
list.exclude('foo/zoobie.txt');
list.exclude(/foo\/src.*.txt/);
console.log(list.toArray());
```

@@ -512,11 +562,13 @@ The `include` method can be called either with an array of items, or multiple

var p = new jake.NpmPublishTask('jake', [
'Makefile'
, 'Jakefile'
, 'README.md'
, 'package.json'
, 'lib/*'
, 'bin/*'
, 'tests/*'
]);
```javascript
var p = new jake.NpmPublishTask('jake', [
'Makefile'
, 'Jakefile'
, 'README.md'
, 'package.json'
, 'lib/*'
, 'bin/*'
, 'tests/*'
]);
```

@@ -541,19 +593,21 @@ The NpmPublishTask will automatically create a `publish` task which performs the

sys = require('sys')
```coffeescript
sys = require('sys')
desc 'This is the default task.'
task 'default', (params) ->
console.log 'Ths is the default task.'
console.log(sys.inspect(arguments))
invoke 'new', []
<<<<<<< HEAD
desc 'This is the default task.'
task 'default', (params) ->
console.log 'Ths is the default task.'
console.log(sys.inspect(arguments))
jake.Task['new'].invoke []
task 'new', ->
console.log 'ello from new'
invoke 'foo:next', ['param']
task 'new', ->
console.log 'ello from new'
jake.Task['foo:next'].invoke ['param']
namespace 'foo', ->
task 'next', (param) ->
console.log 'ello from next with param: ' + param
namespace 'foo', ->
task 'next', (param) ->
console.log 'ello from next with param: ' + param
```
### Related projects

@@ -560,0 +614,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc