forked from mikermcneil/sails-generate-new-but-like-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (71 loc) · 2.28 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Module dependencies
*/
var _ = require('lodash');
/**
* sails-generate-new-but-like-express
*
* Usage:
* `nodeg new foo --like express`
*
* @type {Object}
*/
module.exports = {
targets: {
'./:appPath/app.js': { copy: 'app.js' },
'./:appPath/public/javascripts': { folder: {} },
'./:appPath/public/javascripts/sails.io.js': { copy: 'public/javascripts/sails.io.js' },
'./:appPath/public/stylesheets': { folder: {} },
'./:appPath/public/images': { folder: {} },
'./:appPath/routes': { folder: {} },
'./:appPath/routes/index.js': { template: 'routes/index.js' },
'./:appPath/routes/user.js': { template: 'routes/user.js' },
'./:appPath/views': { folder: {} },
'./:appPath/views/index.jade': { template: 'views/index.jade' },
'./:appPath/views/layout.jade': { template: 'views/layout.jade' },
'./:appPath/package.json': { jsonfile: function (scope) {
return {
name: scope.appName,
'private': true,
version: '0.0.0',
description: 'a Sails application (but like Express)',
dependencies: {
'sails' : '~0.10.0',
'sails-disk' : '~0.10.0',
'jade' : '*'
},
scripts: {
// TODO: Include this later when we have "sails test" ready.
// test: './node_modules/mocha/bin/mocha -b',
start: 'node app.js',
debug: 'node debug app.js'
},
main: 'app.js',
repository: '',
author: scope.author,
license: ''
};
} }
},
before: function(scope, cb) {
// Validate custom scope variables which
// are required by this generator.
if (!scope.rootPath) {
return cb(new Error(
'Missing scope variable: `rootPath`\n' +
'Please make sure it is specified and try again.'
));
}
// Determine default values based on the
// available generator scope.
_.defaults(scope, {
author: 'a Node.js/Sails.js Contributor',
year: (new Date()).getFullYear(),
appName: (scope.args[0] === '.' || !scope.args[0]) ? path.basename(process.cwd()) : scope.args[0],
});
scope.appPath = scope.args[0] || '.';
// Trigger callback with no error to proceed.
cb();
},
templatesDirectory: require('path').resolve('./templates')
};