@contrail/cli 1.0.71 → 2.0.1
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/LICENSE +21 -0
- package/README.md +1034 -5
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/{lib → dist}/api/apps.d.ts +13 -13
- package/dist/api/apps.js +96 -0
- package/{lib → dist}/api/event-workflow-action-definition.d.ts +1 -1
- package/dist/api/event-workflow-action-definition.js +11 -0
- package/{lib → dist}/api/event-workflow-template-definition.d.ts +6 -6
- package/dist/api/event-workflow-template-definition.js +26 -0
- package/{lib → dist}/api/event-workflow-templates.d.ts +7 -7
- package/dist/api/event-workflow-templates.js +32 -0
- package/dist/api/types.d.ts +7 -0
- package/dist/api/types.js +52 -0
- package/{lib → dist}/auth/auth.d.ts +9 -9
- package/dist/auth/auth.js +6 -0
- package/{lib → dist}/auth/login.d.ts +2 -2
- package/{lib → dist}/auth/login.js +146 -141
- package/dist/commands/app/create.d.ts +6 -0
- package/dist/commands/app/create.js +15 -0
- package/dist/commands/app/delete.d.ts +7 -0
- package/dist/commands/app/delete.js +38 -0
- package/dist/commands/app/install.d.ts +11 -0
- package/dist/commands/app/install.js +117 -0
- package/dist/commands/app/publish.d.ts +7 -0
- package/dist/commands/app/publish.js +45 -0
- package/dist/commands/app/uninstall.d.ts +10 -0
- package/dist/commands/app/uninstall.js +58 -0
- package/dist/commands/app/upgrade.d.ts +11 -0
- package/dist/commands/app/upgrade.js +79 -0
- package/dist/commands/colors/deleteAll.d.ts +6 -0
- package/dist/commands/colors/deleteAll.js +30 -0
- package/dist/commands/colors/load.d.ts +6 -0
- package/dist/commands/colors/load.js +29 -0
- package/dist/commands/config/list.d.ts +6 -0
- package/dist/commands/config/list.js +15 -0
- package/dist/commands/config/remove.d.ts +14 -0
- package/dist/commands/config/remove.js +26 -0
- package/dist/commands/config/set.d.ts +13 -0
- package/dist/commands/config/set.js +29 -0
- package/dist/commands/loader-process/load.d.ts +9 -0
- package/dist/commands/loader-process/load.js +33 -0
- package/dist/commands/loader-process/upload-and-load.d.ts +10 -0
- package/dist/commands/loader-process/upload-and-load.js +35 -0
- package/dist/commands/projects/export.d.ts +10 -0
- package/dist/commands/projects/export.js +34 -0
- package/dist/commands/projects/list.d.ts +6 -0
- package/dist/commands/projects/list.js +34 -0
- package/dist/commands/projects/load.d.ts +9 -0
- package/{lib/projects/project-uploader.js → dist/commands/projects/load.js} +106 -105
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +7 -0
- package/{lib/types/option-set-hierarchy-exporter.js → dist/commands/types/exportOptionSetHierarchies.js} +130 -113
- package/{lib/types/types-extractor.d.ts → dist/commands/types/getAll.d.ts} +29 -27
- package/{lib/types/types-extractor.js → dist/commands/types/getAll.js} +267 -318
- package/dist/commands/types/loadAll.d.ts +7 -0
- package/dist/commands/types/loadAll.js +41 -0
- package/dist/commands/types/mergeOptionSets.d.ts +9 -0
- package/{lib/types/option-set-merger.js → dist/commands/types/mergeOptionSets.js} +114 -105
- package/dist/commands/types/mergeTypeProperties.d.ts +11 -0
- package/dist/commands/types/mergeTypeProperties.js +89 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +112 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +14 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.js +153 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +104 -0
- package/dist/commands/types/parseTypesFromFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromFiles.js +34 -0
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromLocalFiles.js +34 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +11 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +36 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +35 -0
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +7 -0
- package/{lib/types/option-set-hierarchy-uploader.js → dist/commands/types/uploadOptionSetHierarchies.js} +130 -113
- package/dist/commands/types/uploadOptionSets.d.ts +7 -0
- package/{lib/types/option-set-uploader.js → dist/commands/types/uploadOptionSets.js} +115 -98
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +11 -0
- package/{lib/types/option-set-hierarchy-parser.js → dist/commands/types/uploadOptionSetsHierarchyLocalFile.js} +128 -140
- package/dist/commands/types/uploadRuleSets.d.ts +7 -0
- package/{lib/types/rule-set-uploader.js → dist/commands/types/uploadRuleSets.js} +189 -172
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +7 -0
- package/{lib/types/type-property-policy-uploader.js → dist/commands/types/uploadTypePropertyPolicies.js} +195 -178
- package/dist/commands/types/uploadUsageInfo.d.ts +7 -0
- package/{lib/types/usage-info-uploader.js → dist/commands/types/uploadUsageInfo.js} +149 -132
- package/dist/commands/users/export.d.ts +9 -0
- package/dist/commands/users/export.js +60 -0
- package/dist/commands/users/upload.d.ts +9 -0
- package/dist/commands/users/upload.js +65 -0
- package/dist/commands/workflow-template-definitions/install.d.ts +6 -0
- package/dist/commands/workflow-template-definitions/install.js +17 -0
- package/dist/commands/workflow-template-definitions/list.d.ts +6 -0
- package/dist/commands/workflow-template-definitions/list.js +17 -0
- package/dist/commands/workflow-templates/delete.d.ts +6 -0
- package/dist/commands/workflow-templates/delete.js +17 -0
- package/dist/commands/workflow-templates/list.d.ts +6 -0
- package/dist/commands/workflow-templates/list.js +17 -0
- package/dist/commands/workflow-templates/load.d.ts +9 -0
- package/dist/commands/workflow-templates/load.js +21 -0
- package/{lib → dist}/common.d.ts +1 -1
- package/dist/common.js +9 -0
- package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.d.ts +11 -11
- package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.js +122 -114
- package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.d.ts +8 -8
- package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.js +98 -93
- package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.d.ts +7 -7
- package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.js +43 -38
- package/dist/helpers/app/load-app-config.d.ts +1 -0
- package/dist/helpers/app/load-app-config.js +18 -0
- package/dist/helpers/app/setup-template.d.ts +1 -0
- package/dist/helpers/app/setup-template.js +38 -0
- package/dist/helpers/colors/helpers.d.ts +4 -0
- package/dist/helpers/colors/helpers.js +74 -0
- package/{lib → dist/helpers}/config/config.d.ts +6 -6
- package/dist/helpers/config/config.js +76 -0
- package/dist/helpers/loader-process/helpers.d.ts +2 -0
- package/{lib/loader-process/loader-process.js → dist/helpers/loader-process/helpers.js} +98 -120
- package/dist/helpers/projects/helpers.d.ts +2 -0
- package/{lib/projects/project-exporter.js → dist/helpers/projects/helpers.js} +165 -187
- package/{lib → dist/helpers}/types/csv-parser.d.ts +1 -1
- package/{lib → dist/helpers}/types/csv-parser.js +56 -51
- package/dist/helpers/types/type-extractor.d.ts +1 -0
- package/dist/helpers/types/type-extractor.js +32 -0
- package/dist/helpers/types/type-parser.d.ts +4 -0
- package/dist/helpers/types/type-parser.js +118 -0
- package/{lib/types/types-uploader.d.ts → dist/helpers/types/type-uploader.d.ts} +1 -1
- package/{lib/types/types-uploader.js → dist/helpers/types/type-uploader.js} +244 -239
- package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
- package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.js +156 -151
- package/{lib/workflow-templates/local-workflow-template-deployer.d.ts → dist/helpers/workflow-templates/helper.d.ts} +17 -11
- package/dist/helpers/workflow-templates/helper.js +166 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/{lib → dist}/interfaces.d.ts +323 -191
- package/dist/interfaces.js +63 -0
- package/{templates → dist/templates}/typescript/Dockerfile +15 -15
- package/{templates → dist/templates}/typescript/README.md +10 -10
- package/{templates → dist/templates}/typescript/app.yml +49 -49
- package/{templates → dist/templates}/typescript/docker_deploy.bat +1 -1
- package/{templates → dist/templates}/typescript/package.json +54 -54
- package/{templates → dist/templates}/typescript/src/actions/logItem.ts +25 -25
- package/{templates → dist/templates}/typescript/src/framework/action-dispatcher.ts +89 -89
- package/{templates → dist/templates}/typescript/src/framework/app-config.ts +26 -26
- package/{templates → dist/templates}/typescript/src/framework/handler.ts +11 -11
- package/{templates → dist/templates}/typescript/src/framework/index.ts +2 -2
- package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
- package/{templates → dist/templates}/typescript/src/framework/logger.ts +21 -21
- package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +31 -31
- package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
- package/oclif.manifest.json +821 -0
- package/package.json +116 -72
- package/.eslintrc.js +0 -53
- package/.vscode/settings.json +0 -6
- package/bin/init +0 -4
- package/lib/api/apps.js +0 -85
- package/lib/api/event-workflow-action-definition.js +0 -7
- package/lib/api/event-workflow-template-definition.js +0 -20
- package/lib/api/event-workflow-templates.js +0 -25
- package/lib/apps/create-app/create.d.ts +0 -1
- package/lib/apps/create-app/create.js +0 -60
- package/lib/apps/create-app/setup-template.d.ts +0 -1
- package/lib/apps/create-app/setup-template.js +0 -34
- package/lib/apps/deploy-app/deploy.d.ts +0 -2
- package/lib/apps/deploy-app/deploy.js +0 -58
- package/lib/apps/install-app/app-installer.d.ts +0 -2
- package/lib/apps/install-app/app-installer.js +0 -120
- package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
- package/lib/apps/upgrade-app/app-upgrader.js +0 -126
- package/lib/auth/auth.js +0 -2
- package/lib/cli.d.ts +0 -5
- package/lib/cli.js +0 -524
- package/lib/colors/color-loader.d.ts +0 -2
- package/lib/colors/color-loader.js +0 -96
- package/lib/common.js +0 -5
- package/lib/config/config.js +0 -70
- package/lib/config/configCommands.d.ts +0 -3
- package/lib/config/configCommands.js +0 -34
- package/lib/interfaces.js +0 -25
- package/lib/loader-process/loader-process.d.ts +0 -2
- package/lib/projects/interfaces.d.ts +0 -77
- package/lib/projects/interfaces.js +0 -23
- package/lib/projects/project-exporter.d.ts +0 -2
- package/lib/projects/project-uploader.d.ts +0 -1
- package/lib/types/allUploader.d.ts +0 -1
- package/lib/types/allUploader.js +0 -24
- package/lib/types/interfaces.d.ts +0 -55
- package/lib/types/interfaces.js +0 -1
- package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
- package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
- package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
- package/lib/types/option-set-merger.d.ts +0 -1
- package/lib/types/option-set-parser.d.ts +0 -3
- package/lib/types/option-set-parser.js +0 -140
- package/lib/types/option-set-uploader.d.ts +0 -1
- package/lib/types/parse-types.d.ts +0 -4
- package/lib/types/parse-types.js +0 -189
- package/lib/types/rule-set-uploader.d.ts +0 -1
- package/lib/types/type-property-policy-uploader.d.ts +0 -1
- package/lib/types/types-properties-merger.d.ts +0 -1
- package/lib/types/types-properties-merger.js +0 -75
- package/lib/types/usage-info-uploader.d.ts +0 -1
- package/lib/users/user-exporter.d.ts +0 -1
- package/lib/users/user-exporter.js +0 -41
- package/lib/users/user-uploader.d.ts +0 -1
- package/lib/users/user-uploader.js +0 -45
- package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
- package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
- package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
- package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
- package/lib/workflow-templates/workflow-template-commands.js +0 -51
- package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
- package/lib/workflow-templates/workflow-template-deployer.js +0 -26
- package/publish.bat +0 -5
- package/publish.sh +0 -5
- package/src/api/apps.ts +0 -97
- package/src/api/event-workflow-action-definition.ts +0 -8
- package/src/api/event-workflow-template-definition.ts +0 -23
- package/src/api/event-workflow-templates.ts +0 -29
- package/src/apps/create-app/create.ts +0 -74
- package/src/apps/create-app/setup-template.ts +0 -38
- package/src/apps/deploy-app/actions-deployer.ts +0 -140
- package/src/apps/deploy-app/app-deployer.ts +0 -105
- package/src/apps/deploy-app/app-template-parsers.ts +0 -44
- package/src/apps/deploy-app/deploy.ts +0 -66
- package/src/apps/install-app/app-installer.ts +0 -126
- package/src/apps/upgrade-app/app-upgrader.ts +0 -132
- package/src/auth/auth.ts +0 -10
- package/src/auth/login.ts +0 -155
- package/src/cli.ts +0 -540
- package/src/colors/color-loader.ts +0 -112
- package/src/colors/colors.csv +0 -866
- package/src/common.ts +0 -5
- package/src/config/config.ts +0 -74
- package/src/config/configCommands.ts +0 -38
- package/src/interfaces.ts +0 -200
- package/src/loader-process/loader-process.ts +0 -152
- package/src/projects/interfaces.ts +0 -73
- package/src/projects/project-exporter.ts +0 -225
- package/src/projects/project-uploader.ts +0 -131
- package/src/types/allUploader.ts +0 -28
- package/src/types/csv-parser.ts +0 -59
- package/src/types/interfaces.ts +0 -58
- package/src/types/option-set-hierarchy-exporter.ts +0 -125
- package/src/types/option-set-hierarchy-parser.ts +0 -169
- package/src/types/option-set-hierarchy-uploader.ts +0 -122
- package/src/types/option-set-merger.ts +0 -124
- package/src/types/option-set-parser.ts +0 -166
- package/src/types/option-set-uploader.ts +0 -108
- package/src/types/parse-types.ts +0 -227
- package/src/types/rule-set-uploader.ts +0 -187
- package/src/types/type-property-policy-uploader.ts +0 -192
- package/src/types/types-extractor.ts +0 -369
- package/src/types/types-properties-merger.ts +0 -90
- package/src/types/types-uploader.ts +0 -271
- package/src/types/usage-info-uploader.ts +0 -139
- package/src/users/user-exporter.ts +0 -52
- package/src/users/user-uploader.ts +0 -58
- package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
- package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
- package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
- package/src/workflow-templates/workflow-template-commands.ts +0 -59
- package/src/workflow-templates/workflow-template-deployer.ts +0 -30
- package/templates/javascript/actions/example/action.js +0 -38
- package/templates/javascript/app.yml +0 -53
- package/templates/javascript/package.json +0 -23
- package/templates/typescript/package-lock.json +0 -14
- package/tsconfig.json +0 -32
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { getOptionSets, getTypes, reduceData } from './types-extractor';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { getSeparatorByPlatform } from '../common';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
const yaml = require('js-yaml');
|
|
7
|
-
export async function MergeTypeProperties(args) {
|
|
8
|
-
try {
|
|
9
|
-
if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
|
|
10
|
-
throw new Error('File name must be included along with a type path.');
|
|
11
|
-
}
|
|
12
|
-
console.log('%s Importing local file', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
|
|
13
|
-
const fileLocation = args[3];
|
|
14
|
-
console.log('Using File: ', fileLocation);
|
|
15
|
-
const typePaths = args.slice(4);
|
|
16
|
-
console.log('Using TypePaths: ', typePaths);
|
|
17
|
-
await mergeTypeProperties(fileLocation, typePaths);
|
|
18
|
-
console.log('%s Merged', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
console.log('%s Merge Complete.', chalk.green.bold('COMPLETE'));
|
|
25
|
-
}
|
|
26
|
-
function loadTypeProperties(fileLocation) {
|
|
27
|
-
const TARGET_DIR = process.cwd();
|
|
28
|
-
try {
|
|
29
|
-
const separator = getSeparatorByPlatform();
|
|
30
|
-
const fullPath = TARGET_DIR + separator + fileLocation;
|
|
31
|
-
console.log('Getting file from path: ', fullPath);
|
|
32
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + fileLocation, 'utf8'));
|
|
33
|
-
return doc.typeProperties;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function mergeTypeProperties(fileLocation, typePaths) {
|
|
40
|
-
const uploadedTypeProperties = loadTypeProperties(fileLocation);
|
|
41
|
-
await authUser();
|
|
42
|
-
const data = {
|
|
43
|
-
types: await getTypes(),
|
|
44
|
-
optionSets: await getOptionSets(),
|
|
45
|
-
optionSetHierarchies: [],
|
|
46
|
-
ruleSets: [],
|
|
47
|
-
ruleSetLinks: [],
|
|
48
|
-
usageInfo: [],
|
|
49
|
-
typePropertyPolicies: [],
|
|
50
|
-
typePropertyPolicyLinks: [],
|
|
51
|
-
};
|
|
52
|
-
const reducedData = await reduceData(data);
|
|
53
|
-
for (const typePath of typePaths) {
|
|
54
|
-
const foundType = reducedData.reducedTypes.find(reducedTypes => reducedTypes.typePath === typePath);
|
|
55
|
-
if (!foundType) {
|
|
56
|
-
console.log(`%s No Type found for: ${typePath}`, chalk.red.bold('WARNING'));
|
|
57
|
-
}
|
|
58
|
-
mergeType(foundType, uploadedTypeProperties);
|
|
59
|
-
}
|
|
60
|
-
saveData({ types: reducedData.reducedTypes });
|
|
61
|
-
}
|
|
62
|
-
function mergeType(reducedType, typePropertiesToAdd) {
|
|
63
|
-
for (const typeProperty of typePropertiesToAdd) {
|
|
64
|
-
const found = reducedType.typeProperties.find(tp => tp.slug === typeProperty.slug);
|
|
65
|
-
if (!found) {
|
|
66
|
-
reducedType.typeProperties.push(typeProperty);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function saveData(data) {
|
|
71
|
-
const yamlStr = yaml.dump(data);
|
|
72
|
-
const CURRENT_DIR = process.cwd();
|
|
73
|
-
const separator = getSeparatorByPlatform();
|
|
74
|
-
fs.writeFileSync(CURRENT_DIR + separator + 'merged_types.yml', yamlStr, 'utf8');
|
|
75
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function uploadUsageInfo(args: any): Promise<void>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function ExportUsers(): Promise<void>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import { getSeparatorByPlatform } from '../common';
|
|
6
|
-
import yaml from 'js-yaml';
|
|
7
|
-
export async function ExportUsers() {
|
|
8
|
-
try {
|
|
9
|
-
await authUser();
|
|
10
|
-
console.log('%s Getting Users.', chalk.blue.bold('START'));
|
|
11
|
-
await exportUsers();
|
|
12
|
-
console.log('%s Done', chalk.yellow.bold('USERS'));
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
console.log(`%s Users download Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
console.log('%s Users download Complete.', chalk.green.bold('COMPLETE'));
|
|
19
|
-
}
|
|
20
|
-
async function exportUsers() {
|
|
21
|
-
const allUsersInOrg = await new Entities().get({
|
|
22
|
-
entityName: 'user-org',
|
|
23
|
-
});
|
|
24
|
-
const users = [];
|
|
25
|
-
for (const userInOrg of allUsersInOrg) {
|
|
26
|
-
delete userInOrg.user.id;
|
|
27
|
-
delete userInOrg.user.updatedBy;
|
|
28
|
-
delete userInOrg.user.createdBy;
|
|
29
|
-
if (userInOrg.user.email.includes('@vibeappuser.com')) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
users.push(Object.assign({ role: userInOrg.role }, userInOrg.user));
|
|
33
|
-
}
|
|
34
|
-
saveData({ users: users }, 'users');
|
|
35
|
-
}
|
|
36
|
-
function saveData(data, name) {
|
|
37
|
-
const yamlStr = yaml.dump(data);
|
|
38
|
-
const CURRENT_DIR = process.cwd();
|
|
39
|
-
const separator = getSeparatorByPlatform();
|
|
40
|
-
fs.writeFileSync(CURRENT_DIR + separator + name + '-export.yml', yamlStr, 'utf8');
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function UploadUsers(): Promise<void>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import yaml from 'js-yaml';
|
|
7
|
-
export async function UploadUsers() {
|
|
8
|
-
try {
|
|
9
|
-
await authUser();
|
|
10
|
-
console.log('%s Uploading Users.', chalk.blue.bold('START'));
|
|
11
|
-
console.log('%s Uploading', chalk.yellow.bold('USER'));
|
|
12
|
-
await uploadUsers();
|
|
13
|
-
console.log('%s Uploaded', chalk.yellow.bold('USER'));
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
console.log(`%s User Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
console.log('%s User Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
20
|
-
}
|
|
21
|
-
function getUsersFile() {
|
|
22
|
-
const CURRENT_DIR = process.cwd();
|
|
23
|
-
try {
|
|
24
|
-
const fullPath = path.join(CURRENT_DIR, 'users.yml');
|
|
25
|
-
console.log('Getting file from path: ', fullPath);
|
|
26
|
-
const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
|
|
27
|
-
return doc.users;
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function uploadUsers() {
|
|
34
|
-
const users = getUsersFile();
|
|
35
|
-
for (const user of users) {
|
|
36
|
-
const role = user.role;
|
|
37
|
-
const email = user.email;
|
|
38
|
-
delete user.role;
|
|
39
|
-
delete user.email;
|
|
40
|
-
await new Entities().create({
|
|
41
|
-
entityName: 'user-org',
|
|
42
|
-
object: Object.assign({ role: role, userEmail: email }, user)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { authUser } from '../auth/login';
|
|
2
|
-
import { WorkflowTemplateDefinitionDeployer } from './workflow-template-definition-deployer';
|
|
3
|
-
export async function cliInstallWorkflowTemplateDefinitions() {
|
|
4
|
-
await authUser();
|
|
5
|
-
await new WorkflowTemplateDefinitionDeployer().cliInstallWorkflowTemplateDefinitions();
|
|
6
|
-
}
|
|
7
|
-
export async function listWorkflowTemplateDefinitions() {
|
|
8
|
-
await authUser();
|
|
9
|
-
await new WorkflowTemplateDefinitionDeployer().listWorkflowTemplateDefinitions();
|
|
10
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { getEventWorkflowActionDefinition } from '../api/event-workflow-action-definition';
|
|
3
|
-
import { createWorkflowTemplate, deleteWorkflowTemplate, getExistingWorkflowTemplates, updateWorkflowTemplate as apiUpdateWorkflowTemplate } from '../api/event-workflow-templates';
|
|
4
|
-
export class LocalWorkflowTemplateDeployer {
|
|
5
|
-
async deployWorkflows(wtDeclaration) {
|
|
6
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
7
|
-
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
8
|
-
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
9
|
-
console.log('%s \tDeploying workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
10
|
-
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
11
|
-
await this.deployWorkflowTemplate(workflowKey, wtDeclaration.workflows[workflowKey], existingWorkflows);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
async deployWorkflowTemplate(workflowKey, workflow, existingWorkflows) {
|
|
15
|
-
console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
16
|
-
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
17
|
-
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
18
|
-
if (existingTemplate) {
|
|
19
|
-
return await this.updateWorkflowTemplate(workflowKey, existingTemplate, workflow);
|
|
20
|
-
}
|
|
21
|
-
return await this.createNewWorkflowTemplate(workflowKey, workflow);
|
|
22
|
-
}
|
|
23
|
-
async createNewWorkflowTemplate(workflowKey, workflowTemplate) {
|
|
24
|
-
await this.populateActionIds(workflowTemplate, workflowKey);
|
|
25
|
-
const newObject = {
|
|
26
|
-
identifier: getWorkflowTemplateIdentifier(workflowKey),
|
|
27
|
-
name: workflowTemplate.name,
|
|
28
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
29
|
-
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
30
|
-
isActive: workflowTemplate.isActive,
|
|
31
|
-
supportingAppId: workflowTemplate.supportingAppId,
|
|
32
|
-
messageGroupId: workflowTemplate.messageGroupId,
|
|
33
|
-
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
34
|
-
};
|
|
35
|
-
const newWorkflowTemplate = await createWorkflowTemplate(newObject);
|
|
36
|
-
console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
37
|
-
return newWorkflowTemplate;
|
|
38
|
-
}
|
|
39
|
-
async populateActionIds(workflowTemplate, workflowKey) {
|
|
40
|
-
var _a;
|
|
41
|
-
if (!((_a = workflowTemplate === null || workflowTemplate === void 0 ? void 0 : workflowTemplate.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
45
|
-
if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
49
|
-
const actionKey = actionConfiguration.action;
|
|
50
|
-
try {
|
|
51
|
-
const actionEntity = await getActionByIdentifier(actionKey);
|
|
52
|
-
actionConfiguration.id = actionEntity.id;
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
console.log(e);
|
|
56
|
-
}
|
|
57
|
-
if (!actionConfiguration.id) {
|
|
58
|
-
throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async updateWorkflowTemplate(workflowKey, existingWorkflowTemplate, workflowTemplate) {
|
|
64
|
-
await this.populateActionIds(workflowTemplate, workflowKey);
|
|
65
|
-
const updates = Object.assign(new Object(), {
|
|
66
|
-
name: workflowTemplate.name,
|
|
67
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
68
|
-
workflowDefinition: workflowTemplate.workflowDefinition
|
|
69
|
-
});
|
|
70
|
-
const updatedWorkflowTemplate = await apiUpdateWorkflowTemplate({ id: existingWorkflowTemplate.id, updates });
|
|
71
|
-
console.log(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
72
|
-
return updatedWorkflowTemplate;
|
|
73
|
-
}
|
|
74
|
-
async deleteWorkflowTemplates(wtDeclaration) {
|
|
75
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
76
|
-
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
77
|
-
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
78
|
-
console.log('%s \tDELETING workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
79
|
-
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
80
|
-
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
81
|
-
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
82
|
-
if (existingTemplate) {
|
|
83
|
-
try {
|
|
84
|
-
await deleteWorkflowTemplate(identifier);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
console.log('%s \tFAILED to delete workflow template %s.', chalk.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.log('%s \tUnable to locate workflow template %s.', chalk.yellow.bold('WORKFLOW TEMPLATES'), identifier);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
export function getWorkflowTemplateIdentifier(workflowKey) {
|
|
97
|
-
return workflowKey;
|
|
98
|
-
}
|
|
99
|
-
export async function getActionByIdentifier(identifier) {
|
|
100
|
-
const result = await getEventWorkflowActionDefinition({ identifier });
|
|
101
|
-
return result.length > 0 ? result[0] : {};
|
|
102
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function deleteWorkflowTemplates(): Promise<void>;
|
|
2
|
-
export declare function localDeleteWorkflowTemplate(): Promise<void>;
|
|
3
|
-
export declare function localDeployWorkflowTemplate(): Promise<void>;
|
|
4
|
-
export declare function listWorkflowTemplate(): Promise<void>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { authUser } from '../auth/login';
|
|
4
|
-
import { getSeparatorByPlatform } from '../common';
|
|
5
|
-
const yaml = require('js-yaml');
|
|
6
|
-
import { LocalWorkflowTemplateDeployer } from './local-workflow-template-deployer';
|
|
7
|
-
import { WorkflowTemplateDeployer } from './workflow-template-deployer';
|
|
8
|
-
export async function deleteWorkflowTemplates() {
|
|
9
|
-
await authUser();
|
|
10
|
-
await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
|
|
11
|
-
}
|
|
12
|
-
export async function localDeleteWorkflowTemplate() {
|
|
13
|
-
let wtDeclaration;
|
|
14
|
-
try {
|
|
15
|
-
wtDeclaration = loadTemplateConfig();
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
await authUser();
|
|
22
|
-
await new LocalWorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
|
|
23
|
-
}
|
|
24
|
-
export async function localDeployWorkflowTemplate() {
|
|
25
|
-
let wtDeclaration;
|
|
26
|
-
try {
|
|
27
|
-
wtDeclaration = loadTemplateConfig();
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
await authUser();
|
|
34
|
-
await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
35
|
-
}
|
|
36
|
-
export async function listWorkflowTemplate() {
|
|
37
|
-
await authUser();
|
|
38
|
-
return await new WorkflowTemplateDeployer().listExistingWorkflowTemplates();
|
|
39
|
-
}
|
|
40
|
-
function loadTemplateConfig() {
|
|
41
|
-
const TARGET_DIR = process.cwd();
|
|
42
|
-
try {
|
|
43
|
-
const separator = getSeparatorByPlatform();
|
|
44
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'workflow.yml', 'utf8'));
|
|
45
|
-
console.log(doc);
|
|
46
|
-
return doc;
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import { deleteWorkflowTemplate as apiDeleteWorkflowTemplate } from '../api/event-workflow-templates';
|
|
4
|
-
import { getExistingWorkflowTemplates } from '../api/event-workflow-templates';
|
|
5
|
-
export class WorkflowTemplateDeployer {
|
|
6
|
-
async deleteWorkflowTemplates() {
|
|
7
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
8
|
-
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
9
|
-
const answers = await inquirer.prompt([{
|
|
10
|
-
type: 'checkbox',
|
|
11
|
-
name: 'wfTemplatesToDelete',
|
|
12
|
-
message: 'Which templates would you like to delete (one or more)?',
|
|
13
|
-
choices: existingWorkflows.map(x => { return { value: x.id, name: `(${x.createdOn}) ${x.name}` }; })
|
|
14
|
-
}]);
|
|
15
|
-
for (const idToDelete of answers.wfTemplatesToDelete) {
|
|
16
|
-
await apiDeleteWorkflowTemplate(idToDelete);
|
|
17
|
-
}
|
|
18
|
-
console.log('%s \tDeleted workflow templates!', chalk.green.bold('WORKFLOW TEMPLATES'));
|
|
19
|
-
}
|
|
20
|
-
async listExistingWorkflowTemplates() {
|
|
21
|
-
const templates = await getExistingWorkflowTemplates();
|
|
22
|
-
console.log('(Date Created) (active) workflow name');
|
|
23
|
-
console.log('------------------------');
|
|
24
|
-
console.log(chalk.green.bold(templates.map(x => `(${x.createdOn}) (${x.isActive ? 'active' : 'inactive'}) ${x.name} `).join('\n')));
|
|
25
|
-
}
|
|
26
|
-
}
|
package/publish.bat
DELETED
package/publish.sh
DELETED
package/src/api/apps.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Auth } from '../auth/auth';
|
|
2
|
-
import { Entities } from '@contrail/sdk';
|
|
3
|
-
import { App, AppOrg, AppVersion, WorkflowDefinition } from '../interfaces';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
|
|
6
|
-
export async function getAllAvailableApps(options: { orgId: string }): Promise<App[]> {
|
|
7
|
-
const apps: App[] = [];
|
|
8
|
-
apps.push(...await new Entities().get({
|
|
9
|
-
entityName: 'app',
|
|
10
|
-
criteria: {
|
|
11
|
-
orgId: options.orgId,
|
|
12
|
-
private: true,
|
|
13
|
-
},
|
|
14
|
-
}));
|
|
15
|
-
apps.push(...await new Entities().get({
|
|
16
|
-
entityName: 'app',
|
|
17
|
-
criteria: {
|
|
18
|
-
orgId: options.orgId,
|
|
19
|
-
private: false,
|
|
20
|
-
},
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
return apps;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function getWorkflowTemplateDefinitionsForApp(options: {appId: string}): Promise<WorkflowDefinition[]> {
|
|
27
|
-
return await new Entities().get({
|
|
28
|
-
entityName: 'event-workflow-template-definition',
|
|
29
|
-
criteria: {
|
|
30
|
-
ownerKey: `app:${options.appId}`
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function getAppVersions(app): Promise<AppVersion[]> {
|
|
36
|
-
return await new Entities().get({
|
|
37
|
-
entityName: 'app-version',
|
|
38
|
-
criteria: {
|
|
39
|
-
appId: app.id
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function upgradeAppVersion(appOrg, appVersionId): Promise<AppOrg> {
|
|
45
|
-
return await new Entities().update({
|
|
46
|
-
entityName: 'app-org',
|
|
47
|
-
id: appOrg.id,
|
|
48
|
-
object: {
|
|
49
|
-
appVersionId: appVersionId
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function deleteAppOrg(appOrgId: string): Promise<AppOrg> {
|
|
55
|
-
return await new Entities().delete({
|
|
56
|
-
entityName: 'app-org',
|
|
57
|
-
id: appOrgId
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function getInstalledApps(): Promise<AppOrg[]> {
|
|
62
|
-
return await new Entities().get({
|
|
63
|
-
entityName: 'app-org',
|
|
64
|
-
relations: ['app']
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function installAppToOrg(app, configProperties): Promise<AppOrg> {
|
|
69
|
-
return await new Entities().create({
|
|
70
|
-
entityName: 'app-org',
|
|
71
|
-
object: {
|
|
72
|
-
appId: app.id,
|
|
73
|
-
appConfig: configProperties
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function getAvailableApps(): Promise<App[]> {
|
|
79
|
-
const orgId = Auth.config.orgId;
|
|
80
|
-
const apps = [];
|
|
81
|
-
apps.push(...await new Entities().get({
|
|
82
|
-
entityName: 'app',
|
|
83
|
-
criteria: {
|
|
84
|
-
orgId,
|
|
85
|
-
private: true,
|
|
86
|
-
},
|
|
87
|
-
}));
|
|
88
|
-
apps.push(...await new Entities().get({
|
|
89
|
-
entityName: 'app',
|
|
90
|
-
criteria: {
|
|
91
|
-
orgId,
|
|
92
|
-
private: false,
|
|
93
|
-
},
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
return apps;
|
|
97
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
|
|
3
|
-
export async function createWorkflowTemplateDefinition(object: any) {
|
|
4
|
-
return await new Entities().create({
|
|
5
|
-
entityName: 'event-workflow-template-definition',
|
|
6
|
-
object: object,
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function updateWorkflowTemplateDefinition(options: {id: string, updates: any}) {
|
|
11
|
-
return await new Entities().update({
|
|
12
|
-
entityName: 'event-workflow-template-definition',
|
|
13
|
-
id: options.id,
|
|
14
|
-
object: options.updates,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function deleteWorkflowTemplateDefinition(templateId: string) {
|
|
19
|
-
return await new Entities().delete({
|
|
20
|
-
entityName: 'event-workflow-template-definition',
|
|
21
|
-
id: templateId,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
|
|
3
|
-
export async function getExistingWorkflowTemplates() {
|
|
4
|
-
return await new Entities().get({
|
|
5
|
-
entityName: 'event-workflow-template'
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function createWorkflowTemplate(object) {
|
|
10
|
-
return await new Entities().create({
|
|
11
|
-
entityName: 'event-workflow-template',
|
|
12
|
-
object
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function deleteWorkflowTemplate(id: string) {
|
|
17
|
-
return await new Entities().delete({
|
|
18
|
-
entityName: 'event-workflow-template',
|
|
19
|
-
id,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function updateWorkflowTemplate(options: { id: string, updates: any }) {
|
|
24
|
-
return await new Entities().update({
|
|
25
|
-
entityName: 'event-workflow-template',
|
|
26
|
-
id: options.id,
|
|
27
|
-
object: options.updates,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import arg from 'arg';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { setUpTemplate } from './setup-template';
|
|
5
|
-
|
|
6
|
-
function parseArgumentsIntoOptions(rawArgs) {
|
|
7
|
-
const args = arg(
|
|
8
|
-
{
|
|
9
|
-
'--app-name': String,
|
|
10
|
-
'--template': String,
|
|
11
|
-
'-n': '--app-name',
|
|
12
|
-
'-t': '--template',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
argv: rawArgs.slice(3),
|
|
16
|
-
},
|
|
17
|
-
);
|
|
18
|
-
return {
|
|
19
|
-
appName: args['--app-name'],
|
|
20
|
-
template: args['--template'],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async function promptForMissingOptions(options) {
|
|
24
|
-
const defaultTemplate = 'TypeScript';
|
|
25
|
-
options.template = defaultTemplate; // Skip javascript option
|
|
26
|
-
|
|
27
|
-
const questions = [];
|
|
28
|
-
if (!options.appName) {
|
|
29
|
-
questions.push({
|
|
30
|
-
type: 'input',
|
|
31
|
-
name: 'appName',
|
|
32
|
-
validate: (val) => !!val,
|
|
33
|
-
message: 'What is the name of your app?',
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!options.template) {
|
|
38
|
-
questions.push({
|
|
39
|
-
type: 'list',
|
|
40
|
-
name: 'template',
|
|
41
|
-
message: 'Which project template would you like to use?',
|
|
42
|
-
choices: ['TypeScript', 'JavaScript'],
|
|
43
|
-
default: defaultTemplate,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const answers = await inquirer.prompt(questions);
|
|
48
|
-
return {
|
|
49
|
-
...options,
|
|
50
|
-
appName: options.appName || answers.appName,
|
|
51
|
-
template: options.template || answers.template,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function create(args) {
|
|
56
|
-
|
|
57
|
-
let options = parseArgumentsIntoOptions(args);
|
|
58
|
-
options = await promptForMissingOptions(options);
|
|
59
|
-
console.log('%s Setting up new new contrail application.', chalk.blue.bold('START'));
|
|
60
|
-
|
|
61
|
-
let error;
|
|
62
|
-
try {
|
|
63
|
-
await setUpTemplate(options);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
error = e;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (error) {
|
|
70
|
-
console.log('%s Application initialization failed.', chalk.red.bold('FAIL'));
|
|
71
|
-
} else {
|
|
72
|
-
console.log('%s Application initialized successfully.', chalk.green.bold('COMPLETE'));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ncp from 'ncp';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { promisify } from 'util';
|
|
5
|
-
const Listr = require('listr');
|
|
6
|
-
import { projectInstall } from 'pkg-install';
|
|
7
|
-
const copy = promisify(ncp);
|
|
8
|
-
|
|
9
|
-
const TARGET_DIR = process.cwd();
|
|
10
|
-
const currentFileUrl = import .meta.url;
|
|
11
|
-
|
|
12
|
-
function copyTemplate(templateDir){
|
|
13
|
-
return copy(templateDir, TARGET_DIR, {
|
|
14
|
-
clobber: false,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function setUpTemplate(options) {
|
|
19
|
-
const templateDir = path.resolve(new URL(currentFileUrl).pathname, `../../../../templates/${options.template.toLocaleLowerCase()}`).replace(/\\/g, '\\').replace(/(.):\\(.):/g, '').replace(/%20/g, ' ');
|
|
20
|
-
try {
|
|
21
|
-
const tasks = new Listr([
|
|
22
|
-
{
|
|
23
|
-
title: 'Copy template files',
|
|
24
|
-
task: () => copyTemplate(templateDir),
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
title: 'Install dependencies',
|
|
28
|
-
task: () =>
|
|
29
|
-
projectInstall({
|
|
30
|
-
cwd: TARGET_DIR,
|
|
31
|
-
}),
|
|
32
|
-
},
|
|
33
|
-
]);
|
|
34
|
-
await tasks.run();
|
|
35
|
-
} catch (e) {
|
|
36
|
-
throw new Error(`Error copying template: ${e}`);
|
|
37
|
-
}
|
|
38
|
-
}
|