@trayio/cdk-cli 2.15.0 → 2.16.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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/add-operation.d.ts +1 -0
  3. package/dist/commands/add-operation.d.ts.map +1 -1
  4. package/dist/commands/add-operation.js +10 -6
  5. package/dist/commands/add-operation.unit.test.d.ts +2 -0
  6. package/dist/commands/add-operation.unit.test.d.ts.map +1 -0
  7. package/dist/commands/add-operation.unit.test.js +119 -0
  8. package/dist/commands/deploy.d.ts.map +1 -1
  9. package/dist/commands/deploy.js +7 -4
  10. package/dist/commands/deployment-status.unit.test.d.ts +2 -0
  11. package/dist/commands/deployment-status.unit.test.d.ts.map +1 -0
  12. package/dist/commands/init.d.ts +1 -0
  13. package/dist/commands/init.d.ts.map +1 -1
  14. package/dist/commands/init.js +11 -6
  15. package/dist/commands/init.unit.test.d.ts +2 -0
  16. package/dist/commands/init.unit.test.d.ts.map +1 -0
  17. package/dist/commands/init.unit.test.js +127 -0
  18. package/dist/utils/check-env.d.ts +2 -0
  19. package/dist/utils/check-env.d.ts.map +1 -0
  20. package/dist/utils/check-env.js +35 -0
  21. package/dist/utils/check-env.unit.test.d.ts +2 -0
  22. package/dist/utils/check-env.unit.test.d.ts.map +1 -0
  23. package/dist/utils/check-env.unit.test.js +46 -0
  24. package/dist/utils/colorizeString.d.ts +4 -4
  25. package/dist/utils/colorizeString.d.ts.map +1 -1
  26. package/dist/utils/colorizeString.js +8 -6
  27. package/oclif.manifest.json +1 -1
  28. package/package.json +7 -7
  29. package/dist/commands/deployment-status.test.d.ts +0 -2
  30. package/dist/commands/deployment-status.test.d.ts.map +0 -1
  31. /package/dist/commands/{deployment-status.test.js → deployment-status.unit.test.js} +0 -0
  32. /package/dist/{commands → templates}/composite-operation-template.zip +0 -0
  33. /package/dist/{commands → templates}/connector-template.zip +0 -0
  34. /package/dist/{commands → templates}/http-operation-template.zip +0 -0
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/2.15.0 linux-x64 node-v18.19.0
22
+ @trayio/cdk-cli/2.16.0 linux-x64 node-v18.19.0
23
23
  $ tray-cdk --help [COMMAND]
24
24
  USAGE
25
25
  $ tray-cdk COMMAND
@@ -5,6 +5,7 @@ export default class AddOperation extends Command {
5
5
  operationName: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
6
6
  operationType: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
7
7
  };
8
+ private generator;
8
9
  run(): Promise<void>;
9
10
  }
10
11
  //# sourceMappingURL=add-operation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"add-operation.d.ts","sourceRoot":"","sources":["../../src/commands/add-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAqB5C,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAChD,MAAM,CAAC,WAAW,SAA2C;IAE7D,MAAM,CAAC,IAAI;;;MAYT;IAEI,GAAG;CAyDT"}
1
+ {"version":3,"file":"add-operation.d.ts","sourceRoot":"","sources":["../../src/commands/add-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAqB5C,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAChD,MAAM,CAAC,WAAW,SAA2C;IAE7D,MAAM,CAAC,IAAI;;;MAYT;IAEF,OAAO,CAAC,SAAS,CAAyB;IAEpC,GAAG;CAqDT"}
@@ -14,11 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const core_1 = require("@oclif/core");
16
16
  const inquirer_1 = __importDefault(require("inquirer"));
17
- const chalk_1 = __importDefault(require("chalk"));
18
17
  const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
19
18
  const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
20
19
  const path_1 = __importDefault(require("path"));
21
20
  const lodash_1 = require("lodash");
21
+ const colorizeString_1 = require("../utils/colorizeString");
22
22
  const isInSrcFolder = (currentDirectory) => {
23
23
  const { base } = path_1.default.parse(currentDirectory);
24
24
  return base === 'src';
@@ -31,6 +31,10 @@ const getConnectorName = (currentDirectory) => {
31
31
  return base;
32
32
  };
33
33
  class AddOperation extends core_1.Command {
34
+ constructor() {
35
+ super(...arguments);
36
+ this.generator = new NodeFsGenerator_1.NodeFsGenerator();
37
+ }
34
38
  run() {
35
39
  return __awaiter(this, void 0, void 0, function* () {
36
40
  const { args } = yield this.parse(AddOperation);
@@ -63,21 +67,21 @@ class AddOperation extends core_1.Command {
63
67
  const connectorNamePascalCase = StringExtensions_1.StringExtensions.pascalCase(getConnectorName(currentDirectory));
64
68
  const operationType = args.operationType || promptRes.operationType;
65
69
  const rootDir = __dirname;
70
+ const templateDir = path_1.default.join(rootDir, '..', 'templates');
66
71
  const templatePath = operationType === 'http'
67
- ? path_1.default.join(rootDir, 'http-operation-template.zip')
68
- : path_1.default.join(rootDir, 'composite-operation-template.zip');
69
- const generator = new NodeFsGenerator_1.NodeFsGenerator();
72
+ ? path_1.default.join(templateDir, 'http-operation-template.zip')
73
+ : path_1.default.join(templateDir, 'composite-operation-template.zip');
70
74
  const targetPath = isInSrcFolder(currentDirectory)
71
75
  ? currentDirectory
72
76
  : path_1.default.join(currentDirectory, 'src');
73
- yield generator.generate(templatePath, targetPath, {
77
+ yield this.generator.generate(templatePath, targetPath, {
74
78
  operationNameKebabCase,
75
79
  operationNamePascalCase,
76
80
  operationNameCamelCase,
77
81
  operationNameSnakeCase,
78
82
  connectorNamePascalCase,
79
83
  })();
80
- this.log(chalk_1.default.bold(chalk_1.default.green(`Success! Added operation: ${operationNameKebabCase}`)));
84
+ this.log((0, colorizeString_1.success)(`Success! Added operation: ${operationNameKebabCase}`));
81
85
  });
82
86
  }
83
87
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=add-operation.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-operation.unit.test.d.ts","sourceRoot":"","sources":["../../src/commands/add-operation.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,119 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const stdout_stderr_1 = require("stdout-stderr");
16
+ const inquirer_1 = __importDefault(require("inquirer"));
17
+ const add_operation_1 = __importDefault(require("./add-operation"));
18
+ jest.mock('inquirer', () => ({
19
+ prompt: jest.fn(),
20
+ registerPrompt: jest.requireActual('inquirer').registerPrompt,
21
+ }));
22
+ describe('AddOperation', () => {
23
+ let operationName = 'my-operation';
24
+ let operationType = 'http';
25
+ const mockInquirer = inquirer_1.default;
26
+ beforeAll(() => {
27
+ mockInquirer.prompt.mockResolvedValue({
28
+ shouldContinue: true,
29
+ operationName,
30
+ operationType,
31
+ });
32
+ });
33
+ beforeEach(() => { });
34
+ afterAll(() => {
35
+ jest.restoreAllMocks();
36
+ });
37
+ it('should prompt for operation name and type if not provided', () => __awaiter(void 0, void 0, void 0, function* () {
38
+ const addOperation = new add_operation_1.default([], {});
39
+ const mockGenerate = jest
40
+ .fn()
41
+ .mockImplementation(() => jest.fn().mockResolvedValue(true));
42
+ addOperation['generator'] = {
43
+ generate: mockGenerate,
44
+ };
45
+ stdout_stderr_1.stdout.start();
46
+ yield addOperation.run();
47
+ stdout_stderr_1.stdout.stop();
48
+ expect(stdout_stderr_1.stdout.output).toContain('Success! Added operation: my-operation');
49
+ expect(mockInquirer.prompt).toBeCalledWith([
50
+ {
51
+ name: 'operationName',
52
+ message: 'Operation name',
53
+ type: 'input',
54
+ when: true,
55
+ default: 'my-operation',
56
+ },
57
+ {
58
+ name: 'operationType',
59
+ message: 'Operation type',
60
+ type: 'list',
61
+ choices: [
62
+ { name: 'HTTP', value: 'http' },
63
+ { name: 'Composite', value: 'composite' },
64
+ ],
65
+ when: true,
66
+ default: 'http',
67
+ },
68
+ ]);
69
+ expect(mockGenerate).toBeCalledWith(expect.stringContaining('modules/cdk-cli/src/templates/http-operation-template.zip'), expect.stringContaining('/src'), {
70
+ connectorNamePascalCase: 'TrayTypescriptSdk',
71
+ operationNameCamelCase: 'myOperation',
72
+ operationNameKebabCase: 'my-operation',
73
+ operationNamePascalCase: 'MyOperation',
74
+ operationNameSnakeCase: 'my_operation',
75
+ });
76
+ }));
77
+ it('should not prompt for operation name and type if provided', () => __awaiter(void 0, void 0, void 0, function* () {
78
+ operationName = 'some-val';
79
+ operationType = 'http';
80
+ const addOperation = new add_operation_1.default([operationName, operationType], {});
81
+ const mockGenerate = jest
82
+ .fn()
83
+ .mockImplementation(() => jest.fn().mockResolvedValue(true));
84
+ addOperation['generator'] = {
85
+ generate: mockGenerate,
86
+ };
87
+ stdout_stderr_1.stdout.start();
88
+ yield addOperation.run();
89
+ stdout_stderr_1.stdout.stop();
90
+ expect(stdout_stderr_1.stdout.output).toContain('Success! Added operation: some-val');
91
+ expect(mockInquirer.prompt).toBeCalledWith([
92
+ {
93
+ name: 'operationName',
94
+ message: 'Operation name',
95
+ type: 'input',
96
+ when: false,
97
+ default: 'my-operation',
98
+ },
99
+ {
100
+ name: 'operationType',
101
+ message: 'Operation type',
102
+ type: 'list',
103
+ choices: [
104
+ { name: 'HTTP', value: 'http' },
105
+ { name: 'Composite', value: 'composite' },
106
+ ],
107
+ when: false,
108
+ default: 'http',
109
+ },
110
+ ]);
111
+ expect(mockGenerate).toBeCalledWith(expect.stringContaining('modules/cdk-cli/src/templates/http-operation-template.zip'), expect.stringContaining('/src'), {
112
+ connectorNamePascalCase: 'TrayTypescriptSdk',
113
+ operationNameCamelCase: 'someVal',
114
+ operationNameKebabCase: 'some-val',
115
+ operationNamePascalCase: 'SomeVal',
116
+ operationNameSnakeCase: 'some_val',
117
+ });
118
+ }));
119
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAUtC,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IACnD,MAAM,CAAC,WAAW,SAAiC;IAEnD,MAAM,CAAC,IAAI,KAAM;IAEjB,OAAO,CAAC,mBAAmB,CAKzB;IAEI,GAAG;CA2CT"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAM,MAAM,aAAa,CAAC;AAW1C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IACnD,MAAM,CAAC,WAAW,SAAiC;IAEnD,MAAM,CAAC,IAAI,KAAM;IAEjB,OAAO,CAAC,mBAAmB,CAKzB;IAEI,GAAG;CA+CT"}
@@ -36,13 +36,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const core_1 = require("@oclif/core");
39
- const chalk_1 = __importDefault(require("chalk"));
40
39
  const pathLib = __importStar(require("path"));
41
40
  const fse = __importStar(require("fs-extra"));
42
41
  const AxiosHttpClient_1 = require("@trayio/axios/http/AxiosHttpClient");
43
42
  const ConnectorDeploymentHttpClient_1 = require("@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient");
44
43
  const test_1 = __importDefault(require("./test"));
45
44
  const build_1 = __importDefault(require("./build"));
45
+ const colorizeString_1 = require("../utils/colorizeString");
46
+ const check_env_1 = require("../utils/check-env");
46
47
  class DeployConnector extends core_1.Command {
47
48
  constructor() {
48
49
  super(...arguments);
@@ -52,6 +53,7 @@ class DeployConnector extends core_1.Command {
52
53
  }
53
54
  run() {
54
55
  return __awaiter(this, void 0, void 0, function* () {
56
+ (0, check_env_1.checkEnv)();
55
57
  yield test_1.default.run([]);
56
58
  yield build_1.default.run([]);
57
59
  const currentDirectory = process.cwd();
@@ -69,14 +71,15 @@ class DeployConnector extends core_1.Command {
69
71
  connectorSourceCode: sourceCode,
70
72
  token: TRAY_API_TOKEN,
71
73
  };
72
- this.log('Connector Deploy Started');
74
+ core_1.ux.action.start('Starting Connector Deployment');
73
75
  const response = yield this.connectorDeployment.deployFromSourceCode(input);
76
+ core_1.ux.action.stop();
74
77
  if (response.isSuccess) {
75
- this.log(chalk_1.default.bold(chalk_1.default.green(`Connector Deploy Request Sent`)));
78
+ this.log((0, colorizeString_1.success)(`Connector Deploy Request Sent`));
76
79
  this.log(`Deployment [${response.value.id}] is in progress`);
77
80
  }
78
81
  if (response.isFailure) {
79
- this.log(chalk_1.default.bold(chalk_1.default.red(`Connector Deploy Failed`)));
82
+ this.log((0, colorizeString_1.error)(`Connector Deploy Failed`));
80
83
  this.log(response.error.message);
81
84
  }
82
85
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=deployment-status.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployment-status.unit.test.d.ts","sourceRoot":"","sources":["../../src/commands/deployment-status.unit.test.ts"],"names":[],"mappings":""}
@@ -7,6 +7,7 @@ export default class Init extends Command {
7
7
  static flags: {
8
8
  install: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
9
  };
10
+ private generator;
10
11
  run(): Promise<void>;
11
12
  }
12
13
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,aAAa,CAAC;AAUnD,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACxC,MAAM,CAAC,WAAW,SAAoC;IAEtD,MAAM,CAAC,IAAI;;MAMT;IAEF,MAAM,CAAC,KAAK;;MAKV;IAEI,GAAG;CAiDT"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAmB,MAAM,aAAa,CAAC;AAUvD,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACxC,MAAM,CAAC,WAAW,SAAoC;IAEtD,MAAM,CAAC,IAAI;;MAMT;IAEF,MAAM,CAAC,KAAK;;MAKV;IAEF,OAAO,CAAC,SAAS,CAAyB;IAEpC,GAAG;CAiDT"}
@@ -14,13 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const core_1 = require("@oclif/core");
16
16
  const inquirer_1 = __importDefault(require("inquirer"));
17
- const chalk_1 = __importDefault(require("chalk"));
18
17
  const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
19
18
  const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
20
19
  const path_1 = require("path");
21
20
  const lodash_1 = require("lodash");
22
21
  const child_process_1 = require("child_process");
22
+ const colorizeString_1 = require("../utils/colorizeString");
23
23
  class Init extends core_1.Command {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.generator = new NodeFsGenerator_1.NodeFsGenerator();
27
+ }
24
28
  run() {
25
29
  return __awaiter(this, void 0, void 0, function* () {
26
30
  const { args, flags } = yield this.parse(Init);
@@ -38,21 +42,22 @@ class Init extends core_1.Command {
38
42
  const connectorNamePascalCase = StringExtensions_1.StringExtensions.pascalCase(connectorNameKebabCase);
39
43
  const connectorNameCamelCase = (0, lodash_1.camelCase)(connectorNameKebabCase);
40
44
  const rootDir = __dirname;
41
- const templatePath = (0, path_1.join)(rootDir, 'connector-template.zip');
42
- const generator = new NodeFsGenerator_1.NodeFsGenerator();
43
- yield generator.generate(templatePath, process.cwd(), {
45
+ const templateDir = (0, path_1.join)(rootDir, '..', 'templates');
46
+ const templatePath = (0, path_1.join)(templateDir, 'connector-template.zip');
47
+ yield this.generator.generate(templatePath, process.cwd(), {
44
48
  connectorNameKebabCase,
45
49
  connectorNameTitleCase,
46
50
  connectorNamePascalCase,
47
51
  connectorNameCamelCase,
48
52
  })();
49
- this.log(chalk_1.default.bold(chalk_1.default.green(`Success! Added ${connectorNameKebabCase}`)));
53
+ this.log((0, colorizeString_1.success)(`Success! Added ${connectorNameKebabCase}`));
50
54
  if (flags.install) {
51
55
  try {
52
- this.log(chalk_1.default.bold(chalk_1.default.gray('Running npm install...')));
56
+ core_1.ux.action.start('Installing dependencies');
53
57
  (0, child_process_1.execSync)(`cd ${connectorNameKebabCase} && npm install`, {
54
58
  stdio: 'inherit',
55
59
  });
60
+ core_1.ux.action.stop();
56
61
  }
57
62
  catch (error) {
58
63
  if (error instanceof Error) {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=init.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.unit.test.d.ts","sourceRoot":"","sources":["../../src/commands/init.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,127 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const stdout_stderr_1 = require("stdout-stderr");
16
+ const inquirer_1 = __importDefault(require("inquirer"));
17
+ const child_process_1 = require("child_process");
18
+ const init_1 = __importDefault(require("./init"));
19
+ jest.mock('inquirer', () => ({
20
+ prompt: jest.fn(),
21
+ registerPrompt: jest.requireActual('inquirer').registerPrompt,
22
+ }));
23
+ jest.mock('child_process', () => (Object.assign(Object.assign({}, jest.requireActual('child_process')), { execSync: jest.fn() })));
24
+ describe('Init', () => {
25
+ let connectorName = 'my-test-connector';
26
+ const mockInquirer = inquirer_1.default;
27
+ beforeAll(() => {
28
+ mockInquirer.prompt.mockResolvedValue({
29
+ shouldContinue: true,
30
+ connectorName,
31
+ });
32
+ });
33
+ afterAll(() => {
34
+ jest.restoreAllMocks();
35
+ });
36
+ it('should prompt for connector name if not provided', () => __awaiter(void 0, void 0, void 0, function* () {
37
+ const init = new init_1.default([], {});
38
+ const mockGenerate = jest
39
+ .fn()
40
+ .mockImplementation(() => jest.fn().mockResolvedValue(true));
41
+ init['generator'] = {
42
+ generate: mockGenerate,
43
+ };
44
+ stdout_stderr_1.stdout.start();
45
+ yield init.run();
46
+ stdout_stderr_1.stdout.stop();
47
+ expect(stdout_stderr_1.stdout.output).toContain('Success! Added my-test-connector');
48
+ expect(mockInquirer.prompt).toBeCalledWith([
49
+ {
50
+ name: 'connectorName',
51
+ message: 'Connector directory name to generate template files',
52
+ type: 'input',
53
+ when: true,
54
+ default: 'my-connector',
55
+ },
56
+ ]);
57
+ expect(mockGenerate).toBeCalledWith(expect.stringContaining('modules/cdk-cli/src/templates/connector-template.zip'), process.cwd(), {
58
+ connectorNameCamelCase: 'myTestConnector',
59
+ connectorNameKebabCase: 'my-test-connector',
60
+ connectorNamePascalCase: 'MyTestConnector',
61
+ connectorNameTitleCase: 'My test connector',
62
+ });
63
+ expect(child_process_1.execSync).not.toBeCalled();
64
+ }));
65
+ it('should not prompt for connector name if provided', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ connectorName = 'my-new-connector';
67
+ const init = new init_1.default([connectorName], {});
68
+ const mockGenerate = jest
69
+ .fn()
70
+ .mockImplementation(() => jest.fn().mockResolvedValue(true));
71
+ init['generator'] = {
72
+ generate: mockGenerate,
73
+ };
74
+ stdout_stderr_1.stdout.start();
75
+ yield init.run();
76
+ stdout_stderr_1.stdout.stop();
77
+ expect(stdout_stderr_1.stdout.output).toContain('Success! Added my-new-connector');
78
+ expect(mockInquirer.prompt).toBeCalledWith([
79
+ {
80
+ name: 'connectorName',
81
+ message: 'Connector directory name to generate template files',
82
+ type: 'input',
83
+ when: false,
84
+ default: 'my-connector',
85
+ },
86
+ ]);
87
+ expect(mockGenerate).toBeCalledWith(expect.stringContaining('modules/cdk-cli/src/templates/connector-template.zip'), process.cwd(), {
88
+ connectorNameCamelCase: 'myNewConnector',
89
+ connectorNameKebabCase: 'my-new-connector',
90
+ connectorNamePascalCase: 'MyNewConnector',
91
+ connectorNameTitleCase: 'My new connector',
92
+ });
93
+ expect(child_process_1.execSync).not.toBeCalled();
94
+ }));
95
+ it('should run npm install if "-i" install flag is passed', () => __awaiter(void 0, void 0, void 0, function* () {
96
+ connectorName = 'my-install-connector';
97
+ const init = new init_1.default([connectorName, '-i'], {});
98
+ const mockGenerate = jest
99
+ .fn()
100
+ .mockImplementation(() => jest.fn().mockResolvedValue(true));
101
+ init['generator'] = {
102
+ generate: mockGenerate,
103
+ };
104
+ stdout_stderr_1.stdout.start();
105
+ yield init.run();
106
+ stdout_stderr_1.stdout.stop();
107
+ expect(stdout_stderr_1.stdout.output).toContain('Success! Added my-install-connector');
108
+ expect(mockInquirer.prompt).toBeCalledWith([
109
+ {
110
+ name: 'connectorName',
111
+ message: 'Connector directory name to generate template files',
112
+ type: 'input',
113
+ when: false,
114
+ default: 'my-connector',
115
+ },
116
+ ]);
117
+ expect(mockGenerate).toBeCalledWith(expect.stringContaining('modules/cdk-cli/src/templates/connector-template.zip'), process.cwd(), {
118
+ connectorNameCamelCase: 'myInstallConnector',
119
+ connectorNameKebabCase: 'my-install-connector',
120
+ connectorNamePascalCase: 'MyInstallConnector',
121
+ connectorNameTitleCase: 'My install connector',
122
+ });
123
+ expect(child_process_1.execSync).toBeCalledWith(`cd ${connectorName} && npm install`, {
124
+ stdio: 'inherit',
125
+ });
126
+ }));
127
+ });
@@ -0,0 +1,2 @@
1
+ export declare const checkEnv: () => void;
2
+ //# sourceMappingURL=check-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-env.d.ts","sourceRoot":"","sources":["../../src/utils/check-env.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,YAIpB,CAAC"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkEnv = void 0;
4
+ const checkEnv = () => {
5
+ checkMissingEnv();
6
+ isApiUrlValid();
7
+ isValidApiToken();
8
+ };
9
+ exports.checkEnv = checkEnv;
10
+ const checkMissingEnv = () => {
11
+ if (!process.env.TRAY_API_URL) {
12
+ throw new Error('required env TRAY_API_URL is not set');
13
+ }
14
+ if (!process.env.TRAY_API_TOKEN) {
15
+ throw new Error('required env TRAY_API_TOKEN is not set');
16
+ }
17
+ };
18
+ const isApiUrlValid = () => {
19
+ const apiUrl = process.env.TRAY_API_URL;
20
+ const validApiUrlRegex = /^https:\/\/api\.(?:ap1\.|eu1\.|staging\.)?tray\.io$/;
21
+ if (!validApiUrlRegex.test(apiUrl)) {
22
+ throw new Error(`TRAY_API_URL is invalid. It should be one of the following: https://api.tray.io, https://api.ap1.tray.io, https://api.eu1.tray.io`);
23
+ }
24
+ };
25
+ const isValidApiToken = () => {
26
+ let apiToken = process.env.TRAY_API_TOKEN;
27
+ if (apiToken.includes('Bearer ') || apiToken.includes('bearer ')) {
28
+ apiToken = apiToken.replace(/Bearer |bearer /, '');
29
+ process.env.TRAY_API_TOKEN = apiToken;
30
+ }
31
+ const validApiTokenRegex = /^.{36,}$/; // Token length is atleast 36 characters
32
+ if (!validApiTokenRegex.test(apiToken)) {
33
+ throw new Error(`TRAY_API_TOKEN is in a invalid format.`);
34
+ }
35
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=check-env.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-env.unit.test.d.ts","sourceRoot":"","sources":["../../src/utils/check-env.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const check_env_1 = require("./check-env");
4
+ describe('checkEnv', () => {
5
+ const subject = check_env_1.checkEnv;
6
+ const { env } = process;
7
+ afterEach(() => {
8
+ process.env = env;
9
+ });
10
+ it('should throw an error if TRAY_API_URL is not set', () => {
11
+ expect(() => subject()).toThrowError('required env TRAY_API_URL is not set');
12
+ });
13
+ it('should throw an error if TRAY_API_TOKEN is not set', () => {
14
+ process.env = { TRAY_API_URL: 'https://api.tray.io' };
15
+ expect(() => subject()).toThrowError('required env TRAY_API_TOKEN is not set');
16
+ });
17
+ it('should throw an error if TRAY_API_URL is invalid', () => {
18
+ process.env = {
19
+ TRAY_API_URL: 'https://api.tray.io/invalid',
20
+ TRAY_API_TOKEN: 'random',
21
+ };
22
+ expect(() => subject()).toThrowError('TRAY_API_URL is invalid. It should be one of the following: https://api.tray.io, https://api.ap1.tray.io, https://api.eu1.tray.io');
23
+ });
24
+ it('should remove bearer prefix if TRAY_API_TOKEN contains Bearer prefix', () => {
25
+ process.env = {
26
+ TRAY_API_URL: 'https://api.tray.io',
27
+ TRAY_API_TOKEN: 'Bearer 1234567890123456789012345678901234567890123456789012345678901234',
28
+ };
29
+ subject();
30
+ expect(process.env.TRAY_API_TOKEN).toEqual('1234567890123456789012345678901234567890123456789012345678901234');
31
+ });
32
+ it('should throw an error if TRAY_API_TOKEN is in an invalid format', () => {
33
+ process.env = {
34
+ TRAY_API_URL: 'https://api.tray.io',
35
+ TRAY_API_TOKEN: '123',
36
+ };
37
+ expect(() => subject()).toThrowError('TRAY_API_TOKEN is in a invalid format.');
38
+ });
39
+ it('should not throw an error if TRAY_API_URL and TRAY_API_TOKEN are valid', () => {
40
+ process.env = {
41
+ TRAY_API_URL: 'https://api.tray.io',
42
+ TRAY_API_TOKEN: '1234567890123456789012345678901234567890123456789012345678901234',
43
+ };
44
+ expect(() => subject()).not.toThrowError();
45
+ });
46
+ });
@@ -1,5 +1,5 @@
1
- export declare const success: (message: string) => any;
2
- export declare const error: (message: string) => any;
3
- export declare const warning: (message: string) => any;
4
- export declare const info: (message: string) => any;
1
+ export declare const success: (message: string) => string;
2
+ export declare const error: (message: string) => string;
3
+ export declare const warning: (message: string) => string;
4
+ export declare const info: (message: string) => string;
5
5
  //# sourceMappingURL=colorizeString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"colorizeString.d.ts","sourceRoot":"","sources":["../../src/utils/colorizeString.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,YAAa,MAAM,QAAqC,CAAC;AAE7E,eAAO,MAAM,KAAK,YAAa,MAAM,QAAmC,CAAC;AAEzE,eAAO,MAAM,OAAO,YAAa,MAAM,QAAsC,CAAC;AAE9E,eAAO,MAAM,IAAI,YAAa,MAAM,QAAoC,CAAC"}
1
+ {"version":3,"file":"colorizeString.d.ts","sourceRoot":"","sources":["../../src/utils/colorizeString.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,YAAa,MAAM,WAAqC,CAAC;AAE7E,eAAO,MAAM,KAAK,YAAa,MAAM,WAAmC,CAAC;AAEzE,eAAO,MAAM,OAAO,YAAa,MAAM,WAAsC,CAAC;AAE9E,eAAO,MAAM,IAAI,YAAa,MAAM,WAAoC,CAAC"}
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.info = exports.warning = exports.error = exports.success = void 0;
4
- // using `import chalk from 'chalk'` will break the tests due to chalk being undefined in the jest context
5
- const chalk = require('chalk');
6
- const success = (message) => chalk.bold(chalk.green(message));
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const success = (message) => chalk_1.default.bold(chalk_1.default.green(message));
7
9
  exports.success = success;
8
- const error = (message) => chalk.bold(chalk.red(message));
10
+ const error = (message) => chalk_1.default.bold(chalk_1.default.red(message));
9
11
  exports.error = error;
10
- const warning = (message) => chalk.bold(chalk.yellow(message));
12
+ const warning = (message) => chalk_1.default.bold(chalk_1.default.yellow(message));
11
13
  exports.warning = warning;
12
- const info = (message) => chalk.bold(chalk.blue(message));
14
+ const info = (message) => chalk_1.default.bold(chalk_1.default.blue(message));
13
15
  exports.info = info;
@@ -228,5 +228,5 @@
228
228
  ]
229
229
  }
230
230
  },
231
- "version": "2.15.0"
231
+ "version": "2.16.0"
232
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-cli",
3
- "version": "2.15.0",
3
+ "version": "2.16.0",
4
4
  "description": "A CLI for connector development",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -19,12 +19,12 @@
19
19
  "@oclif/plugin-help": "6.0.12",
20
20
  "@oclif/plugin-version": "2.0.11",
21
21
  "@oclif/test": "3.1.12",
22
- "@trayio/axios": "2.15.0",
23
- "@trayio/cdk-build": "2.15.0",
24
- "@trayio/commons": "2.15.0",
25
- "@trayio/generator": "2.15.0",
26
- "@trayio/tray-client": "2.15.0",
27
- "@trayio/tray-openapi": "2.15.0",
22
+ "@trayio/axios": "2.16.0",
23
+ "@trayio/cdk-build": "2.16.0",
24
+ "@trayio/commons": "2.16.0",
25
+ "@trayio/generator": "2.16.0",
26
+ "@trayio/tray-client": "2.16.0",
27
+ "@trayio/tray-openapi": "2.16.0",
28
28
  "@types/inquirer": "8.2.6",
29
29
  "chalk": "4.1.2",
30
30
  "inquirer": "8.2.5"
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=deployment-status.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deployment-status.test.d.ts","sourceRoot":"","sources":["../../src/commands/deployment-status.test.ts"],"names":[],"mappings":""}