@trayio/cdk-cli 3.8.0-beta → 3.9.0
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/README.md +1 -1
- package/dist/commands/connector/add-operation.js +61 -75
- package/dist/commands/connector/add-operation.unit.test.js +6 -15
- package/dist/commands/connector/build.js +8 -22
- package/dist/commands/connector/import.js +49 -60
- package/dist/commands/connector/init.js +52 -66
- package/dist/commands/connector/init.unit.test.js +13 -19
- package/dist/commands/connector/test.js +31 -42
- package/dist/commands/deployment/create.js +38 -52
- package/dist/commands/deployment/create.unit.test.js +24 -28
- package/dist/commands/deployment/get.js +115 -129
- package/dist/commands/deployment/get.unit.test.js +35 -39
- package/dist/commands/permissions/add.js +137 -155
- package/dist/commands/permissions/add.unit.test.js +6 -15
- package/dist/commands/permissions/list.js +75 -89
- package/dist/commands/permissions/list.unit.test.js +20 -24
- package/dist/templates/connector-template.zip +0 -0
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ $ npm install -g @trayio/cdk-cli
|
|
|
19
19
|
$ tray-cdk COMMAND
|
|
20
20
|
running command...
|
|
21
21
|
$ tray-cdk (--version|-v)
|
|
22
|
-
@trayio/cdk-cli/3.
|
|
22
|
+
@trayio/cdk-cli/3.9.0 linux-x64 node-v18.19.1
|
|
23
23
|
$ tray-cdk --help [COMMAND]
|
|
24
24
|
USAGE
|
|
25
25
|
$ tray-cdk COMMAND
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -31,72 +22,67 @@ const getConnectorName = (currentDirectory) => {
|
|
|
31
22
|
return base;
|
|
32
23
|
};
|
|
33
24
|
class AddOperation extends core_1.Command {
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
25
|
+
static description = 'Add an operation to connector project';
|
|
26
|
+
static args = {
|
|
27
|
+
operationName: core_1.Args.string({
|
|
28
|
+
name: 'Operation name',
|
|
29
|
+
required: false,
|
|
30
|
+
description: 'Operation name',
|
|
31
|
+
}),
|
|
32
|
+
operationType: core_1.Args.string({
|
|
33
|
+
name: 'Operation type',
|
|
34
|
+
required: false,
|
|
35
|
+
description: 'Operation type',
|
|
36
|
+
options: ['http', 'composite'],
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
40
|
+
async run() {
|
|
41
|
+
const { args } = await this.parse(AddOperation);
|
|
42
|
+
const promptRes = await inquirer_1.default.prompt([
|
|
43
|
+
{
|
|
44
|
+
name: 'operationName',
|
|
45
|
+
message: 'Operation name',
|
|
46
|
+
type: 'input',
|
|
47
|
+
when: !args.operationName,
|
|
48
|
+
default: 'my-operation',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'operationType',
|
|
52
|
+
message: 'Operation type',
|
|
53
|
+
type: 'list',
|
|
54
|
+
choices: [
|
|
55
|
+
{ name: 'HTTP', value: 'http' },
|
|
56
|
+
{ name: 'Composite', value: 'composite' },
|
|
57
|
+
],
|
|
58
|
+
when: !args.operationType,
|
|
59
|
+
default: 'http',
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
const operationName = args.operationName || promptRes.operationName;
|
|
63
|
+
const operationNameKebabCase = (0, lodash_1.kebabCase)(operationName);
|
|
64
|
+
const operationNamePascalCase = StringExtensions_1.StringExtensions.pascalCase(operationName);
|
|
65
|
+
const operationNameCamelCase = (0, lodash_1.camelCase)(operationName);
|
|
66
|
+
const operationNameSnakeCase = (0, lodash_1.snakeCase)(operationName);
|
|
67
|
+
const currentDirectory = process.cwd();
|
|
68
|
+
const connectorNamePascalCase = StringExtensions_1.StringExtensions.pascalCase(getConnectorName(currentDirectory));
|
|
69
|
+
const operationType = args.operationType || promptRes.operationType;
|
|
70
|
+
const rootDir = __dirname;
|
|
71
|
+
const templateDir = path_1.default.join(rootDir, '..', '..', 'templates');
|
|
72
|
+
const templatePath = operationType === 'http'
|
|
73
|
+
? path_1.default.join(templateDir, 'http-operation-template.zip')
|
|
74
|
+
: path_1.default.join(templateDir, 'composite-operation-template.zip');
|
|
75
|
+
const targetPath = isInSrcFolder(currentDirectory)
|
|
76
|
+
? currentDirectory
|
|
77
|
+
: path_1.default.join(currentDirectory, 'src');
|
|
78
|
+
await this.generator.generate(templatePath, targetPath, {
|
|
79
|
+
operationNameKebabCase,
|
|
80
|
+
operationNamePascalCase,
|
|
81
|
+
operationNameCamelCase,
|
|
82
|
+
operationNameSnakeCase,
|
|
83
|
+
connectorNamePascalCase,
|
|
84
|
+
})();
|
|
85
|
+
this.log((0, colorizeString_1.success)(`Success! Added operation: ${operationNameKebabCase}`));
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
AddOperation.description = 'Add an operation to connector project';
|
|
89
|
-
AddOperation.args = {
|
|
90
|
-
operationName: core_1.Args.string({
|
|
91
|
-
name: 'Operation name',
|
|
92
|
-
required: false,
|
|
93
|
-
description: 'Operation name',
|
|
94
|
-
}),
|
|
95
|
-
operationType: core_1.Args.string({
|
|
96
|
-
name: 'Operation type',
|
|
97
|
-
required: false,
|
|
98
|
-
description: 'Operation type',
|
|
99
|
-
options: ['http', 'composite'],
|
|
100
|
-
}),
|
|
101
|
-
};
|
|
102
88
|
exports.default = AddOperation;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -34,7 +25,7 @@ describe('AddOperation', () => {
|
|
|
34
25
|
afterAll(() => {
|
|
35
26
|
jest.restoreAllMocks();
|
|
36
27
|
});
|
|
37
|
-
it('should prompt for operation name and type if not provided', () =>
|
|
28
|
+
it('should prompt for operation name and type if not provided', async () => {
|
|
38
29
|
const addOperation = new add_operation_1.default([], {});
|
|
39
30
|
const mockGenerate = jest
|
|
40
31
|
.fn()
|
|
@@ -43,7 +34,7 @@ describe('AddOperation', () => {
|
|
|
43
34
|
generate: mockGenerate,
|
|
44
35
|
};
|
|
45
36
|
stdout_stderr_1.stdout.start();
|
|
46
|
-
|
|
37
|
+
await addOperation.run();
|
|
47
38
|
stdout_stderr_1.stdout.stop();
|
|
48
39
|
expect(stdout_stderr_1.stdout.output).toContain('Success! Added operation: my-operation');
|
|
49
40
|
expect(mockInquirer.prompt).toBeCalledWith([
|
|
@@ -73,8 +64,8 @@ describe('AddOperation', () => {
|
|
|
73
64
|
operationNamePascalCase: 'MyOperation',
|
|
74
65
|
operationNameSnakeCase: 'my_operation',
|
|
75
66
|
});
|
|
76
|
-
})
|
|
77
|
-
it('should not prompt for operation name and type if provided', () =>
|
|
67
|
+
});
|
|
68
|
+
it('should not prompt for operation name and type if provided', async () => {
|
|
78
69
|
operationName = 'some-val';
|
|
79
70
|
operationType = 'http';
|
|
80
71
|
const addOperation = new add_operation_1.default([operationName, operationType], {});
|
|
@@ -85,7 +76,7 @@ describe('AddOperation', () => {
|
|
|
85
76
|
generate: mockGenerate,
|
|
86
77
|
};
|
|
87
78
|
stdout_stderr_1.stdout.start();
|
|
88
|
-
|
|
79
|
+
await addOperation.run();
|
|
89
80
|
stdout_stderr_1.stdout.stop();
|
|
90
81
|
expect(stdout_stderr_1.stdout.output).toContain('Success! Added operation: some-val');
|
|
91
82
|
expect(mockInquirer.prompt).toBeCalledWith([
|
|
@@ -115,5 +106,5 @@ describe('AddOperation', () => {
|
|
|
115
106
|
operationNamePascalCase: 'SomeVal',
|
|
116
107
|
operationNameSnakeCase: 'some_val',
|
|
117
108
|
});
|
|
118
|
-
})
|
|
109
|
+
});
|
|
119
110
|
});
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -16,19 +7,14 @@ const core_1 = require("@oclif/core");
|
|
|
16
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
8
|
const ConnectorBuilder_1 = require("@trayio/cdk-build/connector/ConnectorBuilder");
|
|
18
9
|
class Build extends core_1.Command {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
yield this.connectorBuilder.buildConnector(currentDirectory)();
|
|
28
|
-
this.log(chalk_1.default.bold(chalk_1.default.green(`Connector Build Finished`)));
|
|
29
|
-
});
|
|
10
|
+
static description = 'Builds a connector project';
|
|
11
|
+
static args = {};
|
|
12
|
+
connectorBuilder = new ConnectorBuilder_1.ConnectorBuilder();
|
|
13
|
+
async run() {
|
|
14
|
+
const currentDirectory = process.cwd();
|
|
15
|
+
this.log('Connector Build Started');
|
|
16
|
+
await this.connectorBuilder.buildConnector(currentDirectory)();
|
|
17
|
+
this.log(chalk_1.default.bold(chalk_1.default.green(`Connector Build Finished`)));
|
|
30
18
|
}
|
|
31
19
|
}
|
|
32
|
-
Build.description = 'Builds a connector project';
|
|
33
|
-
Build.args = {};
|
|
34
20
|
exports.default = Build;
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -44,58 +35,56 @@ const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
|
|
|
44
35
|
const E = __importStar(require("fp-ts/Either"));
|
|
45
36
|
const stream_1 = require("stream");
|
|
46
37
|
class Import extends core_1.Command {
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
38
|
+
static description = 'Create a connector from an OpenAPI specification: Command is still in BETA';
|
|
39
|
+
static args = {
|
|
40
|
+
openApiSpec: core_1.Args.string({
|
|
41
|
+
name: 'OpenAPI specification file path',
|
|
42
|
+
required: false,
|
|
43
|
+
description: 'Location of the OpenAPI specification file',
|
|
44
|
+
}),
|
|
45
|
+
connectorName: core_1.Args.string({
|
|
46
|
+
name: 'Connector name',
|
|
47
|
+
required: false,
|
|
48
|
+
description: 'The name of the connector',
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
async run() {
|
|
52
|
+
const { args } = await this.parse(Import);
|
|
53
|
+
const promptRes = await inquirer_1.default.prompt([
|
|
54
|
+
{
|
|
55
|
+
name: 'openApiSpec',
|
|
56
|
+
message: 'OpenAPI specification file path',
|
|
57
|
+
type: 'input',
|
|
58
|
+
when: !args.openApiSpec,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'connectorName',
|
|
62
|
+
message: 'Connector name',
|
|
63
|
+
type: 'input',
|
|
64
|
+
when: !args.connectorName,
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
const generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
68
|
+
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage(process.cwd());
|
|
69
|
+
const openApiSchemaImporter = new OpenApiSchemaImporter_1.OpenApiSchemaImporter(generator, fileStorage);
|
|
70
|
+
const openApiSpec = promptRes.openApiSpec || args.openApiSpec;
|
|
71
|
+
const connectorName = promptRes.connectorName || args.connectorName;
|
|
72
|
+
const result = await openApiSchemaImporter.buildConnector(openApiSpec, connectorName)();
|
|
73
|
+
if (E.isLeft(result)) {
|
|
74
|
+
this.log(chalk_1.default.red(`Error occurred while importing connector: ${result.left.message}`));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.log(chalk_1.default.bold(chalk_1.default.green(`Success! Added connector: ${connectorName}`)));
|
|
78
|
+
this.log(chalk_1.default.bold.green(`Generated ${result.right.successes.length} Connector Operations`));
|
|
79
|
+
if (result.right.errors.length) {
|
|
80
|
+
this.log(chalk_1.default.bold.red(`Failed to generate ${result.right.errors.length} Connector Operations, errors can be found in the errors.json file`));
|
|
81
|
+
await fileStorage.write({
|
|
82
|
+
key: 'errors.json',
|
|
83
|
+
content: stream_1.Readable.from(JSON.stringify(result.right.errors)),
|
|
84
|
+
metadata: { name: 'errors.json', size: 0 },
|
|
85
|
+
})();
|
|
84
86
|
}
|
|
85
|
-
}
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
|
-
Import.description = 'Create a connector from an OpenAPI specification: Command is still in BETA';
|
|
89
|
-
Import.args = {
|
|
90
|
-
openApiSpec: core_1.Args.string({
|
|
91
|
-
name: 'OpenAPI specification file path',
|
|
92
|
-
required: false,
|
|
93
|
-
description: 'Location of the OpenAPI specification file',
|
|
94
|
-
}),
|
|
95
|
-
connectorName: core_1.Args.string({
|
|
96
|
-
name: 'Connector name',
|
|
97
|
-
required: false,
|
|
98
|
-
description: 'The name of the connector',
|
|
99
|
-
}),
|
|
100
|
-
};
|
|
101
90
|
exports.default = Import;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,65 +12,60 @@ const lodash_1 = require("lodash");
|
|
|
21
12
|
const child_process_1 = require("child_process");
|
|
22
13
|
const colorizeString_1 = require("../../utils/colorizeString");
|
|
23
14
|
class Init extends core_1.Command {
|
|
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
|
-
|
|
15
|
+
static description = 'Initialize a connector project';
|
|
16
|
+
static args = {
|
|
17
|
+
connectorName: core_1.Args.string({
|
|
18
|
+
name: 'Connector directory name',
|
|
19
|
+
required: false,
|
|
20
|
+
description: 'Connector directory name to generate template files',
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
static flags = {
|
|
24
|
+
install: core_1.Flags.boolean({
|
|
25
|
+
char: 'i',
|
|
26
|
+
description: 'Runs `npm install` after successful generation',
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
30
|
+
async run() {
|
|
31
|
+
const { args, flags } = await this.parse(Init);
|
|
32
|
+
const promptRes = await inquirer_1.default.prompt([
|
|
33
|
+
{
|
|
34
|
+
name: 'connectorName',
|
|
35
|
+
message: 'Connector directory name to generate template files',
|
|
36
|
+
type: 'input',
|
|
37
|
+
when: !args.connectorName,
|
|
38
|
+
default: 'my-connector',
|
|
39
|
+
},
|
|
40
|
+
]);
|
|
41
|
+
const connectorNameKebabCase = (0, lodash_1.kebabCase)(args.connectorName || promptRes.connectorName);
|
|
42
|
+
const connectorNameTitleCase = StringExtensions_1.StringExtensions.titleCase(connectorNameKebabCase);
|
|
43
|
+
const connectorNamePascalCase = StringExtensions_1.StringExtensions.pascalCase(connectorNameKebabCase);
|
|
44
|
+
const connectorNameCamelCase = (0, lodash_1.camelCase)(connectorNameKebabCase);
|
|
45
|
+
const rootDir = __dirname;
|
|
46
|
+
const templateDir = (0, path_1.join)(rootDir, '..', '..', 'templates');
|
|
47
|
+
const templatePath = (0, path_1.join)(templateDir, 'connector-template.zip');
|
|
48
|
+
await this.generator.generate(templatePath, process.cwd(), {
|
|
49
|
+
connectorNameKebabCase,
|
|
50
|
+
connectorNameTitleCase,
|
|
51
|
+
connectorNamePascalCase,
|
|
52
|
+
connectorNameCamelCase,
|
|
53
|
+
})();
|
|
54
|
+
this.log((0, colorizeString_1.success)(`Success! Added ${connectorNameKebabCase}`));
|
|
55
|
+
if (flags.install) {
|
|
56
|
+
try {
|
|
57
|
+
core_1.ux.action.start('Installing dependencies');
|
|
58
|
+
(0, child_process_1.execSync)(`cd ${connectorNameKebabCase} && npm install`, {
|
|
59
|
+
stdio: 'inherit',
|
|
60
|
+
});
|
|
61
|
+
core_1.ux.action.stop();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
this.error(new Error(error.message));
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
Init.description = 'Initialize a connector project';
|
|
72
|
-
Init.args = {
|
|
73
|
-
connectorName: core_1.Args.string({
|
|
74
|
-
name: 'Connector directory name',
|
|
75
|
-
required: false,
|
|
76
|
-
description: 'Connector directory name to generate template files',
|
|
77
|
-
}),
|
|
78
|
-
};
|
|
79
|
-
Init.flags = {
|
|
80
|
-
install: core_1.Flags.boolean({
|
|
81
|
-
char: 'i',
|
|
82
|
-
description: 'Runs `npm install` after successful generation',
|
|
83
|
-
}),
|
|
84
|
-
};
|
|
85
71
|
exports.default = Init;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -20,7 +11,10 @@ jest.mock('inquirer', () => ({
|
|
|
20
11
|
prompt: jest.fn(),
|
|
21
12
|
registerPrompt: jest.requireActual('inquirer').registerPrompt,
|
|
22
13
|
}));
|
|
23
|
-
jest.mock('child_process', () => (
|
|
14
|
+
jest.mock('child_process', () => ({
|
|
15
|
+
...jest.requireActual('child_process'),
|
|
16
|
+
execSync: jest.fn(),
|
|
17
|
+
}));
|
|
24
18
|
describe('Init', () => {
|
|
25
19
|
let connectorName = 'my-test-connector';
|
|
26
20
|
const mockInquirer = inquirer_1.default;
|
|
@@ -33,7 +27,7 @@ describe('Init', () => {
|
|
|
33
27
|
afterAll(() => {
|
|
34
28
|
jest.restoreAllMocks();
|
|
35
29
|
});
|
|
36
|
-
it('should prompt for connector name if not provided', () =>
|
|
30
|
+
it('should prompt for connector name if not provided', async () => {
|
|
37
31
|
const init = new init_1.default([], {});
|
|
38
32
|
const mockGenerate = jest
|
|
39
33
|
.fn()
|
|
@@ -42,7 +36,7 @@ describe('Init', () => {
|
|
|
42
36
|
generate: mockGenerate,
|
|
43
37
|
};
|
|
44
38
|
stdout_stderr_1.stdout.start();
|
|
45
|
-
|
|
39
|
+
await init.run();
|
|
46
40
|
stdout_stderr_1.stdout.stop();
|
|
47
41
|
expect(stdout_stderr_1.stdout.output).toContain('Success! Added my-test-connector');
|
|
48
42
|
expect(mockInquirer.prompt).toBeCalledWith([
|
|
@@ -61,8 +55,8 @@ describe('Init', () => {
|
|
|
61
55
|
connectorNameTitleCase: 'My test connector',
|
|
62
56
|
});
|
|
63
57
|
expect(child_process_1.execSync).not.toBeCalled();
|
|
64
|
-
})
|
|
65
|
-
it('should not prompt for connector name if provided', () =>
|
|
58
|
+
});
|
|
59
|
+
it('should not prompt for connector name if provided', async () => {
|
|
66
60
|
connectorName = 'my-new-connector';
|
|
67
61
|
const init = new init_1.default([connectorName], {});
|
|
68
62
|
const mockGenerate = jest
|
|
@@ -72,7 +66,7 @@ describe('Init', () => {
|
|
|
72
66
|
generate: mockGenerate,
|
|
73
67
|
};
|
|
74
68
|
stdout_stderr_1.stdout.start();
|
|
75
|
-
|
|
69
|
+
await init.run();
|
|
76
70
|
stdout_stderr_1.stdout.stop();
|
|
77
71
|
expect(stdout_stderr_1.stdout.output).toContain('Success! Added my-new-connector');
|
|
78
72
|
expect(mockInquirer.prompt).toBeCalledWith([
|
|
@@ -91,8 +85,8 @@ describe('Init', () => {
|
|
|
91
85
|
connectorNameTitleCase: 'My new connector',
|
|
92
86
|
});
|
|
93
87
|
expect(child_process_1.execSync).not.toBeCalled();
|
|
94
|
-
})
|
|
95
|
-
it('should run npm install if "-i" install flag is passed', () =>
|
|
88
|
+
});
|
|
89
|
+
it('should run npm install if "-i" install flag is passed', async () => {
|
|
96
90
|
connectorName = 'my-install-connector';
|
|
97
91
|
const init = new init_1.default([connectorName, '-i'], {});
|
|
98
92
|
const mockGenerate = jest
|
|
@@ -102,7 +96,7 @@ describe('Init', () => {
|
|
|
102
96
|
generate: mockGenerate,
|
|
103
97
|
};
|
|
104
98
|
stdout_stderr_1.stdout.start();
|
|
105
|
-
|
|
99
|
+
await init.run();
|
|
106
100
|
stdout_stderr_1.stdout.stop();
|
|
107
101
|
expect(stdout_stderr_1.stdout.output).toContain('Success! Added my-install-connector');
|
|
108
102
|
expect(mockInquirer.prompt).toBeCalledWith([
|
|
@@ -123,5 +117,5 @@ describe('Init', () => {
|
|
|
123
117
|
expect(child_process_1.execSync).toBeCalledWith(`cd ${connectorName} && npm install`, {
|
|
124
118
|
stdio: 'inherit',
|
|
125
119
|
});
|
|
126
|
-
})
|
|
120
|
+
});
|
|
127
121
|
});
|