Spinner added

This commit is contained in:
ful1e5 2020-09-02 09:03:02 +05:30
parent 53e759f699
commit b0611d8e78

View file

@ -1,4 +1,6 @@
import fs from "fs"; import fs from "fs";
import ora from "ora";
import chalk from "chalk";
import path from "path"; import path from "path";
import { ColorSchemes, Config, PathConfig } from "./types"; import { ColorSchemes, Config, PathConfig } from "./types";
@ -39,75 +41,84 @@ const generateConfigs = ({
for (let [schema] of Object.entries(colorSchemes)) { for (let [schema] of Object.entries(colorSchemes)) {
const schemaName = `${themeName}-${schema}`; const schemaName = `${themeName}-${schema}`;
const spinner = ora();
spinner.text = ` Generating ${chalk.blueBright(schemaName)} Color 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];
const sCursors = staticCursors.map((cursor: string) => { try {
// Read file const sCursors = staticCursors.map((cursor: string) => {
let content = fs.readFileSync(cursor, "utf-8").toString(); // Read file
let content = fs.readFileSync(cursor, "utf-8").toString();
content = content content = content
.replace(new RegExp(baseKeyColor, "g"), base) .replace(new RegExp(baseKeyColor, "g"), base)
.replace(new RegExp(outlineKeyColor, "g"), outline); .replace(new RegExp(outlineKeyColor, "g"), outline);
// Save Schema // Save Schema
cursor = path.basename(cursor); cursor = path.basename(cursor);
writeSchemaData({ writeSchemaData({
path: schemaSvgsPath, path: schemaSvgsPath,
fileName: cursor, fileName: cursor,
content content
});
return path.resolve(schemaSvgsPath, cursor);
}); });
return path.resolve(schemaSvgsPath, cursor); const aCursors = animatedCursors.map((cursor: string) => {
}); // Read file
let content = fs
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString();
const aCursors = animatedCursors.map((cursor: string) => { // Animated Cursors have two parts:
// Read file // 1) Cursor Color
let content = fs // 2) Watch Color
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString();
// Animated Cursors have two parts: content = content
// 1) Cursor Color .replace(new RegExp(baseKeyColor, "g"), base)
// 2) Watch Color .replace(new RegExp(outlineKeyColor, "g"), outline);
content = content // try => replace `customize` colors
.replace(new RegExp(baseKeyColor, "g"), base) // onError => replace `schema` main colors
.replace(new RegExp(outlineKeyColor, "g"), outline); try {
if (!watch) throw new Error("");
const { background: b } = watch;
content = content.replace(new RegExp(watchKeyColor, "g"), b); // Watch Background
} catch (error) {
content = content.replace(new RegExp(watchKeyColor, "g"), base); // on error=> replace as base
}
// try => replace `customize` colors // Save Schema
// onError => replace `schema` main colors cursor = path.basename(cursor);
try { writeSchemaData({
if (!watch) throw new Error(""); path: schemaSvgsPath,
const { background: b } = watch; fileName: cursor,
content = content.replace(new RegExp(watchKeyColor, "g"), b); // Watch Background content
} catch (error) { });
content = content.replace(new RegExp(watchKeyColor, "g"), base); // on error=> replace as base
}
// Save Schema return path.resolve(schemaSvgsPath, cursor);
cursor = path.basename(cursor);
writeSchemaData({
path: schemaSvgsPath,
fileName: cursor,
content
}); });
return path.resolve(schemaSvgsPath, cursor); // Creating Dir for store bitmaps
}); const bitmapsDir = path.resolve(bitmapsPath, schemaName);
fs.mkdirSync(bitmapsDir, { recursive: true });
// Creating Dir for store bitmaps // push config to Object
const bitmapsDir = path.resolve(bitmapsPath, schemaName); configs[schemaName] = {
fs.mkdirSync(bitmapsDir, { recursive: true }); bitmapsDir,
animatedCursors: aCursors,
// push config to Object staticCursors: sCursors
configs[schemaName] = { };
bitmapsDir, spinner.succeed();
animatedCursors: aCursors, } catch (error) {
staticCursors: sCursors console.log(error);
}; spinner.fail();
}
} }
return configs; return configs;