-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.js
80 lines (68 loc) · 1.83 KB
/
program.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
79
80
const logSymbols = require('log-symbols');
const commonUtil = require('./util/common');
const colors = require('colors/safe');
const argv = require('yargs').argv;
const SubPrograms = require('./programs');
class Program {
constructor() {
/**
* Type of sub program to run (case insensitive)
* @type {String} - AWS, Netlify
*/
this.type = '';
/**
* Sub program to run for deployment
* @type {AWSProgram|NetlifyProgram}
*/
this.subProgram = null;
}
/**
* Run program storyboard
*/
async run() {
this.init();
if (argv.version) {
await this.displayVersion();
return;
}
if (!this.validateSubProgram()) throw '';
await this.subProgram.run();
}
/**
* Initialise, set argument variables
*/
init() {
const { type } = argv;
this.type = type || '';
}
/**
* Show current package version
*/
async displayVersion() {
try {
const packageData = await commonUtil.readJsonFile(`${__dirname}/package.json`);
console.log(packageData.version);
} catch (error) {
console.log(logSymbols.error, colors.red('Unable to retrieve package version...'));
}
}
/**
* Check type of deployment program to run
*/
validateSubProgram() {
console.log('Checking deployment type...');
for(const key in SubPrograms) {
if (key.toUpperCase().replace('PROGRAM', '') !== this.type.toUpperCase()) continue;
this.subProgram = new SubPrograms[key];
break;
}
if (this.subProgram) {
console.log(logSymbols.success, `Deployment type set as ${colors.cyan(`[${this.subProgram.constructor.name.replace('Program', '')}]`)}`);
return true;
} else {
console.log(logSymbols.error, colors.red('Unsupported deployment type found...'));
return false;
}
}
}
module.exports = Program;