@factorialco/shadowdog
Version:
<img src="https://raw.githubusercontent.com/factorialco/shadowdog/refs/heads/main/logo.png" alt="drawing" width="100"/>
101 lines (100 loc) • 4.3 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = exports.configSchema = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const utils_1 = require("./utils");
const zod_1 = require("zod");
const chalk_1 = __importDefault(require("chalk"));
const pluginTypes_1 = require("./pluginTypes");
exports.configSchema = zod_1.z
.object({
$schema: zod_1.z.string().optional(),
debounceTime: zod_1.z
.number()
.min(0)
.optional()
.default(2000)
.describe('The time in milliseconds to wait before running the command after a file change.'),
defaultIgnoredFiles: zod_1.z
.array(zod_1.z.string().describe('File path or glob'))
.optional()
.default(['.git', '**/node_modules'])
.describe('Default ignored files when watching files'),
plugins: zod_1.z.array(pluginTypes_1.pluginOptionsSchema).optional().default([]).describe('List of plugins to use'),
watchers: zod_1.z
.array(zod_1.z
.object({
enabled: zod_1.z
.boolean()
.optional()
.default(true)
.describe('Whether the watcher is enabled or not'),
files: zod_1.z
.array(zod_1.z.string().describe('File path'))
.default([])
.describe('List of files to watch'),
invalidators: zod_1.z
.object({
files: zod_1.z
.array(zod_1.z.string().describe('File path'))
.default([])
.describe('List of files that invalidate the cache when they change. These ones are not watched.'),
environment: zod_1.z
.array(zod_1.z.string().describe('Environment variable name'))
.default([])
.describe('List of environment variables that invalidate the cache when they change.'),
})
.default({ files: [], environment: [] })
.describe('List of invalidators for the cache'),
ignored: zod_1.z
.array(zod_1.z.string().describe('File path'))
.default([])
.describe('List of files to ignore when they change'),
label: zod_1.z.string().optional(),
commands: zod_1.z
.array(zod_1.z
.object({
command: zod_1.z.string().describe('The command to run when a file changes'),
workingDirectory: zod_1.z
.string()
.default('')
.describe('The directory where the command should run.'),
tags: zod_1.z
.array(zod_1.z.string())
.default([])
.describe('A list of tags to associate with the command. Used with the `generate` command to filter commands by tag.'),
artifacts: zod_1.z
.array(zod_1.z
.object({
output: zod_1.z.string().describe('Path to the output file or folder'),
description: zod_1.z
.string()
.optional()
.describe('A description of the artifact'),
ignore: zod_1.z
.array(zod_1.z.string())
.optional()
.describe('A list of files to ignore before saving the folder artifacts'),
})
.strict()
.describe('An artifact produced by the command'))
.default([])
.describe('List of artifacts produced by the command'),
})
.strict()
.describe('Command configuration when a file changes'))
.describe('List of commands to run when a file changes'),
})
.strict()
.describe('Watcher configuration'))
.describe('List of watchers to run'),
})
.strict();
const loadConfig = (configFilePath) => {
(0, utils_1.logMessage)(`✨ Reading config file from '${chalk_1.default.blue(configFilePath)}'...`);
return exports.configSchema.parse(JSON.parse(fs_extra_1.default.readFileSync(configFilePath, 'utf-8')));
};
exports.loadConfig = loadConfig;