-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
119 lines (106 loc) · 2.72 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var path = require('path')
, fs = require('fs')
, fork = require('child_process').fork
, geddyPath = path.normalize(path.join(require.resolve('geddy'), '../../'));
module.exports.geddyPath = geddyPath;
module.exports.template = require('./lib/template');
module.exports.jake = require('./lib/jake');
module.exports.bower = require('./lib/bower');
/**
* Checks if a command line flag is set
*
* @param shortName {String} - (optional)
* @param name {String} - (optional)
* @returns {boolean}
*/
function flagSet(shortName, name) {
if (shortName && name) {
return process.argv.indexOf(shortName) !== -1 || process.argv.indexOf(name) !== -1;
}
else if (name && !shortName) {
return process.argv.indexOf(name) !== -1;
}
else if (shortName && !name) {
return process.argv.indexOf(shortName) !== -1;
}
return false;
}
module.exports.flagSet = flagSet;
/**
* Loads the basic geddy environment.
*
* @returns {*}
*/
function loadGeddy()
{
return require(path.join(geddyPath, 'lib/geddy'));
}
module.exports.loadGeddy = loadGeddy;
/**
* Loads the geddy toolkit.
*
* @returns {*}
*/
function loadGeddyUtils()
{
return require(path.join(geddyPath, 'lib/utils'));
}
module.exports.loadGeddyUtils = loadGeddyUtils;
/**
* Executes another generator in a child process
* @param generator {String} - name of the generator e.g. "geddy-gen-model"
* @param args {Array} - generator arguments
* @param shared {Object} - (optional) Data to share between the generators
* @param cb {Function} - (optional) callback(error)
*/
function runGen(/*generator, args, [shared, cb]*/)
{
var args = Array.prototype.slice.call(arguments);
var generator = args.shift();
var _args = args.shift() || [];
var cb = args.pop();
var shared = args.pop();
if (typeof cb !== 'function') {
cb = function() {};
}
// push args to process.argv too
_args.forEach(function(arg) {
if (process.argv.indexOf(arg) === -1) {
process.argv.push(arg);
}
});
var gen = require(generator);
var appPath = process.cwd();
process._shared = shared;
gen(appPath, _args);
cb(null);
}
module.exports.runGen = runGen;
/**
* Returns shared data that has been passed from another generator.
*/
function getShared()
{
return process._shared || {};
}
module.exports.getShared = getShared;
/**
* Return path to generator directory
* @param generator {String}
* @returns {String|null}
*/
function getGenDir(generator)
{
return path.dirname(require.resolve(generator));
}
module.exports.getGenDir = getGenDir;
/**
* Checks if we are in the app's root directory
* @returns {Boolean}
*/
function inAppRoot()
{
var appPath = process.cwd();
return fs.existsSync(path.join(appPath, 'app'));
}
module.exports.inAppRoot = inAppRoot;