💖 spinner

This commit is contained in:
ful1e5 2020-08-19 13:01:56 +05:30
parent 780ce83c4d
commit d59b297a8e

View file

@ -1,6 +1,8 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import { spinner } from "shared";
import { staticCursors, animatedCursors, animatedClip } from "../cursors.json"; import { staticCursors, animatedCursors, animatedClip } from "../cursors.json";
import { schemesPath, bitmapsPath, rawSvgsDir } from "../color"; import { schemesPath, bitmapsPath, rawSvgsDir } from "../color";
import { ColorSchema, Configs } from "../types"; import { ColorSchema, Configs } from "../types";
@ -15,66 +17,76 @@ const generateConfigs = (colorSchemes: ColorSchema, dirPrefix: string) => {
const configs: Configs = {}; const configs: Configs = {};
for (let [schema] of Object.entries(colorSchemes)) { spinner.text = `Generating ${dirPrefix} Color schemes`;
const { base, outline, watch } = colorSchemes[schema]; spinner.start();
const schemaName = `${dirPrefix}-${schema}`;
const schemaSvgsPath = path.resolve(schemesPath, schemaName); try {
fs.mkdirSync(schemaSvgsPath, { recursive: true }); for (let [schema] of Object.entries(colorSchemes)) {
const schemaName = `${dirPrefix}-${schema}`;
staticCursors.map((cursor: string) => { const schemaSvgsPath = path.resolve(schemesPath, schemaName);
// Read file fs.mkdirSync(schemaSvgsPath, { recursive: true });
let content = fs
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString();
content = content.replace("#00FF00", base).replace("#0000FF", outline); const { base, outline, watch } = colorSchemes[schema];
staticCursors.map((cursor: string) => {
// Read file
let content = fs
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString();
// Save Schema content = content.replace("#00FF00", base).replace("#0000FF", outline);
const cursorPath = path.resolve(schemaSvgsPath, cursor);
fs.writeFileSync(cursorPath, content, "utf-8");
});
for (let [cursor] of Object.entries(animatedCursors)) { // Save Schema
// Read file const cursorPath = path.resolve(schemaSvgsPath, cursor);
let content = fs fs.writeFileSync(cursorPath, content, "utf-8");
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8") });
.toString();
// Animated Cursors have two parts: for (let [cursor] of Object.entries(animatedCursors)) {
// 1) Cursor Color // Read file
// 2) Watch Color let content = fs
.readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8")
.toString();
content = content.replace("#00FF00", base).replace("#0000FF", outline); // Animated Cursors have two parts:
// 1) Cursor Color
// 2) Watch Color
// try => replace `customize` colors content = content.replace("#00FF00", base).replace("#0000FF", outline);
// onError => replace `schema` main colors
try {
if (!watch) throw new Error("");
const { background: b } = watch;
content = content.replace("#TODO", b); // Watch Background
} catch (error) {}
// Save Schema // try => replace `customize` colors
const cursorPath = path.resolve(schemaSvgsPath, cursor); // onError => replace `schema` main colors
fs.writeFileSync(cursorPath, content, "utf-8"); try {
if (!watch) throw new Error("");
const { background: b } = watch;
content = content.replace("#TODO", b); // Watch Background
} catch (error) {}
// Save Schema
const cursorPath = path.resolve(schemaSvgsPath, cursor);
fs.writeFileSync(cursorPath, content, "utf-8");
}
// Creating Dir for store bitmaps
const bitmapsDir = path.resolve(bitmapsPath, schemaName);
fs.mkdirSync(bitmapsDir, { recursive: true });
// push config to Object
configs[schema] = {
svgsDir: schemaSvgsPath,
bitmapsDir,
animatedCursors,
staticCursors,
animatedClip
};
spinner.succeed();
} }
// Creating Dir for store bitmaps return configs;
const bitmapsDir = path.resolve(bitmapsPath, schemaName); } catch (error) {
fs.mkdirSync(bitmapsDir, { recursive: true }); spinner.fail();
process.exit(1);
// push config to Object
configs[schema] = {
svgsDir: schemaSvgsPath,
bitmapsDir,
animatedCursors,
staticCursors,
animatedClip
};
} }
return configs;
}; };
export { generateConfigs }; export { generateConfigs };