-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
123 lines (110 loc) · 2.87 KB
/
index.js
File metadata and controls
123 lines (110 loc) · 2.87 KB
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
120
121
122
123
var handlers = require('./command-handlers');
var validator = require('./validate.js');
function onlyNodeEnabled(commandName) {
return function (api) {
var appConfig = api.getConfig().app;
if (appConfig && appConfig.type === 'node') {
return api.runCommand(commandName);
}
}
}
function setDefault(obj, path, value) {
var position = obj;
path.reduce((position, property, index) => {
if (index === path.length - 1) {
if (typeof position[property] === 'undefined') {
position[property] = value;
}
} else {
position[property] = position[property] || {};
return position[property];
}
}, obj);
return obj;
}
module.exports = {
name: 'node',
description: 'Deploy node.js apps',
commands: {
setup: {
description: 'Setup node.js',
handler: handlers.setup
},
deploy: {
description: 'Deploy app',
handler: handlers.deploy
},
reconfig: {
description: 'Reconfig app',
handler: handlers.reconfig
},
start: {
description: 'Start app',
handler: handlers.start
},
stop: {
description: 'Stop app',
handler: handlers.stop
},
logs: {
description: 'View app\'s logs',
handler: handlers.logs
},
destroy: {
description: 'Remove app from server',
handler: handlers.destroy,
builder(subYargs) {
return subYargs.option('force', {
description: 'forces app to be removed',
boolean: true
});
}
},
// hidden commands
build: {
description: false,
handler: handlers.build
},
push: {
description: false,
handler: handlers.push
},
debug: {
name: 'debug [server]',
description: 'Debug the meteor app',
builder(yargs) {
yargs.strict(false);
},
handler: handlers.debugApp
}
},
hooks: {
'post.default.setup': onlyNodeEnabled('node.setup'),
'post.default.reconfig': onlyNodeEnabled('node.reconfig'),
'post.default.deploy': onlyNodeEnabled('node.deploy'),
'post.default.logs': onlyNodeEnabled('node.logs'),
'post.default.start': onlyNodeEnabled('node.start'),
'post.default.stop': onlyNodeEnabled('node.stop')
},
prepareConfig(config) {
var appConfig = config.app;
if (!appConfig || appConfig.type !== 'node') {
return config;
}
setDefault(appConfig, ['env', 'NODE_ENV'], 'production');
setDefault(appConfig, ['env', 'PORT'], 80);
setDefault(appConfig, ['docker', 'buildInstructions'], []);
setDefault(appConfig, ['startScript'], 'start');
setDefault(appConfig, ['nodeVersion'], 'latest');
setDefault(appConfig, ['deployCheckWaitTime'], 60);
return config;
},
validate: {
app(config, utils) {
if (config.app && config.app.type === 'node') {
return validator(config, utils);
}
return [];
}
}
}