📹 Animated Cursors Schema Generations

This commit is contained in:
ful1e5 2020-08-16 17:44:09 +05:30
parent 32103c92d3
commit f45f878445

View file

@ -14,54 +14,65 @@ const generateConfigs = (
const configs: Configs = {}; const configs: Configs = {};
for (let [schema] of Object.entries(colorSchemes)) { for (let [schema] of Object.entries(colorSchemes)) {
const { base, outline } = colorSchemes[schema]; const { base, outline, watchBackground } = colorSchemes[schema];
const schemaName = `${dirPrefix} ${schema}`; const schemaName = `${dirPrefix} ${schema}`;
const schemaSvgsPath = path.resolve(schemesPath, schemaName); const schemaSvgsPath = path.resolve(schemesPath, schemaName);
try {
if (fs.existsSync(schemaSvgsPath)) { if (fs.existsSync(schemaSvgsPath)) {
rimraf(schemaSvgsPath, function () {}); rimraf(schemaSvgsPath, function () {});
fs.mkdirSync(schemaSvgsPath, { recursive: true });
} else { } else {
fs.mkdirSync(schemaSvgsPath); fs.mkdirSync(schemaSvgsPath, { recursive: true });
} }
// Static .svg generation // Static .svg generation
const staticSvgs = staticCursors.map((svgFile: string) => { staticCursors.map((cursor: string) => {
// Read file // Read file
const filePath = path.resolve(schemaSvgsPath, svgFile); const cursorPath = path.resolve(schemaSvgsPath, cursor);
// Replacing colorSchema // Replacing colorSchema
let content = fs let content = fs
.readFileSync(path.resolve(rawSvgsDir, svgFile), "utf-8") .readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString(); .toString();
content = content.replace("#00FF00", base).replace("#0000FF", outline); content = content.replace("#00FF00", base).replace("#0000FF", outline);
// Writing new svg // Writing new svg
fs.writeFileSync(filePath, content, "utf-8"); fs.writeFileSync(cursorPath, content, "utf-8");
return filePath;
}); });
// Out Directory // Out Directory
const bitmapsDir = path.resolve( for (let [cursor] of Object.entries(animatedCursors)) {
process.cwd(), // Read file
"bitmaps", const cursorPath = path.resolve(schemaSvgsPath, cursor);
`Bibata_${schema}`
); // Replacing colorSchema
if (!fs.existsSync(bitmapsDir)) fs.mkdirSync(bitmapsDir); let content = fs
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString();
content = content.replace("#00FF00", watchBackground);
// Writing new svg
fs.writeFileSync(cursorPath, content, "utf-8");
}
const bitmapsDir = path.resolve(process.cwd(), "bitmaps", schemaName);
if (fs.existsSync(bitmapsDir)) {
rimraf(bitmapsDir, function () {});
fs.mkdirSync(bitmapsDir, { recursive: true });
} else {
fs.mkdirSync(bitmapsDir, { recursive: true });
}
configs[schema] = { configs[schema] = {
svgsDir: schemaSvgsPath, svgsDir: schemaSvgsPath,
staticSvgs,
bitmapsDir, bitmapsDir,
animatedCursors, animatedCursors,
staticCursors,
animatedClip animatedClip
}; };
} catch (error) {
console.error("An error occurred in .svg files generation.");
}
} }
return configs; return configs;