@varlet/cli 3.1.0-alpha.1709284240068 → 3.1.0-alpha.1709654106927
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/README.md +1 -0
- package/README.zh-CN.md +1 -0
- package/lib/node/bin.js +3 -2
- package/lib/node/commands/icons.d.ts +10 -1
- package/lib/node/commands/icons.js +25 -17
- package/package.json +9 -9
package/README.md
CHANGED
package/README.zh-CN.md
CHANGED
package/lib/node/bin.js
CHANGED
|
@@ -49,10 +49,11 @@ program
|
|
|
49
49
|
});
|
|
50
50
|
program
|
|
51
51
|
.command('build:icons')
|
|
52
|
+
.option('-w --watch', 'Watch icons for changes and rebuild')
|
|
52
53
|
.description('Build icons')
|
|
53
|
-
.action(async () => {
|
|
54
|
+
.action(async (options) => {
|
|
54
55
|
const { icons } = await import('./commands/icons.js');
|
|
55
|
-
return icons();
|
|
56
|
+
return icons(options);
|
|
56
57
|
});
|
|
57
58
|
program
|
|
58
59
|
.command('preview')
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { VarletConfig } from '../config/varlet.config.js';
|
|
2
|
+
export interface IconsIo {
|
|
3
|
+
entry: string;
|
|
4
|
+
output: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function buildIcons(varletConfig: Required<VarletConfig>, io: IconsIo): Promise<void>;
|
|
7
|
+
export interface IconsCommandOptions {
|
|
8
|
+
watch?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function icons({ watch }?: IconsCommandOptions): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fse from 'fs-extra';
|
|
2
2
|
import sharp from 'sharp';
|
|
3
3
|
import slash from 'slash';
|
|
4
|
+
import chokidar from 'chokidar';
|
|
4
5
|
import webfont from 'webfont';
|
|
5
6
|
import logger from '../shared/logger.js';
|
|
6
7
|
import { parse, resolve } from 'path';
|
|
@@ -50,30 +51,21 @@ function buildWebFont(name, entry) {
|
|
|
50
51
|
descent: 64,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
export async function
|
|
54
|
-
const
|
|
55
|
-
const { name, namespace, base64, publicPath, fontFamilyClassName, fontWeight, fontStyle, genPng = true, entry = './svg', output = './dist', } = get(varletConfig, 'icons');
|
|
56
|
-
const io = {
|
|
57
|
-
entry: resolve(CWD, entry),
|
|
58
|
-
output: resolve(CWD, output),
|
|
59
|
-
};
|
|
54
|
+
export async function buildIcons(varletConfig, io) {
|
|
55
|
+
const { name, namespace, base64, publicPath, fontFamilyClassName, fontWeight, fontStyle, genPng = true, } = get(varletConfig, 'icons');
|
|
60
56
|
const fontsDir = resolve(io.output, ICONS_FONTS_DIR_NAME);
|
|
61
57
|
const cssDir = resolve(io.output, ICONS_CSS_DIR_NAME);
|
|
62
58
|
const pngDir = resolve(io.output, ICONS_PNG_DIR_NAME);
|
|
63
59
|
await removeDir(io.output, fontsDir, cssDir, pngDir);
|
|
64
|
-
const svgFiles = readdirSync(io.entry).filter((svgFile) => svgFile.
|
|
65
|
-
const [{ ttf }] = await Promise.all([
|
|
60
|
+
const svgFiles = readdirSync(io.entry).filter((svgFile) => svgFile.endsWith('.svg'));
|
|
61
|
+
const [{ ttf, glyphsData }] = await Promise.all([
|
|
66
62
|
buildWebFont(name, io.entry),
|
|
67
63
|
genPng ? buildPNG(io.entry, pngDir, svgFiles) : Promise.resolve(),
|
|
68
64
|
]);
|
|
69
|
-
const icons =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
name: svgName.slice(i + 1, extIndex),
|
|
74
|
-
pointCode: svgName.slice(1, i),
|
|
75
|
-
};
|
|
76
|
-
});
|
|
65
|
+
const icons = glyphsData.map((i) => ({
|
|
66
|
+
name: i.metadata.name,
|
|
67
|
+
pointCode: i.metadata.unicode[0].charCodeAt(0).toString(16),
|
|
68
|
+
}));
|
|
77
69
|
const iconNames = icons.map((iconName) => ` '${iconName.name}'`);
|
|
78
70
|
const indexTemplate = `\
|
|
79
71
|
export const pointCodes = {
|
|
@@ -110,3 +102,19 @@ ${icons
|
|
|
110
102
|
]);
|
|
111
103
|
logger.success('build success!');
|
|
112
104
|
}
|
|
105
|
+
export async function icons({ watch = false } = {}) {
|
|
106
|
+
const varletConfig = await getVarletConfig();
|
|
107
|
+
const { entry = './svg', output = './dist' } = varletConfig.icons;
|
|
108
|
+
const io = {
|
|
109
|
+
entry: resolve(CWD, entry),
|
|
110
|
+
output: resolve(CWD, output),
|
|
111
|
+
};
|
|
112
|
+
const task = () => buildIcons(varletConfig, io);
|
|
113
|
+
if (watch) {
|
|
114
|
+
await buildIcons(varletConfig, io);
|
|
115
|
+
chokidar.watch(io.entry, { ignoreInitial: true }).on('all', task);
|
|
116
|
+
logger.info(`watching for ${io.entry} changes...`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
await task();
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "3.1.0-alpha.
|
|
3
|
+
"version": "3.1.0-alpha.1709654106927",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"slash": "^3.0.0",
|
|
65
65
|
"typescript": "^5.1.5",
|
|
66
66
|
"webfont": "11.2.26",
|
|
67
|
-
"@varlet/shared": "3.1.0-alpha.
|
|
68
|
-
"@varlet/vite-plugins": "3.1.0-alpha.
|
|
67
|
+
"@varlet/shared": "3.1.0-alpha.1709654106927",
|
|
68
|
+
"@varlet/vite-plugins": "3.1.0-alpha.1709654106927"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/babel__core": "^7.20.1",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"@types/semver": "^7.3.9",
|
|
81
81
|
"@types/sharp": "0.31.1",
|
|
82
82
|
"rimraf": "^5.0.1",
|
|
83
|
-
"@varlet/ui": "3.1.0-alpha.
|
|
84
|
-
"@varlet/icons": "3.1.0-alpha.
|
|
85
|
-
"@varlet/touch-emulator": "3.1.0-alpha.
|
|
83
|
+
"@varlet/ui": "3.1.0-alpha.1709654106927",
|
|
84
|
+
"@varlet/icons": "3.1.0-alpha.1709654106927",
|
|
85
|
+
"@varlet/touch-emulator": "3.1.0-alpha.1709654106927"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"@vue/runtime-core": "3.4.15",
|
|
@@ -95,9 +95,9 @@
|
|
|
95
95
|
"lodash-es": "^4.17.21",
|
|
96
96
|
"vue": "3.4.15",
|
|
97
97
|
"vue-router": "4.2.0",
|
|
98
|
-
"@varlet/ui": "3.1.0-alpha.
|
|
99
|
-
"@varlet/
|
|
100
|
-
"@varlet/
|
|
98
|
+
"@varlet/ui": "3.1.0-alpha.1709654106927",
|
|
99
|
+
"@varlet/icons": "3.1.0-alpha.1709654106927",
|
|
100
|
+
"@varlet/touch-emulator": "3.1.0-alpha.1709654106927"
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
103
|
"dev": "tsc --watch",
|