@ikona/cli
Version:
52 lines (51 loc) • 1.36 kB
JavaScript
// src/utils/config.ts
import { bundleNRequire } from "bundle-n-require";
import findUp from "escalade/sync";
import { resolve } from "path";
var defaultConfig = {
verbose: false,
outputDir: ".ikona",
force: false,
icons: {
optimize: false,
inputDir: "icons",
spriteOutputDir: "output",
hash: false
},
illustrations: {
inputDir: "illustrations",
extensions: ["svg", "png", "jpg", "jpeg", "webp"]
},
cwd: process.cwd()
};
var configs = [".ts", ".js", ".mts", ".mjs", ".cts", ".cjs"];
var configRegex = new RegExp(`ikona.config(${configs.join("|")})$`);
var isConfig = (file) => configRegex.test(file);
function findConfigFile({ cwd, file }) {
if (file)
return resolve(cwd, file);
return findUp(cwd, (_dir, paths) => {
return paths.find(isConfig);
});
}
async function bundle(filepath, cwd) {
const { mod: config, dependencies } = await bundleNRequire(filepath, {
cwd,
interopDefault: true
});
return { config: config?.default ?? config, dependencies };
}
var resolveFileConfig = async () => {
const currentDir = process.cwd();
const filePath = findConfigFile({ cwd: currentDir });
if (!filePath) {
throw new Error("Config file not found");
}
const { config } = await bundle(filePath, currentDir);
return config;
};
export {
defaultConfig,
findConfigFile,
resolveFileConfig
};