mstate-cli 0.2.9 → 0.4.0
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/.prettierrc +5 -5
- package/Readme.md +50 -50
- package/dist/index.js +298 -0
- package/package.json +46 -45
- package/rollup.config.mjs +34 -34
- package/src/common/constant.ts +19 -26
- package/src/common/enum.ts +26 -16
- package/src/common/helpers.ts +58 -42
- package/src/common/utils.ts +67 -67
- package/src/handlers/action.handler.ts +94 -131
- package/src/handlers/company.handler.ts +202 -274
- package/src/handlers/environment.handler.ts +77 -111
- package/src/handlers/help.handler.ts +80 -48
- package/src/handlers/mobioffice.handler.ts +43 -78
- package/src/handlers/workflow.handler.ts +171 -238
- package/src/index.ts +85 -85
- package/src/interface.d.ts +43 -43
- package/tsconfig.json +18 -18
package/src/index.ts
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
import packageJSON from '../package.json';
|
4
|
-
|
5
|
-
import { actionHandler } from './handlers/action.handler';
|
6
|
-
import { workflowHandler } from './handlers/workflow.handler';
|
7
|
-
import { CmdAction } from './common/enum';
|
8
|
-
import { mobiofficeHandler } from './handlers/mobioffice.handler';
|
9
|
-
import { customLog } from './common/utils';
|
10
|
-
import { hasFlag } from './common/helpers';
|
11
|
-
import { environmentHandler } from './handlers/environment.handler';
|
12
|
-
import { companyHandler } from './handlers/company.handler';
|
13
|
-
import { argv } from 'process';
|
14
|
-
import { helpHandler } from './handlers/help.handler';
|
15
|
-
|
16
|
-
const [action] = argv.slice(2);
|
17
|
-
(async function () {
|
18
|
-
switch (action as CmdAction) {
|
19
|
-
case CmdAction.VERSION:
|
20
|
-
case CmdAction.VERSION_FLAG:
|
21
|
-
console.log(`v${packageJSON.version}`);
|
22
|
-
break;
|
23
|
-
|
24
|
-
case CmdAction.LINK:
|
25
|
-
case CmdAction.UNLINK:
|
26
|
-
await mobiofficeHandler.linkToMobioffice(
|
27
|
-
action as CmdAction.LINK | CmdAction.UNLINK,
|
28
|
-
);
|
29
|
-
break;
|
30
|
-
|
31
|
-
case CmdAction.PERMISSION:
|
32
|
-
if (hasFlag(
|
33
|
-
else await companyHandler.addToken();
|
34
|
-
break;
|
35
|
-
|
36
|
-
case CmdAction.SET:
|
37
|
-
companyHandler.handleUpdateSavedSecretKey();
|
38
|
-
break;
|
39
|
-
|
40
|
-
case CmdAction.
|
41
|
-
await companyHandler.addUser();
|
42
|
-
break;
|
43
|
-
|
44
|
-
case CmdAction.DEV: // comment this case on production build
|
45
|
-
companyHandler.logToken();
|
46
|
-
break;
|
47
|
-
|
48
|
-
case CmdAction.LOGIN:
|
49
|
-
await companyHandler.handleLogin();
|
50
|
-
break;
|
51
|
-
|
52
|
-
case CmdAction.CLONE:
|
53
|
-
await workflowHandler.cloneWorkflow();
|
54
|
-
await actionHandler.cloneActions();
|
55
|
-
await environmentHandler.cloneEnvironments();
|
56
|
-
break;
|
57
|
-
case CmdAction.ADD:
|
58
|
-
await workflowHandler.copyWorkflow();
|
59
|
-
case CmdAction.PUSH:
|
60
|
-
await workflowHandler.updateWorkflowToDB();
|
61
|
-
await actionHandler.saveToDB();
|
62
|
-
await environmentHandler.saveToDB();
|
63
|
-
await workflowHandler.resetCache();
|
64
|
-
break;
|
65
|
-
case CmdAction.HELP:
|
66
|
-
case CmdAction.HELP_FLAG:
|
67
|
-
helpHandler.logCommandInfo();
|
68
|
-
break;
|
69
|
-
|
70
|
-
default:
|
71
|
-
customLog.error(
|
72
|
-
`${action ? 'Invalid' : 'Missing'}
|
73
|
-
);
|
74
|
-
console.log(
|
75
|
-
|
76
|
-
);
|
77
|
-
}
|
78
|
-
})()
|
79
|
-
.then()
|
80
|
-
.catch((error: any) => {
|
81
|
-
if (hasFlag(
|
82
|
-
helpHandler.logActionInfo(action as CmdAction);
|
83
|
-
} else customLog.error(error.message);
|
84
|
-
});
|
85
|
-
console.log('');
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
import packageJSON from '../package.json';
|
4
|
+
|
5
|
+
import { actionHandler } from './handlers/action.handler';
|
6
|
+
import { workflowHandler } from './handlers/workflow.handler';
|
7
|
+
import { CmdAction } from './common/enum';
|
8
|
+
import { mobiofficeHandler } from './handlers/mobioffice.handler';
|
9
|
+
import { customLog } from './common/utils';
|
10
|
+
import { hasFlag } from './common/helpers';
|
11
|
+
import { environmentHandler } from './handlers/environment.handler';
|
12
|
+
import { companyHandler } from './handlers/company.handler';
|
13
|
+
import { argv } from 'process';
|
14
|
+
import { helpHandler } from './handlers/help.handler';
|
15
|
+
|
16
|
+
const [action] = argv.slice(2);
|
17
|
+
(async function () {
|
18
|
+
switch (action as CmdAction) {
|
19
|
+
case CmdAction.VERSION:
|
20
|
+
case CmdAction.VERSION_FLAG:
|
21
|
+
console.log(`v${packageJSON.version}`);
|
22
|
+
break;
|
23
|
+
|
24
|
+
case CmdAction.LINK:
|
25
|
+
case CmdAction.UNLINK:
|
26
|
+
await mobiofficeHandler.linkToMobioffice(
|
27
|
+
action as CmdAction.LINK | CmdAction.UNLINK,
|
28
|
+
);
|
29
|
+
break;
|
30
|
+
|
31
|
+
case CmdAction.PERMISSION:
|
32
|
+
if (hasFlag('-d')) await companyHandler.revokePermission();
|
33
|
+
else await companyHandler.addToken();
|
34
|
+
break;
|
35
|
+
|
36
|
+
case CmdAction.SET:
|
37
|
+
companyHandler.handleUpdateSavedSecretKey();
|
38
|
+
break;
|
39
|
+
|
40
|
+
case CmdAction.ADD_USER:
|
41
|
+
await companyHandler.addUser();
|
42
|
+
break;
|
43
|
+
|
44
|
+
case CmdAction.DEV: // comment this case on production build
|
45
|
+
companyHandler.logToken();
|
46
|
+
break;
|
47
|
+
|
48
|
+
case CmdAction.LOGIN:
|
49
|
+
await companyHandler.handleLogin();
|
50
|
+
break;
|
51
|
+
|
52
|
+
case CmdAction.CLONE:
|
53
|
+
await workflowHandler.cloneWorkflow();
|
54
|
+
await actionHandler.cloneActions();
|
55
|
+
await environmentHandler.cloneEnvironments();
|
56
|
+
break;
|
57
|
+
case CmdAction.ADD:
|
58
|
+
await workflowHandler.copyWorkflow();
|
59
|
+
case CmdAction.PUSH:
|
60
|
+
await workflowHandler.updateWorkflowToDB();
|
61
|
+
await actionHandler.saveToDB();
|
62
|
+
await environmentHandler.saveToDB();
|
63
|
+
await workflowHandler.resetCache();
|
64
|
+
break;
|
65
|
+
case CmdAction.HELP:
|
66
|
+
case CmdAction.HELP_FLAG:
|
67
|
+
helpHandler.logCommandInfo();
|
68
|
+
break;
|
69
|
+
|
70
|
+
default:
|
71
|
+
customLog.error(
|
72
|
+
`${action ? 'Invalid' : 'Missing'} command: ${action ?? ''}`,
|
73
|
+
);
|
74
|
+
console.log(
|
75
|
+
`\t\t use 'mstate <command>? ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
76
|
+
);
|
77
|
+
}
|
78
|
+
})()
|
79
|
+
.then()
|
80
|
+
.catch((error: any) => {
|
81
|
+
if (hasFlag(CmdAction.HELP) || hasFlag(CmdAction.HELP_FLAG)) {
|
82
|
+
helpHandler.logActionInfo(action as CmdAction);
|
83
|
+
} else customLog.error(error.message);
|
84
|
+
});
|
85
|
+
console.log('');
|
package/src/interface.d.ts
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
interface WorkflowConfig {
|
2
|
-
name: string;
|
3
|
-
states: State[];
|
4
|
-
}
|
5
|
-
|
6
|
-
interface State {
|
7
|
-
name: string;
|
8
|
-
actions: Action[];
|
9
|
-
}
|
10
|
-
|
11
|
-
interface Action {
|
12
|
-
name: string;
|
13
|
-
when?: string;
|
14
|
-
on: {
|
15
|
-
[key: string]: {
|
16
|
-
name: string;
|
17
|
-
type: 'ACTION' | 'STATE';
|
18
|
-
};
|
19
|
-
done: {
|
20
|
-
name: string;
|
21
|
-
type: 'ACTION' | 'STATE';
|
22
|
-
};
|
23
|
-
error: {
|
24
|
-
name: string;
|
25
|
-
type: 'ACTION' | 'STATE';
|
26
|
-
};
|
27
|
-
};
|
28
|
-
}
|
29
|
-
|
30
|
-
interface ActionConfig {
|
31
|
-
name: string;
|
32
|
-
version: string;
|
33
|
-
meta?: unknown;
|
34
|
-
type: 'MANUAL' | 'AUTO' | 'CHAINED';
|
35
|
-
steps: Step[];
|
36
|
-
completionWebhook?: string;
|
37
|
-
}
|
38
|
-
|
39
|
-
interface Step {
|
40
|
-
id: string;
|
41
|
-
module: string;
|
42
|
-
config: unknown;
|
43
|
-
}
|
1
|
+
interface WorkflowConfig {
|
2
|
+
name: string;
|
3
|
+
states: State[];
|
4
|
+
}
|
5
|
+
|
6
|
+
interface State {
|
7
|
+
name: string;
|
8
|
+
actions: Action[];
|
9
|
+
}
|
10
|
+
|
11
|
+
interface Action {
|
12
|
+
name: string;
|
13
|
+
when?: string;
|
14
|
+
on: {
|
15
|
+
[key: string]: {
|
16
|
+
name: string;
|
17
|
+
type: 'ACTION' | 'STATE';
|
18
|
+
};
|
19
|
+
done: {
|
20
|
+
name: string;
|
21
|
+
type: 'ACTION' | 'STATE';
|
22
|
+
};
|
23
|
+
error: {
|
24
|
+
name: string;
|
25
|
+
type: 'ACTION' | 'STATE';
|
26
|
+
};
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
interface ActionConfig {
|
31
|
+
name: string;
|
32
|
+
version: string;
|
33
|
+
meta?: unknown;
|
34
|
+
type: 'MANUAL' | 'AUTO' | 'CHAINED';
|
35
|
+
steps: Step[];
|
36
|
+
completionWebhook?: string;
|
37
|
+
}
|
38
|
+
|
39
|
+
interface Step {
|
40
|
+
id: string;
|
41
|
+
module: string;
|
42
|
+
config: unknown;
|
43
|
+
}
|
package/tsconfig.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
{
|
2
|
-
"extends": "../tsconfig.base.json",
|
3
|
-
"compilerOptions": {
|
4
|
-
"target": "ESNext",
|
5
|
-
"module": "ESNext",
|
6
|
-
"moduleResolution": "Node",
|
7
|
-
"strict": true,
|
8
|
-
"rootDir": "../",
|
9
|
-
"baseUrl": ".",
|
10
|
-
"esModuleInterop": true,
|
11
|
-
"resolveJsonModule": true,
|
12
|
-
"skipLibCheck": true,
|
13
|
-
"outDir": "./dist",
|
14
|
-
"declaration": true
|
15
|
-
},
|
16
|
-
"include": ["src/**/*.ts", "../shared/**/*"],
|
17
|
-
"exclude": ["node_modules", "dist", ".vscode"]
|
18
|
-
}
|
1
|
+
{
|
2
|
+
"extends": "../tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"target": "ESNext",
|
5
|
+
"module": "ESNext",
|
6
|
+
"moduleResolution": "Node",
|
7
|
+
"strict": true,
|
8
|
+
"rootDir": "../",
|
9
|
+
"baseUrl": ".",
|
10
|
+
"esModuleInterop": true,
|
11
|
+
"resolveJsonModule": true,
|
12
|
+
"skipLibCheck": true,
|
13
|
+
"outDir": "./dist",
|
14
|
+
"declaration": true
|
15
|
+
},
|
16
|
+
"include": ["src/**/*.ts", "../shared/**/*"],
|
17
|
+
"exclude": ["node_modules", "dist", ".vscode"]
|
18
|
+
}
|