@cspell/cspell-tools
Version:
Tools to assist with the development of cSpell
36 lines • 1.5 kB
JavaScript
import * as path from 'node:path';
import { cosmiconfig } from 'cosmiconfig';
import { compile } from './compiler/index.js';
import { normalizeConfig } from './config/index.js';
const moduleName = 'cspell-tools';
const searchPlaces = [
`${moduleName}.config.json`,
`${moduleName}.config.yaml`,
`${moduleName}.config.yml`,
'package.json',
];
export async function build(targets, options) {
const allowedTargets = new Set(targets || []);
function filter(target) {
return !allowedTargets.size || allowedTargets.has(target.name);
}
const searchDir = path.resolve(options.root || options.cwd || '.');
const explorer = cosmiconfig(moduleName, {
searchPlaces,
stopDir: searchDir,
transform: normalizeConfig,
});
const config = await (options.config ? explorer.load(options.config) : explorer.search(searchDir));
if (!config?.config) {
console.error('root: %s', options.root);
throw 'cspell-tools.config not found.';
}
const configDir = path.dirname(config.filepath);
const buildInfo = normalizeRequest(config.config, path.resolve(configDir, options.root || configDir));
await compile(buildInfo, { filter, cwd: options.cwd, conditionalBuild: options.conditional || false });
}
function normalizeRequest(buildInfo, root) {
const { rootDir = root, targets = [], checksumFile } = buildInfo;
return { rootDir: path.resolve(rootDir), targets, checksumFile };
}
//# sourceMappingURL=build.js.map