✨(bin) add tokens repo
This repo is made for the bin script that generates the tokens files, at the moment it only generates a css file, but it is designed to be able to generate any other file format ( Typescript, Javascript for example )
This commit is contained in:
32
packages/tokens/src/bin/ConfigLoader.ts
Normal file
32
packages/tokens/src/bin/ConfigLoader.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import path from "path";
|
||||
import * as fs from "fs";
|
||||
import deepmerge from "deepmerge";
|
||||
import Config from "./Config";
|
||||
import { ConfigShape } from "./TokensGenerator";
|
||||
import { workPath } from "./Paths";
|
||||
|
||||
const getLocalConfig = async () => {
|
||||
const filename = Config.configurationFilenames
|
||||
.map((filename_) => path.join(workPath(), filename_))
|
||||
.find((filename_) => fs.existsSync(filename_));
|
||||
|
||||
if (!filename) {
|
||||
console.log("No local config found, using default config.");
|
||||
return {};
|
||||
}
|
||||
|
||||
const config = await import(filename);
|
||||
return config.default;
|
||||
};
|
||||
|
||||
const getDistConfig = async () => {
|
||||
const config = await import("./cunningham.dist.js");
|
||||
return config.default;
|
||||
};
|
||||
|
||||
export const getConfig = async () => {
|
||||
const localConfig = await getLocalConfig();
|
||||
const distConfig = await getDistConfig();
|
||||
const config: ConfigShape = deepmerge(distConfig, localConfig);
|
||||
return config;
|
||||
};
|
||||
Reference in New Issue
Block a user