🌈 Schema generator

This commit is contained in:
ful1e5 2020-08-31 17:30:27 +05:30
parent 3f573c17c6
commit 656bb2bb0d

View file

@ -10,10 +10,11 @@ import {
staticCursors staticCursors
} from "../config"; } from "../config";
import { ColorSchema, Config } from "../types"; import { ColorSchema, Config } from "../types";
import { writeSchemaData } from "./writeSchema";
// --------------------------------------- Generate Configs 🛠 // --------------------------------------- Generate Configs 🛠
const generateConfigs = (colorSchemes: ColorSchema, dirPrefix: string) => { const generateConfigs = (colorSchemes: ColorSchema, themeName: string) => {
if (!fs.existsSync(rawSvgsDir)) { if (!fs.existsSync(rawSvgsDir)) {
console.error(`🚨 .svg files not found in ${rawSvgsDir}`); console.error(`🚨 .svg files not found in ${rawSvgsDir}`);
process.exit(1); process.exit(1);
@ -22,14 +23,14 @@ const generateConfigs = (colorSchemes: ColorSchema, dirPrefix: string) => {
const configs: Record<string, Config> = {}; const configs: Record<string, Config> = {};
for (let [schema] of Object.entries(colorSchemes)) { for (let [schema] of Object.entries(colorSchemes)) {
const schemaName = `${dirPrefix}-${schema}`; const schemaName = `${themeName}-${schema}`;
const schemaSvgsPath = path.resolve(schemesPath, schemaName); const schemaSvgsPath = path.resolve(schemesPath, schemaName);
fs.mkdirSync(schemaSvgsPath, { recursive: true }); fs.mkdirSync(schemaSvgsPath, { recursive: true });
const { base, outline, watch } = colorSchemes[schema]; const { base, outline, watch } = colorSchemes[schema];
staticCursors.forEach((cursor: string) => { const sCursors = staticCursors.map((cursor: string) => {
// Read file // Read file
let content = fs.readFileSync(cursor, "utf-8").toString(); let content = fs.readFileSync(cursor, "utf-8").toString();
@ -38,11 +39,16 @@ const generateConfigs = (colorSchemes: ColorSchema, dirPrefix: string) => {
.replace(new RegExp(outlineKeyColor, "g"), outline); .replace(new RegExp(outlineKeyColor, "g"), outline);
// Save Schema // Save Schema
const cursorPath = path.resolve(schemaSvgsPath, "static", cursor); const cursorPath = path.resolve(
fs.writeFileSync(cursorPath, content, "utf-8"); schemaSvgsPath,
"static",
path.basename(cursor)
);
writeSchemaData(cursorPath, content);
return cursorPath;
}); });
animatedCursors.forEach((cursor: string) => { const aCursors = animatedCursors.map((cursor: string) => {
// Read file // Read file
let content = fs let content = fs
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8") .readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
@ -67,8 +73,14 @@ const generateConfigs = (colorSchemes: ColorSchema, dirPrefix: string) => {
} }
// Save Schema // Save Schema
const cursorPath = path.resolve(schemaSvgsPath, "animated", cursor); const cursorPath = path.resolve(
fs.writeFileSync(cursorPath, content, "utf-8"); schemaSvgsPath,
"animated",
path.basename(cursor)
);
writeSchemaData(cursorPath, content);
return cursorPath;
}); });
// Creating Dir for store bitmaps // Creating Dir for store bitmaps
@ -78,8 +90,8 @@ const generateConfigs = (colorSchemes: ColorSchema, dirPrefix: string) => {
// push config to Object // push config to Object
configs[schema] = { configs[schema] = {
bitmapsDir, bitmapsDir,
animatedCursors, animatedCursors: aCursors,
staticCursors staticCursors: sCursors
}; };
} }