@contrail/cli 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +5 -5
- package/bin/init +3 -3
- package/lib/auth/auth.d.ts +9 -9
- package/lib/auth/auth.js +2 -2
- package/lib/auth/login.d.ts +1 -1
- package/lib/auth/login.js +112 -96
- package/lib/cli.d.ts +5 -5
- package/lib/cli.js +30 -30
- package/lib/create-app/create.d.ts +1 -1
- package/lib/create-app/create.js +63 -48
- package/lib/create-app/setup-template.d.ts +1 -1
- package/lib/create-app/setup-template.js +34 -48
- package/lib/deploy-app/actions-deployer.d.ts +10 -10
- package/lib/deploy-app/actions-deployer.js +86 -75
- package/lib/deploy-app/app-deployer.d.ts +8 -10
- package/lib/deploy-app/app-deployer.js +79 -84
- package/lib/deploy-app/app-template-parsers.d.ts +7 -0
- package/lib/deploy-app/app-template-parsers.js +37 -0
- package/lib/deploy-app/deploy.d.ts +2 -2
- package/lib/deploy-app/deploy.js +56 -30
- package/lib/deploy-app/interfaces.d.ts +74 -43
- package/lib/deploy-app/interfaces.js +4 -0
- package/package.json +63 -63
- package/publish.sh +5 -0
- package/src/auth/auth.ts +9 -9
- package/src/auth/login.ts +124 -107
- package/src/cli.ts +32 -33
- package/src/create-app/create.ts +73 -58
- package/src/create-app/setup-template.ts +37 -56
- package/src/deploy-app/actions-deployer.ts +109 -84
- package/src/deploy-app/app-deployer.ts +86 -89
- package/src/deploy-app/app-template-parsers.ts +43 -0
- package/src/deploy-app/deploy.ts +64 -33
- package/src/deploy-app/interfaces.ts +78 -43
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/javascript/app.yml +54 -42
- package/templates/javascript/package.json +23 -23
- package/templates/javascript/set_auth.bat +3 -0
- package/templates/javascript/set_auth.sh +3 -0
- package/templates/typescript/actions/exampleAction.ts +38 -0
- package/templates/typescript/app.yml +56 -0
- package/templates/typescript/package.json +24 -0
- package/templates/typescript/set_auth.bat +3 -0
- package/templates/typescript/set_auth.sh +3 -0
- package/templates/typescript/tsconfig.json +31 -0
- package/tsconfig.json +22 -22
- package/tslint.json +57 -57
- package/lib/deploy-app/actions.d.ts +0 -5
- package/lib/deploy-app/actions.js +0 -17
- package/lib/deploy-app/app-declaration.d.ts +0 -20
- package/lib/deploy-app/app-declaration.js +0 -0
- package/lib/deploy-app/app.d.ts +0 -8
- package/lib/deploy-app/app.js +0 -56
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@contrail/cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"@contrail/contrail-cli": "bin/init",
|
|
8
|
-
"contrail": "bin/init"
|
|
9
|
-
},
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"cli",
|
|
15
|
-
"contrail-cli"
|
|
16
|
-
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "tsc",
|
|
19
|
-
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
20
|
-
"lint": "tslint -p tsconfig.json",
|
|
21
|
-
"test": "jest --watch"
|
|
22
|
-
},
|
|
23
|
-
"author": "",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@contrail/sdk": "^1.0.91",
|
|
27
|
-
"amazon-cognito-identity-js": "^5.2.3",
|
|
28
|
-
"arg": "^4.0.1",
|
|
29
|
-
"aws-sdk": "^2.1044.0",
|
|
30
|
-
"chalk": "^4.0.0",
|
|
31
|
-
"esm": "^3.2.25",
|
|
32
|
-
"execa": "^5.0.0",
|
|
33
|
-
"inquirer": "^8.2.0",
|
|
34
|
-
"js-yaml": "^4.1.0",
|
|
35
|
-
"listr": "^0.14.3",
|
|
36
|
-
"ncp": "^2.0.0",
|
|
37
|
-
"pkg-install": "^1.0.0"
|
|
38
|
-
},
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@types/jest": "^23.3.14",
|
|
41
|
-
"jest": "^23.6.0",
|
|
42
|
-
"prettier": "^1.19.1",
|
|
43
|
-
"ts-jest": "^23.10.5",
|
|
44
|
-
"tslint": "^5.11.0",
|
|
45
|
-
"tslint-config-prettier": "^1.18.0",
|
|
46
|
-
"typescript": "^3.0.1",
|
|
47
|
-
"@types/node": "^14.6.4"
|
|
48
|
-
},
|
|
49
|
-
"jest": {
|
|
50
|
-
"moduleFileExtensions": [
|
|
51
|
-
"js",
|
|
52
|
-
"json",
|
|
53
|
-
"ts"
|
|
54
|
-
],
|
|
55
|
-
"rootDir": "src",
|
|
56
|
-
"testRegex": ".spec.ts$",
|
|
57
|
-
"transform": {
|
|
58
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
59
|
-
},
|
|
60
|
-
"coverageDirectory": "../coverage",
|
|
61
|
-
"testEnvironment": "node"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@contrail/cli",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"@contrail/contrail-cli": "bin/init",
|
|
8
|
+
"contrail": "bin/init"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"cli",
|
|
15
|
+
"contrail-cli"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
20
|
+
"lint": "tslint -p tsconfig.json",
|
|
21
|
+
"test": "jest --watch"
|
|
22
|
+
},
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@contrail/sdk": "^1.0.91",
|
|
27
|
+
"amazon-cognito-identity-js": "^5.2.3",
|
|
28
|
+
"arg": "^4.0.1",
|
|
29
|
+
"aws-sdk": "^2.1044.0",
|
|
30
|
+
"chalk": "^4.0.0",
|
|
31
|
+
"esm": "^3.2.25",
|
|
32
|
+
"execa": "^5.0.0",
|
|
33
|
+
"inquirer": "^8.2.0",
|
|
34
|
+
"js-yaml": "^4.1.0",
|
|
35
|
+
"listr": "^0.14.3",
|
|
36
|
+
"ncp": "^2.0.0",
|
|
37
|
+
"pkg-install": "^1.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/jest": "^23.3.14",
|
|
41
|
+
"jest": "^23.6.0",
|
|
42
|
+
"prettier": "^1.19.1",
|
|
43
|
+
"ts-jest": "^23.10.5",
|
|
44
|
+
"tslint": "^5.11.0",
|
|
45
|
+
"tslint-config-prettier": "^1.18.0",
|
|
46
|
+
"typescript": "^3.0.1",
|
|
47
|
+
"@types/node": "^14.6.4"
|
|
48
|
+
},
|
|
49
|
+
"jest": {
|
|
50
|
+
"moduleFileExtensions": [
|
|
51
|
+
"js",
|
|
52
|
+
"json",
|
|
53
|
+
"ts"
|
|
54
|
+
],
|
|
55
|
+
"rootDir": "src",
|
|
56
|
+
"testRegex": ".spec.ts$",
|
|
57
|
+
"transform": {
|
|
58
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
59
|
+
},
|
|
60
|
+
"coverageDirectory": "../coverage",
|
|
61
|
+
"testEnvironment": "node"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/publish.sh
ADDED
package/src/auth/auth.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export interface AuthContext {
|
|
2
|
-
apiUserToken: string;
|
|
3
|
-
apiGateway?: string;
|
|
4
|
-
orgSlug?: string;
|
|
5
|
-
orgId?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class Auth {
|
|
9
|
-
public static config: AuthContext;
|
|
1
|
+
export interface AuthContext {
|
|
2
|
+
apiUserToken: string;
|
|
3
|
+
apiGateway?: string;
|
|
4
|
+
orgSlug?: string;
|
|
5
|
+
orgId?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class Auth {
|
|
9
|
+
public static config: AuthContext;
|
|
10
10
|
}
|
package/src/auth/login.ts
CHANGED
|
@@ -1,108 +1,125 @@
|
|
|
1
|
-
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import {
|
|
4
|
-
import { Auth } from './auth';
|
|
5
|
-
|
|
6
|
-
const CONFIGURATION = {
|
|
7
|
-
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
8
|
-
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export async function authUser(){
|
|
12
|
-
const questions = [];
|
|
13
|
-
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
14
|
-
questions.push({
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'email',
|
|
17
|
-
validate: (val) => !!val,
|
|
18
|
-
message: 'Email',
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
22
|
-
questions.push({
|
|
23
|
-
type: 'password',
|
|
24
|
-
name: 'password',
|
|
25
|
-
validate: (val) => !!val,
|
|
26
|
-
message: 'Password',
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
if (!process.env.CONTRAIL_CLI_ORGSLUG) {
|
|
30
|
-
questions.push({
|
|
31
|
-
type: 'input',
|
|
32
|
-
name: 'orgSlug',
|
|
33
|
-
validate: (val) => !!val,
|
|
34
|
-
message: 'Org (slug)',
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const answers = await inquirer.prompt(questions);
|
|
39
|
-
const params = {
|
|
40
|
-
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
41
|
-
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
42
|
-
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
43
|
-
};
|
|
44
|
-
if (!params.email || !params.password){
|
|
45
|
-
throw new Error('
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const poolData = {
|
|
49
|
-
UserPoolId: CONFIGURATION.userPoolId,
|
|
50
|
-
ClientId: CONFIGURATION.clientId,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
|
|
54
|
-
const authData = {
|
|
55
|
-
Username: params.email,
|
|
56
|
-
Password: params.password,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
|
|
60
|
-
const userData = {
|
|
61
|
-
Username: params.email,
|
|
62
|
-
Pool: userPool,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
66
|
-
|
|
67
|
-
return new Promise( (resolve, reject) => {
|
|
68
|
-
cognitoUser.authenticateUser(authDetails, {
|
|
69
|
-
onSuccess: async (result) => {
|
|
70
|
-
const user = result;
|
|
71
|
-
await setAuthContext(user, params);
|
|
72
|
-
|
|
73
|
-
resolve({success: true, data: result});
|
|
74
|
-
},
|
|
75
|
-
onFailure: (err) => {
|
|
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
|
-
}
|
|
1
|
+
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { Request, setConfig } from '@contrail/sdk';
|
|
4
|
+
import { Auth } from './auth';
|
|
5
|
+
|
|
6
|
+
const CONFIGURATION = {
|
|
7
|
+
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
8
|
+
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function authUser(){
|
|
12
|
+
const questions = [];
|
|
13
|
+
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
14
|
+
questions.push({
|
|
15
|
+
type: 'input',
|
|
16
|
+
name: 'email',
|
|
17
|
+
validate: (val) => !!val,
|
|
18
|
+
message: 'Email',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
22
|
+
questions.push({
|
|
23
|
+
type: 'password',
|
|
24
|
+
name: 'password',
|
|
25
|
+
validate: (val) => !!val,
|
|
26
|
+
message: 'Password',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!process.env.CONTRAIL_CLI_ORGSLUG) {
|
|
30
|
+
questions.push({
|
|
31
|
+
type: 'input',
|
|
32
|
+
name: 'orgSlug',
|
|
33
|
+
validate: (val) => !!val,
|
|
34
|
+
message: 'Org (slug)',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const answers = await inquirer.prompt(questions);
|
|
39
|
+
const params = {
|
|
40
|
+
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
41
|
+
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
42
|
+
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
43
|
+
};
|
|
44
|
+
if (!params.email || !params.password){
|
|
45
|
+
throw new Error('Email and Password required');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const poolData = {
|
|
49
|
+
UserPoolId: CONFIGURATION.userPoolId,
|
|
50
|
+
ClientId: CONFIGURATION.clientId,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
|
|
54
|
+
const authData = {
|
|
55
|
+
Username: params.email,
|
|
56
|
+
Password: params.password,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
|
|
60
|
+
const userData = {
|
|
61
|
+
Username: params.email,
|
|
62
|
+
Pool: userPool,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
66
|
+
|
|
67
|
+
return new Promise( (resolve, reject) => {
|
|
68
|
+
cognitoUser.authenticateUser(authDetails, {
|
|
69
|
+
onSuccess: async (result) => {
|
|
70
|
+
const user = result;
|
|
71
|
+
await setAuthContext(user, params);
|
|
72
|
+
|
|
73
|
+
resolve({success: true, data: result});
|
|
74
|
+
},
|
|
75
|
+
onFailure: (err) => {
|
|
76
|
+
reject(err);
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function setAuthContext(user, params){
|
|
83
|
+
|
|
84
|
+
// TODO Dont allow user to set this - they could set dev
|
|
85
|
+
const questions = [];
|
|
86
|
+
questions.push({
|
|
87
|
+
type: 'list',
|
|
88
|
+
name: 'environment',
|
|
89
|
+
message: 'Which environment would you like to use?',
|
|
90
|
+
choices: ['Dev', 'Prod'],
|
|
91
|
+
default: 'Dev',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
let apiGateway;
|
|
95
|
+
const answers = await inquirer.prompt(questions);
|
|
96
|
+
if (answers.environment === 'Dev') {
|
|
97
|
+
apiGateway = 'https://api.vibeiq.com/dev/api';
|
|
98
|
+
} else {
|
|
99
|
+
apiGateway = 'https://api.vibeiq.com/prod/api';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Set Auth Config
|
|
103
|
+
Auth.config = {
|
|
104
|
+
apiUserToken: user.idToken.jwtToken,
|
|
105
|
+
apiGateway,
|
|
106
|
+
orgSlug: params.orgSlug,
|
|
107
|
+
};
|
|
108
|
+
// SET SDK CONFIG
|
|
109
|
+
setConfig(Auth.config);
|
|
110
|
+
|
|
111
|
+
const currentUser = await Request.request('/users/current', {
|
|
112
|
+
method: 'GET',
|
|
113
|
+
headers: {
|
|
114
|
+
'Accept': 'application/json',
|
|
115
|
+
'Content-Type': 'application/json',
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
if (!currentUser) {
|
|
119
|
+
throw Error('Could not get current user');
|
|
120
|
+
}
|
|
121
|
+
const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
|
|
122
|
+
if (org) {
|
|
123
|
+
Auth.config.orgId = org.orgId || org.id;
|
|
124
|
+
}
|
|
108
125
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import { create } from './create-app/create';
|
|
3
|
-
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
4
|
-
/**
|
|
5
|
-
* Built using documentation here:
|
|
6
|
-
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export async function cli(args) {
|
|
10
|
-
const command = args[2];
|
|
11
|
-
switch (command) {
|
|
12
|
-
case 'create-app': {
|
|
13
|
-
create(args);
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
case 'deploy-app': {
|
|
17
|
-
deployApp(args);
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
case 'remove-app': {
|
|
21
|
-
removeApp(args);
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
case 'extract-types': {
|
|
25
|
-
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
default: {
|
|
29
|
-
console.log('Illegal command.');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
1
|
+
|
|
2
|
+
import { create } from './create-app/create';
|
|
3
|
+
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
4
|
+
/**
|
|
5
|
+
* Built using documentation here:
|
|
6
|
+
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export async function cli(args) {
|
|
10
|
+
const command = args[2];
|
|
11
|
+
switch (command) {
|
|
12
|
+
case 'create-app': {
|
|
13
|
+
create(args);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case 'deploy-app': {
|
|
17
|
+
deployApp(args);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case 'remove-app': {
|
|
21
|
+
removeApp(args);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
case 'extract-types': {
|
|
25
|
+
// TODO
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
default: {
|
|
29
|
+
console.log('Illegal command.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/create-app/create.ts
CHANGED
|
@@ -1,58 +1,73 @@
|
|
|
1
|
-
import arg from 'arg';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'--
|
|
11
|
-
'--app-name'
|
|
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
|
-
|
|
1
|
+
import arg from 'arg';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { setUpTemplate } from './setup-template';
|
|
5
|
+
|
|
6
|
+
function parseArgumentsIntoOptions(rawArgs) {
|
|
7
|
+
const args = arg(
|
|
8
|
+
{
|
|
9
|
+
'--app-name': String,
|
|
10
|
+
'--template': String,
|
|
11
|
+
'-n': '--app-name',
|
|
12
|
+
'-t': '--template',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
argv: rawArgs.slice(3),
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
return {
|
|
19
|
+
appName: args['--app-name'],
|
|
20
|
+
template: args['--template'],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function promptForMissingOptions(options) {
|
|
24
|
+
const defaultTemplate = 'JavaScript';
|
|
25
|
+
|
|
26
|
+
const questions = [];
|
|
27
|
+
if (!options.appName) {
|
|
28
|
+
questions.push({
|
|
29
|
+
type: 'input',
|
|
30
|
+
name: 'appName',
|
|
31
|
+
validate: (val) => !!val,
|
|
32
|
+
message: 'What is the name of your app?',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!options.template) {
|
|
37
|
+
questions.push({
|
|
38
|
+
type: 'list',
|
|
39
|
+
name: 'template',
|
|
40
|
+
message: 'Which project template would you like to use?',
|
|
41
|
+
choices: ['JavaScript', 'TypeScript'],
|
|
42
|
+
default: defaultTemplate,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const answers = await inquirer.prompt(questions);
|
|
47
|
+
return {
|
|
48
|
+
...options,
|
|
49
|
+
appName: options.appName || answers.appName,
|
|
50
|
+
template: options.template || answers.template,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function create(args) {
|
|
55
|
+
|
|
56
|
+
let options = parseArgumentsIntoOptions(args);
|
|
57
|
+
options = await promptForMissingOptions(options);
|
|
58
|
+
console.log('%s Setting up new new contrail application.', chalk.blue.bold('START'));
|
|
59
|
+
|
|
60
|
+
let error;
|
|
61
|
+
try {
|
|
62
|
+
await setUpTemplate(options);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
error = e;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (error) {
|
|
69
|
+
console.log('%s Application initialization failed.', chalk.red.bold('FAIL'));
|
|
70
|
+
} else {
|
|
71
|
+
console.log('%s Application initialized successfully.', chalk.green.bold('COMPLETE'));
|
|
72
|
+
}
|
|
73
|
+
}
|