@illlia/css-merge
Version:
css-merge is a tiny package to compose css classes on the 'last class wins' basis
30 lines (29 loc) • 1.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeToFile = void 0;
const promises_1 = __importDefault(require("fs/promises"));
const writeToFile = (path) => async (content) => {
const split = path.split("/");
const filePath = split.at(-1);
const dirPath = split.slice(0, split.length - 1).join("/");
// const dirPath = __dirname + '/../test/_generated'
// dirPath + '/tw-config.ts'
await tryCreateDir(dirPath);
await promises_1.default.writeFile(`${dirPath}/${filePath}`, content
// `export default ${JSON.stringify(data)};`
);
};
exports.writeToFile = writeToFile;
const tryCreateDir = async (dirPath) => {
try {
// Try to access the directory
await promises_1.default.access(dirPath);
}
catch (error) {
// If the directory does not exist, create it
await promises_1.default.mkdir(dirPath, { recursive: true });
}
};