json-instruction-single 1.4.2 → 1.5.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/package.json +5 -4
- package/src/index.js +2 -2
- package/src/v5/index.js +57 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-instruction-single",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"json-source-path": "^1.2.1",
|
|
14
15
|
"json-transformer-funcs-one-dimension": "^1.6.1",
|
|
15
16
|
"json-transformer-funcs-primitive": "^1.9.3",
|
|
16
|
-
"json-write-path": "^1.2
|
|
17
|
-
"spec-repo": "^1.2
|
|
17
|
+
"json-write-path": "^1.3.2",
|
|
18
|
+
"spec-repo": "^1.4.2"
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export { default } from "./
|
|
1
|
+
export * from "./v5/index.js";
|
|
2
|
+
export { default } from "./v5/index.js";
|
package/src/v5/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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 fallbackSpec from "spec-repo";
|
|
8
|
+
|
|
9
|
+
const functions = { applyTemplate, fromCollection };
|
|
10
|
+
|
|
11
|
+
const getSource = (instruction, registry, showLog) => {
|
|
12
|
+
if (instruction?.sourcePath === null) {
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return resolvePath(registry, instruction.sourcePath);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const runSingleInstruction = (instruction, registry, showLog) => {
|
|
20
|
+
// Prefer the caller's specification. This lets a renderer provide
|
|
21
|
+
// its own templates without coupling the runner to a global spec package.
|
|
22
|
+
const localSpec = registry?.spec ?? fallbackSpec;
|
|
23
|
+
const localTemplateKey = instruction.templateKey;
|
|
24
|
+
const localFunc = instruction?.func;
|
|
25
|
+
|
|
26
|
+
const template = localSpec[localTemplateKey];
|
|
27
|
+
|
|
28
|
+
const source = getSource(instruction, registry, showLog);
|
|
29
|
+
|
|
30
|
+
const localFuncResult = localFunc === null
|
|
31
|
+
? template
|
|
32
|
+
: functions[instruction.func](source, template);
|
|
33
|
+
|
|
34
|
+
// console.log("111111111 ----: ", localFuncResult, localFunc, template);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const result = source === null
|
|
38
|
+
? template
|
|
39
|
+
: localFuncResult;
|
|
40
|
+
|
|
41
|
+
// console.log("runSingleInstruction ----: ", source, result, localFunc, template, localTemplateKey, localSpec);
|
|
42
|
+
|
|
43
|
+
writePath(registry, instruction.destinationPath, result);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const startFunc = (instructions, registry, showLog, returnLog) => {
|
|
47
|
+
// console.log("instructions: ", instructions[0]);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
instructions.forEach(instruction => {
|
|
51
|
+
// console.log("instruction ----: ", instruction?.sourcePath, instruction?.templateKey);
|
|
52
|
+
|
|
53
|
+
runSingleInstruction(instruction, registry, showLog, returnLog);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default startFunc;
|