json-instruction-single 1.5.3 → 1.6.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 +3 -3
- package/src/index.js +2 -2
- package/src/v6/getResult.js +38 -0
- package/src/v6/index.js +10 -0
- package/src/v6/runSingleInstruction.js +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-instruction-single",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"json-source-path": "^1.2.1",
|
|
15
|
-
"json-transformer-funcs-one-dimension": "^1.
|
|
15
|
+
"json-transformer-funcs-one-dimension": "^1.8.2",
|
|
16
16
|
"json-transformer-funcs-primitive": "^1.9.3",
|
|
17
|
-
"json-write-path": "^1.
|
|
17
|
+
"json-write-path": "^1.4.1",
|
|
18
18
|
"spec-repo": "^1.4.2"
|
|
19
19
|
}
|
|
20
20
|
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export { default } from "./
|
|
1
|
+
export * from "./v6/index.js";
|
|
2
|
+
export { default, runSingleInstruction, getResult } from "./v6/index.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import applyTemplate from "json-transformer-funcs-primitive";
|
|
2
|
+
import fromCollection from "json-transformer-funcs-one-dimension";
|
|
3
|
+
|
|
4
|
+
import resolvePath from "json-source-path";
|
|
5
|
+
|
|
6
|
+
import fallbackSpec from "spec-repo";
|
|
7
|
+
|
|
8
|
+
const functions = { applyTemplate, fromCollection };
|
|
9
|
+
|
|
10
|
+
const getSource = (instruction, registry, showLog) => {
|
|
11
|
+
if (instruction?.sourcePath === null) {
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return resolvePath(registry, instruction.sourcePath);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const startFunc = (instruction, registry, showLog) => {
|
|
19
|
+
const localSpec = registry?.spec ?? fallbackSpec;
|
|
20
|
+
const localTemplateKey = instruction.templateKey;
|
|
21
|
+
const localFunc = instruction?.func;
|
|
22
|
+
|
|
23
|
+
const template = localSpec[localTemplateKey];
|
|
24
|
+
|
|
25
|
+
const source = getSource(instruction, registry, showLog);
|
|
26
|
+
|
|
27
|
+
const localFuncResult = localFunc === null
|
|
28
|
+
? template
|
|
29
|
+
: functions[instruction.func](source, template);
|
|
30
|
+
|
|
31
|
+
const result = source === null
|
|
32
|
+
? template
|
|
33
|
+
: localFuncResult;
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default startFunc;
|
package/src/v6/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import runSingleInstruction, { getResult } from "./runSingleInstruction.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = (instructions, registry, showLog, returnLog) => {
|
|
4
|
+
instructions.forEach(instruction => {
|
|
5
|
+
runSingleInstruction(instruction, registry, showLog, returnLog);
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { runSingleInstruction, getResult };
|
|
10
|
+
export default startFunc;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import writePath from "json-write-path";
|
|
2
|
+
|
|
3
|
+
import getResult from "./getResult.js";
|
|
4
|
+
|
|
5
|
+
const startFunc = (instruction, registry, showLog) => {
|
|
6
|
+
const localShowLog = showLog;
|
|
7
|
+
// console.log("localShowLog : ", localShowLog);
|
|
8
|
+
if (localShowLog) console.log("runSingleInstruction 1 :", instruction, registry);
|
|
9
|
+
|
|
10
|
+
const result = getResult(instruction, registry, showLog);
|
|
11
|
+
|
|
12
|
+
if (localShowLog) console.log("runSingleInstruction 2 :", result);
|
|
13
|
+
|
|
14
|
+
writePath(registry, instruction.destinationPath, result);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { getResult };
|
|
18
|
+
export default startFunc;
|