@contrail/cli 2.1.20 → 2.1.22
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 +311 -105
- package/dist/api/apps.js +15 -15
- package/dist/api/event-workflow-action-definition.d.ts +1 -1
- package/dist/api/event-workflow-action-definition.js +1 -1
- package/dist/api/event-workflow-template-definition.d.ts +4 -3
- package/dist/api/event-workflow-templates.d.ts +5 -4
- package/dist/api/event-workflow-templates.js +2 -2
- package/dist/api/types.d.ts +10 -10
- package/dist/api/users.js +4 -2
- package/dist/auth/login.js +12 -14
- package/dist/commands/app/create.d.ts +2 -2
- package/dist/commands/app/create.js +15 -10
- package/dist/commands/app/delete.d.ts +2 -2
- package/dist/commands/app/delete.js +4 -2
- package/dist/commands/app/getApiKey.d.ts +2 -2
- package/dist/commands/app/getApiKey.js +17 -11
- package/dist/commands/app/install.d.ts +2 -2
- package/dist/commands/app/install.js +42 -25
- package/dist/commands/app/publish.d.ts +2 -2
- package/dist/commands/app/publish.js +26 -11
- package/dist/commands/app/uninstall.d.ts +2 -2
- package/dist/commands/app/uninstall.js +20 -11
- package/dist/commands/app/upgrade.d.ts +2 -2
- package/dist/commands/app/upgrade.js +46 -23
- package/dist/commands/basecommand.d.ts +7 -0
- package/dist/commands/basecommand.js +29 -0
- package/dist/commands/colors/deleteAll.d.ts +2 -2
- package/dist/commands/colors/deleteAll.js +8 -5
- package/dist/commands/colors/load.d.ts +2 -2
- package/dist/commands/colors/load.js +10 -7
- package/dist/commands/config/list.d.ts +2 -2
- package/dist/commands/config/list.js +4 -2
- package/dist/commands/config/remove.d.ts +2 -2
- package/dist/commands/config/remove.js +4 -2
- package/dist/commands/config/set.d.ts +3 -2
- package/dist/commands/config/set.js +21 -7
- package/dist/commands/groups/export.d.ts +2 -2
- package/dist/commands/groups/export.js +20 -8
- package/dist/commands/groups/upload.d.ts +3 -3
- package/dist/commands/groups/upload.js +44 -32
- package/dist/commands/instance/export.d.ts +2 -2
- package/dist/commands/instance/export.js +15 -3
- package/dist/commands/instance/import.d.ts +2 -2
- package/dist/commands/instance/import.js +9 -2
- package/dist/commands/loader-process/load.d.ts +2 -2
- package/dist/commands/loader-process/load.js +13 -6
- package/dist/commands/loader-process/upload-and-load.d.ts +2 -2
- package/dist/commands/loader-process/upload-and-load.js +18 -7
- package/dist/commands/projects/export.d.ts +2 -2
- package/dist/commands/projects/export.js +4 -2
- package/dist/commands/projects/list.d.ts +2 -2
- package/dist/commands/projects/list.js +6 -4
- package/dist/commands/projects/load.d.ts +2 -2
- package/dist/commands/projects/load.js +16 -8
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +2 -2
- package/dist/commands/types/exportOptionSetHierarchies.js +15 -12
- package/dist/commands/types/getAll.d.ts +2 -2
- package/dist/commands/types/getAll.js +107 -76
- package/dist/commands/types/loadAll.d.ts +2 -2
- package/dist/commands/types/loadAll.js +12 -4
- package/dist/commands/types/mergeOptionSets.d.ts +2 -2
- package/dist/commands/types/mergeOptionSets.js +13 -10
- package/dist/commands/types/mergeTypeProperties.d.ts +2 -2
- package/dist/commands/types/mergeTypeProperties.js +12 -9
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +19 -15
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.js +102 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsLocalFiles.js +21 -21
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +17 -18
- package/dist/commands/types/parseTypesFromFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromFiles.js +14 -8
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromLocalFiles.js +10 -7
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +11 -8
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +11 -8
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +2 -2
- package/dist/commands/types/uploadOptionSetHierarchies.js +44 -32
- package/dist/commands/types/uploadOptionSets.d.ts +2 -2
- package/dist/commands/types/uploadOptionSets.js +21 -13
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +2 -2
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.js +26 -19
- package/dist/commands/types/uploadRuleSets.d.ts +2 -2
- package/dist/commands/types/uploadRuleSets.js +34 -26
- package/dist/commands/types/uploadTypePolicies.d.ts +2 -2
- package/dist/commands/types/uploadTypePolicies.js +37 -29
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +2 -2
- package/dist/commands/types/uploadTypePropertyPolicies.js +38 -30
- package/dist/commands/types/uploadTypes.d.ts +2 -2
- package/dist/commands/types/uploadTypes.js +10 -4
- package/dist/commands/types/uploadUsageInfo.d.ts +2 -2
- package/dist/commands/types/uploadUsageInfo.js +32 -24
- package/dist/commands/users/export.d.ts +2 -2
- package/dist/commands/users/export.js +15 -4
- package/dist/commands/users/upload.d.ts +2 -2
- package/dist/commands/users/upload.js +6 -4
- package/dist/commands/webhooks/create.d.ts +2 -2
- package/dist/commands/webhooks/create.js +8 -6
- package/dist/commands/webhooks/delete.d.ts +2 -2
- package/dist/commands/webhooks/delete.js +8 -5
- package/dist/commands/webhooks/getWebhookTrigger.d.ts +2 -2
- package/dist/commands/webhooks/getWebhookTrigger.js +10 -9
- package/dist/commands/webhooks/list.d.ts +2 -2
- package/dist/commands/webhooks/list.js +8 -6
- package/dist/commands/workflow-template-definitions/install.d.ts +2 -2
- package/dist/commands/workflow-template-definitions/install.js +4 -2
- package/dist/commands/workflow-template-definitions/list.d.ts +2 -2
- package/dist/commands/workflow-template-definitions/list.js +4 -2
- package/dist/commands/workflow-templates/delete.d.ts +2 -2
- package/dist/commands/workflow-templates/delete.js +4 -2
- package/dist/commands/workflow-templates/export.d.ts +2 -2
- package/dist/commands/workflow-templates/export.js +19 -17
- package/dist/commands/workflow-templates/list.d.ts +2 -2
- package/dist/commands/workflow-templates/list.js +4 -2
- package/dist/commands/workflow-templates/load.d.ts +2 -2
- package/dist/commands/workflow-templates/load.js +8 -3
- package/dist/common.d.ts +4 -1
- package/dist/common.js +10 -1
- package/dist/helpers/app/actions-deployer.d.ts +2 -2
- package/dist/helpers/app/actions-deployer.js +12 -7
- package/dist/helpers/app/app-deployer.d.ts +1 -1
- package/dist/helpers/app/app-deployer.js +70 -52
- package/dist/helpers/app/app-template-parsers.js +3 -1
- package/dist/helpers/app/load-app-config.d.ts +2 -1
- package/dist/helpers/app/load-app-config.js +2 -2
- package/dist/helpers/app/setup-template.js +4 -3
- package/dist/helpers/colors/helpers.d.ts +10 -2
- package/dist/helpers/colors/helpers.js +11 -10
- package/dist/helpers/config/config.js +15 -10
- package/dist/helpers/file-helpers.js +7 -4
- package/dist/helpers/loader-process/helpers.js +14 -13
- package/dist/helpers/projects/helpers.d.ts +2 -1
- package/dist/helpers/projects/helpers.js +16 -15
- package/dist/helpers/types/csv-parser.js +17 -14
- package/dist/helpers/types/type-extractor.d.ts +1 -1
- package/dist/helpers/types/type-extractor.js +3 -2
- package/dist/helpers/types/type-parser.js +22 -21
- package/dist/helpers/types/type-uploader.js +19 -15
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.d.ts +1 -1
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +47 -28
- package/dist/helpers/workflow-templates/helper.d.ts +3 -3
- package/dist/helpers/workflow-templates/helper.js +33 -23
- package/dist/interface-converters.spec.js +15 -15
- package/dist/interfaces.d.ts +6 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.js +32 -0
- package/dist/templates/typescript/src/actions/logItem.ts +9 -4
- package/dist/templates/typescript/src/main.ts +13 -8
- package/oclif.manifest.json +861 -31
- package/package.json +10 -7
|
@@ -11,8 +11,9 @@ const workflow_template_definition_deployer_1 = require("../workflow-template-de
|
|
|
11
11
|
const apps_1 = require("../../api/apps");
|
|
12
12
|
const zip_a_folder_1 = require("zip-a-folder");
|
|
13
13
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
15
|
+
const child_process_1 = tslib_1.__importDefault(require("child_process"));
|
|
16
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
16
17
|
class AppDeployer {
|
|
17
18
|
constructor(debug = false, dryRun = false) {
|
|
18
19
|
this.debug = debug;
|
|
@@ -22,15 +23,15 @@ class AppDeployer {
|
|
|
22
23
|
async deploy(appDeclaration) {
|
|
23
24
|
let app = await this.getExistingApp(appDeclaration);
|
|
24
25
|
if (!app) {
|
|
25
|
-
|
|
26
|
+
logger_1.default.info('%s Creating new app.', chalk_1.default.yellow.bold('APP'));
|
|
26
27
|
app = await this.createNewApp(appDeclaration);
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
|
-
|
|
30
|
+
logger_1.default.info('%s Updating existing app.', chalk_1.default.yellow.bold('APP'));
|
|
30
31
|
app = await this.updateExistingApp(appDeclaration, app);
|
|
31
32
|
}
|
|
32
33
|
if (this.dryRun) {
|
|
33
|
-
|
|
34
|
+
logger_1.default.info('Dry run, skipping action and workflow template definition deployment.');
|
|
34
35
|
return {};
|
|
35
36
|
}
|
|
36
37
|
await new actions_deployer_1.ActionsDeployer().deployActions(appDeclaration, app);
|
|
@@ -40,7 +41,7 @@ class AppDeployer {
|
|
|
40
41
|
async getExistingApp(appDeclaration) {
|
|
41
42
|
const orgId = auth_1.Auth.config.orgId;
|
|
42
43
|
const apps = await (0, apps_1.getAvailableApps)({ orgId });
|
|
43
|
-
return apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
44
|
+
return apps.find((app) => app.identifier === appDeclaration.appIdentifier);
|
|
44
45
|
}
|
|
45
46
|
async createNewApp(appDeclaration) {
|
|
46
47
|
var _a;
|
|
@@ -48,7 +49,9 @@ class AppDeployer {
|
|
|
48
49
|
if (appDeclaration === null || appDeclaration === void 0 ? void 0 : appDeclaration.appConfiguration) {
|
|
49
50
|
configProperties = app_template_parsers_1.ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration);
|
|
50
51
|
}
|
|
51
|
-
const externalLinks = appDeclaration.externalLinks
|
|
52
|
+
const externalLinks = appDeclaration.externalLinks
|
|
53
|
+
? app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks(appDeclaration.externalLinks)
|
|
54
|
+
: [];
|
|
52
55
|
let triggerKeyDefinitions;
|
|
53
56
|
if (appDeclaration === null || appDeclaration === void 0 ? void 0 : appDeclaration.triggers) {
|
|
54
57
|
triggerKeyDefinitions = app_template_parsers_1.TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration);
|
|
@@ -70,17 +73,18 @@ class AppDeployer {
|
|
|
70
73
|
frameworkVersion: 2,
|
|
71
74
|
};
|
|
72
75
|
if (this.dryRun) {
|
|
73
|
-
|
|
76
|
+
logger_1.default.info('Dry run, not creating app');
|
|
74
77
|
return {};
|
|
75
78
|
}
|
|
76
79
|
let app = await new sdk_1.Entities().create({ entityName: 'app', object: newApp });
|
|
77
|
-
|
|
80
|
+
logger_1.default.info(`%s Created new app: ${app.name}`, chalk_1.default.yellow.bold('APP'));
|
|
78
81
|
const isDocker = Object.hasOwnProperty.call(appDeclaration, 'dockerImageRef');
|
|
79
|
-
if (!isDocker) {
|
|
82
|
+
if (!isDocker) {
|
|
83
|
+
// this is the expected default behavior
|
|
80
84
|
const appCodePackage = await createNodePackage(appDeclaration.appIdentifier, this.debug, this.dryRun);
|
|
81
85
|
app.appCodePackageId = appCodePackage.id;
|
|
82
86
|
app = await new sdk_1.Entities().update({ entityName: 'app', id: app.id, object: app });
|
|
83
|
-
|
|
87
|
+
logger_1.default.info(`%s Updated app with code package: ${app.name}`, chalk_1.default.yellow.bold('APP'));
|
|
84
88
|
}
|
|
85
89
|
return app;
|
|
86
90
|
}
|
|
@@ -97,11 +101,14 @@ class AppDeployer {
|
|
|
97
101
|
// does appDeclaration have dockerImageRef
|
|
98
102
|
const isDocker = Object.hasOwnProperty.call(appDeclaration, 'dockerImageRef');
|
|
99
103
|
let appCodePackageId;
|
|
100
|
-
if (!isDocker) {
|
|
104
|
+
if (!isDocker) {
|
|
105
|
+
// this is the expected default behavior
|
|
101
106
|
const appCodePackage = await createNodePackage(appDeclaration.appIdentifier, this.debug, this.dryRun);
|
|
102
107
|
appCodePackageId = appCodePackage.id;
|
|
103
108
|
}
|
|
104
|
-
const externalLinks = appDeclaration.externalLinks
|
|
109
|
+
const externalLinks = appDeclaration.externalLinks
|
|
110
|
+
? app_template_parsers_1.ExternalLinkParser.validateAndGetExternalLinks(appDeclaration.externalLinks)
|
|
111
|
+
: [];
|
|
105
112
|
const updates = {
|
|
106
113
|
name: appDeclaration.appName,
|
|
107
114
|
public: appDeclaration.visibility === 'public',
|
|
@@ -119,11 +126,15 @@ class AppDeployer {
|
|
|
119
126
|
frameworkVersion: 2,
|
|
120
127
|
};
|
|
121
128
|
if (this.dryRun) {
|
|
122
|
-
|
|
129
|
+
logger_1.default.info('Dry run, not creating app');
|
|
123
130
|
return {};
|
|
124
131
|
}
|
|
125
|
-
const app = await new sdk_1.Entities().update({
|
|
126
|
-
|
|
132
|
+
const app = await new sdk_1.Entities().update({
|
|
133
|
+
entityName: 'app',
|
|
134
|
+
id: existingApp.id,
|
|
135
|
+
object: updates,
|
|
136
|
+
});
|
|
137
|
+
logger_1.default.info(`%s Updated app: ${app.name}`, chalk_1.default.yellow.bold('APP'));
|
|
127
138
|
return app;
|
|
128
139
|
}
|
|
129
140
|
async remove(appDeclaration) {
|
|
@@ -131,11 +142,11 @@ class AppDeployer {
|
|
|
131
142
|
if (app) {
|
|
132
143
|
const actions = await (0, actions_deployer_1.getActionsForAppVersion)(app);
|
|
133
144
|
for (const action of actions) {
|
|
134
|
-
|
|
145
|
+
logger_1.default.info(`%s Deleting action: ${action.identifier}`, chalk_1.default.yellow.bold('APP'));
|
|
135
146
|
await (0, actions_deployer_1.deleteAction)(action.id);
|
|
136
147
|
}
|
|
137
148
|
app = await new sdk_1.Entities().delete({ entityName: 'app', id: app.id });
|
|
138
|
-
|
|
149
|
+
logger_1.default.info(`%s Deleted app: ${app.name}`, chalk_1.default.yellow.bold('APP'));
|
|
139
150
|
}
|
|
140
151
|
else {
|
|
141
152
|
throw new Error('App not found.');
|
|
@@ -149,51 +160,54 @@ async function createNodePackage(appIdentifier, debug, dryRun) {
|
|
|
149
160
|
const entitiesClient = new sdk_1.Entities();
|
|
150
161
|
try {
|
|
151
162
|
// clear and make temp directory
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
fs_1.default.rmSync('tmp/', { recursive: true, force: true });
|
|
164
|
+
fs_1.default.cpSync('package.json', 'tmp/package.json');
|
|
154
165
|
//copy package-lock.json if it exists
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
if (fs_1.default.existsSync('package-lock.json')) {
|
|
167
|
+
fs_1.default.cpSync('package-lock.json', 'tmp/package-lock.json');
|
|
168
|
+
}
|
|
169
|
+
fs_1.default.mkdirSync('tmp/node_modules', { recursive: true });
|
|
170
|
+
logger_1.default.info('Installing production dependencies started...');
|
|
171
|
+
child_process_1.default.execSync('npm install --omit=dev --prefix tmp/');
|
|
172
|
+
logger_1.default.info('Installing production dependencies done.');
|
|
173
|
+
logger_1.default.info('Building package...');
|
|
163
174
|
try {
|
|
164
|
-
|
|
175
|
+
child_process_1.default.execSync('npx tsc --outDir tmp/dist');
|
|
165
176
|
}
|
|
166
177
|
catch (e) {
|
|
167
|
-
|
|
178
|
+
logger_1.default.error('%s Failed to build package.', chalk_1.default.red.bold('APP'));
|
|
168
179
|
const stdOut = e.stdout.toString();
|
|
169
180
|
const stdErr = e.stderr.toString();
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
logger_1.default.error('Build Error(stdout):', stdOut);
|
|
182
|
+
logger_1.default.error('Build Error(stderr):', stdErr);
|
|
172
183
|
throw e;
|
|
173
184
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
185
|
+
logger_1.default.info('Building package done.');
|
|
186
|
+
logger_1.default.info('Copying Assets...');
|
|
187
|
+
child_process_1.default.execSync('npx copyfiles assets/**/* tmp/dist/');
|
|
188
|
+
logger_1.default.info('Copying Assets done.');
|
|
178
189
|
// including the app.yml file in the package at the dist level
|
|
179
|
-
|
|
180
|
-
|
|
190
|
+
fs_1.default.cpSync('app.yml', 'tmp/dist/app.yml');
|
|
191
|
+
logger_1.default.info('Zipping package...');
|
|
181
192
|
await (0, zip_a_folder_1.zip)('tmp/', 'tmp.zip');
|
|
182
|
-
|
|
193
|
+
logger_1.default.info('Zipping package done.');
|
|
183
194
|
if (dryRun) {
|
|
184
|
-
|
|
195
|
+
logger_1.default.info('Dry run, skipping cloud updates');
|
|
185
196
|
return {};
|
|
186
197
|
}
|
|
187
|
-
|
|
198
|
+
logger_1.default.info('Uploading package to S3...');
|
|
188
199
|
let apps = await entitiesClient.get({ entityName: 'app', criteria: { hidden: true } });
|
|
189
200
|
apps = apps.concat(await entitiesClient.get({ entityName: 'app', criteria: { private: true } }));
|
|
190
|
-
const thisApp = apps.find(x => x.identifier === appIdentifier);
|
|
201
|
+
const thisApp = apps.find((x) => x.identifier === appIdentifier);
|
|
191
202
|
if (!thisApp) {
|
|
192
203
|
throw new Error('App not found');
|
|
193
204
|
}
|
|
194
|
-
const appCodePackage = await entitiesClient.create({
|
|
205
|
+
const appCodePackage = await entitiesClient.create({
|
|
206
|
+
entityName: 'app-code-package',
|
|
207
|
+
object: { appId: thisApp.id },
|
|
208
|
+
});
|
|
195
209
|
// upload an s3 object using a signed url with an https put request
|
|
196
|
-
const readStream =
|
|
210
|
+
const readStream = fs_1.default.readFileSync('tmp.zip');
|
|
197
211
|
const postBody = Buffer.from(readStream);
|
|
198
212
|
// await axios.put(uploadUrlObject.signedUrl, postBody.toString());
|
|
199
213
|
await axios_1.default.request({
|
|
@@ -203,14 +217,18 @@ async function createNodePackage(appIdentifier, debug, dryRun) {
|
|
|
203
217
|
headers: {
|
|
204
218
|
// explicitly do not include content type because that breaks S3
|
|
205
219
|
'content-type': '',
|
|
206
|
-
}
|
|
220
|
+
},
|
|
207
221
|
});
|
|
208
222
|
// update app with the most recent code package
|
|
209
|
-
await entitiesClient.update({
|
|
223
|
+
await entitiesClient.update({
|
|
224
|
+
entityName: 'app',
|
|
225
|
+
id: thisApp.id,
|
|
226
|
+
object: { appCodePackageId: appCodePackage.id },
|
|
227
|
+
});
|
|
210
228
|
return appCodePackage;
|
|
211
229
|
}
|
|
212
230
|
catch (e) {
|
|
213
|
-
|
|
231
|
+
logger_1.default.error('%s Failed to create app package.', chalk_1.default.red.bold('APP'));
|
|
214
232
|
throw e;
|
|
215
233
|
}
|
|
216
234
|
finally {
|
|
@@ -221,11 +239,11 @@ async function createNodePackage(appIdentifier, debug, dryRun) {
|
|
|
221
239
|
}
|
|
222
240
|
exports.createNodePackage = createNodePackage;
|
|
223
241
|
function cleanUp() {
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
242
|
+
logger_1.default.info('cleaning up');
|
|
243
|
+
if (fs_1.default.existsSync('tmp')) {
|
|
244
|
+
fs_1.default.rmSync('tmp', { recursive: true, force: true });
|
|
227
245
|
}
|
|
228
|
-
if (
|
|
229
|
-
|
|
246
|
+
if (fs_1.default.existsSync('tmp.zip')) {
|
|
247
|
+
fs_1.default.rmSync('tmp.zip');
|
|
230
248
|
}
|
|
231
249
|
}
|
|
@@ -7,7 +7,9 @@ class TriggerKeyDefinitionParser {
|
|
|
7
7
|
for (const triggerName of Object.keys(appDeclaration.triggers)) {
|
|
8
8
|
const triggerDeclaration = appDeclaration.triggers[triggerName];
|
|
9
9
|
const triggerDefinition = {
|
|
10
|
-
triggerKey: triggerDeclaration.external
|
|
10
|
+
triggerKey: triggerDeclaration.external
|
|
11
|
+
? `${appDeclaration.appIdentifier}:${triggerDeclaration.key}`
|
|
12
|
+
: triggerDeclaration.key,
|
|
11
13
|
name: triggerDeclaration.name,
|
|
12
14
|
external: triggerDeclaration.external,
|
|
13
15
|
description: triggerDeclaration.description,
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { AppDeclaration } from '../../interfaces';
|
|
2
|
+
export declare function loadAppConfig(): AppDeclaration;
|
|
@@ -4,11 +4,11 @@ exports.loadAppConfig = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
-
const
|
|
7
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
8
8
|
function loadAppConfig() {
|
|
9
9
|
const TARGET_DIR = process.cwd();
|
|
10
10
|
try {
|
|
11
|
-
const doc =
|
|
11
|
+
const doc = js_yaml_1.default.load(fs_1.default.readFileSync(path.resolve(path.join(TARGET_DIR, 'app.yml')), 'utf8'));
|
|
12
12
|
return doc;
|
|
13
13
|
}
|
|
14
14
|
catch (e) {
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const ncp_1 = tslib_1.__importDefault(require("ncp"));
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const util_1 = require("util");
|
|
8
|
-
const
|
|
8
|
+
const listr_1 = tslib_1.__importDefault(require("listr"));
|
|
9
9
|
const pkg_install_1 = require("pkg-install");
|
|
10
10
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
11
11
|
const copy = (0, util_1.promisify)(ncp_1.default);
|
|
@@ -18,7 +18,7 @@ function copyTemplate(templateDir) {
|
|
|
18
18
|
async function setUpTemplate(appInput) {
|
|
19
19
|
const templateDir = path_1.default.resolve(path_1.default.join(__dirname, '../../templates/typescript'));
|
|
20
20
|
try {
|
|
21
|
-
const tasks = new
|
|
21
|
+
const tasks = new listr_1.default([
|
|
22
22
|
{
|
|
23
23
|
title: 'Copy template files',
|
|
24
24
|
task: () => copyTemplate(templateDir),
|
|
@@ -34,7 +34,8 @@ async function setUpTemplate(appInput) {
|
|
|
34
34
|
// replace properties in yml file with appName
|
|
35
35
|
const appYmlFileLoc = path_1.default.join(TARGET_DIR, 'app.yml');
|
|
36
36
|
const appYml = fs_1.default.readFileSync(appYmlFileLoc, 'utf8');
|
|
37
|
-
const newAppYml = appYml
|
|
37
|
+
const newAppYml = appYml
|
|
38
|
+
.replace(/APP_IDENTIFIER_STUB/g, appInput.appIdentifier)
|
|
38
39
|
.replace(/APP_NAME_STUB/g, appInput.appName)
|
|
39
40
|
.replace(/APP_DESCRIPTION_STUB/g, appInput.appDescription);
|
|
40
41
|
fs_1.default.writeFileSync(appYmlFileLoc, newAppYml);
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface Color {
|
|
2
|
+
name: string;
|
|
3
|
+
hex: string;
|
|
4
|
+
red?: number;
|
|
5
|
+
green?: number;
|
|
6
|
+
blue?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function getLocalColors(): Promise<Color[]>;
|
|
9
|
+
export declare function getExistingColors(): Promise<Color[]>;
|
|
3
10
|
export declare function deleteColor(color: any): Promise<void>;
|
|
4
11
|
export declare function uploadColors(): Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -5,14 +5,15 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const sdk_1 = require("@contrail/sdk");
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
7
|
const common_1 = require("../../common");
|
|
8
|
-
const
|
|
8
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
9
|
+
const csvtojson_1 = tslib_1.__importDefault(require("csvtojson"));
|
|
9
10
|
async function getLocalColors() {
|
|
10
|
-
|
|
11
|
+
logger_1.default.info('loading colors from local file');
|
|
11
12
|
const TARGET_DIR = process.cwd();
|
|
12
13
|
try {
|
|
13
14
|
const separator = (0, common_1.getSeparatorByPlatform)();
|
|
14
|
-
const csvFilePath = TARGET_DIR + separator
|
|
15
|
-
return await
|
|
15
|
+
const csvFilePath = `${TARGET_DIR + separator}colors.csv`;
|
|
16
|
+
return await (0, csvtojson_1.default)().fromFile(csvFilePath);
|
|
16
17
|
}
|
|
17
18
|
catch (e) {
|
|
18
19
|
throw new Error(`ERROR PARSING COLORS CSV: ${e}`);
|
|
@@ -20,10 +21,10 @@ async function getLocalColors() {
|
|
|
20
21
|
}
|
|
21
22
|
exports.getLocalColors = getLocalColors;
|
|
22
23
|
async function getExistingColors() {
|
|
23
|
-
|
|
24
|
+
logger_1.default.info('%s Getting Existing Colors', chalk_1.default.yellow.bold('COLORS'));
|
|
24
25
|
try {
|
|
25
26
|
const result = await new sdk_1.Entities().get({ entityName: 'color', take: 3000 }); //, useSearch: false }); Not in EntitiesClientGetOptions yet
|
|
26
|
-
|
|
27
|
+
logger_1.default.info('Found %s existing colors', result.length);
|
|
27
28
|
return result;
|
|
28
29
|
}
|
|
29
30
|
catch (e) {
|
|
@@ -43,10 +44,10 @@ exports.deleteColor = deleteColor;
|
|
|
43
44
|
async function uploadColors() {
|
|
44
45
|
const colors = await getLocalColors();
|
|
45
46
|
const existingColors = await getExistingColors();
|
|
46
|
-
const existingNamesValues = existingColors.filter(x => x.name).map(x => x.name);
|
|
47
|
+
const existingNamesValues = existingColors.filter((x) => x.name).map((x) => x.name);
|
|
47
48
|
for (const color of colors) {
|
|
48
49
|
if (existingNamesValues.includes(color.name)) {
|
|
49
|
-
|
|
50
|
+
logger_1.default.info('%s SKIPPING %s (%s)', chalk_1.default.yellow.bold('COLORS'), color.hex, color.name);
|
|
50
51
|
continue;
|
|
51
52
|
}
|
|
52
53
|
if (color.hex.length > 1 && color.hex[0] === '#') {
|
|
@@ -54,7 +55,7 @@ async function uploadColors() {
|
|
|
54
55
|
}
|
|
55
56
|
const o = {
|
|
56
57
|
hex: color.hex,
|
|
57
|
-
name: color.name
|
|
58
|
+
name: color.name,
|
|
58
59
|
};
|
|
59
60
|
if (color.red) {
|
|
60
61
|
o.red = color.red;
|
|
@@ -67,7 +68,7 @@ async function uploadColors() {
|
|
|
67
68
|
}
|
|
68
69
|
await new sdk_1.Entities().create({
|
|
69
70
|
entityName: 'color',
|
|
70
|
-
object: o
|
|
71
|
+
object: o,
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.storeConfig = exports.deleteConfigs = exports.getConfig = exports.writeVibeIQConfig = exports.readVibeIQConfig = exports.initializeVibeIQConfig = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const node_fs_1 = require("node:fs");
|
|
5
6
|
const node_path_1 = require("node:path");
|
|
6
7
|
const node_os_1 = require("node:os");
|
|
8
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
7
9
|
const userHomeDir = (0, node_os_1.homedir)();
|
|
8
10
|
const configDirectoryLocation = (0, node_path_1.join)(userHomeDir, '.vibeiq');
|
|
9
11
|
const configFileLocation = (0, node_path_1.join)(configDirectoryLocation, 'config.json');
|
|
@@ -12,14 +14,14 @@ async function initializeVibeIQConfig() {
|
|
|
12
14
|
await node_fs_1.promises.mkdir(configDirectoryLocation, { recursive: true });
|
|
13
15
|
}
|
|
14
16
|
catch (error) {
|
|
15
|
-
|
|
17
|
+
logger_1.default.error('could not initialize vibeiq directory');
|
|
16
18
|
throw error;
|
|
17
19
|
}
|
|
18
20
|
try {
|
|
19
21
|
await node_fs_1.promises.writeFile(configFileLocation, '{}');
|
|
20
22
|
}
|
|
21
23
|
catch (error) {
|
|
22
|
-
|
|
24
|
+
logger_1.default.error(`could not initialize config file (${configFileLocation}).`);
|
|
23
25
|
throw error;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -30,8 +32,8 @@ async function readVibeIQConfig() {
|
|
|
30
32
|
fileContent = await (await node_fs_1.promises.readFile(configFileLocation)).toString();
|
|
31
33
|
}
|
|
32
34
|
catch {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
logger_1.default.debug(`failed to open config file (${configFileLocation}) for reading.`);
|
|
36
|
+
logger_1.default.debug('trying to initialize config file');
|
|
35
37
|
await initializeVibeIQConfig();
|
|
36
38
|
fileContent = await (await node_fs_1.promises.readFile(configFileLocation)).toString();
|
|
37
39
|
}
|
|
@@ -39,7 +41,7 @@ async function readVibeIQConfig() {
|
|
|
39
41
|
return JSON.parse(fileContent);
|
|
40
42
|
}
|
|
41
43
|
catch {
|
|
42
|
-
|
|
44
|
+
logger_1.default.error(`Could not parse local vibeiq config. The file (${configFileLocation}) might be malformed`);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
exports.readVibeIQConfig = readVibeIQConfig;
|
|
@@ -48,13 +50,13 @@ async function writeVibeIQConfig(config) {
|
|
|
48
50
|
await node_fs_1.promises.writeFile(configFileLocation, JSON.stringify(config, null, 2));
|
|
49
51
|
}
|
|
50
52
|
catch (error) {
|
|
51
|
-
|
|
53
|
+
logger_1.default.error(`Could not open config file (${configFileLocation}) for writing.`);
|
|
52
54
|
throw error;
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
exports.writeVibeIQConfig = writeVibeIQConfig;
|
|
56
58
|
async function getConfig() {
|
|
57
|
-
|
|
59
|
+
logger_1.default.debug('getting config from file system');
|
|
58
60
|
return await readVibeIQConfig();
|
|
59
61
|
}
|
|
60
62
|
exports.getConfig = getConfig;
|
|
@@ -67,10 +69,13 @@ async function deleteConfigs(configNames) {
|
|
|
67
69
|
}
|
|
68
70
|
exports.deleteConfigs = deleteConfigs;
|
|
69
71
|
async function storeConfig(incomingConfig, merge = true) {
|
|
70
|
-
|
|
71
|
-
...await readVibeIQConfig(),
|
|
72
|
+
let config = {
|
|
73
|
+
...(await readVibeIQConfig()),
|
|
72
74
|
...incomingConfig,
|
|
73
|
-
}
|
|
75
|
+
};
|
|
76
|
+
if (!merge) {
|
|
77
|
+
config = incomingConfig;
|
|
78
|
+
}
|
|
74
79
|
await writeVibeIQConfig(config);
|
|
75
80
|
}
|
|
76
81
|
exports.storeConfig = storeConfig;
|
|
@@ -3,19 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.safeFileOverwrite = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
6
|
+
const logger_1 = tslib_1.__importDefault(require("../logger"));
|
|
6
7
|
const PASS_FORCE_TO_OVERWRITE = 'Pass --overwrite to overwrite without prompting';
|
|
7
8
|
//throws an error if the user declines to overwrite the file
|
|
8
9
|
async function safeFileOverwrite(fileLocation, overwrite) {
|
|
9
10
|
if (overwrite) {
|
|
10
|
-
|
|
11
|
+
logger_1.default.info(`overwriting ${fileLocation}`);
|
|
11
12
|
return true;
|
|
12
13
|
}
|
|
13
|
-
const answers = await inquirer_1.default.prompt([
|
|
14
|
+
const answers = await inquirer_1.default.prompt([
|
|
15
|
+
{
|
|
14
16
|
type: 'confirm',
|
|
15
17
|
name: 'shouldOverwrite',
|
|
16
18
|
message: `The file ${fileLocation} already exists. Do you wish to overwrite it?\n${PASS_FORCE_TO_OVERWRITE}`,
|
|
17
|
-
default: false
|
|
18
|
-
}
|
|
19
|
+
default: false,
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
19
22
|
if (!answers.shouldOverwrite) {
|
|
20
23
|
throw new Error('File was not overwritten. Cancelling process...');
|
|
21
24
|
}
|
|
@@ -6,6 +6,7 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
6
6
|
const sdk_1 = require("@contrail/sdk");
|
|
7
7
|
const fs = tslib_1.__importStar(require("fs"));
|
|
8
8
|
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
9
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
9
10
|
async function getLocalFile(incomingFileName) {
|
|
10
11
|
const ext = getFileExtension(incomingFileName);
|
|
11
12
|
if (ext !== '.csv') {
|
|
@@ -19,14 +20,14 @@ async function getLocalFile(incomingFileName) {
|
|
|
19
20
|
throw new Error(`ERROR LOADING CSV: ${e}`);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
function getLocalUploadConfig(configFileName) {
|
|
23
24
|
const ext = getFileExtension(configFileName);
|
|
24
25
|
if (ext !== '.json' && ext !== '.yml') {
|
|
25
26
|
throw new Error('Upload file must be a .json or .yml');
|
|
26
27
|
}
|
|
27
28
|
const CURRENT_DIR = process.cwd();
|
|
28
29
|
const fullPath = path.join(CURRENT_DIR, configFileName);
|
|
29
|
-
|
|
30
|
+
logger_1.default.info('Getting config from path: ', fullPath);
|
|
30
31
|
if (ext === '.yml') {
|
|
31
32
|
try {
|
|
32
33
|
const doc = js_yaml_1.default.load(fs.readFileSync(fullPath, 'utf8'));
|
|
@@ -50,41 +51,41 @@ async function uploadFile(incomingFileName) {
|
|
|
50
51
|
const fileName = `${incomingFileName.slice(0, incomingFileName.length - 4)}-Upload-${new Date().getTime()}.csv`;
|
|
51
52
|
const file = await entities.create({
|
|
52
53
|
entityName: 'file',
|
|
53
|
-
object: { contentType: 'text/csv', fileName: fileName, ttl: 24 * 60 * 60 * 1000 }
|
|
54
|
+
object: { contentType: 'text/csv', fileName: fileName, ttl: 24 * 60 * 60 * 1000 },
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
+
logger_1.default.info('VibeIQ file ID:', file.id);
|
|
56
57
|
// Upload the CSV data to the newly created VibeIQ file
|
|
57
58
|
const fileDetails = {
|
|
58
59
|
contentType: 'text/csv',
|
|
59
60
|
};
|
|
60
61
|
await new sdk_1.Files().uploadFileAsStream(file.uploadPost, csvContent, fileDetails);
|
|
61
|
-
|
|
62
|
+
logger_1.default.info('File uploaded.');
|
|
62
63
|
return file;
|
|
63
64
|
}
|
|
64
65
|
async function loadFile(config) {
|
|
65
66
|
const entities = new sdk_1.Entities();
|
|
66
67
|
// start a load job referencing the newly created file
|
|
67
|
-
|
|
68
|
+
logger_1.default.info('Loading with config: ', config);
|
|
68
69
|
const loadJob = await entities.create({
|
|
69
70
|
entityName: 'loader-process',
|
|
70
71
|
object: {
|
|
71
|
-
...config
|
|
72
|
-
}
|
|
72
|
+
...config,
|
|
73
|
+
},
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
+
logger_1.default.info('Load has been kicked off. loader-process ID: ', loadJob.id);
|
|
75
76
|
}
|
|
76
77
|
async function uploadAndLoadLocalFile(incomingFileName, configFileName) {
|
|
77
78
|
const file = await uploadFile(incomingFileName);
|
|
78
|
-
const config =
|
|
79
|
+
const config = getLocalUploadConfig(configFileName);
|
|
79
80
|
const fullConfig = {
|
|
80
81
|
fileLocation: file.id,
|
|
81
|
-
...config
|
|
82
|
+
...config,
|
|
82
83
|
};
|
|
83
84
|
await loadFile(fullConfig);
|
|
84
85
|
}
|
|
85
86
|
exports.uploadAndLoadLocalFile = uploadAndLoadLocalFile;
|
|
86
87
|
async function loadLocalFile(configFileName) {
|
|
87
|
-
const config =
|
|
88
|
+
const config = getLocalUploadConfig(configFileName);
|
|
88
89
|
await loadFile(config);
|
|
89
90
|
}
|
|
90
91
|
exports.loadLocalFile = loadLocalFile;
|
|
@@ -92,7 +93,7 @@ function getFileExtension(fileName) {
|
|
|
92
93
|
let ext = '';
|
|
93
94
|
const parts = fileName === null || fileName === void 0 ? void 0 : fileName.split('.');
|
|
94
95
|
if ((parts === null || parts === void 0 ? void 0 : parts.length) > 1) {
|
|
95
|
-
ext =
|
|
96
|
+
ext = `.${parts[(parts === null || parts === void 0 ? void 0 : parts.length) - 1]}`;
|
|
96
97
|
}
|
|
97
98
|
return ext;
|
|
98
99
|
}
|