-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcivicstack-install
executable file
·54 lines (46 loc) · 1.39 KB
/
civicstack-install
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
#!/usr/bin/env node
/**
* Module dependencies.
*/
var fs = require('fs');
var exists = fs.existsSync;
var read = fs.readFileSync;
var write = fs.writeFileSync;
var parse = JSON.parse;
var stringify = JSON.stringify;
var path = require('path');
var resolve = path.resolve;
var merge = require('merge-util');
var exec = require('child_process').exec;
var program = require('commander');
var installc = resolve('./node_modules/.bin/component-install');
var env = process.env.NODE_ENV || 'development';
program
.option('-c, --config', 'copy and/or merge configuration file')
.option('-C, --no-components', 'ignore components install')
.parse(process.argv);
/**
* Make sure there is a config file
*/
if (program.config) {
var dest = resolve('./lib/config/' + env + '.json');
var orig = resolve('./lib/config/sample.json');
if (!exists(dest)) {
// non-simple copying
write(dest, read(orig));
} else {
var conf = parse(read(dest));
var sample = parse(read(orig));
// Merge current config into original sample
merge(sample, conf);
// save config file
write(dest, stringify(sample, null, 2));
}
};
if (program.components && exists(installc)) {
exec(installc, function(err, stdout, stderr) {
if (stdout.length) console.log(stdout);
if (stderr.length) return console.log(stderr), process.exit(1);
if (err != null) return console.log(err), process.exit(1);
});
};