@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/.vscode/settings.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"editor.tabSize": 2,
|
|
3
|
-
"editor.codeActionsOnSave": {
|
|
4
|
-
"source.fixAll.tslint": true
|
|
5
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"editor.tabSize": 2,
|
|
3
|
+
"editor.codeActionsOnSave": {
|
|
4
|
+
"source.fixAll.tslint": true
|
|
5
|
+
}
|
|
6
6
|
}
|
package/bin/init
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
require = require('esm')(module /*, options*/);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
require = require('esm')(module /*, options*/);
|
|
4
4
|
require('../lib/cli').cli(process.argv);
|
package/lib/auth/auth.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export interface AuthContext {
|
|
2
|
-
apiUserToken: string;
|
|
3
|
-
apiGateway?: string;
|
|
4
|
-
orgSlug?: string;
|
|
5
|
-
orgId?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class Auth {
|
|
8
|
-
static config: AuthContext;
|
|
9
|
-
}
|
|
1
|
+
export interface AuthContext {
|
|
2
|
+
apiUserToken: string;
|
|
3
|
+
apiGateway?: string;
|
|
4
|
+
orgSlug?: string;
|
|
5
|
+
orgId?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Auth {
|
|
8
|
+
static config: AuthContext;
|
|
9
|
+
}
|
package/lib/auth/auth.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export class Auth {
|
|
2
|
-
}
|
|
1
|
+
export class Auth {
|
|
2
|
+
}
|
package/lib/auth/login.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function authUser(): Promise<unknown>;
|
|
1
|
+
export declare function authUser(): Promise<unknown>;
|
package/lib/auth/login.js
CHANGED
|
@@ -1,96 +1,112 @@
|
|
|
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
|
-
const CONFIGURATION = {
|
|
6
|
-
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
7
|
-
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
8
|
-
};
|
|
9
|
-
export async function authUser() {
|
|
10
|
-
const questions = [];
|
|
11
|
-
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
12
|
-
questions.push({
|
|
13
|
-
type: 'input',
|
|
14
|
-
name: 'email',
|
|
15
|
-
validate: (val) => !!val,
|
|
16
|
-
message: 'Email',
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
20
|
-
questions.push({
|
|
21
|
-
type: 'password',
|
|
22
|
-
name: 'password',
|
|
23
|
-
validate: (val) => !!val,
|
|
24
|
-
message: 'Password',
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
if (!process.env.CONTRAIL_CLI_ORGSLUG) {
|
|
28
|
-
questions.push({
|
|
29
|
-
type: 'input',
|
|
30
|
-
name: 'orgSlug',
|
|
31
|
-
validate: (val) => !!val,
|
|
32
|
-
message: 'Org (slug)',
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
const answers = await inquirer.prompt(questions);
|
|
36
|
-
const params = {
|
|
37
|
-
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
38
|
-
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
39
|
-
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
40
|
-
};
|
|
41
|
-
if (!params.email || !params.password) {
|
|
42
|
-
throw new Error('
|
|
43
|
-
}
|
|
44
|
-
const poolData = {
|
|
45
|
-
UserPoolId: CONFIGURATION.userPoolId,
|
|
46
|
-
ClientId: CONFIGURATION.clientId,
|
|
47
|
-
};
|
|
48
|
-
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
|
|
49
|
-
const authData = {
|
|
50
|
-
Username: params.email,
|
|
51
|
-
Password: params.password,
|
|
52
|
-
};
|
|
53
|
-
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
|
|
54
|
-
const userData = {
|
|
55
|
-
Username: params.email,
|
|
56
|
-
Pool: userPool,
|
|
57
|
-
};
|
|
58
|
-
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
cognitoUser.authenticateUser(authDetails, {
|
|
61
|
-
onSuccess: async (result) => {
|
|
62
|
-
const user = result;
|
|
63
|
-
await setAuthContext(user, params);
|
|
64
|
-
resolve({ success: true, data: result });
|
|
65
|
-
},
|
|
66
|
-
onFailure: (err) => {
|
|
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
|
-
|
|
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
|
+
const CONFIGURATION = {
|
|
6
|
+
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
7
|
+
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
8
|
+
};
|
|
9
|
+
export async function authUser() {
|
|
10
|
+
const questions = [];
|
|
11
|
+
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
12
|
+
questions.push({
|
|
13
|
+
type: 'input',
|
|
14
|
+
name: 'email',
|
|
15
|
+
validate: (val) => !!val,
|
|
16
|
+
message: 'Email',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
20
|
+
questions.push({
|
|
21
|
+
type: 'password',
|
|
22
|
+
name: 'password',
|
|
23
|
+
validate: (val) => !!val,
|
|
24
|
+
message: 'Password',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (!process.env.CONTRAIL_CLI_ORGSLUG) {
|
|
28
|
+
questions.push({
|
|
29
|
+
type: 'input',
|
|
30
|
+
name: 'orgSlug',
|
|
31
|
+
validate: (val) => !!val,
|
|
32
|
+
message: 'Org (slug)',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const answers = await inquirer.prompt(questions);
|
|
36
|
+
const params = {
|
|
37
|
+
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
38
|
+
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
39
|
+
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
40
|
+
};
|
|
41
|
+
if (!params.email || !params.password) {
|
|
42
|
+
throw new Error('Email and Password required');
|
|
43
|
+
}
|
|
44
|
+
const poolData = {
|
|
45
|
+
UserPoolId: CONFIGURATION.userPoolId,
|
|
46
|
+
ClientId: CONFIGURATION.clientId,
|
|
47
|
+
};
|
|
48
|
+
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
|
|
49
|
+
const authData = {
|
|
50
|
+
Username: params.email,
|
|
51
|
+
Password: params.password,
|
|
52
|
+
};
|
|
53
|
+
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
|
|
54
|
+
const userData = {
|
|
55
|
+
Username: params.email,
|
|
56
|
+
Pool: userPool,
|
|
57
|
+
};
|
|
58
|
+
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
cognitoUser.authenticateUser(authDetails, {
|
|
61
|
+
onSuccess: async (result) => {
|
|
62
|
+
const user = result;
|
|
63
|
+
await setAuthContext(user, params);
|
|
64
|
+
resolve({ success: true, data: result });
|
|
65
|
+
},
|
|
66
|
+
onFailure: (err) => {
|
|
67
|
+
reject(err);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function setAuthContext(user, params) {
|
|
73
|
+
// TODO Dont allow user to set this - they could set dev
|
|
74
|
+
const questions = [];
|
|
75
|
+
questions.push({
|
|
76
|
+
type: 'list',
|
|
77
|
+
name: 'environment',
|
|
78
|
+
message: 'Which environment would you like to use?',
|
|
79
|
+
choices: ['Dev', 'Prod'],
|
|
80
|
+
default: 'Dev',
|
|
81
|
+
});
|
|
82
|
+
let apiGateway;
|
|
83
|
+
const answers = await inquirer.prompt(questions);
|
|
84
|
+
if (answers.environment === 'Dev') {
|
|
85
|
+
apiGateway = 'https://api.vibeiq.com/dev/api';
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
apiGateway = 'https://api.vibeiq.com/prod/api';
|
|
89
|
+
}
|
|
90
|
+
// Set Auth Config
|
|
91
|
+
Auth.config = {
|
|
92
|
+
apiUserToken: user.idToken.jwtToken,
|
|
93
|
+
apiGateway,
|
|
94
|
+
orgSlug: params.orgSlug,
|
|
95
|
+
};
|
|
96
|
+
// SET SDK CONFIG
|
|
97
|
+
setConfig(Auth.config);
|
|
98
|
+
const currentUser = await Request.request('/users/current', {
|
|
99
|
+
method: 'GET',
|
|
100
|
+
headers: {
|
|
101
|
+
'Accept': 'application/json',
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
if (!currentUser) {
|
|
106
|
+
throw Error('Could not get current user');
|
|
107
|
+
}
|
|
108
|
+
const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
|
|
109
|
+
if (org) {
|
|
110
|
+
Auth.config.orgId = org.orgId || org.id;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built using documentation here:
|
|
3
|
-
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
4
|
-
*/
|
|
5
|
-
export declare function cli(args: any): Promise<void>;
|
|
1
|
+
/**
|
|
2
|
+
* Built using documentation here:
|
|
3
|
+
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
4
|
+
*/
|
|
5
|
+
export declare function cli(args: any): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { create } from './create-app/create';
|
|
2
|
-
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
3
|
-
/**
|
|
4
|
-
* Built using documentation here:
|
|
5
|
-
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
6
|
-
*/
|
|
7
|
-
export async function cli(args) {
|
|
8
|
-
const command = args[2];
|
|
9
|
-
switch (command) {
|
|
10
|
-
case 'create-app': {
|
|
11
|
-
create(args);
|
|
12
|
-
break;
|
|
13
|
-
}
|
|
14
|
-
case 'deploy-app': {
|
|
15
|
-
deployApp(args);
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
case 'remove-app': {
|
|
19
|
-
removeApp(args);
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
case 'extract-types': {
|
|
23
|
-
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
default: {
|
|
27
|
-
console.log('Illegal command.');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { create } from './create-app/create';
|
|
2
|
+
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
3
|
+
/**
|
|
4
|
+
* Built using documentation here:
|
|
5
|
+
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
6
|
+
*/
|
|
7
|
+
export async function cli(args) {
|
|
8
|
+
const command = args[2];
|
|
9
|
+
switch (command) {
|
|
10
|
+
case 'create-app': {
|
|
11
|
+
create(args);
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
case 'deploy-app': {
|
|
15
|
+
deployApp(args);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'remove-app': {
|
|
19
|
+
removeApp(args);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 'extract-types': {
|
|
23
|
+
// TODO
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
default: {
|
|
27
|
+
console.log('Illegal command.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function create(args: any): Promise<void>;
|
|
1
|
+
export declare function create(args: any): Promise<void>;
|
package/lib/create-app/create.js
CHANGED
|
@@ -1,48 +1,63 @@
|
|
|
1
|
-
import arg from 'arg';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { setUpTemplate } from './setup-template';
|
|
5
|
-
function parseArgumentsIntoOptions(rawArgs) {
|
|
6
|
-
const args = arg({
|
|
7
|
-
'--
|
|
8
|
-
'--
|
|
9
|
-
'-
|
|
10
|
-
'-
|
|
11
|
-
}, {
|
|
12
|
-
argv: rawArgs.slice(
|
|
13
|
-
});
|
|
14
|
-
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
async function promptForMissingOptions(options) {
|
|
20
|
-
const defaultTemplate = 'JavaScript';
|
|
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
|
-
|
|
1
|
+
import arg from 'arg';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { setUpTemplate } from './setup-template';
|
|
5
|
+
function parseArgumentsIntoOptions(rawArgs) {
|
|
6
|
+
const args = arg({
|
|
7
|
+
'--app-name': String,
|
|
8
|
+
'--template': String,
|
|
9
|
+
'-n': '--app-name',
|
|
10
|
+
'-t': '--template',
|
|
11
|
+
}, {
|
|
12
|
+
argv: rawArgs.slice(3),
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
appName: args['--app-name'],
|
|
16
|
+
template: args['--template'],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function promptForMissingOptions(options) {
|
|
20
|
+
const defaultTemplate = 'JavaScript';
|
|
21
|
+
const questions = [];
|
|
22
|
+
if (!options.appName) {
|
|
23
|
+
questions.push({
|
|
24
|
+
type: 'input',
|
|
25
|
+
name: 'appName',
|
|
26
|
+
validate: (val) => !!val,
|
|
27
|
+
message: 'What is the name of your app?',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!options.template) {
|
|
31
|
+
questions.push({
|
|
32
|
+
type: 'list',
|
|
33
|
+
name: 'template',
|
|
34
|
+
message: 'Which project template would you like to use?',
|
|
35
|
+
choices: ['JavaScript', 'TypeScript'],
|
|
36
|
+
default: defaultTemplate,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const answers = await inquirer.prompt(questions);
|
|
40
|
+
return {
|
|
41
|
+
...options,
|
|
42
|
+
appName: options.appName || answers.appName,
|
|
43
|
+
template: options.template || answers.template,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export async function create(args) {
|
|
47
|
+
let options = parseArgumentsIntoOptions(args);
|
|
48
|
+
options = await promptForMissingOptions(options);
|
|
49
|
+
console.log('%s Setting up new new contrail application.', chalk.blue.bold('START'));
|
|
50
|
+
let error;
|
|
51
|
+
try {
|
|
52
|
+
await setUpTemplate(options);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
error = e;
|
|
56
|
+
}
|
|
57
|
+
if (error) {
|
|
58
|
+
console.log('%s Application initialization failed.', chalk.red.bold('FAIL'));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log('%s Application initialized successfully.', chalk.green.bold('COMPLETE'));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function setUpTemplate(): Promise<void>;
|
|
1
|
+
export declare function setUpTemplate(options: any): Promise<void>;
|
|
@@ -1,48 +1,34 @@
|
|
|
1
|
-
import ncp from 'ncp';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { promisify } from 'util';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
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
|
-
title: 'Install dependencies',
|
|
38
|
-
task: () => projectInstall({
|
|
39
|
-
cwd: TARGET_DIR,
|
|
40
|
-
}),
|
|
41
|
-
},
|
|
42
|
-
]);
|
|
43
|
-
await tasks.run();
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
console.log('Error copying template: ', e);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
import ncp from 'ncp';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
const Listr = require('listr');
|
|
5
|
+
import { projectInstall } from 'pkg-install';
|
|
6
|
+
const copy = promisify(ncp);
|
|
7
|
+
const TARGET_DIR = process.cwd();
|
|
8
|
+
const currentFileUrl = import.meta.url;
|
|
9
|
+
function copyTemplate(templateDir) {
|
|
10
|
+
return copy(templateDir, TARGET_DIR, {
|
|
11
|
+
clobber: false,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export async function setUpTemplate(options) {
|
|
15
|
+
const templateDir = path.resolve(new URL(currentFileUrl).pathname, `../../../templates/${options.template.toLocaleLowerCase()}`).replace(/\\/g, '\\').replace(/(.):\\(.):/g, '').replace(/%20/g, ' ');
|
|
16
|
+
try {
|
|
17
|
+
const tasks = new Listr([
|
|
18
|
+
{
|
|
19
|
+
title: 'Copy template files',
|
|
20
|
+
task: () => copyTemplate(templateDir),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: 'Install dependencies',
|
|
24
|
+
task: () => projectInstall({
|
|
25
|
+
cwd: TARGET_DIR,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
await tasks.run();
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new Error(`Error copying template: ${e}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { App,
|
|
2
|
-
export declare class ActionsDeployer {
|
|
3
|
-
deployActions(appDeclaration:
|
|
4
|
-
getActionsForApp(app: App): Promise<any>;
|
|
5
|
-
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
-
private createNewActionDefinition;
|
|
7
|
-
private updateActionDefinition;
|
|
8
|
-
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
-
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
|
-
}
|
|
1
|
+
import { App, AppDeclaration, AppActionDeclaration } from './interfaces';
|
|
2
|
+
export declare class ActionsDeployer {
|
|
3
|
+
deployActions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
+
getActionsForApp(app: App): Promise<any>;
|
|
5
|
+
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
+
private createNewActionDefinition;
|
|
7
|
+
private updateActionDefinition;
|
|
8
|
+
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
+
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
|
+
}
|