forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sails-www.js
60 lines (48 loc) · 1.45 KB
/
sails-www.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
/**
* Module dependencies
*/
var nodepath = require('path');
var _ = require('lodash');
var CaptainsLog = require('captains-log');
var Sails = require('../lib/app');
var rconf = require('../lib/app/configuration/rc');
var __Grunt = require('../lib/hooks/grunt');
/**
* `sails www`
*
* Run the `grunt build` task
*/
module.exports = function() {
var log = CaptainsLog(rconf.log);
var wwwPath = nodepath.resolve(process.cwd(), './www'),
GRUNT_TASK_NAME = 'build';
log.info('Compiling assets into standalone `www` directory with `grunt ' + GRUNT_TASK_NAME + '`...');
var sails = Sails();
sails.load(_.merge({}, rconf, {
hooks: {
grunt: false
},
globals: false
}), function sailsReady(err) {
if (err) return Err.fatal.failedToLoadSails(err);
// Run Grunt task
var Grunt = __Grunt(sails);
Grunt.runTask(GRUNT_TASK_NAME);
// Bind error event
sails.on('hook:grunt:error', function(err) {
log.error('Error occured starting `grunt ' + GRUNT_TASK_NAME + '`');
log.error('Please resolve any issues and try running `sails www` again.');
log.error(err);
process.exit(1);
});
// Task is not actually complete yet-- it's just been started
// We'll bind an event listener so we know when it is
sails.on('hook:grunt:done', function() {
log.info();
log.info('Created `www` directory at:');
log.info(wwwPath);
process.exit(0);
});
});
};