-
Notifications
You must be signed in to change notification settings - Fork 22
/
init.js
63 lines (37 loc) · 1.46 KB
/
init.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
var fs = require('fs');
var path = require('path');
var cwdpath = process.cwd();
var pkgpath = path.resolve(cwdpath, './package.json');
var startpath = path.resolve(cwdpath, './start.js');
var tplpath = path.resolve(__dirname, './start.tpl.js');
console.log('@pkgpath:', pkgpath);
fs.exists(pkgpath, function (exists) {
if (exists) {
fs.readFile(pkgpath, function(err, data) {
try {
var info = JSON.parse(data.toString());
var deps = info.dependencies;
if (deps) {
var keys = Object.keys(deps);
var rapidlibs = keys.filter(function(lib) {
return (lib.indexOf('rapid-') >= 0);
});
var requires = '';
rapidlibs.forEach(function(lib) {
requires += 'require(\"' + lib + '\");\n';
});
console.log('@tplpath:', tplpath);
fs.readFile(tplpath, function(err, tpl) {
var content = tpl.toString().replace('$_requires_$', requires);
console.log('@startpath:', startpath);
fs.writeFile(startpath, content);
});
}
} catch (e) {
console.log('err with package.json', e);
}
});
} else {
console.log('cannot find package.json');
}
});