mstate-cli 0.4.2 → 0.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mstate-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "mstate": "./dist/index.js"
@@ -56,3 +56,28 @@ export function getMacID() {
56
56
 
57
57
  return macAddresses[0];
58
58
  }
59
+
60
+ export function sortJSON(data: any): any {
61
+ if (Array.isArray(data)) {
62
+ const newArr = [];
63
+ for (const val of data) {
64
+ newArr.push(sortJSON(val));
65
+ }
66
+
67
+ return newArr;
68
+ } else if (typeof data === 'object') {
69
+ const entries = Object.entries(data);
70
+ const sortedObject = entries.sort(([, d1]) =>
71
+ typeof d1 === 'string' || typeof d1 === 'number' ? -1 : 1,
72
+ );
73
+
74
+ let newObj: any = {};
75
+ for (const [k, d] of sortedObject) {
76
+ newObj[k] = sortJSON(d);
77
+ }
78
+
79
+ return newObj;
80
+ }
81
+
82
+ return data;
83
+ }
@@ -1,7 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import path from 'path';
3
3
  import { MSTATE_URL } from '../common/constant';
4
- import { getValueFromArgs } from '../common/helpers';
4
+ import { getValueFromArgs, sortJSON } from '../common/helpers';
5
5
  import { customLog, getSecretKey } from '../common/utils';
6
6
  import { Variables } from 'src/common/enum';
7
7
 
@@ -29,7 +29,7 @@ class ActionHandler {
29
29
  ...response?.errors,
30
30
  );
31
31
  } else {
32
- const actionConfigs = response?.data;
32
+ const actionConfigs = sortJSON(response?.data);
33
33
 
34
34
  const folderPath = path.resolve(workflowName, 'actions');
35
35
  fs.mkdirSync(folderPath, { recursive: true });
@@ -2,7 +2,7 @@ import * as fs from 'fs';
2
2
  import path from 'path';
3
3
  import { MSTATE_URL } from '../common/constant';
4
4
  import { customLog, getSecretKey } from '../common/utils';
5
- import { getValueFromArgs } from '../common/helpers';
5
+ import { getValueFromArgs, sortJSON } from '../common/helpers';
6
6
  import { Variables } from 'src/common/enum';
7
7
 
8
8
  class WorkflowHandler {
@@ -112,7 +112,10 @@ class WorkflowHandler {
112
112
  ...response?.errors,
113
113
  );
114
114
  } else {
115
- const workflowConfig = response?.data;
115
+ const workflowConfig = sortJSON(response?.data);
116
+ if (workflowConfig) {
117
+ delete workflowConfig?.id;
118
+ }
116
119
 
117
120
  const folderPath = path.resolve(workflowName);
118
121
  fs.mkdirSync(folderPath, { recursive: true });