-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsiteglide-cli-push.js
More file actions
executable file
·77 lines (66 loc) · 1.94 KB
/
siteglide-cli-push.js
File metadata and controls
executable file
·77 lines (66 loc) · 1.94 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
#!/usr/bin/env node
const program = require('commander'),
fs = require('fs'),
ora = require('ora'),
validate = require('./lib/validators'),
Gateway = require('./lib/proxy'),
ServerError = require('./lib/ServerError'),
version = require('./package.json').version;
const checkParams = params => {
validate.existence({ argumentValue: params.token, argumentName: 'token', fail: program.help.bind(program) });
validate.existence({ argumentValue: params.url, argumentName: 'url', fail: program.help.bind(program) });
if (params.url.slice(-1) != '/') {
params.url = params.url + '/';
}
};
program
.version(version)
.option('--email <email>', 'developer email', process.env.SITEGLIDE_EMAIL)
.option('--token <token>', 'authentication token', process.env.SITEGLIDE_TOKEN)
.option('--url <url>', 'site url', process.env.SITEGLIDE_URL);
program.parse(process.argv);
checkParams(program.opts());
const spinner = ora({ text: `Deploying codebase to: ${program.opts().url}`, stream: process.stdout }).start();
const gateway = new Gateway(program.opts());
const formData = {
'marketplace_builder_file_body': fs.createReadStream('.tmp/marketplace-release.zip')
};
const getDeploymentStatus = ({ id }) => {
return new Promise((resolve, reject) => {
if(id===undefined){
reject();
}
(getStatus = () => {
gateway.getStatus(id).then(response => {
if (response.status==='ready_for_import') {
setTimeout(getStatus, 2000);
} else if (response.status==='error') {
ServerError.deploy(response.error);
reject();
} else {
spinner.stopAndPersist().succeed(`Deploying codebase succeeded`);
resolve();
}
});
})();
});
};
gateway
.push(formData)
.then((res) => {
if(res==='LIMIT_FILE_SIZE'){
throw res;
}
getDeploymentStatus(res)
.catch(() => {
process.exit(3);
});
})
.catch((err) => {
spinner.fail(`Deploy failed`);
if(err==='LIMIT_FILE_SIZE'){
process.exit(2);
}else{
process.exit(1);
}
});