For example, I have config in package.json
"build": {
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
}
]
}
}
And I want validate this before start build process or CI/CD pipeline.
Example of how electron-builder check config.
Then we can try to use the same method and tools - @develar/schema-utils and scheme which uses electron-builder for validation
// validate.js
const validate = require('@develar/schema-utils');
const schema = require('./schemas/schema.json');
const options = {
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
}
]
}
};
const configuration = {
name: 'electron-builder'
};
try {
validate(schema, options, configuration);
} catch(e) {
console.log(e.message)
}
If we execute command:
node validate.js
We have not something input.
But if we use wrong config. For example,
const options = {
"win": {
"target": [
{
"target": ["nsis"],
"arch": [
"x64",
"ia32"
]
}
]
}
};
The output of the command will be:
Invalid configuration object. electron-builder has been initialized using a configuration object that does not match the API schema.
- configuration.win.target[0].target should be a string.
-> The target name. e.g. `snap`.