@brickflow/cli 0.0.44 → 0.0.46
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/CHANGELOG.md +12 -0
- package/package.json +8 -1
- package/src/icon/generate.d.ts +14 -0
- package/src/icon/generate.js +77 -0
- package/src/icon/index.js +3 -54
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brickflow/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.mjs",
|
|
9
|
+
"./icon": {
|
|
10
|
+
"types": "./src/icon/generate.d.ts",
|
|
11
|
+
"import": "./src/icon/generate.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"bin": {
|
|
8
15
|
"brick": "./index.mjs"
|
|
9
16
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface GeneratedIconFiles {
|
|
2
|
+
cssPath: string
|
|
3
|
+
minifiedCssPath: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface GenerateIconsOptions {
|
|
7
|
+
inputDir: string
|
|
8
|
+
name: string
|
|
9
|
+
outputDir: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare const getIconFontCssPath: (outputDir: string, name: string) => string
|
|
13
|
+
|
|
14
|
+
export declare function generateIcons(options: GenerateIconsOptions): Promise<GeneratedIconFiles>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FontAssetType, generateFonts, OtherAssetType } from 'fantasticon'
|
|
2
|
+
import { access, mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { join, parse } from 'node:path'
|
|
4
|
+
|
|
5
|
+
export const getIconFontCssPath = (outputDir, name) => join(outputDir, `${name}.minify.css`)
|
|
6
|
+
|
|
7
|
+
export async function generateIcons({ inputDir, name, outputDir }) {
|
|
8
|
+
await mkdir(outputDir, { recursive: true })
|
|
9
|
+
await generateFonts({
|
|
10
|
+
assetTypes: [OtherAssetType.CSS, OtherAssetType.JSON],
|
|
11
|
+
fontsUrl: '.',
|
|
12
|
+
fontTypes: [FontAssetType.EOT, FontAssetType.WOFF2, FontAssetType.WOFF],
|
|
13
|
+
formatOptions: {
|
|
14
|
+
json: {
|
|
15
|
+
indent: 2,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
inputDir,
|
|
19
|
+
name,
|
|
20
|
+
normalize: true,
|
|
21
|
+
outputDir,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
let cssSourceFile
|
|
25
|
+
|
|
26
|
+
for (const file of [`${name}.css`, 'icons.css', 'icon.css']) {
|
|
27
|
+
try {
|
|
28
|
+
await access(join(outputDir, file))
|
|
29
|
+
cssSourceFile = file
|
|
30
|
+
break
|
|
31
|
+
} catch {
|
|
32
|
+
// Try the next filename supported by fantasticon.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!cssSourceFile) {
|
|
37
|
+
throw new Error(`CSS output file was not generated for icon set "${name}"`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const cssPath = join(outputDir, cssSourceFile)
|
|
41
|
+
const minifiedCssPath = join(outputDir, `${parse(cssSourceFile).name}.minify.css`)
|
|
42
|
+
const cssContent = await readFile(cssPath, 'utf8')
|
|
43
|
+
const normalizedCssContent = normalizeGeneratedCss(cssContent)
|
|
44
|
+
|
|
45
|
+
if (normalizedCssContent !== cssContent) {
|
|
46
|
+
await writeFile(cssPath, normalizedCssContent)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await writeFile(minifiedCssPath, minifyCss(normalizedCssContent))
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
cssPath,
|
|
53
|
+
minifiedCssPath,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function minifyCss(css) {
|
|
58
|
+
return css
|
|
59
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
60
|
+
.replace(/\s+/g, ' ')
|
|
61
|
+
.replace(/\s*([{}:;,>+~])\s*/g, '$1')
|
|
62
|
+
.replace(/;\}/g, '}')
|
|
63
|
+
.trim()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function normalizeGeneratedCss(css) {
|
|
67
|
+
return `${css
|
|
68
|
+
.replace(/"/g, "'")
|
|
69
|
+
.replace(/^ {4}/gm, ' ')
|
|
70
|
+
.replace(/src: ([^\n]+),\n([^\n]+),\n([^\n]+);/, 'src:\n $1,\n $2,\n $3;')
|
|
71
|
+
.replace(
|
|
72
|
+
/i\[class\^='icon-'\]:before, i\[class\*=' icon-'\]:before \{/,
|
|
73
|
+
"i[class^='icon-']:before,\ni[class*=' icon-']:before {",
|
|
74
|
+
)
|
|
75
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
76
|
+
.trim()}\n`
|
|
77
|
+
}
|
package/src/icon/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { FontAssetType, generateFonts, OtherAssetType } from 'fantasticon'
|
|
2
1
|
import fs from 'fs'
|
|
3
2
|
import path from 'path'
|
|
4
3
|
import { fileURLToPath } from 'url'
|
|
5
4
|
|
|
5
|
+
import { generateIcons } from './generate.js'
|
|
6
|
+
|
|
6
7
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
|
7
8
|
const workspaceRoot = path.resolve(currentDir, '../../../..')
|
|
8
9
|
const args = process.argv.slice(3)
|
|
@@ -37,68 +38,16 @@ if (/[\\/]/.test(iconName)) {
|
|
|
37
38
|
throw new Error(`Icon name must not contain path separators: ${iconName}`)
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await generateFonts({
|
|
43
|
-
assetTypes: [OtherAssetType.CSS, OtherAssetType.JSON],
|
|
44
|
-
fontsUrl: '.',
|
|
45
|
-
fontTypes: [FontAssetType.EOT, FontAssetType.WOFF2, FontAssetType.WOFF],
|
|
46
|
-
formatOptions: {
|
|
47
|
-
json: {
|
|
48
|
-
indent: 2,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
41
|
+
await generateIcons({
|
|
51
42
|
inputDir,
|
|
52
43
|
name: iconName,
|
|
53
|
-
normalize: true,
|
|
54
44
|
outputDir,
|
|
55
45
|
})
|
|
56
46
|
|
|
57
|
-
const cssSourceFile = [`${iconName}.css`, 'icons.css', 'icon.css'].find((file) =>
|
|
58
|
-
fs.existsSync(path.join(outputDir, file)),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
if (!cssSourceFile) {
|
|
62
|
-
throw new Error(`CSS output file was not generated for icon set "${iconName}"`)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const cssPath = path.join(outputDir, cssSourceFile)
|
|
66
|
-
const minifiedCssPath = path.join(outputDir, `${path.parse(cssSourceFile).name}.minify.css`)
|
|
67
|
-
const cssContent = fs.readFileSync(cssPath, 'utf8')
|
|
68
|
-
const normalizedCssContent = normalizeGeneratedCss(cssContent)
|
|
69
|
-
|
|
70
|
-
if (normalizedCssContent !== cssContent) {
|
|
71
|
-
fs.writeFileSync(cssPath, normalizedCssContent)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
fs.writeFileSync(minifiedCssPath, minifyCss(normalizedCssContent))
|
|
75
|
-
|
|
76
47
|
console.log(`✅ Icons generated for ${iconName}`)
|
|
77
48
|
console.log(` input: ${inputDir}`)
|
|
78
49
|
console.log(` output: ${outputDir}`)
|
|
79
50
|
|
|
80
|
-
function minifyCss(css) {
|
|
81
|
-
return css
|
|
82
|
-
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
83
|
-
.replace(/\s+/g, ' ')
|
|
84
|
-
.replace(/\s*([{}:;,>+~])\s*/g, '$1')
|
|
85
|
-
.replace(/;\}/g, '}')
|
|
86
|
-
.trim()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function normalizeGeneratedCss(css) {
|
|
90
|
-
return `${css
|
|
91
|
-
.replace(/"/g, "'")
|
|
92
|
-
.replace(/^ {4}/gm, ' ')
|
|
93
|
-
.replace(/src: ([^\n]+),\n([^\n]+),\n([^\n]+);/, 'src:\n $1,\n $2,\n $3;')
|
|
94
|
-
.replace(
|
|
95
|
-
/i\[class\^='icon-'\]:before, i\[class\*=' icon-'\]:before \{/,
|
|
96
|
-
"i[class^='icon-']:before,\ni[class*=' icon-']:before {",
|
|
97
|
-
)
|
|
98
|
-
.replace(/\n{3,}/g, '\n\n')
|
|
99
|
-
.trim()}\n`
|
|
100
|
-
}
|
|
101
|
-
|
|
102
51
|
function parseArgs(rawArgs) {
|
|
103
52
|
const parsedOptions = {
|
|
104
53
|
name: null,
|