verify-build
This package verifies your build files via pattern/schemas. Verify build will fail on the first use case where it does not match the schema provided and reports an error.
Installation:
npm install verify-build
Usage
You need to specify the path to a configuration file that contains the schemas as modules.
verify-build --config ./build-files-schema.js
Writing schema configuration file
Here is a basic sample configuration that verify build script expects. Note it starts with modules array and some global check configurations.
checkNonEmptyFiles: false logLevel: 'info' modules: JSFiles CSSFiles images fonts
logLevel accepts two values ('info' and 'error'). Choose error when you want to trace where error occured. For detailed logging use info.
modules is a array of small independent module that define their own set of path, schemas. Lets explore a sample module
moduleexports = _name: "js bundles" desc: "Javascipt bundle for dev and prod" cwd: "../build/js/" checkFolderCount: 1 checkFileCount: 2 filesSchema: fileName: "bundles.js" fileName: "vendor.js" folderName: "minified" checkFileCount: 2 filesSchema: fileName: "bundles.min.js" checkEmpty: true fileName: "vendor.min.js" ;
Here is the details about the above configuration
keys | description |
---|---|
_name | Name of the module |
desc | Description of the module. This is optional ans is used for understanding purpose |
cwd | You must provide cwd parameter to indicate the root for module files. |
checkFolderCount | Optional config if you wish to check folder count in the cwd. This checks if there are exact no of folders exist in the build. |
checkFileCount | Optional and similar to checkFolderCount but this checks for number of files. Note: you may apply this check at any folder level schema. |
filesSchema | filesSchema is a representation of nested folder structure where you can define child schemas using the same filesSchema representation. |
fileName | fileName is the name of the file to be checked used inside a filesSchema |
folderName | This key is used for finding folder path and determining if the schema is for a folder |
checkEmpty | checkEmpty checks if file is not blank. Its not required in case of contentMatch key is provided. |
Repeating a similar schema check for muiltiple folders in a directory
folderIterator key helps to repeat the same schema check for number of items in the folderIterator key.
filesSchema: isFolder: true folderIterator: "folderNameA" "folderNameB" "folderNameC" filesSchema: fileName: "bundles.min.js" fileName: "vendor.min.js"
fileIterator key helps to repeat the same schema check for multiple files in the same folder.
filesSchema: fileIterator: "jquery.js" "lodash.js" "underscore.js" "asf.t" checkEmpty: true ;
Checking content of a file
For checking content inside a file, use contentMatch key. You can specify a string or a custom function which can return a boolean value. A sample usage is given below.
/** * Custom function to do content matching * It should return a boolean value */ const checkDataJSON = { // verify fileContent based on schema and additional logic } ... filesSchema: fileName: "bundles.min.js" contentMatch: "#ad46dgsksjdf7df45lks9dsn48ng" fileName: "data.json" contentMatch: checkDataJSON
Change log
Major change logs can be found here
version | description |
---|---|
1.2.0 | Optimizations and bug fixes for faster check |
1.0.1 | Child is born |