Skip to content

Commit

Permalink
was validating the wrong presets. Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartondock committed Nov 3, 2021
1 parent 7285cbe commit 6ae851f
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions .validate-files.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { configPresets } from "./src/renderer/schemas/config-presets.schema";
import { customVariables } from "./src/renderer/schemas/custom-variables.schema";
import * as json from "./src/lib/helpers/json";
import * as glob from "glob";

let isValid = true;
const validator = new json.Validator(undefined, undefined, { useDefaults: false });

json.read('./files/configPresets.json').then((data: object) => {
if (data !== null && !validator.setSchema(configPresets).validate(data).isValid()){
throw new Error(`\r\n${validator.errorString}`);
}
}).catch((error: Error) => {
process.stderr.write(`${error.stack}\r\n`);
isValid = false;
let presetFiles: string[] = glob.sync("./files/presets/*.json")
let presetPromises: Promise<object|void>[] = []
for(let i=0; i <presetFiles.length; i++) {
presetPromises.push(json.read(presetFiles[i])
.then((data: object|void) => {
if (data !== null && !validator.setSchema(configPresets).validate(data||{}).isValid()){
throw new Error(`\r\n${validator.errorString}`);
}
}));
}
Promise.all(presetPromises).catch((error: Error) => {
process.stderr.write(`${error.stack}\r\n`);
isValid = false;
}).then(() => {
return json.read('./files/customVariables.json');
return json.read('./files/customVariables.json');
}).then((data: object) => {
if (data !== null && !validator.setSchema(customVariables).validate(data).isValid()){
throw new Error(`\r\n${validator.errorString}`);
}
if (data !== null && !validator.setSchema(customVariables).validate(data).isValid()){
throw new Error(`\r\n${validator.errorString}`);
}
}).catch((error: Error) => {
process.stderr.write(`${error.stack}\r\n`);
isValid = false;
process.stderr.write(`${error.stack}\r\n`);
isValid = false;
}).then(() => {
process.exit(isValid ? 0 : 1);
process.exit(isValid ? 0 : 1);
});

0 comments on commit 6ae851f

Please sign in to comment.