1.2.0 • Published 4 years ago

verify-build v1.2.0

Weekly downloads
6
License
ISC
Repository
-
Last release
4 years ago

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

module.exports = {
    _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

keysdescription
_nameName of the module
descDescription of the module. This is optional ans is used for understanding purpose
cwdYou must provide cwd parameter to indicate the root for module files.
checkFolderCountOptional config if you wish to check folder count in the cwd. This checks if there are exact no of folders exist in the build.
checkFileCountOptional and similar to checkFolderCount but this checks for number of files. Note: you may apply this check at any folder level schema.
filesSchemafilesSchema is a representation of nested folder structure where you can define child schemas using the same filesSchema representation.
fileNamefileName is the name of the file to be checked used inside a filesSchema
folderNameThis key is used for finding folder path and determining if the schema is for a folder
checkEmptycheckEmpty 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 = (schema, fileContent) => {
        // 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

versiondescription
1.2.0Optimizations and bug fixes for faster check
1.0.1Child is born
1.2.0

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.1.2

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago