@varlet/cli 3.1.0-alpha.1709537939980 → 3.1.0-alpha.1709717246484

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 CHANGED
@@ -168,6 +168,7 @@ varlet-cli build:extension
168
168
 
169
169
  ```shell
170
170
  # playground-ignore
171
+ varlet-cli build:icons -w
171
172
  varlet-cli build:icons
172
173
  ```
173
174
 
package/README.zh-CN.md CHANGED
@@ -167,6 +167,7 @@ varlet-cli build:extension
167
167
 
168
168
  ```shell
169
169
  # playground-ignore
170
+ varlet-cli build:icons -w
170
171
  varlet-cli build:icons
171
172
  ```
172
173
 
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
- export declare function icons(): Promise<void>;
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 icons() {
54
- const varletConfig = await getVarletConfig();
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.startsWith('u') && svgFile.endsWith('.svg'));
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 = svgFiles.map((svgName) => {
70
- const i = svgName.indexOf('-');
71
- const extIndex = svgName.lastIndexOf('.');
72
- return {
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.1709537939980",
3
+ "version": "3.1.0-alpha.1709717246484",
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.1709537939980",
68
- "@varlet/vite-plugins": "3.1.0-alpha.1709537939980"
67
+ "@varlet/shared": "3.1.0-alpha.1709717246484",
68
+ "@varlet/vite-plugins": "3.1.0-alpha.1709717246484"
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.1709537939980",
84
- "@varlet/icons": "3.1.0-alpha.1709537939980",
85
- "@varlet/touch-emulator": "3.1.0-alpha.1709537939980"
83
+ "@varlet/ui": "3.1.0-alpha.1709717246484",
84
+ "@varlet/icons": "3.1.0-alpha.1709717246484",
85
+ "@varlet/touch-emulator": "3.1.0-alpha.1709717246484"
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.1709537939980",
99
- "@varlet/touch-emulator": "3.1.0-alpha.1709537939980",
100
- "@varlet/icons": "3.1.0-alpha.1709537939980"
98
+ "@varlet/ui": "3.1.0-alpha.1709717246484",
99
+ "@varlet/icons": "3.1.0-alpha.1709717246484",
100
+ "@varlet/touch-emulator": "3.1.0-alpha.1709717246484"
101
101
  },
102
102
  "scripts": {
103
103
  "dev": "tsc --watch",