UNPKG

@mischback/buster

Version:

buster is a tool to support cache busting for static assets of a website.

67 lines 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.busterMain = void 0; const fileobject_walker_1 = require("@mischback/fileobject-walker"); const configure_1 = require("./lib/configure"); const filesystem_1 = require("./lib/hashwalker/filesystem"); const hash_1 = require("./lib/hashwalker/hash"); const hashwalker_1 = require("./lib/hashwalker/hashwalker"); const logging_1 = require("./lib/logging"); const manifest_1 = require("./lib/manifest"); const EXIT_SUCCESS = 0; const EXIT_PROCESSING_ERROR = 10; const EXIT_INTERNAL_ERROR = 70; const EXIT_CONFIG_ERROR = 78; const EXIT_SIGINT = 130; function busterMain(argv) { return new Promise((resolve, reject) => { process.on("SIGINT", () => { logging_1.logger.info("Caught interrupt signal (Ctrl-C). Exiting!"); return reject(EXIT_SIGINT); }); const quietKey = configure_1.cmdLineOptions.quiet["key"]; if (argv.indexOf(`-${quietKey}`) > -1) { (0, logging_1.suppressLogOutput)(); } const debugKey = configure_1.cmdLineOptions.debug["key"]; if (argv.indexOf(`-${debugKey}`) > -1) { (0, logging_1.applyDebugConfiguration)(); } let config; (0, configure_1.getConfig)(argv) .then(configure_1.checkConfig) .then((checkedConfig) => { config = checkedConfig; logging_1.logger.debug(config); return Promise.resolve(config); }) .then(hashwalker_1.hashWalker) .then((result) => { logging_1.logger.debug(result); return (0, manifest_1.createManifestFile)(result, config); }) .then(() => { return resolve(EXIT_SUCCESS); }) .catch((err) => { if (err instanceof configure_1.BusterConfigError) { logging_1.logger.error(err.message); logging_1.logger.fatal("Could not determine configuration for buster!"); return reject(EXIT_CONFIG_ERROR); } if (err instanceof hash_1.BusterHashError || err instanceof filesystem_1.BusterFileSystemError || err instanceof fileobject_walker_1.FileObjectWalkerError || err instanceof manifest_1.BusterManifestError) { logging_1.logger.error(err.message); logging_1.logger.fatal("Error during processing!"); return reject(EXIT_PROCESSING_ERROR); } logging_1.logger.error(err); logging_1.logger.fatal("This was unexpected! Aborting!"); return reject(EXIT_INTERNAL_ERROR); }); }); } exports.busterMain = busterMain; //# sourceMappingURL=main.js.map