forked from Platform-OS/pos-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarketplace-kit-deploy.js
executable file
·78 lines (70 loc) · 2.54 KB
/
marketplace-kit-deploy.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
#!/usr/bin/env node
const program = require('commander'),
fetchAuthData = require('./lib/settings').fetchSettings,
spawn = require('child_process').spawn,
command = require('./lib/command'),
logger = require('./lib/logger'),
validate = require('./lib/validators'),
Gateway = require('./lib/proxy'),
deployServiceClient = require('./lib/deployServiceClient'),
version = require('./package.json').version;
const uploadArchive = (env, usingDeploymentService) => {
const options = usingDeploymentService ? ['--without-assets'] : [];
const archive = spawn(command('marketplace-kit-archive'), options, {
stdio: 'inherit'
});
archive.on('close', code => {
if (code === 1) {
logger.Error('Deploy failed.');
process.exit(1);
}
const push = spawn(command('marketplace-kit-push'), [], {
stdio: 'inherit',
env: env
});
push.on('close', exitCode => {
if (exitCode === 1) {
logger.Error('Deploy failed.');
process.exit(1);
} else if(exitCode === 0) {
process.exit(0);
}
});
});
};
program
.version(version)
.arguments('[environment]', 'name of environment. Example: staging')
.option('-f --force', 'force update. Removes instance-admin lock')
.option('-d --direct-assets-upload', 'Uploads assets straight to S3 servers')
.option('-p --partial-deploy', 'Partial deployment, does not remove data from directories missing from the build')
.option('-c --config-file <config-file>', 'config file path', '.marketplace-kit')
.action((environment, params) => {
process.env.CONFIG_FILE_PATH = params.configFile;
if (params.force) process.env.FORCE = params.force;
if (params.partialDeploy) process.env.PARTIAL_DEPLOY = params.partialDeploy;
const authData = fetchAuthData(environment, program);
const env = Object.assign(process.env, {
MARKETPLACE_EMAIL: authData.email,
MARKETPLACE_TOKEN: authData.token,
MARKETPLACE_URL: authData.url,
MARKETPLACE_ENV: environment
});
if (params.directAssetsUpload) {
const gateway = new Gateway(authData);
deployServiceClient.deployAssets(gateway).then(
() => {
logger.Success('Assets deployed to S3. Uploading manifest.');
uploadArchive(env, true);
},
err => {
logger.Debug(err);
logger.Warn('Communication problem with deployment service, using classic deployment.');
uploadArchive(env, false);
}
);
} else {
uploadArchive(env, false);
}
});
program.parse(process.argv);