json-instruction-single 1.2.2 → 1.3.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/package.json +4 -3
- package/src/index.js +2 -2
- package/src/v3/index.js +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-instruction-single",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"json-instruction-guards": "^1.0.0",
|
|
15
15
|
"json-source-path": "^1.2.1",
|
|
16
|
-
"json-
|
|
16
|
+
"json-transformer-funcs-one-dimension": "^1.6.1",
|
|
17
17
|
"json-transformer-funcs-primitive": "^1.9.3",
|
|
18
|
-
"json-
|
|
18
|
+
"json-write-path": "^1.2.1",
|
|
19
|
+
"spec-repo": "^1.2.1"
|
|
19
20
|
}
|
|
20
21
|
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export { default } from "./
|
|
1
|
+
export * from "./v3/index.js";
|
|
2
|
+
export { default } from "./v3/index.js";
|
package/src/v3/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import applyTemplate from "json-transformer-funcs-primitive";
|
|
2
|
+
import fromCollection from "json-transformer-funcs-one-dimension";
|
|
3
|
+
|
|
4
|
+
import writePath from "json-write-path";
|
|
5
|
+
import resolvePath from "json-source-path";
|
|
6
|
+
|
|
7
|
+
import spec from "spec-repo";
|
|
8
|
+
|
|
9
|
+
const functions = { applyTemplate, fromCollection };
|
|
10
|
+
|
|
11
|
+
const getSource = (instruction, registry) => {
|
|
12
|
+
if (instruction?.sourcePath === null) {
|
|
13
|
+
// Runs ONLY if value is exactly null
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const source = resolvePath(registry, instruction.sourcePath);
|
|
18
|
+
|
|
19
|
+
return source;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const runSingleInstruction = (instruction, registry, showLog, returnLog) => {
|
|
23
|
+
const localSpec = spec;
|
|
24
|
+
const templateKey = instruction.templateKey;
|
|
25
|
+
let localSpecKey = localSpec[templateKey];
|
|
26
|
+
let result;
|
|
27
|
+
|
|
28
|
+
const source = getSource(instruction, registry);
|
|
29
|
+
// console.log("source : ", source);
|
|
30
|
+
|
|
31
|
+
if (source === null) {
|
|
32
|
+
result = localSpecKey;
|
|
33
|
+
} else {
|
|
34
|
+
result = functions[instruction.func](source, localSpecKey);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
writePath(registry, instruction.destinationPath, result);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const startFunc = (instructions, registry, showLog, returnLog) => {
|
|
41
|
+
instructions.forEach(instruction => {
|
|
42
|
+
runSingleInstruction(instruction, registry, showLog, returnLog);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default startFunc;
|