forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsails-www.js
59 lines (47 loc) · 1.35 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
#!/usr/bin/env node
/**
* Module dependencies
*/
var Sails = require('../lib/app')
, path = require('path')
, _ = require('lodash')
, rconf = require('../lib/configuration/rc')
, captains = require('captains-log');
/**
* `sails www`
*
* Run the `grunt build` task
*/
module.exports = function () {
var log = captains(rconf.log);
var wwwPath = path.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 = require('../lib/hooks/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);
});
});
};