@trayio/cdk-cli 0.0.3 → 0.0.5-beta
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/INTRODUCTION.md +54 -0
- package/LICENSE.txt +22 -0
- package/README.md +150 -46
- package/bin/dev +0 -0
- package/dist/commands/add-operation.d.ts +11 -0
- package/dist/commands/add-operation.d.ts.map +1 -0
- package/dist/commands/add-operation.js +102 -0
- package/dist/commands/add-operation.unit.test.d.ts +2 -0
- package/dist/commands/add-operation.unit.test.d.ts.map +1 -0
- package/dist/commands/add-operation.unit.test.js +119 -0
- package/dist/commands/build.d.ts +8 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +34 -0
- package/dist/commands/deploy.d.ts +8 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +90 -0
- package/dist/commands/deployment-status.d.ts +12 -0
- package/dist/commands/deployment-status.d.ts.map +1 -0
- package/dist/commands/deployment-status.js +78 -0
- package/dist/commands/deployment-status.unit.test.d.ts +2 -0
- package/dist/commands/deployment-status.unit.test.d.ts.map +1 -0
- package/dist/commands/deployment-status.unit.test.js +82 -0
- package/dist/commands/import-openapi-spec-tst.d.ts +10 -0
- package/dist/commands/import-openapi-spec-tst.d.ts.map +1 -0
- package/dist/commands/import-openapi-spec-tst.js +101 -0
- package/dist/commands/import-openapi-spec.d.ts +10 -0
- package/dist/commands/import-openapi-spec.d.ts.map +1 -0
- package/dist/commands/import-openapi-spec.js +101 -0
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +5 -0
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +85 -0
- package/dist/commands/init.unit.test.d.ts +2 -0
- package/dist/commands/init.unit.test.d.ts.map +1 -0
- package/dist/commands/init.unit.test.js +127 -0
- package/dist/commands/test.d.ts +12 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +55 -0
- package/dist/templates/composite-operation-template.zip +0 -0
- package/dist/templates/connector-template.zip +0 -0
- package/dist/templates/http-operation-template.zip +0 -0
- package/dist/utils/check-env.d.ts +2 -0
- package/dist/utils/check-env.d.ts.map +1 -0
- package/dist/utils/check-env.js +35 -0
- package/dist/utils/check-env.unit.test.d.ts +2 -0
- package/dist/utils/check-env.unit.test.d.ts.map +1 -0
- package/dist/utils/check-env.unit.test.js +46 -0
- package/dist/utils/colorizeString.d.ts +5 -0
- package/dist/utils/colorizeString.d.ts.map +1 -0
- package/dist/utils/colorizeString.js +15 -0
- package/oclif.manifest.json +243 -16
- package/package.json +68 -53
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const core_1 = require("@oclif/core");
|
|
39
|
+
const pathLib = __importStar(require("path"));
|
|
40
|
+
const fse = __importStar(require("fs-extra"));
|
|
41
|
+
const AxiosHttpClient_1 = require("@trayio/axios/http/AxiosHttpClient");
|
|
42
|
+
const ConnectorDeploymentHttpClient_1 = require("@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient");
|
|
43
|
+
const test_1 = __importDefault(require("./test"));
|
|
44
|
+
const build_1 = __importDefault(require("./build"));
|
|
45
|
+
const colorizeString_1 = require("../utils/colorizeString");
|
|
46
|
+
const check_env_1 = require("../utils/check-env");
|
|
47
|
+
class DeployConnector extends core_1.Command {
|
|
48
|
+
constructor() {
|
|
49
|
+
super(...arguments);
|
|
50
|
+
this.connectorDeployment = new ConnectorDeploymentHttpClient_1.ConnectorDeploymentHttpClient({
|
|
51
|
+
baseUrl: process.env.TRAY_API_URL,
|
|
52
|
+
}, new AxiosHttpClient_1.AxiosHttpClient());
|
|
53
|
+
}
|
|
54
|
+
run() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
(0, check_env_1.checkEnv)();
|
|
57
|
+
yield test_1.default.run([]);
|
|
58
|
+
yield build_1.default.run([]);
|
|
59
|
+
const currentDirectory = process.cwd();
|
|
60
|
+
const connectorZipPath = pathLib.join(currentDirectory, 'dist', 'connector.zip');
|
|
61
|
+
const TRAY_API_TOKEN = process.env.TRAY_API_TOKEN;
|
|
62
|
+
const zipFile = fse.readFileSync(connectorZipPath);
|
|
63
|
+
const sourceCode = Buffer.from(zipFile).toString('base64');
|
|
64
|
+
const connectorJsonPath = pathLib.join(currentDirectory, 'connector.json');
|
|
65
|
+
const connectorJson = fse.readJsonSync(connectorJsonPath);
|
|
66
|
+
const connectorName = connectorJson.name;
|
|
67
|
+
const connectorVersion = connectorJson.version;
|
|
68
|
+
const input = {
|
|
69
|
+
connectorName,
|
|
70
|
+
connectorVersion,
|
|
71
|
+
connectorSourceCode: sourceCode,
|
|
72
|
+
token: TRAY_API_TOKEN,
|
|
73
|
+
};
|
|
74
|
+
core_1.ux.action.start('Starting Connector Deployment');
|
|
75
|
+
const response = yield this.connectorDeployment.deployFromSourceCode(input);
|
|
76
|
+
core_1.ux.action.stop();
|
|
77
|
+
if (response.isSuccess) {
|
|
78
|
+
this.log((0, colorizeString_1.success)(`Connector Deploy Request Sent`));
|
|
79
|
+
this.log(`Deployment [${response.value.id}] is in progress`);
|
|
80
|
+
}
|
|
81
|
+
if (response.isFailure) {
|
|
82
|
+
this.log((0, colorizeString_1.error)(`Connector Deploy Failed`));
|
|
83
|
+
this.log(response.error.message);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
DeployConnector.description = 'Deploys a connector project';
|
|
89
|
+
DeployConnector.args = {};
|
|
90
|
+
exports.default = DeployConnector;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class GetDeploymentStatus extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
connectorName: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
connectorVersion: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
uuid: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
private connectorDeployment;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=deployment-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployment-status.d.ts","sourceRoot":"","sources":["../../src/commands/deployment-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,aAAa,CAAC;AAMhD,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,OAAO;IACvD,MAAM,CAAC,WAAW,SAAoD;IAEtE,MAAM,CAAC,IAAI;;;;MAiBT;IAEF,OAAO,CAAC,mBAAmB,CAKzB;IAEI,GAAG;CAuDT"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const core_1 = require("@oclif/core");
|
|
13
|
+
const AxiosHttpClient_1 = require("@trayio/axios/http/AxiosHttpClient");
|
|
14
|
+
const ConnectorDeploymentHttpClient_1 = require("@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient");
|
|
15
|
+
const ConnectorDeploymentApi_1 = require("@trayio/tray-api/connector/deployment/ConnectorDeploymentApi");
|
|
16
|
+
const colorizeString_1 = require("../utils/colorizeString");
|
|
17
|
+
class GetDeploymentStatus extends core_1.Command {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.connectorDeployment = new ConnectorDeploymentHttpClient_1.ConnectorDeploymentHttpClient({
|
|
21
|
+
baseUrl: process.env.TRAY_API_URL,
|
|
22
|
+
}, new AxiosHttpClient_1.AxiosHttpClient());
|
|
23
|
+
}
|
|
24
|
+
run() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { args } = yield this.parse(GetDeploymentStatus);
|
|
27
|
+
const TRAY_API_TOKEN = process.env.TRAY_API_TOKEN;
|
|
28
|
+
const input = {
|
|
29
|
+
connectorName: args.connectorName,
|
|
30
|
+
connectorVersion: args.connectorVersion,
|
|
31
|
+
id: args.uuid,
|
|
32
|
+
token: TRAY_API_TOKEN,
|
|
33
|
+
};
|
|
34
|
+
core_1.ux.action.start(`Checking the connector deployment status`);
|
|
35
|
+
const response = yield this.connectorDeployment.get(input);
|
|
36
|
+
core_1.ux.action.stop();
|
|
37
|
+
if (response.isSuccess) {
|
|
38
|
+
switch (response.value.deploymentStatus) {
|
|
39
|
+
case ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deploying:
|
|
40
|
+
this.log((0, colorizeString_1.info)(`Connector is currently being deployed, this could take a few minutes. Please check the connector status again later.`));
|
|
41
|
+
break;
|
|
42
|
+
case ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deployed:
|
|
43
|
+
this.log((0, colorizeString_1.success)(`Connector Deployed Successfully! 🎉 🎉 🎉`));
|
|
44
|
+
break;
|
|
45
|
+
case ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Failed:
|
|
46
|
+
this.log((0, colorizeString_1.error)(`Connector Deploy Failed, please try again or contact support`));
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
this.log((0, colorizeString_1.error)(`Connector Deploy Failed, please try again or contact support`));
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (response.isFailure) {
|
|
54
|
+
this.log((0, colorizeString_1.error)(`Connector Deploy Failed, please try again or contact support`));
|
|
55
|
+
this.log(response.error.message);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
GetDeploymentStatus.description = 'Retrieves the status of a connector deployment';
|
|
61
|
+
GetDeploymentStatus.args = {
|
|
62
|
+
connectorName: core_1.Args.string({
|
|
63
|
+
name: 'Connector Name',
|
|
64
|
+
required: true,
|
|
65
|
+
description: 'The name of the connector',
|
|
66
|
+
}),
|
|
67
|
+
connectorVersion: core_1.Args.string({
|
|
68
|
+
name: 'Connector Version',
|
|
69
|
+
required: true,
|
|
70
|
+
description: 'The version of the connector',
|
|
71
|
+
}),
|
|
72
|
+
uuid: core_1.Args.string({
|
|
73
|
+
name: 'Deployment UUID',
|
|
74
|
+
required: true,
|
|
75
|
+
description: 'The UUID of the deployment, this is included in the tray-cdk deploy output',
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
exports.default = GetDeploymentStatus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployment-status.unit.test.d.ts","sourceRoot":"","sources":["../../src/commands/deployment-status.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 ConnectorDeploymentApi_1 = require("@trayio/tray-api/connector/deployment/ConnectorDeploymentApi");
|
|
17
|
+
const ConnectorDeploymentHttpClient_1 = require("@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient");
|
|
18
|
+
const deployment_status_1 = __importDefault(require("./deployment-status"));
|
|
19
|
+
jest.mock('@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient', () => ({
|
|
20
|
+
ConnectorDeploymentHttpClient: jest.fn(),
|
|
21
|
+
}));
|
|
22
|
+
jest.mock('fs-extra', () => ({
|
|
23
|
+
readJsonSync: jest.fn().mockReturnValue({
|
|
24
|
+
name: 'connectorName',
|
|
25
|
+
version: '1.0',
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
describe('GetDeploymentStatus', () => {
|
|
29
|
+
let status;
|
|
30
|
+
let success = true;
|
|
31
|
+
let failure = false;
|
|
32
|
+
const connectorName = 'some-connector-name';
|
|
33
|
+
const connectorVersion = '1.0';
|
|
34
|
+
const uuid = 'test-uuid';
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
ConnectorDeploymentHttpClient_1.ConnectorDeploymentHttpClient.mockImplementation(() => ({
|
|
37
|
+
get: jest.fn().mockReturnValue(Object.assign(Object.assign(Object.assign({ isSuccess: success }, (success && {
|
|
38
|
+
value: {
|
|
39
|
+
deploymentStatus: status,
|
|
40
|
+
},
|
|
41
|
+
})), { isFailure: failure }), (failure && {
|
|
42
|
+
error: {
|
|
43
|
+
message: 'There was an error fetching deployment status',
|
|
44
|
+
},
|
|
45
|
+
}))),
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
48
|
+
afterAll(() => {
|
|
49
|
+
jest.clearAllMocks();
|
|
50
|
+
});
|
|
51
|
+
it('should log success message when connector is deployed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deployed;
|
|
53
|
+
stdout_stderr_1.stdout.start();
|
|
54
|
+
yield deployment_status_1.default.run([connectorName, connectorVersion, uuid]);
|
|
55
|
+
stdout_stderr_1.stdout.stop();
|
|
56
|
+
expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deployed Successfully!'));
|
|
57
|
+
}));
|
|
58
|
+
it('should log failed message when connector failed to deploy', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Failed;
|
|
60
|
+
stdout_stderr_1.stdout.start();
|
|
61
|
+
yield deployment_status_1.default.run([connectorName, connectorVersion, uuid]);
|
|
62
|
+
stdout_stderr_1.stdout.stop();
|
|
63
|
+
expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deploy Failed, please try again or contact support'));
|
|
64
|
+
}));
|
|
65
|
+
it('should log connector is still deploying message when deploying', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deploying;
|
|
67
|
+
stdout_stderr_1.stdout.start();
|
|
68
|
+
yield deployment_status_1.default.run([connectorName, connectorVersion, uuid]);
|
|
69
|
+
stdout_stderr_1.stdout.stop();
|
|
70
|
+
expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector is currently being deployed, this could take a few minutes. Please check the connector status again later.'));
|
|
71
|
+
}));
|
|
72
|
+
it('should log error messages when the request fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
success = false;
|
|
74
|
+
failure = true;
|
|
75
|
+
status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Failed;
|
|
76
|
+
stdout_stderr_1.stdout.start();
|
|
77
|
+
yield deployment_status_1.default.run([connectorName, connectorVersion, uuid]);
|
|
78
|
+
stdout_stderr_1.stdout.stop();
|
|
79
|
+
expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deploy Failed, please try again or contact support'));
|
|
80
|
+
expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('There was an error fetching deployment status'));
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class ImportOpenApiSpecTst extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
openApiSpec: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
6
|
+
connectorName: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=import-openapi-spec-tst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-openapi-spec-tst.d.ts","sourceRoot":"","sources":["../../src/commands/import-openapi-spec-tst.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAS5C,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,OAAO;IACxD,MAAM,CAAC,WAAW,SAC4D;IAE9E,MAAM,CAAC,IAAI;;;MAWT;IAEI,GAAG;CAiET"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const core_1 = require("@oclif/core");
|
|
39
|
+
const OpenApiSchemaImporter_1 = require("@trayio/tray-openapi/OpenApiSchemaImporter");
|
|
40
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
|
|
43
|
+
const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
|
|
44
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
45
|
+
const stream_1 = require("stream");
|
|
46
|
+
class ImportOpenApiSpecTst extends core_1.Command {
|
|
47
|
+
run() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { args } = yield this.parse(ImportOpenApiSpecTst);
|
|
50
|
+
const promptRes = yield inquirer_1.default.prompt([
|
|
51
|
+
{
|
|
52
|
+
name: 'openApiSpec',
|
|
53
|
+
message: 'OpenAPI specification file path',
|
|
54
|
+
type: 'input',
|
|
55
|
+
when: !args.openApiSpec,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'connectorName',
|
|
59
|
+
message: 'Connector name',
|
|
60
|
+
type: 'input',
|
|
61
|
+
when: !args.connectorName,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
const generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
65
|
+
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage(process.cwd());
|
|
66
|
+
const openApiSchemaImporter = new OpenApiSchemaImporter_1.OpenApiSchemaImporter(generator, fileStorage);
|
|
67
|
+
const openApiSpec = promptRes.openApiSpec || args.openApiSpec;
|
|
68
|
+
const connectorName = promptRes.connectorName || args.connectorName;
|
|
69
|
+
const result = yield openApiSchemaImporter.buildConnector(openApiSpec, connectorName)();
|
|
70
|
+
if (E.isLeft(result)) {
|
|
71
|
+
this.log(chalk_1.default.red(`Error occurred while importing connector: ${result.left.message}`));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.log(chalk_1.default.bold(chalk_1.default.green(`Success! Added connector: ${connectorName}`)));
|
|
75
|
+
this.log(chalk_1.default.bold.green(`Generated ${result.right.successes.length} Connector Operations`));
|
|
76
|
+
if (result.right.errors.length) {
|
|
77
|
+
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`));
|
|
78
|
+
yield fileStorage.write({
|
|
79
|
+
key: 'errors.json',
|
|
80
|
+
content: stream_1.Readable.from(JSON.stringify(result.right.errors)),
|
|
81
|
+
metadata: { name: 'errors.json', size: 0 },
|
|
82
|
+
})();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
ImportOpenApiSpecTst.description = 'Create a connector from an OpenAPI specification: Command is still in BETA';
|
|
89
|
+
ImportOpenApiSpecTst.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
|
+
exports.default = ImportOpenApiSpecTst;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class ImportOpenApiSpec extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
openApiSpec: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
6
|
+
connectorName: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=import-openapi-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-openapi-spec.d.ts","sourceRoot":"","sources":["../../src/commands/import-openapi-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAC;AAS5C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,OAAO;IACrD,MAAM,CAAC,WAAW,SAC4D;IAE9E,MAAM,CAAC,IAAI;;;MAWT;IAEI,GAAG;CAiET"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const core_1 = require("@oclif/core");
|
|
39
|
+
const OpenApiSchemaImporter_1 = require("@trayio/tray-openapi/OpenApiSchemaImporter");
|
|
40
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
|
|
43
|
+
const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
|
|
44
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
45
|
+
const stream_1 = require("stream");
|
|
46
|
+
class ImportOpenApiSpec extends core_1.Command {
|
|
47
|
+
run() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { args } = yield this.parse(ImportOpenApiSpec);
|
|
50
|
+
const promptRes = yield inquirer_1.default.prompt([
|
|
51
|
+
{
|
|
52
|
+
name: 'openApiSpec',
|
|
53
|
+
message: 'OpenAPI specification file path',
|
|
54
|
+
type: 'input',
|
|
55
|
+
when: !args.openApiSpec,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'connectorName',
|
|
59
|
+
message: 'Connector name',
|
|
60
|
+
type: 'input',
|
|
61
|
+
when: !args.connectorName,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
const generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
65
|
+
const fileStorage = new NodeFsFileStorage_1.NodeFsFileStorage(process.cwd());
|
|
66
|
+
const openApiSchemaImporter = new OpenApiSchemaImporter_1.OpenApiSchemaImporter(generator, fileStorage);
|
|
67
|
+
const openApiSpec = promptRes.openApiSpec || args.openApiSpec;
|
|
68
|
+
const connectorName = promptRes.connectorName || args.connectorName;
|
|
69
|
+
const result = yield openApiSchemaImporter.buildConnector(openApiSpec, connectorName)();
|
|
70
|
+
if (E.isLeft(result)) {
|
|
71
|
+
this.log(chalk_1.default.red(`Error occurred while importing connector: ${result.left.message}`));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.log(chalk_1.default.bold(chalk_1.default.green(`Success! Added connector: ${connectorName}`)));
|
|
75
|
+
this.log(chalk_1.default.bold.green(`Generated ${result.right.successes.length} Connector Operations`));
|
|
76
|
+
if (result.right.errors.length) {
|
|
77
|
+
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`));
|
|
78
|
+
yield fileStorage.write({
|
|
79
|
+
key: 'errors.json',
|
|
80
|
+
content: stream_1.Readable.from(JSON.stringify(result.right.errors)),
|
|
81
|
+
metadata: { name: 'errors.json', size: 0 },
|
|
82
|
+
})();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
ImportOpenApiSpec.description = 'Create a connector from an OpenAPI specification: Command is still in BETA';
|
|
89
|
+
ImportOpenApiSpec.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
|
+
exports.default = ImportOpenApiSpec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Init extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
connectorName: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static flags: {
|
|
8
|
+
install: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
private generator;
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 core_1 = require("@oclif/core");
|
|
16
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
+
const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
|
|
18
|
+
const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const lodash_1 = require("lodash");
|
|
21
|
+
const child_process_1 = require("child_process");
|
|
22
|
+
const colorizeString_1 = require("../utils/colorizeString");
|
|
23
|
+
class Init extends core_1.Command {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
27
|
+
}
|
|
28
|
+
run() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const { args, flags } = yield this.parse(Init);
|
|
31
|
+
const promptRes = yield inquirer_1.default.prompt([
|
|
32
|
+
{
|
|
33
|
+
name: 'connectorName',
|
|
34
|
+
message: 'Connector directory name to generate template files',
|
|
35
|
+
type: 'input',
|
|
36
|
+
when: !args.connectorName,
|
|
37
|
+
default: 'my-connector',
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
const connectorNameKebabCase = (0, lodash_1.kebabCase)(args.connectorName || promptRes.connectorName);
|
|
41
|
+
const connectorNameTitleCase = StringExtensions_1.StringExtensions.titleCase(connectorNameKebabCase);
|
|
42
|
+
const connectorNamePascalCase = StringExtensions_1.StringExtensions.pascalCase(connectorNameKebabCase);
|
|
43
|
+
const connectorNameCamelCase = (0, lodash_1.camelCase)(connectorNameKebabCase);
|
|
44
|
+
const rootDir = __dirname;
|
|
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(), {
|
|
48
|
+
connectorNameKebabCase,
|
|
49
|
+
connectorNameTitleCase,
|
|
50
|
+
connectorNamePascalCase,
|
|
51
|
+
connectorNameCamelCase,
|
|
52
|
+
})();
|
|
53
|
+
this.log((0, colorizeString_1.success)(`Success! Added ${connectorNameKebabCase}`));
|
|
54
|
+
if (flags.install) {
|
|
55
|
+
try {
|
|
56
|
+
core_1.ux.action.start('Installing dependencies');
|
|
57
|
+
(0, child_process_1.execSync)(`cd ${connectorNameKebabCase} && npm install`, {
|
|
58
|
+
stdio: 'inherit',
|
|
59
|
+
});
|
|
60
|
+
core_1.ux.action.stop();
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof Error) {
|
|
64
|
+
this.error(new Error(error.message));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
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
|
+
exports.default = Init;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.unit.test.d.ts","sourceRoot":"","sources":["../../src/commands/init.unit.test.ts"],"names":[],"mappings":""}
|