@terrazzo/cli
Version:
CLI for managing design tokens using the Design Tokens Community Group (DTCG) standard and generating code for any platform via plugins.
29 lines • 1.48 kB
JavaScript
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
import { defineConfig as defineConfigCore } from '@terrazzo/parser';
import { cwd } from './shared.js';
const require = createRequire(cwd);
// wrap defineConfig from @terrazzo/parser and add Node.js resolution
export function defineConfig(config) {
const normalizedConfig = { ...config }; // note: we only need a shallow copy because we’re only mutating top-level `tokens`
// Resolve tokens from npm modules, if any
if (typeof normalizedConfig.tokens === 'string' || Array.isArray(normalizedConfig.tokens)) {
normalizedConfig.tokens = (Array.isArray(normalizedConfig.tokens) ? normalizedConfig.tokens : [normalizedConfig.tokens]).map((tokenPath) => {
if (tokenPath.startsWith('.') || /^(https?|file):\/\//i.test(tokenPath)) {
return tokenPath;
}
try {
return pathToFileURL(require.resolve(tokenPath));
}
catch (err) {
console.error(err);
// this will throw an error if Node couldn’t automatically resolve it,
// which will be true for many token paths. We don’t need to surface
// that error; it’ll get its own error down the line if it’s a bad path.
return tokenPath;
}
});
}
return defineConfigCore(normalizedConfig, { cwd });
}
//# sourceMappingURL=index.js.map