@contrail/cli 3.5.3-alpha.915cfe5 → 3.5.3-alpha.acdaae3
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 +5 -11
- package/dist/commands/types/getAll.js +2 -2
- package/dist/commands/types/getOptionSets.js +2 -2
- package/dist/commands/types/parseOptionSetsLocalFiles.js +1 -1
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +1 -1
- package/dist/commands/workflow-templates/export.d.ts +1 -3
- package/dist/commands/workflow-templates/export.js +28 -99
- package/dist/common.d.ts +1 -1
- package/dist/common.js +12 -5
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +22 -0
- package/dist/helpers/workflow-templates/helper.d.ts +0 -1
- package/dist/helpers/workflow-templates/helper.js +6 -27
- package/oclif.manifest.json +5 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
|
|
|
17
17
|
$ contrail COMMAND
|
|
18
18
|
running command...
|
|
19
19
|
$ contrail (--version)
|
|
20
|
-
@contrail/cli/3.5.3-alpha.
|
|
20
|
+
@contrail/cli/3.5.3-alpha.acdaae3 linux-x64 node-v24.18.0
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -1611,31 +1611,25 @@ EXAMPLES
|
|
|
1611
1611
|
|
|
1612
1612
|
## `contrail workflow-templates export`
|
|
1613
1613
|
|
|
1614
|
-
Export all workflows in the org.
|
|
1614
|
+
Export all workflows in the org.
|
|
1615
1615
|
|
|
1616
1616
|
```
|
|
1617
1617
|
USAGE
|
|
1618
|
-
$ contrail workflow-templates export [-l error|warn|info|debug] [-e true|false] [-f <value>] [
|
|
1619
|
-
[--overwrite]
|
|
1618
|
+
$ contrail workflow-templates export [-l error|warn|info|debug] [-e true|false] [-f <value>] [--overwrite]
|
|
1620
1619
|
|
|
1621
1620
|
FLAGS
|
|
1622
|
-
-d, --dir=<value> [default: .] Directory to write per-app workflow files
|
|
1623
1621
|
-e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
|
|
1624
1622
|
<options: true|false>
|
|
1625
|
-
-f, --outFile=<value>
|
|
1623
|
+
-f, --outFile=<value> [default: workflows.yml] The location for the file to be saved
|
|
1626
1624
|
-l, --logLevel=<option> The Log Level
|
|
1627
1625
|
<options: error|warn|info|debug>
|
|
1628
1626
|
--overwrite Replaces existing files if they exist
|
|
1629
1627
|
|
|
1630
1628
|
DESCRIPTION
|
|
1631
|
-
Export all workflows in the org.
|
|
1629
|
+
Export all workflows in the org.
|
|
1632
1630
|
|
|
1633
1631
|
EXAMPLES
|
|
1634
1632
|
$ contrail workflow-templates export
|
|
1635
|
-
|
|
1636
|
-
$ contrail workflow-templates export --dir ./workflows
|
|
1637
|
-
|
|
1638
|
-
$ contrail workflow-templates export --outFile workflows.yml
|
|
1639
1633
|
```
|
|
1640
1634
|
|
|
1641
1635
|
## `contrail workflow-templates list`
|
|
@@ -99,7 +99,7 @@ const saveTypesFunction = async (data, dir, overwrite) => {
|
|
|
99
99
|
if (!fileLabel) {
|
|
100
100
|
logger_1.default.warn(`skipping bad type root: ${root}`);
|
|
101
101
|
}
|
|
102
|
-
const pathToWrite = path.join(subDir, `${(0, common_1.
|
|
102
|
+
const pathToWrite = path.join(subDir, `${(0, common_1.sanitizeFileName)(fileLabel)}.yml`);
|
|
103
103
|
if (fs_1.default.existsSync(pathToWrite)) {
|
|
104
104
|
await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
|
|
105
105
|
}
|
|
@@ -150,7 +150,7 @@ async function saveData(reducedData, dir, overwrite) {
|
|
|
150
150
|
logger_1.default.warn(`skipping bad data: ${item}`);
|
|
151
151
|
continue;
|
|
152
152
|
}
|
|
153
|
-
const pathToWrite = path.join(subDir, `${(0, common_1.
|
|
153
|
+
const pathToWrite = path.join(subDir, `${(0, common_1.sanitizeFileName)(fileLabel)}.yml`);
|
|
154
154
|
if (fs_1.default.existsSync(pathToWrite)) {
|
|
155
155
|
await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
|
|
156
156
|
}
|
|
@@ -136,7 +136,7 @@ async function saveOptionSetsToCSV(optionSets, dir, fileLabel, overwrite, combin
|
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
dataToAdd = [];
|
|
139
|
-
pathToWrite = path.join(dir, `${(0, common_1.
|
|
139
|
+
pathToWrite = path.join(dir, `${(0, common_1.sanitizeFileName)(fileLabelValue)}.csv`);
|
|
140
140
|
const csvHeaders = 'Option Set Name,Value Key,Label\n'; // CSV headers
|
|
141
141
|
if (!fs_1.default.existsSync(pathToWrite)) {
|
|
142
142
|
fs_1.default.writeFileSync(pathToWrite, csvHeaders, 'utf8');
|
|
@@ -162,7 +162,7 @@ async function saveOptionSetsToYAML(optionSets, dir, fileLabel, overwrite) {
|
|
|
162
162
|
logger_1.default.warn('skipping bad data:', item);
|
|
163
163
|
continue;
|
|
164
164
|
}
|
|
165
|
-
const pathToWrite = path.join(dir, `${(0, common_1.
|
|
165
|
+
const pathToWrite = path.join(dir, `${(0, common_1.sanitizeFileName)(fileLabelValue)}.yml`);
|
|
166
166
|
if (fs_1.default.existsSync(pathToWrite)) {
|
|
167
167
|
await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
|
|
168
168
|
}
|
|
@@ -139,7 +139,7 @@ function saveDataInFolders(data) {
|
|
|
139
139
|
if (!fileLabel) {
|
|
140
140
|
logger_1.default.warn('skipping bad data:', item);
|
|
141
141
|
}
|
|
142
|
-
fs_1.default.writeFileSync(path.join(subDir, `${(0, common_1.
|
|
142
|
+
fs_1.default.writeFileSync(path.join(subDir, `${(0, common_1.sanitizeFileName)(fileLabel)}.yml`), yamlStr, 'utf8');
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
@@ -63,6 +63,6 @@ function saveDataInFolders(data) {
|
|
|
63
63
|
if (!fileLabel) {
|
|
64
64
|
logger_1.default.warn('skipping bad data:', item);
|
|
65
65
|
}
|
|
66
|
-
fs_1.default.writeFileSync(path.join(subDir, `${(0, common_1.
|
|
66
|
+
fs_1.default.writeFileSync(path.join(subDir, `${(0, common_1.sanitizeFileName)(fileLabel)}.yml`), yamlStr, 'utf8');
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -5,12 +5,10 @@ export default class ExportWorkflows extends BaseCommand {
|
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: {
|
|
7
7
|
outFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
-
dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
8
|
overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
9
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
10
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
11
|
};
|
|
13
12
|
run(): Promise<void>;
|
|
14
13
|
}
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function exportWorkflowsToFile(fileLocation: string, overwrite: boolean): Promise<void>;
|
|
14
|
+
export declare function exportWorkflows(fileLocation: string, overwrite: boolean): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.exportWorkflows = exports.DEFAULT_FILE_LOCATION = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
@@ -11,30 +11,22 @@ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
|
11
11
|
const core_1 = require("@oclif/core");
|
|
12
12
|
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
13
13
|
const event_workflow_templates_1 = require("../../api/event-workflow-templates");
|
|
14
|
-
const schedules_1 = require("../../api/schedules");
|
|
15
|
-
const apps_1 = require("../../api/apps");
|
|
16
14
|
const helper_1 = require("../../helpers/workflow-templates/helper");
|
|
17
15
|
const basecommand_1 = require("../../basecommand");
|
|
18
16
|
exports.DEFAULT_FILE_LOCATION = 'workflows.yml';
|
|
19
17
|
class ExportWorkflows extends basecommand_1.BaseCommand {
|
|
20
|
-
static description = 'Export all workflows in the org.
|
|
18
|
+
static description = 'Export all workflows in the org.';
|
|
21
19
|
static examples = [
|
|
22
|
-
`$ contrail workflow-templates export
|
|
23
|
-
|
|
24
|
-
`$ contrail workflow-templates export --outFile workflows.yml`,
|
|
20
|
+
`$ contrail workflow-templates export
|
|
21
|
+
`,
|
|
25
22
|
];
|
|
26
23
|
static flags = {
|
|
27
24
|
...basecommand_1.BaseCommand.baseFlags,
|
|
28
25
|
outFile: core_1.Flags.string({
|
|
29
26
|
char: 'f',
|
|
30
|
-
description: '
|
|
27
|
+
description: 'The location for the file to be saved',
|
|
31
28
|
required: false,
|
|
32
|
-
|
|
33
|
-
dir: core_1.Flags.string({
|
|
34
|
-
char: 'd',
|
|
35
|
-
description: 'Directory to write per-app workflow files',
|
|
36
|
-
required: false,
|
|
37
|
-
default: '.',
|
|
29
|
+
default: exports.DEFAULT_FILE_LOCATION,
|
|
38
30
|
}),
|
|
39
31
|
overwrite: core_1.Flags.boolean({
|
|
40
32
|
description: 'Replaces existing files if they exist',
|
|
@@ -46,12 +38,7 @@ class ExportWorkflows extends basecommand_1.BaseCommand {
|
|
|
46
38
|
try {
|
|
47
39
|
await (0, login_1.authUser)();
|
|
48
40
|
this.log(`${chalk_1.default.blue.bold('START')} Getting Workflows.`);
|
|
49
|
-
|
|
50
|
-
await exportWorkflowsToFile(this.flags.outFile, this.flags.overwrite);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
await exportWorkflowsByApp(this.flags.dir ?? '.', this.flags.overwrite);
|
|
54
|
-
}
|
|
41
|
+
await exportWorkflows(this.flags.outFile ?? exports.DEFAULT_FILE_LOCATION, this.flags.overwrite);
|
|
55
42
|
this.log(`${chalk_1.default.yellow.bold('WORKFLOWS')} Done`);
|
|
56
43
|
}
|
|
57
44
|
catch (e) {
|
|
@@ -62,89 +49,31 @@ class ExportWorkflows extends basecommand_1.BaseCommand {
|
|
|
62
49
|
}
|
|
63
50
|
}
|
|
64
51
|
exports.default = ExportWorkflows;
|
|
65
|
-
async function
|
|
66
|
-
const allWorkflowsInOrg = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
67
|
-
const allSchedules = await (0, schedules_1.getExistingSchedules)();
|
|
68
|
-
const installedApps = await (0, apps_1.getInstalledApps)();
|
|
69
|
-
const appIdToIdentifier = new Map(installedApps.map((a) => [a.appId, a.app.identifier]));
|
|
70
|
-
const workflowsByApp = new Map();
|
|
71
|
-
const unassigned = [];
|
|
72
|
-
for (const workflow of allWorkflowsInOrg) {
|
|
73
|
-
let appIdentifier = workflow.supportingAppId
|
|
74
|
-
? appIdToIdentifier.get(workflow.supportingAppId)
|
|
75
|
-
: undefined;
|
|
76
|
-
// If no supportingAppId, try to extract app identifier from workflow identifier
|
|
77
|
-
// Format: @{appIdentifier}@{randomId}:{workflowName}
|
|
78
|
-
if (!appIdentifier && workflow.identifier) {
|
|
79
|
-
const match = workflow.identifier.match(/^@([^@]+)@/);
|
|
80
|
-
if (match) {
|
|
81
|
-
// Keep the @ prefix in the appIdentifier
|
|
82
|
-
appIdentifier = `@${match[1]}`;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (appIdentifier) {
|
|
86
|
-
if (!workflowsByApp.has(appIdentifier)) {
|
|
87
|
-
workflowsByApp.set(appIdentifier, []);
|
|
88
|
-
}
|
|
89
|
-
const workflows = workflowsByApp.get(appIdentifier);
|
|
90
|
-
if (workflows) {
|
|
91
|
-
workflows.push(workflow);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
unassigned.push(workflow);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const resolvedDir = path.resolve(process.cwd(), outputDir);
|
|
99
|
-
for (const [appIdentifier, workflows] of workflowsByApp.entries()) {
|
|
100
|
-
const exportObj = { appIdentifier, workflows: [] };
|
|
101
|
-
for (const workflow of workflows) {
|
|
102
|
-
exportObj.workflows.push(await buildExportWorkflow(workflow, allSchedules));
|
|
103
|
-
}
|
|
104
|
-
const safeAppIdentifier = appIdentifier.replace(/[\\/]/g, '-');
|
|
105
|
-
const filePath = path.join(resolvedDir, `workflows-${safeAppIdentifier}.yml`);
|
|
106
|
-
await writeYamlFile(exportObj, filePath, overwrite);
|
|
107
|
-
console.log(`${chalk_1.default.green('EXPORTED')} ${filePath}`);
|
|
108
|
-
}
|
|
109
|
-
if (unassigned.length > 0) {
|
|
110
|
-
console.log(`${chalk_1.default.yellow('SKIPPED')} ${unassigned.length} workflows could not be associated with an app. Re-run with --outFile to export them to a single file.`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.exportWorkflowsByApp = exportWorkflowsByApp;
|
|
114
|
-
async function exportWorkflowsToFile(fileLocation, overwrite) {
|
|
52
|
+
async function exportWorkflows(fileLocation, overwrite) {
|
|
115
53
|
const allWorkflowsInOrg = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
116
|
-
const allSchedules = await (0, schedules_1.getExistingSchedules)();
|
|
117
54
|
const workflowsObj = { workflows: [] };
|
|
118
55
|
for (const workflow of allWorkflowsInOrg) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
'isActive',
|
|
131
|
-
'messageGroup',
|
|
132
|
-
'dynamicMessageGroupId',
|
|
133
|
-
'parallelWorkerCount',
|
|
134
|
-
'workflowDefinition',
|
|
135
|
-
]);
|
|
136
|
-
const schedules = allSchedules.filter((s) => s.ownerReference === `event-workflow-template:${workflow.id}`);
|
|
137
|
-
if (schedules.length > 0) {
|
|
138
|
-
exportWorkflow.crons = schedules.map((s) => ({ name: s.name, cron: s.cron }));
|
|
56
|
+
const exportWorkflow = lodash_1.default.pick(workflow, [
|
|
57
|
+
'triggerKey',
|
|
58
|
+
'workflowDefinition',
|
|
59
|
+
'name',
|
|
60
|
+
'isActive',
|
|
61
|
+
'identifier',
|
|
62
|
+
'messageGroup',
|
|
63
|
+
'dynamicMessageGroupId',
|
|
64
|
+
]);
|
|
65
|
+
await (0, helper_1.populateActionIdentifiers)(exportWorkflow);
|
|
66
|
+
workflowsObj.workflows.push(exportWorkflow);
|
|
139
67
|
}
|
|
140
|
-
await (
|
|
141
|
-
(0, helper_1.extractShortActionKeys)(exportWorkflow);
|
|
142
|
-
return exportWorkflow;
|
|
68
|
+
await saveData(workflowsObj, fileLocation, overwrite);
|
|
143
69
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
70
|
+
exports.exportWorkflows = exportWorkflows;
|
|
71
|
+
async function saveData(data, fileLocation, overwrite) {
|
|
72
|
+
const yamlStr = js_yaml_1.default.dump(data);
|
|
73
|
+
const CURRENT_DIR = process.cwd();
|
|
74
|
+
const pathToWrite = path.resolve(path.join(CURRENT_DIR, fileLocation));
|
|
75
|
+
if (fs_1.default.existsSync(pathToWrite)) {
|
|
76
|
+
await (0, file_helpers_1.safeFileOverwrite)(pathToWrite, overwrite);
|
|
147
77
|
}
|
|
148
|
-
fs_1.default.
|
|
149
|
-
fs_1.default.writeFileSync(absolutePath, js_yaml_1.default.dump(data), 'utf8');
|
|
78
|
+
fs_1.default.writeFileSync(pathToWrite, yamlStr, 'utf8');
|
|
150
79
|
}
|
package/dist/common.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
export declare function getSeparatorByPlatform(): string;
|
|
3
3
|
export declare function delay(ms: number): Promise<NodeJS.Timeout>;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function sanitizeFileName(name: string): string;
|
package/dist/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.sanitizeFileName = exports.delay = exports.getSeparatorByPlatform = void 0;
|
|
4
4
|
function getSeparatorByPlatform() {
|
|
5
5
|
const isWin = process.platform === 'win32';
|
|
6
6
|
const separator = isWin ? '\\' : '/';
|
|
@@ -11,8 +11,15 @@ function delay(ms) {
|
|
|
11
11
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
12
12
|
}
|
|
13
13
|
exports.delay = delay;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// Characters that are invalid in Windows filenames (superset of POSIX, which only forbids `/`)
|
|
15
|
+
// eslint-disable-next-line no-control-regex
|
|
16
|
+
const INVALID_FILENAME_CHARS = /[<>:"/\\|?*\x00-\x1f]/g;
|
|
17
|
+
const WINDOWS_RESERVED_NAMES = /^(con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
18
|
+
function sanitizeFileName(name) {
|
|
19
|
+
let sanitized = name.replace(INVALID_FILENAME_CHARS, '-').replace(/[. ]+$/, '');
|
|
20
|
+
if (WINDOWS_RESERVED_NAMES.test(sanitized)) {
|
|
21
|
+
sanitized = `${sanitized}-`;
|
|
22
|
+
}
|
|
23
|
+
return sanitized;
|
|
17
24
|
}
|
|
18
|
-
exports.
|
|
25
|
+
exports.sanitizeFileName = sanitizeFileName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("./common");
|
|
4
|
+
describe('sanitizeFileName', () => {
|
|
5
|
+
it('replaces slashes with dashes', () => {
|
|
6
|
+
expect((0, common_1.sanitizeFileName)('a/b/c')).toEqual('a-b-c');
|
|
7
|
+
});
|
|
8
|
+
it('replaces Windows-invalid characters with dashes', () => {
|
|
9
|
+
expect((0, common_1.sanitizeFileName)('isArchived?')).toEqual('isArchived-');
|
|
10
|
+
expect((0, common_1.sanitizeFileName)('a<b>c:d"e\\f|g?h*i')).toEqual('a-b-c-d-e-f-g-h-i');
|
|
11
|
+
});
|
|
12
|
+
it('strips trailing dots and spaces', () => {
|
|
13
|
+
expect((0, common_1.sanitizeFileName)('label. ')).toEqual('label');
|
|
14
|
+
});
|
|
15
|
+
it('escapes Windows reserved device names', () => {
|
|
16
|
+
expect((0, common_1.sanitizeFileName)('CON')).toEqual('CON-');
|
|
17
|
+
expect((0, common_1.sanitizeFileName)('com1')).toEqual('com1-');
|
|
18
|
+
});
|
|
19
|
+
it('leaves safe labels unchanged', () => {
|
|
20
|
+
expect((0, common_1.sanitizeFileName)('My Label - v2')).toEqual('My Label - v2');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -18,4 +18,3 @@ export declare class WorkflowTemplateDeployer {
|
|
|
18
18
|
export declare function deleteWorkflowTemplates(): Promise<void>;
|
|
19
19
|
export declare function localDeployWorkflowTemplate(saveFileLocation: string): Promise<void>;
|
|
20
20
|
export declare function populateActionIdentifiers(workflowTemplate: WorkflowTemplate): Promise<void>;
|
|
21
|
-
export declare function extractShortActionKeys(workflowTemplate: WorkflowTemplate): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.populateActionIdentifiers = exports.localDeployWorkflowTemplate = exports.deleteWorkflowTemplates = exports.WorkflowTemplateDeployer = exports.getActionByIdentifier = exports.getWorkflowTemplateIdentifier = exports.LocalWorkflowTemplateDeployer = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const util_1 = require("@contrail/util");
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
@@ -20,6 +20,7 @@ class LocalWorkflowTemplateDeployer {
|
|
|
20
20
|
const existingWorkflows = await (0, event_workflow_templates_1.getExistingWorkflowTemplates)();
|
|
21
21
|
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
22
22
|
logger_1.default.info(`${chalk_1.default.yellow.bold('WORKFLOW TEMPLATES')} Deploying workflow templates.`);
|
|
23
|
+
logger_1.default.info(wtDeclaration);
|
|
23
24
|
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
24
25
|
await this.deployWorkflowTemplate(wtDeclaration.workflows[workflowKey], existingWorkflows, wtDeclaration.appIdentifier);
|
|
25
26
|
}
|
|
@@ -34,7 +35,7 @@ class LocalWorkflowTemplateDeployer {
|
|
|
34
35
|
return await this.createNewWorkflowTemplate(identifier, workflow, appIdentifier);
|
|
35
36
|
}
|
|
36
37
|
async createNewWorkflowTemplate(workflowKey, workflowTemplate, appIdentifier) {
|
|
37
|
-
this.populateActionIds(workflowTemplate, workflowKey, appIdentifier);
|
|
38
|
+
await this.populateActionIds(workflowTemplate, workflowKey, appIdentifier);
|
|
38
39
|
const newObject = {
|
|
39
40
|
identifier: getWorkflowTemplateIdentifier(workflowTemplate),
|
|
40
41
|
name: workflowTemplate.name,
|
|
@@ -43,8 +44,6 @@ class LocalWorkflowTemplateDeployer {
|
|
|
43
44
|
isActive: workflowTemplate.isActive,
|
|
44
45
|
supportingAppId: workflowTemplate.supportingAppId,
|
|
45
46
|
messageGroupId: workflowTemplate.messageGroupId,
|
|
46
|
-
messageGroup: workflowTemplate.messageGroup,
|
|
47
|
-
dynamicMessageGroupId: workflowTemplate.dynamicMessageGroupId,
|
|
48
47
|
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
49
48
|
};
|
|
50
49
|
const newWorkflowTemplate = await (0, event_workflow_templates_1.createWorkflowTemplate)(newObject);
|
|
@@ -56,10 +55,8 @@ class LocalWorkflowTemplateDeployer {
|
|
|
56
55
|
}
|
|
57
56
|
async populateActionIds(workflowTemplate, workflowKey, appIdentifier) {
|
|
58
57
|
const installedApps = await (0, apps_1.getInstalledApps)();
|
|
59
|
-
const appOrg = installedApps.find((x) => x.app
|
|
60
|
-
|
|
61
|
-
throw new Error(`Could not find installed app with identifier "${appIdentifier}". Make sure the app is installed in this org before importing workflows.`);
|
|
62
|
-
}
|
|
58
|
+
const appOrg = installedApps.find((x) => x.app.identifier === appIdentifier);
|
|
59
|
+
logger_1.default.info('workflow template:', JSON.stringify(workflowTemplate, null, 2));
|
|
63
60
|
if (!workflowTemplate?.workflowDefinition?.paths) {
|
|
64
61
|
return;
|
|
65
62
|
}
|
|
@@ -89,7 +86,7 @@ class LocalWorkflowTemplateDeployer {
|
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
async createWorkflowSchedule(workflowTemplate, workflowId) {
|
|
92
|
-
if (!workflowTemplate?.crons?.length) {
|
|
89
|
+
if (!workflowTemplate?.crons?.length || !workflowTemplate.id) {
|
|
93
90
|
return;
|
|
94
91
|
}
|
|
95
92
|
const crons = [];
|
|
@@ -286,21 +283,3 @@ async function populateActionIdentifiers(workflowTemplate) {
|
|
|
286
283
|
}
|
|
287
284
|
}
|
|
288
285
|
exports.populateActionIdentifiers = populateActionIdentifiers;
|
|
289
|
-
function extractShortActionKeys(workflowTemplate) {
|
|
290
|
-
if (!workflowTemplate?.workflowDefinition?.paths) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
for (const wfPath of workflowTemplate.workflowDefinition.paths) {
|
|
294
|
-
if (!wfPath?.actionDefinitionConfigs) {
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
for (const actionConfig of wfPath.actionDefinitionConfigs) {
|
|
298
|
-
if (actionConfig.action?.includes(':')) {
|
|
299
|
-
// Full identifier format: "app-id@version:action-name" -> "action-name"
|
|
300
|
-
actionConfig.action = actionConfig.action.split(':').pop();
|
|
301
|
-
}
|
|
302
|
-
delete actionConfig.identifier;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
exports.extractShortActionKeys = extractShortActionKeys;
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.5.3-alpha.
|
|
2
|
+
"version": "3.5.3-alpha.acdaae3",
|
|
3
3
|
"commands": {
|
|
4
4
|
"app:create": {
|
|
5
5
|
"id": "app:create",
|
|
@@ -2956,16 +2956,14 @@
|
|
|
2956
2956
|
},
|
|
2957
2957
|
"workflow-templates:export": {
|
|
2958
2958
|
"id": "workflow-templates:export",
|
|
2959
|
-
"description": "Export all workflows in the org.
|
|
2959
|
+
"description": "Export all workflows in the org.",
|
|
2960
2960
|
"strict": true,
|
|
2961
2961
|
"pluginName": "@contrail/cli",
|
|
2962
2962
|
"pluginAlias": "@contrail/cli",
|
|
2963
2963
|
"pluginType": "core",
|
|
2964
2964
|
"aliases": [],
|
|
2965
2965
|
"examples": [
|
|
2966
|
-
"$ contrail workflow-templates export"
|
|
2967
|
-
"$ contrail workflow-templates export --dir ./workflows",
|
|
2968
|
-
"$ contrail workflow-templates export --outFile workflows.yml"
|
|
2966
|
+
"$ contrail workflow-templates export\n"
|
|
2969
2967
|
],
|
|
2970
2968
|
"flags": {
|
|
2971
2969
|
"logLevel": {
|
|
@@ -2999,18 +2997,10 @@
|
|
|
2999
2997
|
"name": "outFile",
|
|
3000
2998
|
"type": "option",
|
|
3001
2999
|
"char": "f",
|
|
3002
|
-
"description": "
|
|
3003
|
-
"required": false,
|
|
3004
|
-
"multiple": false
|
|
3005
|
-
},
|
|
3006
|
-
"dir": {
|
|
3007
|
-
"name": "dir",
|
|
3008
|
-
"type": "option",
|
|
3009
|
-
"char": "d",
|
|
3010
|
-
"description": "Directory to write per-app workflow files",
|
|
3000
|
+
"description": "The location for the file to be saved",
|
|
3011
3001
|
"required": false,
|
|
3012
3002
|
"multiple": false,
|
|
3013
|
-
"default": "."
|
|
3003
|
+
"default": "workflows.yml"
|
|
3014
3004
|
},
|
|
3015
3005
|
"overwrite": {
|
|
3016
3006
|
"name": "overwrite",
|