@caleuche/cli 0.2.4 → 0.3.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/CHANGELOG.md +6 -0
- package/dist/batch.js +41 -28
- package/dist/utils.js +19 -3
- package/package.json +1 -1
- package/src/batch.ts +65 -48
- package/src/interfaces.ts +27 -10
- package/src/utils.ts +28 -6
- package/test/bach.test.ts +43 -26
- package/test/common.test.ts +1 -5
package/CHANGELOG.md
CHANGED
package/dist/batch.js
CHANGED
|
@@ -4,54 +4,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.batchCompile = batchCompile;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
7
|
const utils_1 = require("./utils");
|
|
9
8
|
const common_1 = require("./common");
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
|
-
function
|
|
12
|
-
if ((0, utils_1.
|
|
13
|
-
return
|
|
10
|
+
function loadVariantInputDefinition(variantInput, workingDirectory) {
|
|
11
|
+
if ((0, utils_1.isVariantInputDefinition)(variantInput)) {
|
|
12
|
+
return variantInput;
|
|
14
13
|
}
|
|
15
|
-
else
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
|
|
14
|
+
else {
|
|
15
|
+
const absolutePath = path_1.default.join(workingDirectory, variantInput.value);
|
|
16
|
+
if ((0, utils_1.isFile)(absolutePath)) {
|
|
17
|
+
const v = (0, utils_1.parse)(absolutePath);
|
|
18
|
+
if (!v) {
|
|
19
|
+
console.error(`Failed to parse variant at path: ${absolutePath}`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.error(`Variant input path "${variantInput.value}" does not exist or is not a file.`);
|
|
19
26
|
return null;
|
|
20
27
|
}
|
|
21
|
-
return v;
|
|
22
28
|
}
|
|
23
|
-
return null;
|
|
24
29
|
}
|
|
25
30
|
function loadVariantDefinitions(variants, workingDirectory) {
|
|
26
31
|
if (!variants)
|
|
27
32
|
return {};
|
|
28
33
|
const definitions = {};
|
|
29
|
-
for (const
|
|
30
|
-
const v =
|
|
34
|
+
for (const { name, input } of variants) {
|
|
35
|
+
const v = loadVariantInputDefinition(input, workingDirectory);
|
|
31
36
|
if (!v) {
|
|
32
|
-
console.error(`Failed to load variant definition for key "${
|
|
37
|
+
console.error(`Failed to load variant definition for key "${name}": ${input}`);
|
|
33
38
|
return null;
|
|
34
39
|
}
|
|
35
|
-
definitions[
|
|
40
|
+
definitions[name] = v;
|
|
36
41
|
}
|
|
37
42
|
return definitions;
|
|
38
43
|
}
|
|
39
44
|
function resolveVariantDefinition(variant, variantRegistry, workingDirectory) {
|
|
40
|
-
if ((0, utils_1.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if ((0, utils_1.isFile)(path_1.default.join(workingDirectory, variant.data))) {
|
|
44
|
-
const v = (0, utils_1.parse)(path_1.default.join(workingDirectory, variant.data));
|
|
45
|
+
if ((0, utils_1.isVariantInputReference)(variant.input)) {
|
|
46
|
+
const ref = (0, utils_1.getVariantInputReferenceValue)(variant.input);
|
|
47
|
+
const v = variantRegistry[ref];
|
|
45
48
|
if (v) {
|
|
46
49
|
return v;
|
|
47
50
|
}
|
|
51
|
+
console.error(`Variant "${ref}" could not be resolved.`);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
else if ((0, utils_1.isVariantInputDefinition)(variant.input)) {
|
|
55
|
+
return variant.input;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
else {
|
|
58
|
+
const absolutePath = path_1.default.join(workingDirectory, variant.input.value);
|
|
59
|
+
if ((0, utils_1.isFile)(absolutePath)) {
|
|
60
|
+
const v = (0, utils_1.parse)(absolutePath);
|
|
61
|
+
if (v) {
|
|
62
|
+
return v;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
console.error(`Variant input path "${variant.input.value}" does not exist or is not a file.`);
|
|
66
|
+
return null;
|
|
52
67
|
}
|
|
53
|
-
console.error(`Variant "${variant.data}" could not be resolved.`);
|
|
54
|
-
return null;
|
|
55
68
|
}
|
|
56
69
|
function batchCompile(batchFile) {
|
|
57
70
|
if (!(0, utils_1.isFile)(batchFile)) {
|
|
@@ -60,17 +73,17 @@ function batchCompile(batchFile) {
|
|
|
60
73
|
}
|
|
61
74
|
const workingDirectory = (0, utils_1.getAbsoluteDirectoryPath)(batchFile);
|
|
62
75
|
console.log(`Working directory: ${workingDirectory}`);
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
76
|
+
const batchDefinition = (0, utils_1.parse)(batchFile);
|
|
77
|
+
if (!batchDefinition) {
|
|
65
78
|
console.error(`Failed to parse batch file: ${batchFile}`);
|
|
66
79
|
process.exit(1);
|
|
67
80
|
}
|
|
68
|
-
const variants = loadVariantDefinitions(
|
|
81
|
+
const variants = loadVariantDefinitions(batchDefinition.variants, workingDirectory);
|
|
69
82
|
console.log(`Loaded ${Object.keys(variants || {}).length} variant definitions from batch file.`);
|
|
70
83
|
if (!variants) {
|
|
71
84
|
process.exit(1);
|
|
72
85
|
}
|
|
73
|
-
const samples =
|
|
86
|
+
const samples = batchDefinition.samples;
|
|
74
87
|
for (const sampleDefinition of samples) {
|
|
75
88
|
console.log(`Processing sample: ${sampleDefinition.templatePath}`);
|
|
76
89
|
const templatePath = path_1.default.join(workingDirectory, sampleDefinition.templatePath);
|
package/dist/utils.js
CHANGED
|
@@ -9,7 +9,10 @@ exports.isDirectory = isDirectory;
|
|
|
9
9
|
exports.createOutputDirectory = createOutputDirectory;
|
|
10
10
|
exports.resolveTemplate = resolveTemplate;
|
|
11
11
|
exports.isObject = isObject;
|
|
12
|
-
exports.
|
|
12
|
+
exports.isVariantInputDefinition = isVariantInputDefinition;
|
|
13
|
+
exports.isVariantInputPath = isVariantInputPath;
|
|
14
|
+
exports.isVariantInputReference = isVariantInputReference;
|
|
15
|
+
exports.getVariantInputReferenceValue = getVariantInputReferenceValue;
|
|
13
16
|
exports.getAbsoluteDirectoryPath = getAbsoluteDirectoryPath;
|
|
14
17
|
exports.isFile = isFile;
|
|
15
18
|
const yaml_1 = require("yaml");
|
|
@@ -57,8 +60,21 @@ function resolveTemplate(samplePath, sample) {
|
|
|
57
60
|
function isObject(value) {
|
|
58
61
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
59
62
|
}
|
|
60
|
-
function
|
|
61
|
-
return isObject(variant) &&
|
|
63
|
+
function isVariantInputDefinition(variant) {
|
|
64
|
+
return isObject(variant) && variant.type === "object";
|
|
65
|
+
}
|
|
66
|
+
function isVariantInputPath(variant) {
|
|
67
|
+
return isObject(variant) && variant.type === "path";
|
|
68
|
+
}
|
|
69
|
+
function isVariantInputReference(variant) {
|
|
70
|
+
return ((isObject(variant) && variant.type === "reference") ||
|
|
71
|
+
typeof variant === "string");
|
|
72
|
+
}
|
|
73
|
+
function getVariantInputReferenceValue(variant) {
|
|
74
|
+
if (typeof variant === "string") {
|
|
75
|
+
return variant;
|
|
76
|
+
}
|
|
77
|
+
return variant.value;
|
|
62
78
|
}
|
|
63
79
|
function getAbsoluteDirectoryPath(filePath) {
|
|
64
80
|
return path_1.default.dirname(path_1.default.resolve(filePath));
|
package/package.json
CHANGED
package/src/batch.ts
CHANGED
|
@@ -1,72 +1,85 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
1
|
import {
|
|
3
2
|
getAbsoluteDirectoryPath,
|
|
3
|
+
getVariantInputReferenceValue,
|
|
4
4
|
isFile,
|
|
5
|
-
|
|
5
|
+
isVariantInputDefinition,
|
|
6
|
+
isVariantInputReference,
|
|
6
7
|
parse,
|
|
7
8
|
} from "./utils";
|
|
8
9
|
import { compileAndWriteOutput, resolveAndParseSample } from "./common";
|
|
9
10
|
import path from "path";
|
|
10
11
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
workingDirectory: string
|
|
14
|
-
):
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
17
|
-
} else
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
12
|
+
function loadVariantInputDefinition(
|
|
13
|
+
variantInput: SampleVariantInputDefinition | SampleVariantInputPath,
|
|
14
|
+
workingDirectory: string,
|
|
15
|
+
): SampleVariantInputDefinition | null {
|
|
16
|
+
if (isVariantInputDefinition(variantInput)) {
|
|
17
|
+
return variantInput;
|
|
18
|
+
} else {
|
|
19
|
+
const absolutePath = path.join(workingDirectory, variantInput.value);
|
|
20
|
+
if (isFile(absolutePath)) {
|
|
21
|
+
const v = parse<SampleVariantInputDefinition>(absolutePath);
|
|
22
|
+
if (!v) {
|
|
23
|
+
console.error(`Failed to parse variant at path: ${absolutePath}`);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return v;
|
|
27
|
+
} else {
|
|
28
|
+
console.error(
|
|
29
|
+
`Variant input path "${variantInput.value}" does not exist or is not a file.`,
|
|
30
|
+
);
|
|
21
31
|
return null;
|
|
22
32
|
}
|
|
23
|
-
return v;
|
|
24
33
|
}
|
|
25
|
-
return null;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
function loadVariantDefinitions(
|
|
29
|
-
variants:
|
|
30
|
-
workingDirectory: string
|
|
31
|
-
): Record<string,
|
|
37
|
+
variants: SampleVariantInputEntry[] | undefined,
|
|
38
|
+
workingDirectory: string,
|
|
39
|
+
): Record<string, SampleVariantInputDefinition> | null {
|
|
32
40
|
if (!variants) return {};
|
|
33
|
-
const definitions: Record<string,
|
|
34
|
-
for (const
|
|
35
|
-
const v =
|
|
41
|
+
const definitions: Record<string, SampleVariantInputDefinition> = {};
|
|
42
|
+
for (const { name, input } of variants) {
|
|
43
|
+
const v = loadVariantInputDefinition(input, workingDirectory);
|
|
36
44
|
if (!v) {
|
|
37
45
|
console.error(
|
|
38
|
-
`Failed to load variant definition for key "${
|
|
46
|
+
`Failed to load variant definition for key "${name}": ${input}`,
|
|
39
47
|
);
|
|
40
48
|
return null;
|
|
41
49
|
}
|
|
42
|
-
definitions[
|
|
50
|
+
definitions[name] = v;
|
|
43
51
|
}
|
|
44
52
|
return definitions;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
function resolveVariantDefinition(
|
|
48
56
|
variant: SampleVariantConfig,
|
|
49
|
-
variantRegistry: Record<string,
|
|
50
|
-
workingDirectory: string
|
|
51
|
-
):
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (isFile(path.join(workingDirectory, variant.data))) {
|
|
57
|
-
const v = parse<SampleVariantDefinition>(path.join(workingDirectory, variant.data));
|
|
57
|
+
variantRegistry: Record<string, SampleVariantInputDefinition>,
|
|
58
|
+
workingDirectory: string,
|
|
59
|
+
): SampleVariantInputDefinition | null {
|
|
60
|
+
if (isVariantInputReference(variant.input)) {
|
|
61
|
+
const ref = getVariantInputReferenceValue(variant.input);
|
|
62
|
+
const v = variantRegistry[ref];
|
|
58
63
|
if (v) {
|
|
59
64
|
return v;
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
console.error(`Variant "${ref}" could not be resolved.`);
|
|
67
|
+
return null;
|
|
68
|
+
} else if (isVariantInputDefinition(variant.input)) {
|
|
69
|
+
return variant.input;
|
|
70
|
+
} else {
|
|
71
|
+
const absolutePath = path.join(workingDirectory, variant.input.value);
|
|
72
|
+
if (isFile(absolutePath)) {
|
|
73
|
+
const v = parse<SampleVariantInputDefinition>(absolutePath);
|
|
74
|
+
if (v) {
|
|
75
|
+
return v;
|
|
76
|
+
}
|
|
67
77
|
}
|
|
68
|
-
console.error(
|
|
69
|
-
|
|
78
|
+
console.error(
|
|
79
|
+
`Variant input path "${variant.input.value}" does not exist or is not a file.`,
|
|
80
|
+
);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
export function batchCompile(batchFile: string) {
|
|
@@ -76,19 +89,22 @@ export function batchCompile(batchFile: string) {
|
|
|
76
89
|
}
|
|
77
90
|
const workingDirectory = getAbsoluteDirectoryPath(batchFile);
|
|
78
91
|
console.log(`Working directory: ${workingDirectory}`);
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
92
|
+
const batchDefinition = parse<BatchCompileDescription>(batchFile);
|
|
93
|
+
if (!batchDefinition) {
|
|
81
94
|
console.error(`Failed to parse batch file: ${batchFile}`);
|
|
82
95
|
process.exit(1);
|
|
83
96
|
}
|
|
84
|
-
const variants = loadVariantDefinitions(
|
|
97
|
+
const variants = loadVariantDefinitions(
|
|
98
|
+
batchDefinition.variants,
|
|
99
|
+
workingDirectory,
|
|
100
|
+
);
|
|
85
101
|
console.log(
|
|
86
102
|
`Loaded ${Object.keys(variants || {}).length} variant definitions from batch file.`,
|
|
87
103
|
);
|
|
88
104
|
if (!variants) {
|
|
89
105
|
process.exit(1);
|
|
90
106
|
}
|
|
91
|
-
const samples =
|
|
107
|
+
const samples = batchDefinition.samples;
|
|
92
108
|
for (const sampleDefinition of samples) {
|
|
93
109
|
console.log(`Processing sample: ${sampleDefinition.templatePath}`);
|
|
94
110
|
const templatePath = path.join(
|
|
@@ -102,15 +118,16 @@ export function batchCompile(batchFile: string) {
|
|
|
102
118
|
|
|
103
119
|
for (const variant of sampleDefinition.variants) {
|
|
104
120
|
console.log("Processing variant...");
|
|
105
|
-
const resolvedVariant = resolveVariantDefinition(
|
|
121
|
+
const resolvedVariant = resolveVariantDefinition(
|
|
122
|
+
variant,
|
|
123
|
+
variants,
|
|
124
|
+
workingDirectory,
|
|
125
|
+
);
|
|
106
126
|
if (!resolvedVariant) {
|
|
107
127
|
process.exit(1);
|
|
108
128
|
}
|
|
109
129
|
|
|
110
|
-
const effectiveOutputPath = path.join(
|
|
111
|
-
workingDirectory,
|
|
112
|
-
variant.output,
|
|
113
|
-
);
|
|
130
|
+
const effectiveOutputPath = path.join(workingDirectory, variant.output);
|
|
114
131
|
|
|
115
132
|
if (
|
|
116
133
|
!compileAndWriteOutput(sample, resolvedVariant, effectiveOutputPath, {
|
package/src/interfaces.ts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
interface SampleVariantInputDefinition {
|
|
2
|
+
type: "object";
|
|
3
|
+
properties: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface SampleVariantInputReference {
|
|
7
|
+
type: "reference";
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface SampleVariantInputPath {
|
|
12
|
+
type: "path";
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type SampleVariantInput =
|
|
17
|
+
| SampleVariantInputDefinition
|
|
18
|
+
| SampleVariantInputReference
|
|
19
|
+
| SampleVariantInputPath;
|
|
8
20
|
|
|
9
21
|
interface SampleVariantConfig {
|
|
10
22
|
output: string;
|
|
11
|
-
|
|
23
|
+
input: SampleVariantInput | string;
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
interface SampleDefinition {
|
|
@@ -16,7 +28,12 @@ interface SampleDefinition {
|
|
|
16
28
|
variants: SampleVariantConfig[];
|
|
17
29
|
}
|
|
18
30
|
|
|
19
|
-
interface
|
|
20
|
-
|
|
31
|
+
interface SampleVariantInputEntry {
|
|
32
|
+
name: string;
|
|
33
|
+
input: SampleVariantInputDefinition | SampleVariantInputPath;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface BatchCompileDescription {
|
|
37
|
+
variants?: SampleVariantInputEntry[];
|
|
21
38
|
samples: SampleDefinition[];
|
|
22
39
|
}
|
package/src/utils.ts
CHANGED
|
@@ -52,15 +52,37 @@ export function isObject(value: any): value is Record<string, any> {
|
|
|
52
52
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export function
|
|
56
|
-
variant:
|
|
57
|
-
): variant is
|
|
58
|
-
return isObject(variant) &&
|
|
55
|
+
export function isVariantInputDefinition(
|
|
56
|
+
variant: SampleVariantInput,
|
|
57
|
+
): variant is SampleVariantInputDefinition {
|
|
58
|
+
return isObject(variant) && variant.type === "object";
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export function
|
|
62
|
-
|
|
61
|
+
export function isVariantInputPath(
|
|
62
|
+
variant: SampleVariantInput,
|
|
63
|
+
): variant is SampleVariantInputPath {
|
|
64
|
+
return isObject(variant) && variant.type === "path";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isVariantInputReference(
|
|
68
|
+
variant: SampleVariantInput | string,
|
|
69
|
+
): variant is SampleVariantInputReference | string {
|
|
70
|
+
return (
|
|
71
|
+
(isObject(variant) && variant.type === "reference") ||
|
|
72
|
+
typeof variant === "string"
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getVariantInputReferenceValue(
|
|
77
|
+
variant: SampleVariantInputReference | string,
|
|
63
78
|
): string {
|
|
79
|
+
if (typeof variant === "string") {
|
|
80
|
+
return variant;
|
|
81
|
+
}
|
|
82
|
+
return variant.value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function getAbsoluteDirectoryPath(filePath: string): string {
|
|
64
86
|
return path.dirname(path.resolve(filePath));
|
|
65
87
|
}
|
|
66
88
|
|
package/test/bach.test.ts
CHANGED
|
@@ -15,15 +15,21 @@ import {
|
|
|
15
15
|
resolveSampleFile,
|
|
16
16
|
createOutputDirectory,
|
|
17
17
|
resolveTemplate,
|
|
18
|
-
|
|
18
|
+
isVariantInputDefinition,
|
|
19
19
|
getAbsoluteDirectoryPath,
|
|
20
20
|
isFile,
|
|
21
|
+
isVariantInputReference,
|
|
22
|
+
getVariantInputReferenceValue,
|
|
21
23
|
} from "../src/utils";
|
|
22
24
|
const mockParse = vi.mocked(parse);
|
|
23
25
|
const mockResolveSampleFile = vi.mocked(resolveSampleFile);
|
|
24
26
|
const mockCreateOutputDirectory = vi.mocked(createOutputDirectory);
|
|
25
27
|
const mockResolveTemplate = vi.mocked(resolveTemplate);
|
|
26
|
-
const
|
|
28
|
+
const mockIsVariantInputReference = vi.mocked(isVariantInputReference);
|
|
29
|
+
const mockGetVariantInputReferenceValue = vi.mocked(
|
|
30
|
+
getVariantInputReferenceValue,
|
|
31
|
+
);
|
|
32
|
+
const mockIsVariantInputDefinition = vi.mocked(isVariantInputDefinition);
|
|
27
33
|
const mockGetAbsoluteDirectoryPath = vi.mocked(getAbsoluteDirectoryPath);
|
|
28
34
|
const mockIsFile = vi.mocked(isFile);
|
|
29
35
|
|
|
@@ -51,7 +57,7 @@ describe("batchCompile", () => {
|
|
|
51
57
|
batchCompile("batch.yaml");
|
|
52
58
|
}).toThrow("process.exit");
|
|
53
59
|
expect(mockConsoleError).toHaveBeenCalledWith(
|
|
54
|
-
|
|
60
|
+
'Batch file "batch.yaml" does not exist or is not a file.',
|
|
55
61
|
);
|
|
56
62
|
expect(mockExit).toHaveBeenCalledWith(1);
|
|
57
63
|
});
|
|
@@ -63,7 +69,7 @@ describe("batchCompile", () => {
|
|
|
63
69
|
batchCompile("batch.yaml");
|
|
64
70
|
}).toThrow("process.exit");
|
|
65
71
|
expect(mockConsoleError).toHaveBeenCalledWith(
|
|
66
|
-
|
|
72
|
+
'Batch file "batch.yaml" does not exist or is not a file.',
|
|
67
73
|
);
|
|
68
74
|
expect(mockExit).toHaveBeenCalledWith(1);
|
|
69
75
|
});
|
|
@@ -76,7 +82,7 @@ describe("batchCompile", () => {
|
|
|
76
82
|
batchCompile("batch.yaml");
|
|
77
83
|
}).toThrow("process.exit");
|
|
78
84
|
expect(mockConsoleError).toHaveBeenCalledWith(
|
|
79
|
-
|
|
85
|
+
'Batch file "batch.yaml" does not exist or is not a file.',
|
|
80
86
|
);
|
|
81
87
|
expect(mockExit).toHaveBeenCalledWith(1);
|
|
82
88
|
});
|
|
@@ -86,7 +92,9 @@ describe("batchCompile", () => {
|
|
|
86
92
|
mockFs.lstatSync.mockReturnValue({ isFile: () => true } as any);
|
|
87
93
|
mockParse
|
|
88
94
|
.mockImplementationOnce(() => ({
|
|
89
|
-
variants:
|
|
95
|
+
variants: [
|
|
96
|
+
{ name: "foo", input: { type: "path", value: "badvariant.yaml" } },
|
|
97
|
+
],
|
|
90
98
|
samples: [],
|
|
91
99
|
}))
|
|
92
100
|
.mockImplementationOnce(() => null);
|
|
@@ -103,7 +111,7 @@ describe("batchCompile", () => {
|
|
|
103
111
|
mockIsFile.mockReturnValue(true);
|
|
104
112
|
mockGetAbsoluteDirectoryPath.mockReturnValue("/working/directory");
|
|
105
113
|
mockParse.mockReturnValueOnce({
|
|
106
|
-
variants:
|
|
114
|
+
variants: [],
|
|
107
115
|
samples: [{ templatePath: "sample.yaml", variants: [], output: "out" }],
|
|
108
116
|
});
|
|
109
117
|
mockResolveSampleFile.mockReturnValue("sample.yaml");
|
|
@@ -121,10 +129,10 @@ describe("batchCompile", () => {
|
|
|
121
129
|
mockFs.existsSync.mockReturnValue(true);
|
|
122
130
|
mockFs.lstatSync.mockReturnValue({ isFile: () => true } as any);
|
|
123
131
|
mockParse.mockReturnValueOnce({
|
|
124
|
-
variants:
|
|
132
|
+
variants: [],
|
|
125
133
|
samples: [
|
|
126
134
|
{ templatePath: "sample.yaml", variants: ["v1"], output: "out" },
|
|
127
|
-
]
|
|
135
|
+
],
|
|
128
136
|
});
|
|
129
137
|
mockResolveSampleFile.mockReturnValue("/path/to/sample.yaml");
|
|
130
138
|
mockParse.mockReturnValueOnce(null);
|
|
@@ -132,7 +140,7 @@ describe("batchCompile", () => {
|
|
|
132
140
|
batchCompile("batch.yaml");
|
|
133
141
|
}).toThrow("process.exit");
|
|
134
142
|
expect(mockConsoleError).toHaveBeenCalledWith(
|
|
135
|
-
|
|
143
|
+
'Batch file "batch.yaml" does not exist or is not a file.',
|
|
136
144
|
);
|
|
137
145
|
expect(mockExit).toHaveBeenCalledWith(1);
|
|
138
146
|
});
|
|
@@ -141,9 +149,12 @@ describe("batchCompile", () => {
|
|
|
141
149
|
mockIsFile.mockReturnValue(true);
|
|
142
150
|
mockGetAbsoluteDirectoryPath.mockReturnValue("/working/directory");
|
|
143
151
|
mockParse.mockReturnValueOnce({
|
|
144
|
-
variants:
|
|
152
|
+
variants: [],
|
|
145
153
|
samples: [
|
|
146
|
-
{
|
|
154
|
+
{
|
|
155
|
+
templatePath: "sample.yaml",
|
|
156
|
+
variants: [{ output: "out", input: "v1" }],
|
|
157
|
+
},
|
|
147
158
|
],
|
|
148
159
|
});
|
|
149
160
|
mockResolveSampleFile.mockReturnValue("/path/to/sample.yaml");
|
|
@@ -154,7 +165,9 @@ describe("batchCompile", () => {
|
|
|
154
165
|
input: [],
|
|
155
166
|
});
|
|
156
167
|
mockResolveTemplate.mockReturnValue("resolved template");
|
|
157
|
-
|
|
168
|
+
mockIsVariantInputReference.mockReturnValue(true);
|
|
169
|
+
mockGetVariantInputReferenceValue.mockReturnValue("v1");
|
|
170
|
+
mockIsVariantInputDefinition.mockReturnValue(false);
|
|
158
171
|
expect(() => {
|
|
159
172
|
batchCompile("batch.yaml");
|
|
160
173
|
}).toThrow("process.exit");
|
|
@@ -168,11 +181,11 @@ describe("batchCompile", () => {
|
|
|
168
181
|
mockIsFile.mockReturnValue(true);
|
|
169
182
|
mockGetAbsoluteDirectoryPath.mockReturnValue("/working/directory");
|
|
170
183
|
mockParse.mockReturnValueOnce({
|
|
171
|
-
variants:
|
|
184
|
+
variants: [],
|
|
172
185
|
samples: [
|
|
173
186
|
{
|
|
174
187
|
templatePath: "sample.yaml",
|
|
175
|
-
variants: [{ output: "out",
|
|
188
|
+
variants: [{ output: "out", input: "v1" }],
|
|
176
189
|
},
|
|
177
190
|
],
|
|
178
191
|
});
|
|
@@ -184,7 +197,7 @@ describe("batchCompile", () => {
|
|
|
184
197
|
input: [],
|
|
185
198
|
});
|
|
186
199
|
mockResolveTemplate.mockReturnValue("resolved template");
|
|
187
|
-
|
|
200
|
+
mockIsVariantInputDefinition.mockReturnValue(true);
|
|
188
201
|
mockCompileSample.mockImplementation(() => {
|
|
189
202
|
throw new Error("Compilation error");
|
|
190
203
|
});
|
|
@@ -197,7 +210,7 @@ describe("batchCompile", () => {
|
|
|
197
210
|
);
|
|
198
211
|
expect(mockConsoleError).toHaveBeenNthCalledWith(
|
|
199
212
|
2,
|
|
200
|
-
'Sample: sample.yaml, Variant: {"output":"out","
|
|
213
|
+
'Sample: sample.yaml, Variant: {"output":"out","input":"v1"}',
|
|
201
214
|
);
|
|
202
215
|
expect(mockExit).toHaveBeenCalledWith(1);
|
|
203
216
|
});
|
|
@@ -206,11 +219,11 @@ describe("batchCompile", () => {
|
|
|
206
219
|
mockIsFile.mockReturnValue(true);
|
|
207
220
|
mockGetAbsoluteDirectoryPath.mockReturnValue("/working/directory");
|
|
208
221
|
mockParse.mockReturnValueOnce({
|
|
209
|
-
variants:
|
|
222
|
+
variants: [],
|
|
210
223
|
samples: [
|
|
211
224
|
{
|
|
212
225
|
templatePath: "sample.yaml",
|
|
213
|
-
variants: [{ output: "out",
|
|
226
|
+
variants: [{ output: "out", input: "v1" }],
|
|
214
227
|
},
|
|
215
228
|
],
|
|
216
229
|
});
|
|
@@ -222,7 +235,7 @@ describe("batchCompile", () => {
|
|
|
222
235
|
input: [],
|
|
223
236
|
});
|
|
224
237
|
mockResolveTemplate.mockReturnValue("resolved template");
|
|
225
|
-
|
|
238
|
+
mockIsVariantInputDefinition.mockReturnValue(true);
|
|
226
239
|
mockCompileSample.mockImplementation(() => {
|
|
227
240
|
throw "Unknown error";
|
|
228
241
|
});
|
|
@@ -239,13 +252,13 @@ describe("batchCompile", () => {
|
|
|
239
252
|
mockIsFile.mockReturnValue(true);
|
|
240
253
|
mockGetAbsoluteDirectoryPath.mockReturnValue("/working/directory");
|
|
241
254
|
mockParse.mockReturnValueOnce({
|
|
242
|
-
variants:
|
|
255
|
+
variants: [],
|
|
243
256
|
samples: [
|
|
244
257
|
{
|
|
245
258
|
templatePath: "sample.yaml",
|
|
246
259
|
variants: [
|
|
247
|
-
{ output: "v1.output",
|
|
248
|
-
{ output: "v2.output",
|
|
260
|
+
{ output: "v1.output", input: {} },
|
|
261
|
+
{ output: "v2.output", input: {} },
|
|
249
262
|
],
|
|
250
263
|
output: "out",
|
|
251
264
|
},
|
|
@@ -259,7 +272,7 @@ describe("batchCompile", () => {
|
|
|
259
272
|
input: [],
|
|
260
273
|
});
|
|
261
274
|
mockResolveTemplate.mockReturnValue("resolved template");
|
|
262
|
-
|
|
275
|
+
mockIsVariantInputDefinition.mockReturnValue(true);
|
|
263
276
|
mockCompileSample.mockReturnValue({
|
|
264
277
|
items: [
|
|
265
278
|
{ fileName: "file1.js", content: "console.log('1');" },
|
|
@@ -269,8 +282,12 @@ describe("batchCompile", () => {
|
|
|
269
282
|
mockCreateOutputDirectory.mockImplementation(() => {});
|
|
270
283
|
mockFs.writeFileSync.mockImplementation(() => {});
|
|
271
284
|
batchCompile("batch.yaml");
|
|
272
|
-
expect(mockCreateOutputDirectory).toHaveBeenCalledWith(
|
|
273
|
-
|
|
285
|
+
expect(mockCreateOutputDirectory).toHaveBeenCalledWith(
|
|
286
|
+
"/working/directory/v1.output",
|
|
287
|
+
);
|
|
288
|
+
expect(mockCreateOutputDirectory).toHaveBeenCalledWith(
|
|
289
|
+
"/working/directory/v2.output",
|
|
290
|
+
);
|
|
274
291
|
expect(mockFs.writeFileSync).toHaveBeenCalledWith(
|
|
275
292
|
path.join("/working/directory", "v1.output", "file1.js"),
|
|
276
293
|
"console.log('1');",
|
package/test/common.test.ts
CHANGED
|
@@ -6,11 +6,7 @@ import fs from "fs";
|
|
|
6
6
|
const mockFs = vi.mocked(fs);
|
|
7
7
|
|
|
8
8
|
vi.mock("../src/utils");
|
|
9
|
-
import {
|
|
10
|
-
parse,
|
|
11
|
-
resolveSampleFile,
|
|
12
|
-
isFile,
|
|
13
|
-
} from "../src/utils";
|
|
9
|
+
import { parse, resolveSampleFile, isFile } from "../src/utils";
|
|
14
10
|
import { resolveAndParseSample } from "../src/common";
|
|
15
11
|
const mockParse = vi.mocked(parse);
|
|
16
12
|
const mockResolveSampleFile = vi.mocked(resolveSampleFile);
|