Skip to content

Commit

Permalink
Merge pull request #250 from db-ui/feat-overwrite-sources
Browse files Browse the repository at this point in the history
feat: add overwrite sources for cli
  • Loading branch information
nmerget authored Sep 5, 2024
2 parents 6fd7bf8 + d45f8cf commit e6a1bd9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
21 changes: 8 additions & 13 deletions src/generate-icon-fonts/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,17 @@ export const gifOptions: ProgrammOptionsType[] = [
description: "Extra logging",
defaultValue: false,
},
// TODO: This is buggy we should fix it by making a PR to https://github.com/jaywcjlove/svgtofont
/* {
{
name: "overwriteSources",
short: "ows",
description: "Overwrite all svgs inside src directory",
defaultValue: false,
},
// TODO: This is buggy we should fix it by making a PR to https://github.com/jaywcjlove/svgtofont
/* {
name: "outSVGReact",
description: "Creates react svg components",
short: "react",
defaultValue: false,
},*/
];

export const fileEndingsToDelete = [
"eot",
"less",
"module.less",
"styl",
"svg",
"symbol.svg",
"ttf",
"woff",
];
2 changes: 1 addition & 1 deletion src/generate-icon-fonts/gather-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const gatherIcons = (
}
}

return undefined;
return globPaths;
};

export default gatherIcons;
21 changes: 13 additions & 8 deletions src/generate-icon-fonts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import FSE from "fs-extra";

import { fileEndingsToDelete } from "./data";
import svgToFont from "./svg-to-font";
import cleanIcons from "../clean-icons";
import { OptionsType } from "../types";
Expand All @@ -18,7 +17,6 @@ const debugLog = (debug: boolean, message: string) => {
const generateIconFonts = async (values: OptionsType): Promise<unknown> => {
const {
src,
fontName,
dryRun,
cleanIgnoreVariants,
debug = false,
Expand All @@ -44,7 +42,7 @@ const generateIconFonts = async (values: OptionsType): Promise<unknown> => {
}

debugLog(debug, "---Start gathering icon---");
gatherIcons(temporaryDirectory, values);
const iconPaths = gatherIcons(temporaryDirectory, values);

debugLog(debug, "---Start cleaning icon---");
await cleanIcons(
Expand All @@ -61,16 +59,23 @@ const generateIconFonts = async (values: OptionsType): Promise<unknown> => {
const subTemporaryDir = `${temporaryDirectory}/${directory}`;
debugLog(debug, `svgToFont for ${subTemporaryDir}`);
await svgToFont(subTemporaryDir, subDist, values);
for (const ending of fileEndingsToDelete) {
FSE.removeSync(`${subDist}/${fontName}.${ending}`);
}

FSE.removeSync(`${subDist}/symbol.html`);
FSE.removeSync(`${subDist}/unicode.html`);
}

if (overwriteSources) {
FSE.copySync(`${temporaryDirectory}/all`, `${src}`, { overwrite: true });
if (overwriteSources && iconPaths) {
const tempAllDir = `${temporaryDirectory}/all`;
iconPaths.forEach((svgPath) => {
const paths = svgPath.split("/");
const filename: string = paths.at(-1) || "";
const tmpFile = `${tempAllDir}/${filename}`;
if (FSE.existsSync(`${tempAllDir}/${filename}`)) {
FSE.copySync(tmpFile, svgPath, {
overwrite: true,
});
}
});
}

if (!debug) {
Expand Down

0 comments on commit e6a1bd9

Please sign in to comment.