forked from DemocracyOS/democracyos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dos-install
executable file
·61 lines (52 loc) · 1.5 KB
/
dos-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
55
56
57
58
59
60
61
#!/usr/bin/env node
/**
* Module dependencies.
*/
var fs = require('fs');
var exists = fs.existsSync;
var read = fs.readFileSync;
var write = fs.writeFileSync;
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 crypto = require('crypto');
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 && env !== 'production') {
var dest = resolve('./config/' + env + '.json');
if (!exists(dest)) {
console.log('Creating ' + dest);
var defaults = require(resolve('./config/defaults'));
var config = {
jwtSecret: crypto.randomBytes(32).toString('hex')
};
[
"protocol",
"host",
"publicPort",
"mongoUrl",
"locale",
"organizationName",
"organizationUrl",
].forEach(function(key){
config[key] = defaults[key];
});
write(dest, JSON.stringify(config, 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);
});
}