@charcoal-ui/icons-cli 4.10.0 → 4.12.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/v2/transformDataUri.ts +65 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/icons-cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.0-beta.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"build": "FORCE_COLOR=1 tsup-node",
|
|
49
49
|
"build:react": "pnpm svgr ../icon-files/v2/svg/ --out-dir ../icons/src/react/v2 --typescript --ref --no-index --no-svgo && OUTPUT_ROOT_DIR=../icons/src/react/v2 pnpm tsx src/v2/transformReact.ts",
|
|
50
50
|
"build:css": "OUTPUT_ROOT_DIR=../icons/css/v2 pnpm tsx src/v2/transformCSS.ts",
|
|
51
|
+
"build:uri": "OUTPUT_ROOT_DIR=../icon-files/v2-datauri pnpm tsx src/v2/transformDataUri.ts",
|
|
51
52
|
"typecheck": "tsc --project tsconfig.build.json --pretty --noEmit",
|
|
52
53
|
"clean": "rimraf dist .tsbuildinfo",
|
|
53
54
|
"cli:icons": "./dist/index.js",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { glob } from 'fast-glob'
|
|
2
|
+
import { ensureDir, readFile, writeFile } from 'fs-extra'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { mustBeDefined } from '../utils'
|
|
5
|
+
import { escape } from 'querystring'
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
mustBeDefined(process.env.OUTPUT_ROOT_DIR, 'OUTPUT_ROOT_DIR')
|
|
9
|
+
const outDir = process.env.OUTPUT_ROOT_DIR
|
|
10
|
+
const inputDir = path.join(__dirname, '../../../icon-files/v2/svg')
|
|
11
|
+
await ensureDir(outDir)
|
|
12
|
+
const fileNames = await glob('**/*.svg', { cwd: inputDir })
|
|
13
|
+
const dataUris = await Promise.all(
|
|
14
|
+
fileNames.map(async (fileName) => {
|
|
15
|
+
const filePath = path.join(inputDir, fileName)
|
|
16
|
+
const content = await readFile(filePath, 'utf-8')
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
iconName: fileName.replace('.svg', ''),
|
|
20
|
+
uri: `data:image/svg+xml;utf8,${escape(content).replace("'", "\\'")}`,
|
|
21
|
+
isSetCurrentcolor: !content.includes('<def'),
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const js = `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
${dataUris
|
|
30
|
+
.map(
|
|
31
|
+
(it) =>
|
|
32
|
+
`'${it.iconName}': {uri: '${it.uri}', isSetCurrentcolor: ${
|
|
33
|
+
it.isSetCurrentcolor ? 'true' : 'false'
|
|
34
|
+
}}`
|
|
35
|
+
)
|
|
36
|
+
.join(',\n')}
|
|
37
|
+
}`
|
|
38
|
+
await writeFile(path.join(outDir, 'index.mjs'), js)
|
|
39
|
+
|
|
40
|
+
const cjs = `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
${dataUris
|
|
44
|
+
.map(
|
|
45
|
+
(it) =>
|
|
46
|
+
`'${it.iconName}': {uri: '${it.uri}', isSetCurrentcolor: ${
|
|
47
|
+
it.isSetCurrentcolor ? 'true' : 'false'
|
|
48
|
+
}}`
|
|
49
|
+
)
|
|
50
|
+
.join(',\n')}
|
|
51
|
+
}`
|
|
52
|
+
await writeFile(path.join(outDir, 'index.cjs'), cjs)
|
|
53
|
+
|
|
54
|
+
const dts = `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
55
|
+
|
|
56
|
+
declare var _default: {
|
|
57
|
+
${dataUris
|
|
58
|
+
.map((it) => `'${it.iconName}': { uri: string, isSetCurrentcolor: boolean }`)
|
|
59
|
+
.join(';\n')}}
|
|
60
|
+
export default _default;
|
|
61
|
+
`
|
|
62
|
+
|
|
63
|
+
await writeFile(path.join(outDir, 'index.d.ts'), dts)
|
|
64
|
+
}
|
|
65
|
+
void main()
|