@contrail/cli 1.0.65 → 1.0.67
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/lib/apps/create-app/create.js +2 -2
- package/lib/apps/upgrade-app/app-upgrader.js +4 -3
- package/package.json +1 -1
- package/src/apps/create-app/create.ts +2 -2
- package/src/apps/upgrade-app/app-upgrader.ts +4 -3
- package/templates/typescript/actions/handler.ts +6 -9
- package/templates/typescript/actions/mock-server.ts +24 -0
- package/templates/typescript/actions/utils/logger.ts +3 -3
- package/templates/typescript/package.json +6 -0
- package/templates/typescript/tsconfig.json +6 -10
|
@@ -17,7 +17,7 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
async function promptForMissingOptions(options) {
|
|
20
|
-
const defaultTemplate = '
|
|
20
|
+
const defaultTemplate = 'TypeScript';
|
|
21
21
|
const questions = [];
|
|
22
22
|
if (!options.appName) {
|
|
23
23
|
questions.push({
|
|
@@ -32,7 +32,7 @@ async function promptForMissingOptions(options) {
|
|
|
32
32
|
type: 'list',
|
|
33
33
|
name: 'template',
|
|
34
34
|
message: 'Which project template would you like to use?',
|
|
35
|
-
choices: ['
|
|
35
|
+
choices: ['TypeScript', 'JavaScript'],
|
|
36
36
|
default: defaultTemplate,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -66,12 +66,13 @@ export async function upgradeApp() {
|
|
|
66
66
|
type: 'list',
|
|
67
67
|
name: 'appVersion',
|
|
68
68
|
message: 'Which app version would you like to upgrade to?',
|
|
69
|
-
choices: versions.
|
|
70
|
-
const
|
|
69
|
+
choices: versions.map(x => {
|
|
70
|
+
const number = x.versionNumber.toString().padStart(4, '0');
|
|
71
|
+
const name = x.id === appOrgToUpgrade.appVersionId ? `${number} (${x.createdOn}) (current)` : `${number} (${x.createdOn})`;
|
|
71
72
|
return {
|
|
72
73
|
value: x.id, name
|
|
73
74
|
};
|
|
74
|
-
})
|
|
75
|
+
}).sort((x, y) => { return x.name > y.name ? -1 : 1; })
|
|
75
76
|
}]);
|
|
76
77
|
console.log(`%s Upgrading app to version ${answers.appVersion}`, chalk.green.bold('APP INSTALLATION'));
|
|
77
78
|
await upgradeAppVersion(appOrgToUpgrade, answers.appVersion);
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
async function promptForMissingOptions(options) {
|
|
24
|
-
const defaultTemplate = '
|
|
24
|
+
const defaultTemplate = 'TypeScript';
|
|
25
25
|
|
|
26
26
|
const questions = [];
|
|
27
27
|
if (!options.appName) {
|
|
@@ -38,7 +38,7 @@ async function promptForMissingOptions(options) {
|
|
|
38
38
|
type: 'list',
|
|
39
39
|
name: 'template',
|
|
40
40
|
message: 'Which project template would you like to use?',
|
|
41
|
-
choices: ['
|
|
41
|
+
choices: ['TypeScript', 'JavaScript'],
|
|
42
42
|
default: defaultTemplate,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -68,12 +68,13 @@ export async function upgradeApp() {
|
|
|
68
68
|
type: 'list',
|
|
69
69
|
name: 'appVersion',
|
|
70
70
|
message: 'Which app version would you like to upgrade to?',
|
|
71
|
-
choices: versions.
|
|
72
|
-
const
|
|
71
|
+
choices: versions.map(x => {
|
|
72
|
+
const number = x.versionNumber.toString().padStart(4, '0');
|
|
73
|
+
const name = x.id === appOrgToUpgrade.appVersionId ? `${number} (${x.createdOn}) (current)` : `${number} (${x.createdOn})`;
|
|
73
74
|
return {
|
|
74
75
|
value: x.id, name
|
|
75
76
|
};
|
|
76
|
-
})
|
|
77
|
+
}).sort((x, y) => { return x.name > y.name ? -1 : 1; })
|
|
77
78
|
}]);
|
|
78
79
|
|
|
79
80
|
console.log(`%s Upgrading app to version ${answers.appVersion}`, chalk.green.bold('APP INSTALLATION'));
|
|
@@ -3,13 +3,13 @@ import { Logger } from './utils/logger';
|
|
|
3
3
|
|
|
4
4
|
export async function execute(data) {
|
|
5
5
|
const logger = new Logger();
|
|
6
|
-
logger.log(JSON.stringify(data))
|
|
7
6
|
const event = (typeof data.event === 'string')
|
|
8
7
|
? JSON.parse(data.event)
|
|
9
8
|
: data.event;
|
|
10
9
|
data = JSON.parse(JSON.stringify(data));
|
|
11
|
-
|
|
12
|
-
if (!
|
|
10
|
+
logger.log(JSON.stringify(data, null, 2));
|
|
11
|
+
if (!data.apiHost || !data.userName || !data.password) {
|
|
12
|
+
// not really. This is just to demo how to retrieve an app config
|
|
13
13
|
const message = 'This action requires an api host, a username, and a password to run';
|
|
14
14
|
const body = {
|
|
15
15
|
message,
|
|
@@ -22,25 +22,22 @@ export async function execute(data) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
|
-
login({ apiKey:
|
|
25
|
+
await login({ apiKey: data.apiKey, orgSlug: data.orgSlug });
|
|
26
26
|
const results = {};
|
|
27
27
|
|
|
28
28
|
logger.log('Sending message: ', event);
|
|
29
|
-
const response = await fetch(
|
|
30
|
-
method: 'POST',
|
|
31
|
-
body: event,
|
|
29
|
+
const response = await fetch(data.apiHost, {
|
|
32
30
|
headers: { 'Content-Type': 'application/json' }
|
|
33
31
|
});
|
|
34
32
|
if (!response.ok) {
|
|
35
33
|
logger.log('Webhook event failed to publish');
|
|
36
|
-
logger.log('Response: ', JSON.stringify(response));
|
|
37
34
|
}
|
|
38
35
|
else {
|
|
39
36
|
logger.log('Published!');
|
|
40
37
|
}
|
|
38
|
+
logger.log('Response: ', JSON.stringify(response));
|
|
41
39
|
|
|
42
40
|
results['logs'] = logger.getEntries();
|
|
43
|
-
results['config'] = config;
|
|
44
41
|
|
|
45
42
|
logger.log('returning: ' + JSON.stringify(results));
|
|
46
43
|
return {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { execute } from './handler';
|
|
2
|
+
const express = require('express');
|
|
3
|
+
const bodyParser = require('body-parser');
|
|
4
|
+
const app = express();
|
|
5
|
+
const port = 5050;
|
|
6
|
+
|
|
7
|
+
// parse application/x-www-form-urlencoded
|
|
8
|
+
app.use(bodyParser.urlencoded({ extended: false }));
|
|
9
|
+
// parse application/json
|
|
10
|
+
app.use(bodyParser.json());
|
|
11
|
+
|
|
12
|
+
app.get('/health_check', (req, res) => {
|
|
13
|
+
res.send('Hello World!');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// DO NOT CHANGE THIS IMPLEMENTATION
|
|
17
|
+
app.post('/', async (req, res) => {
|
|
18
|
+
const result = await execute(req.body);
|
|
19
|
+
res.send(result);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app.listen(port, () => {
|
|
23
|
+
console.log(`Mock server listening on port ${port}`);
|
|
24
|
+
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export class Logger {
|
|
2
2
|
allEntries = [];
|
|
3
3
|
public log(...args){
|
|
4
|
-
console.log(args);
|
|
4
|
+
console.log(...args);
|
|
5
5
|
this.allEntries.push(args);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
public getEntries(){
|
|
9
|
-
return this.allEntries;
|
|
9
|
+
return this.allEntries.join('\n');
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
public clearEntries(){
|
|
13
13
|
this.allEntries = [];
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
|
+
"start": "nodemon --watch 'actions/**/*.ts' --exec ts-node actions/mock-server.ts",
|
|
19
|
+
"debug": "nodemon -r ts-node/register --inspect=127.0.0.1:60002 --watch 'actions/**/*.ts' --exec node actions/mock-server.ts",
|
|
18
20
|
"lint": "eslint . --fix",
|
|
19
21
|
"test": "jest",
|
|
20
22
|
"test-watch": "jest --watch",
|
|
@@ -39,8 +41,12 @@
|
|
|
39
41
|
"chalk": "^4.0.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
44
|
+
"body-parser": "^1.20.2",
|
|
45
|
+
"express": "^4.18.2",
|
|
46
|
+
"nodemon": "^1.19.4",
|
|
42
47
|
"jest": "^29.2.2",
|
|
43
48
|
"ts-jest": "^29.0.3",
|
|
49
|
+
"ts-node": "^7.0.1",
|
|
44
50
|
"typescript": "^4.7.4"
|
|
45
51
|
}
|
|
46
52
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2020",
|
|
4
4
|
"module": "commonjs",
|
|
5
5
|
"declaration": true,
|
|
6
6
|
"esModuleInterop": true,
|
|
@@ -17,15 +17,11 @@
|
|
|
17
17
|
"ES2015",
|
|
18
18
|
"ES2016",
|
|
19
19
|
"ES2017",
|
|
20
|
+
"ES2020",
|
|
20
21
|
"dom",
|
|
21
22
|
"esnext.asynciterable"
|
|
22
|
-
]
|
|
23
|
+
]
|
|
23
24
|
},
|
|
24
|
-
"include": [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"exclude": [
|
|
28
|
-
"node_modules",
|
|
29
|
-
"**/__tests__/*"
|
|
30
|
-
]
|
|
31
|
-
}
|
|
25
|
+
"include": ["actions"],
|
|
26
|
+
"exclude": ["node_modules", "**/__tests__/*"]
|
|
27
|
+
}
|