mstate-cli 0.0.1 → 0.0.2
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 +6 -0
- package/dist/actions/workflow.action.js +39 -0
- package/dist/common/enum.js +1 -0
- package/dist/index.js +3 -0
- package/package.json +1 -1
- package/src/actions/workflow.action.ts +47 -0
- package/src/common/enum.ts +1 -0
- package/src/index.ts +3 -0
package/Readme.md
CHANGED
@@ -43,6 +43,7 @@ var Key;
|
|
43
43
|
(function (Key) {
|
44
44
|
Key["PATH"] = "path";
|
45
45
|
Key["SECRET_KEY"] = "secret";
|
46
|
+
Key["WORKFLOW"] = "workflow";
|
46
47
|
})(Key || (Key = {}));
|
47
48
|
class WorkflowAction {
|
48
49
|
constructor() { }
|
@@ -129,5 +130,43 @@ class WorkflowAction {
|
|
129
130
|
linkToMobioffice() {
|
130
131
|
return __awaiter(this, void 0, void 0, function* () { });
|
131
132
|
}
|
133
|
+
cloneWorkflow(args) {
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
135
|
+
var _a, _b, _c;
|
136
|
+
try {
|
137
|
+
const workflowName = (_b = (_a = args
|
138
|
+
.find((str) => str.includes(Key.WORKFLOW))) === null || _a === void 0 ? void 0 : _a.replace(Key.WORKFLOW + '=', '')) !== null && _b !== void 0 ? _b : '';
|
139
|
+
const secretKey = ((_c = args.find((str) => str.includes(Key.SECRET_KEY))) !== null && _c !== void 0 ? _c : '').replace(Key.SECRET_KEY + '=', '');
|
140
|
+
if (!secretKey) {
|
141
|
+
console.error(`Parameter secret is required`);
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
if (!workflowName) {
|
145
|
+
console.error(`Parameter workflow is required`);
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config/${workflowName}`;
|
149
|
+
console.log({ url });
|
150
|
+
const responseJSON = yield fetch(url, {
|
151
|
+
headers: {
|
152
|
+
'secret-key': secretKey,
|
153
|
+
},
|
154
|
+
});
|
155
|
+
const response = yield responseJSON.json();
|
156
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
157
|
+
console.error('Mstate error', 'Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
158
|
+
}
|
159
|
+
else {
|
160
|
+
const workflowConfig = response === null || response === void 0 ? void 0 : response.data;
|
161
|
+
const filePath = path_1.default.resolve(workflowName);
|
162
|
+
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
163
|
+
console.log(`Workflow "${workflowName}" is cloned successfully`);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
catch (error) {
|
167
|
+
console.error(error.message);
|
168
|
+
}
|
169
|
+
});
|
170
|
+
}
|
132
171
|
}
|
133
172
|
exports.workflowAction = new WorkflowAction();
|
package/dist/common/enum.js
CHANGED
package/dist/index.js
CHANGED
@@ -7,6 +7,9 @@ const [action, ...params] = process.argv.slice(2);
|
|
7
7
|
switch (action) {
|
8
8
|
case enum_1.CmdAction.LINK:
|
9
9
|
break;
|
10
|
+
case enum_1.CmdAction.CLONE:
|
11
|
+
workflow_action_1.workflowAction.cloneWorkflow(params);
|
12
|
+
break;
|
10
13
|
case enum_1.CmdAction.ADD:
|
11
14
|
workflow_action_1.workflowAction.saveToDB(params);
|
12
15
|
break;
|
package/package.json
CHANGED
@@ -10,6 +10,7 @@ interface AddWorkflow extends WorkflowConfig {
|
|
10
10
|
enum Key {
|
11
11
|
PATH = 'path',
|
12
12
|
SECRET_KEY = 'secret',
|
13
|
+
WORKFLOW = 'workflow',
|
13
14
|
}
|
14
15
|
|
15
16
|
class WorkflowAction {
|
@@ -111,6 +112,52 @@ class WorkflowAction {
|
|
111
112
|
}
|
112
113
|
|
113
114
|
async linkToMobioffice() {}
|
115
|
+
|
116
|
+
async cloneWorkflow(args: string[]) {
|
117
|
+
try {
|
118
|
+
const workflowName =
|
119
|
+
args
|
120
|
+
.find((str) => str.includes(Key.WORKFLOW))
|
121
|
+
?.replace(Key.WORKFLOW + '=', '') ?? '';
|
122
|
+
|
123
|
+
const secretKey = (
|
124
|
+
args.find((str) => str.includes(Key.SECRET_KEY)) ?? ''
|
125
|
+
).replace(Key.SECRET_KEY + '=', '');
|
126
|
+
|
127
|
+
if (!secretKey) {
|
128
|
+
console.error(`Parameter secret is required`);
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
|
132
|
+
if (!workflowName) {
|
133
|
+
console.error(`Parameter workflow is required`);
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
|
137
|
+
const url = `${MSTATE_URL}/workflow/config/${workflowName}`;
|
138
|
+
|
139
|
+
console.log({ url });
|
140
|
+
const responseJSON = await fetch(url, {
|
141
|
+
headers: {
|
142
|
+
'secret-key': secretKey,
|
143
|
+
},
|
144
|
+
});
|
145
|
+
|
146
|
+
const response = await responseJSON.json();
|
147
|
+
if (response?.errors) {
|
148
|
+
console.error('Mstate error', 'Invalid Parameters: ', response?.errors);
|
149
|
+
} else {
|
150
|
+
const workflowConfig = response?.data;
|
151
|
+
|
152
|
+
const filePath = path.resolve(workflowName);
|
153
|
+
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
154
|
+
|
155
|
+
console.log(`Workflow "${workflowName}" is cloned successfully`);
|
156
|
+
}
|
157
|
+
} catch (error: any) {
|
158
|
+
console.error(error.message);
|
159
|
+
}
|
160
|
+
}
|
114
161
|
}
|
115
162
|
|
116
163
|
export const workflowAction = new WorkflowAction();
|
package/src/common/enum.ts
CHANGED
package/src/index.ts
CHANGED