Skip to content

Commit 6ab49f9

Browse files
Handle missing feature directory case
1 parent f1bea31 commit 6ab49f9

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

scripts/generate-json-definitions.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
isLibSonnetFile,
1111
getOutputPath,
1212
} from "./utils.js";
13-
import log from "./log-styling.js";
13+
import logger from "./log-styling.js";
1414

1515
const __filename = fileURLToPath(import.meta.url);
1616
const __dirname = path.dirname(__filename);
@@ -24,7 +24,7 @@ function buildJsonnetFile(inputPath) {
2424

2525
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
2626

27-
log.info(`Compiling Jsonnet to JSON for: ${relativePath}`);
27+
logger.info(`Compiling Jsonnet to JSON for: ${relativePath}`);
2828
try {
2929
execSync(`jsonnet ${inputPath} > ${outputFile}`);
3030
} catch (err) {
@@ -33,18 +33,23 @@ function buildJsonnetFile(inputPath) {
3333
}
3434
}
3535

36-
log.heading("Generating features JSON files from Jsonnet definitions...");
37-
log.blank();
36+
logger.heading("Generating features JSON files from Jsonnet definitions...");
37+
logger.blank();
38+
39+
if (!fs.existsSync(INPUT_DIR)) {
40+
logger.warn(`Features directory missing: ${INPUT_DIR}`);
41+
process.exit(0);
42+
}
3843

3944
walkDir(INPUT_DIR, (filePath) => {
4045
if (isJsonnetFile(filePath)) {
4146
buildJsonnetFile(filePath);
4247
} else if (!isLibSonnetFile(filePath)) {
43-
log.warn(
48+
logger.warn(
4449
`Skipping unsupported file: ${path.relative(INPUT_DIR, filePath)}`
4550
);
4651
}
4752
});
4853

49-
log.blank();
50-
log.success("Jsonnet files transformed to JSON successfully!");
54+
logger.blank();
55+
logger.success("Jsonnet files transformed to JSON successfully!");

scripts/log-styling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import chalk from "chalk";
22

3-
const log = {
3+
const logger = {
44
heading: (msg) => {
55
console.log(chalk.bold.cyan(`\n🚀 ${msg}`));
66
},
@@ -21,4 +21,4 @@ const log = {
2121
},
2222
};
2323

24-
export default log;
24+
export default logger;

scripts/validate-json-generated.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import path from "path";
33
import { fileURLToPath } from "url";
4-
import log from "./log-styling.js";
4+
import logger from "./log-styling.js";
55
import { walkDir, isJsonnetFile, getOutputPath } from "./utils.js";
66

77
const __filename = fileURLToPath(import.meta.url);
@@ -10,6 +10,11 @@ const __dirname = path.dirname(__filename);
1010
const INPUT_DIR = path.resolve(__dirname, "../features");
1111
const OUTPUT_DIR = path.resolve(__dirname, "../generated/json");
1212

13+
if (!fs.existsSync(INPUT_DIR)) {
14+
logger.warn(`Features directory missing: ${INPUT_DIR}`);
15+
process.exit(0);
16+
}
17+
1318
let missingFiles = [];
1419

1520
walkDir(INPUT_DIR, (inputPath) => {
@@ -24,14 +29,14 @@ walkDir(INPUT_DIR, (inputPath) => {
2429
});
2530

2631
if (missingFiles.length === 0) {
27-
log.success("All Jsonnet files have corresponding generated JSON files!");
32+
logger.success("All Jsonnet files have corresponding generated JSON files!");
2833
process.exit(0);
2934
} else {
30-
log.error(
35+
logger.error(
3136
"Missing generated JSON files for the following Jsonnet definitions:"
3237
);
3338
missingFiles.forEach((file) => {
34-
log.error(` - ${file}`);
39+
logger.error(` - ${file}`);
3540
});
3641
process.exit(1);
3742
}

0 commit comments

Comments
 (0)