@factorialco/shadowdog
Version:
<img src="https://raw.githubusercontent.com/factorialco/shadowdog/refs/heads/main/logo.png" alt="drawing" width="100"/>
57 lines (56 loc) • 3.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const package_json_1 = __importDefault(require("../package.json"));
const path_1 = __importDefault(require("path"));
const daemon_1 = require("./daemon");
const generate_1 = require("./generate");
const utils_1 = require("./utils");
const chalk_1 = __importDefault(require("chalk"));
const events_1 = require("./events");
const plugins_1 = require("./plugins");
const config_1 = require("./config");
const DEFAULT_CONFIG_FILENAME = 'shadowdog.json';
const cli = new commander_1.Command();
const eventEmitter = new events_1.ShadowdogEventEmitter();
cli.version(package_json_1.default.version).description('TBA');
cli
.option('-c, --config <path>', `Config file path (default: ${DEFAULT_CONFIG_FILENAME} in current working directory)`, path_1.default.join(process.cwd(), DEFAULT_CONFIG_FILENAME))
.option('-w, --watch', 'Watch for changes in the configured files and run the tasks automatically')
.action(async ({ config: configFilePath, watch }) => {
if (watch) {
(0, utils_1.logMessage)(`
███████╗██╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗██████╗ ██████╗ ██████╗
██╔════╝██║ ██║██╔══██╗██╔══██╗██╔═══██╗██║ ██║██╔══██╗██╔═══██╗██╔════╝
███████╗███████║███████║██║ ██║██║ ██║██║ █╗ ██║██║ ██║██║ ██║██║ ███╗
╚════██║██╔══██║██╔══██║██║ ██║██║ ██║██║███╗██║██║ ██║██║ ██║██║ ██║
███████║██║ ██║██║ ██║██████╔╝╚██████╔╝╚███╔███╔╝██████╔╝╚██████╔╝╚██████╔╝
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═════╝ ╚═════╝
`);
}
(0, utils_1.logMessage)(`🚀 Shadowdog ${chalk_1.default.blue((0, utils_1.readShadowdogVersion)())} is booting!`);
const configRelativePath = path_1.default.relative(process.cwd(), configFilePath);
const config = (0, config_1.loadConfig)(configRelativePath);
(0, plugins_1.filterEventListenerPlugins)(config.plugins).forEach(({ fn, options }) => {
fn.listener(eventEmitter, options !== null && options !== void 0 ? options : {});
});
try {
await (0, generate_1.generate)(config, eventEmitter, { continueOnError: watch });
}
catch (error) {
(0, utils_1.logMessage)(`🚫 Unable to perform the initial generation because some command has failed.`);
(0, utils_1.logError)(error);
return (0, utils_1.exit)(eventEmitter, 1);
}
if (watch) {
(0, daemon_1.runDaemon)(config, configRelativePath, eventEmitter);
}
else {
return (0, utils_1.exit)(eventEmitter, 0);
}
});
cli.parse(process.argv);