jake
JavaScript build tool, similar to Make or Rake. Built to work with Node.js.
Jake: JavaScript build tool task runner for NodeJS
Can someone help me with closing the database after two models are added to the database? I've tried reading
http://howtonode.org/intro-to-jake
Node.js and Jake - How to call system commands synchronously within a task?
and the github readme at
https://github.com/mde/jake
but still can't seem to figure it out. Here's an excerpt from the readme
Cleanup after all tasks run, jake 'complete' event
The base 'jake' object is an EventEmitter, and fires a 'complete' event after running all tasks.
This is sometimes useful when a task starts a process which keeps the Node event-loop running (e.g., a database connection). If you know you want to stop the running Node process after all tasks have finished, you can set a listener for the 'complete' event, like so:
jake.addListener('complete', function () {
process.exit();
});
As it is now, it's closing the connection before it even opens it.
// db connect
var db = require('./schema');
desc('Seed MongoDB with initial data');
task('seed', [], function () {
//******* Populate the database
var user1 = new db.userModel({ email: 'x@x.com', password: 'x', phone: x });
user1.save(function(err) {
if(err) {
console.log(err);
} else {
console.log('user: '+user1.email +' saved');
}
});
var user2 = new db.userModel({ email: 'x', password: 'x', phone: x });
user2.save(function(err) {
if(err) {
console.log(err);
} else {
console.log('user: '+user2.email +' saved');
}
});
db.mongoose.connection.close();
console.log('Closed mongodb connection');
});
Edit:
I was able to accomplish what I was going for using parallel flow from the parseq module.
par(
function() {
fs.readFile("file1", this);
},
function() {
fs.readFile("file2", this);
},
function done(err, results) {
...
}
);
Edit2:
So I REALLY appreciate all the help. I also saw you were the maintainer of parseq :). Thx for that! I'm still struggling with this last bit and my function is hanging and not calling done() when function 5 is complete. I'm sure I'm calling 'this' incorrectly. Any advice?
seq(
function f1() {
var user = new db.userModel({ email: 'x'
, password: 'x'
, phone: x });
user.save(this);
},
function f2(err, value) {
var user = new db.userModel({ email: 'x'
, password: 'x'
, phone: x });
user.save(this);
},
function f3(err, value) {
var merchant = new db.merchantModel({ name: 'x'
, logourl: 'x' });
merchant.save(this);
},
function f4(err, value) {
var merchant = new db.merchantModel({ name: 'x'
, logourl: 'x' });
merchant.save(this);
},
function f5(err, value) {
db.merchantModel.findOne({ name: 'x' }, function(err, merchant) {
var coupon = new db.couponModel({ merchant_id: merchant.id
, name: 'x'
, imageurl: 'x'
, expiration: Date.UTC(2013,3,15) });
//, expiration: new Date(2013,3,15) }); //alternate date creation method
coupon.save(this);
});
},
function done(err) {
if(err) {
console.log(err);
} else {
console.log('successfully seeded db');
}
db.mongoose.connection.close();
console.log('Closed mongodb connection');
}
);
Source: (StackOverflow)
I want to execute a jake task on crontab for my node js project. I learned to create and run jake in node js. And i also learned to work with crontab. If i add the following to create cronjob, the jake task didn't gave the right result.
* * * * * jake -f ~/Documents/Dev/MyProject-Workplace/web-njs/jake/import/my_jake_file jake_state:add_states >> ~/states.txt
But if i run in command line manually it running perfectly.
Thanks in advance, can anyone tell me what change to made to make it to run properly.
Source: (StackOverflow)
If I wanted to invoke jshint from a jake script, I'd do something like this:
var jshint = require("jshint").JSHINT;
var pass = jshint(sourceCode, options, globals);
I'd like to do something similar with tsc - but does anyone know how to do this? The documentation only tells you how to run this from the command line, and not how to invoke it programmatically.
Source: (StackOverflow)
I have a post build task that I run on my MVC 3 project, 'jake build', that combines a bunch of coffee script files and runs some tests using Phantom.js.
I don't expect appharbor to run this when I deploy, but it is trying to. It is of course failing because node, jake, and any number of other node modules are not installed. Is there a way to have this post build process run on my local machine when I build but have appharbor ignore it?
Source: (StackOverflow)
im trying to run a task 10 times in jake:
task 'default', (page) ->
page = process.env.page
running = 0
while running < 10
ex = jake.createExec(["casperjs test.coffee --page=#{page}"],
printStdout: true
)
ex.run()
running++
page++
this will run the test 10 times. which is deos fine. however i want it to run in order, so for instance page1 first, then page2, then page3 etc. so first page 1 has to finish before it deos page2. at the momment it runs them in parallel, or asynchronously. thanks for your help.
Source: (StackOverflow)
I'm trying to setup a task to kill certain server processes when the server gets into a weird state such as when it fails to boot one process, but another process gets keeps running and so not everything boots up. This is mainly a task for development so you can do jake killall
to kill all processes associated with this project.
I'm having trouble figuring out how to get the pid
after doing: ps aux | grep [p]rocess\ name | {HOW DO I GET THE PID NOW?}
and then after getting the ID how do I pass that to kill -9 {PID HERE}
Source: (StackOverflow)
When i try to use jshint on multiplie files only the first file checked properly.
On all next files i get error about undefined var. I make dump of config for each run and notice that 'pregef' becomes undefined after first run.
{ browser: true,
node: true,
predef: ['G'],
...
}
{ browser: true,
node: true,
...
}
src/line.js line 1 col 1 'G' is not defined.
src/line.js line 78 col 17 'G' is not defined.
Source: (StackOverflow)
While beeing used to using Rakefile, Cakefile and Jakefile, they all had some convenient way of listing the available tasks.
Like
jake -T
jake db:dump # Dump the database
jake db:load # Populate the database
..etc.
or even filtering
"jake -T dum", to only show "the "jake db:dump" task.
So, is there a way to do the same using grunt?
I was thinking of maybe creating a default task that iterates the entire grunt config object and write it to stdout via console.log, but does someone know a better way?
Thanks.
Source: (StackOverflow)
A Jake task executes a long-running system command. Another task depends on the first task being completely finished before starting. The 'exec' function of 'child_process' executes system commands asynchronously, making it possible to for the second task to begin before the first task is complete.
What's the cleanest way to write the Jakefile to ensure that the long-running system command in the first task finishes before the second task starts?
I've thought about using polling in a dummy loop at the end of the first task, but this just smells bad. It seems like there must be a better way. I've seen this SO question, but it doesn't quite address my question.
var exec = require('child_process').exec;
desc('first task');
task('first', [], function(params) {
exec('long running system command');
});
desc('second task');
task('second', ['first'], function(params) {
// do something dependent on the completion of 'first' task
});
Source: (StackOverflow)
I'm able to kick off IIS express to run my mvc 3 app with the following coffeescript line:
iisex = jake.createExec(['iisexpress /path:' + process.cwd() + ' /port:9090 /systray:false'], {printStdout: true})
#listening code here
iisex.run()
I then run some jasmine tests using
ex = jake.createExec(['phantomjs run_jasmine_test.coffee http://localhost:9090/app/applebees_testrunner.html'], {printStdout: true});
Test pass and now I want to kill IISExpress.
The problem is that now I have a long running process and the process wants me to 'press q' to stop the server. Is there a way to send a q to the running process so that the server will stop?
Source: (StackOverflow)
I would like to have generators for my migration like:
jake migration:create <name>
jake migration:remove <name>
jake migration:execute <name>
code is
namespace('migration', function(){
desc('Create migration file');
task('create', [], function(params) {
console.log(arguments);
//some code for creation
});
desc('Remove migration file');
task('remove', [], function(params) {
console.log(arguments);
//some code for removing
});
desc('Execute migration file');
task('execute', [], function(params) {
console.log(arguments);
//some code for executing
});
});
but I didn't find how to pass parameter <name>
inside 'namespaced' jake task.
Could you please help me?
UPD:
even examples from https://github.com/isaacs/node-jake "Passing parameters to jake" doesn't work for me, every time arguments
is empty,
any suggestion?
Source: (StackOverflow)
I have a simple hello world jake file, which gives an error:
victors-macbook-pro:votefor Victor$ jake -f jakefile asynchronous
(in /Users/Victor/Documents/workspace/votefor/votefor)
Error on line 1 of file [unknown]
ReferenceError: Can't find variable: desc
victors-macbook-pro:votefor Victor$ cat jakefile
desc('This is an asynchronous task.');
task('asynchronous', [], function () {
setTimeout(function () {
console.log("Yay, I'm asynchronous!");
complete();
}, 1000);
}, true);
Is there anything that i am doing wrong ?
The code was copied and pasted from http://howtonode.org/intro-to-jake
Source: (StackOverflow)
I've done some basic Google'n and haven't found any compelling reasons to choose Jake over Cake for my node.js build process (mostly just compiling *.coffee to *.js in correct folders). Can anyone provide a few quick bullet points of why one would choose Jake or Cake over the other?
If applicable: I am coming in from a Java/Grails/RoR developer point of view so I am familiar with ant/mvn/gradle/rake/etc...
https://github.com/mde/jake
http://coffeescript.org/documentation/docs/cake.html
Please reopen this question! There is a def lack of comparisons/highlights on the www, so, or anywhere else and I need to draw on the community of those with direct experience with the tools. This topic has gather 43 views in the less than 24 hours, obviously a topic the community is interested in.
Source: (StackOverflow)
I have this jake task to run all my tests:
desc('Run all tests')
task('test', {async: true}, function(args) {
process.env.NODE_ENV = 'test';
var Mocha = require('mocha');
var fs = require('fs'), path = require('path');
var mocha = new Mocha({reporter: 'spec', ui: 'bdd'});
fs.readdirSync('test/unit').forEach(function(file) {
mocha.addFile(path.join('test/unit', file));
});
fs.readdirSync('test/functional').forEach(function(file) {
mocha.addFile(path.join('test/functional', file));
});
mocha.run(function(failures) {
if (failures) {
fail(failures);
} else {
complete();
}
});
});
But when tests are passed, jake doesn't exit automatically. I have to kill it every time. Did I do anything wrong?
Source: (StackOverflow)