-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
209 additions
and
172 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
import { OptionsType, ProgrammOptionsType } from '../types'; | ||
import { OptionsType, ProgrammOptionsType } from "../types"; | ||
import cleanIcons from "./index"; | ||
import startProgram from "../program"; | ||
|
||
|
||
const options: ProgrammOptionsType[] = [ | ||
{ | ||
name: 'ignoreGlobs', | ||
short: 'ig', | ||
description: 'Path icon glob to exclude from the fonts', | ||
array: true | ||
}, | ||
{ | ||
name: 'src', | ||
description: 'Src folder with all svgs', | ||
required: true | ||
}, | ||
{ | ||
name: 'debug', | ||
description: 'Extra logging', | ||
defaultValue: false | ||
} | ||
{ | ||
name: "ignoreGlobs", | ||
short: "ig", | ||
description: "Path icon glob to exclude from the fonts", | ||
array: true, | ||
}, | ||
{ | ||
name: "src", | ||
description: "Src folder with all svgs", | ||
required: true, | ||
}, | ||
{ | ||
name: "traceResolution", | ||
description: "Src folder with all svgs", | ||
defaultValue: "600", | ||
required: false, | ||
}, | ||
{ | ||
name: "debug", | ||
description: "Extra logging", | ||
defaultValue: false, | ||
}, | ||
]; | ||
|
||
const action = async (_: string, options: { _optionValues: OptionsType }) => { | ||
const { src, ignoreGlobs, debug } = options._optionValues; | ||
await cleanIcons(src, ignoreGlobs, debug); | ||
const { | ||
src, | ||
ignoreGlobs, | ||
debug, | ||
traceResolution = "600", | ||
} = options._optionValues; | ||
await cleanIcons(src, ignoreGlobs, traceResolution, debug); | ||
}; | ||
|
||
startProgram( | ||
'@db-ui/foundations - clean icons', | ||
'CLI to clean icon for icon fonts to work', | ||
options, | ||
action | ||
"@db-ui/foundations - clean icons", | ||
"CLI to clean icon for icon fonts to work", | ||
options, | ||
action, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,68 @@ | ||
import { ProgrammOptionsType } from '../types'; | ||
import { ProgrammOptionsType } from "../types"; | ||
|
||
export const gifOptions: ProgrammOptionsType[] = [ | ||
{ | ||
name: 'ignoreGlobs', | ||
description: 'Path icon glob to exclude from the fonts', | ||
array: true | ||
}, | ||
{ | ||
name: 'variants', | ||
description: | ||
'Font variants e.g. solid, inverted, etc. We always add a "default" variant for icons.', | ||
array: true, | ||
defaultValue: [] | ||
}, | ||
{ | ||
name: 'cleanIgnoreVariants', | ||
description: | ||
'Ignore variants which should not be cleaned automatically', | ||
array: true, | ||
defaultValue: [] | ||
}, | ||
{ | ||
name: 'withSizes', | ||
description: 'Splits the font into different sizes' | ||
}, | ||
{ | ||
name: 'src', | ||
description: 'Src folder with all svgs', | ||
required: true | ||
}, | ||
{ | ||
name: 'prefix', | ||
description: 'Prefix of icons to delete for icons' | ||
}, | ||
{ | ||
name: 'fontName', | ||
description: 'The name of your font', | ||
required: true | ||
}, | ||
{ | ||
name: 'dryRun', | ||
description: 'prints the output of the command' | ||
}, | ||
{ | ||
name: 'debug', | ||
description: 'Extra logging', | ||
defaultValue: false | ||
} | ||
{ | ||
name: "ignoreGlobs", | ||
description: "Path icon glob to exclude from the fonts", | ||
array: true, | ||
}, | ||
{ | ||
name: "variants", | ||
description: | ||
'Font variants e.g. solid, inverted, etc. We always add a "default" variant for icons.', | ||
array: true, | ||
defaultValue: [], | ||
}, | ||
{ | ||
name: "cleanIgnoreVariants", | ||
description: "Ignore variants which should not be cleaned automatically", | ||
array: true, | ||
defaultValue: [], | ||
}, | ||
{ | ||
name: "withSizes", | ||
description: "Splits the font into different sizes", | ||
}, | ||
{ | ||
name: "src", | ||
description: "Src folder with all svgs", | ||
required: true, | ||
}, | ||
{ | ||
name: "prefix", | ||
description: "Prefix of icons to delete for icons", | ||
}, | ||
{ | ||
name: "fontName", | ||
description: "The name of your font", | ||
required: true, | ||
}, | ||
{ | ||
name: "dryRun", | ||
short: "dry", | ||
description: "prints the output of the command", | ||
}, | ||
{ | ||
name: "debug", | ||
description: "Extra logging", | ||
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' | ||
"eot", | ||
"less", | ||
"module.less", | ||
"styl", | ||
"svg", | ||
"symbol.svg", | ||
"ttf", | ||
"woff", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
import path from 'node:path'; | ||
import path from "node:path"; | ||
|
||
import svgtofont from 'svgtofont'; | ||
import { OptionsType } from '../types'; | ||
import svgtofont from "svgtofont"; | ||
import { OptionsType } from "../types"; | ||
import { log } from "console"; | ||
|
||
const svgToFont = async ( | ||
temporaryDirectory: string, | ||
dist: string, | ||
options: OptionsType | ||
temporaryDirectory: string, | ||
dist: string, | ||
options: OptionsType, | ||
) => { | ||
const { fontName, debug } = options; | ||
const fileName = __filename; | ||
let lastSlashIndex = fileName.lastIndexOf('\\'); | ||
if (lastSlashIndex === -1) { | ||
lastSlashIndex = fileName.lastIndexOf('/'); | ||
} | ||
const { fontName, debug, svgoOptions, outSVGReact, svgicons2svgfont } = | ||
options; | ||
const fileName = __filename; | ||
let lastSlashIndex = fileName.lastIndexOf("\\"); | ||
if (lastSlashIndex === -1) { | ||
lastSlashIndex = fileName.lastIndexOf("/"); | ||
} | ||
|
||
const generateIconFontsDir = fileName.slice(0, Math.max(0, lastSlashIndex)); | ||
const generateIconFontsDir = fileName.slice(0, Math.max(0, lastSlashIndex)); | ||
|
||
try { | ||
return svgtofont({ | ||
src: temporaryDirectory, | ||
dist, | ||
fontName, | ||
log: debug, | ||
css: true, | ||
outSVGReact: false, // TODO: Consider if we want to give this to users | ||
outSVGPath: false, | ||
useNameAsUnicode: true, | ||
generateInfoData: true, | ||
// SvgoOptions: TODO: https://github.com/svg/svgo#configuration, | ||
svgicons2svgfont: { | ||
fontHeight: 1000, | ||
normalize: true, | ||
centerHorizontally: true | ||
}, | ||
website: { | ||
index: 'font-class', | ||
template: path.resolve( | ||
generateIconFontsDir, | ||
'templates/template.ejs' | ||
), | ||
links: [{ title: '', url: '' }] | ||
}, | ||
styleTemplates: path.resolve(generateIconFontsDir, 'styles') | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
try { | ||
return svgtofont({ | ||
src: temporaryDirectory, | ||
dist, | ||
fontName, | ||
log: debug, | ||
logger: (message) => log(message), | ||
css: true, | ||
outSVGReact, | ||
outSVGPath: true, | ||
useNameAsUnicode: true, | ||
generateInfoData: true, | ||
svgoOptions, | ||
svgicons2svgfont: { | ||
fontHeight: 1000, | ||
normalize: true, | ||
centerHorizontally: true, | ||
...svgicons2svgfont, | ||
}, | ||
website: { | ||
index: "font-class", | ||
template: path.resolve(generateIconFontsDir, "templates/template.ejs"), | ||
links: [{ title: "", url: "" }], | ||
}, | ||
styleTemplates: path.resolve(generateIconFontsDir, "styles"), | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
return true; | ||
return true; | ||
}; | ||
|
||
export default svgToFont; |
Oops, something went wrong.