@varlet/cli 3.1.4 → 3.2.0-alpha.1710928822670

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.
@@ -1,9 +1,8 @@
1
1
  import { VarletConfig } from '../config/varlet.config.js';
2
- export interface IconsIo {
2
+ export declare function build(varletConfig: Required<VarletConfig>, io: {
3
3
  entry: string;
4
4
  output: string;
5
- }
6
- export declare function buildIcons(varletConfig: Required<VarletConfig>, io: IconsIo): Promise<void>;
5
+ }): Promise<void>;
7
6
  export interface IconsCommandOptions {
8
7
  watch?: boolean;
9
8
  }
@@ -1,22 +1,24 @@
1
1
  import fse from 'fs-extra';
2
2
  import sharp from 'sharp';
3
- import slash from 'slash';
4
3
  import chokidar from 'chokidar';
5
- import webfont from 'webfont';
6
4
  import logger from '../shared/logger.js';
7
5
  import { parse, resolve } from 'path';
8
- import { ICONS_CSS_DIR_NAME, ICONS_FONTS_DIR_NAME, ICONS_PNG_DIR_NAME, CWD } from '../shared/constant.js';
9
6
  import { getVarletConfig } from '../config/varlet.config.js';
10
7
  import { get } from 'lodash-es';
11
- const { removeSync, ensureDir, writeFile, readdirSync } = fse;
12
- async function removeDir(output, fontsDir, cssDir, pngDir) {
13
- removeSync(output);
14
- await Promise.all([ensureDir(fontsDir), ensureDir(cssDir), ensureDir(pngDir)]);
15
- }
16
- async function buildPNG(entry, pngDir, svgFiles) {
8
+ import { buildIcons, getIo } from '@varlet/icon-builder';
9
+ import { ICONS_PNG_DIR_NAME } from '../shared/constant.js';
10
+ const { removeSync, ensureDirSync, readdirSync } = fse;
11
+ async function clearPngOutputs(pngDir) {
12
+ removeSync(pngDir);
13
+ ensureDirSync(pngDir);
14
+ }
15
+ async function buildPNG(io) {
16
+ const svgFiles = readdirSync(io.entry).filter((svgFile) => svgFile.endsWith('.svg'));
17
+ const pngDir = resolve(io.output, ICONS_PNG_DIR_NAME);
18
+ clearPngOutputs(pngDir);
17
19
  await Promise.all(svgFiles.map((svg) => new Promise((done) => {
18
20
  const { name } = parse(svg);
19
- sharp(resolve(entry, svg))
21
+ sharp(resolve(io.entry, svg))
20
22
  .resize({ height: 100 })
21
23
  .toBuffer()
22
24
  .then((buffer) => {
@@ -41,77 +43,17 @@ async function buildPNG(entry, pngDir, svgFiles) {
41
43
  });
42
44
  });
43
45
  })));
46
+ logger.success('build png success!');
44
47
  }
45
- function buildWebFont(name, entry) {
46
- return webfont.default({
47
- files: `${slash(entry)}/*.svg`,
48
- fontName: name,
49
- formats: ['ttf'],
50
- fontHeight: 512,
51
- descent: 64,
52
- });
53
- }
54
- export async function buildIcons(varletConfig, io) {
55
- const { name, namespace, base64, publicPath, fontFamilyClassName, fontWeight, fontStyle, genPng = true, } = get(varletConfig, 'icons');
56
- const fontsDir = resolve(io.output, ICONS_FONTS_DIR_NAME);
57
- const cssDir = resolve(io.output, ICONS_CSS_DIR_NAME);
58
- const pngDir = resolve(io.output, ICONS_PNG_DIR_NAME);
59
- await removeDir(io.output, fontsDir, cssDir, pngDir);
60
- const svgFiles = readdirSync(io.entry).filter((svgFile) => svgFile.endsWith('.svg'));
61
- const [{ ttf, glyphsData }] = await Promise.all([
62
- buildWebFont(name, io.entry),
63
- genPng ? buildPNG(io.entry, pngDir, svgFiles) : Promise.resolve(),
64
- ]);
65
- const icons = glyphsData.map((i) => ({
66
- name: i.metadata.name,
67
- pointCode: i.metadata.unicode[0].charCodeAt(0).toString(16),
68
- }));
69
- const iconNames = icons.map((iconName) => ` '${iconName.name}'`);
70
- const indexTemplate = `\
71
- export const pointCodes = {
72
- ${icons.map(({ pointCode, name }) => `'${name}': '${pointCode}'`).join(',\n ')}
73
- }
74
-
75
- export default [
76
- ${iconNames.join(',\n')}
77
- ]
78
- `;
79
- const cssTemplate = `\
80
- @font-face {
81
- font-family: "${name}";
82
- src: url("${base64 ? `data:font/truetype;charset=utf-8;base64,${ttf.toString('base64')}` : `${publicPath}${name}-webfont.ttf`}") format("truetype");
83
- font-weight: ${fontWeight};
84
- font-style: ${fontStyle};
85
- }
86
-
87
- .${fontFamilyClassName} {
88
- font-family: "${name}";
89
- }
90
-
91
- ${icons
92
- .map((icon) => `.${namespace}-${icon.name}::before {
93
- content: "\\${icon.pointCode}";
94
- }`)
95
- .join('\n\n')}
96
- `;
97
- await Promise.all([
98
- writeFile(resolve(fontsDir, `${name}-webfont.ttf`), ttf),
99
- writeFile(resolve(cssDir, `${name}.css`), cssTemplate),
100
- writeFile(resolve(cssDir, `${name}.less`), cssTemplate),
101
- writeFile(resolve(io.output, 'index.js'), indexTemplate),
102
- ]);
103
- logger.success('build success!');
48
+ export async function build(varletConfig, io) {
49
+ await Promise.all([buildPNG(io), buildIcons(get(varletConfig, 'icons'))]);
104
50
  }
105
51
  export async function icons({ watch = false } = {}) {
106
52
  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);
53
+ const io = getIo(get(varletConfig, 'icons'));
54
+ const task = () => build(varletConfig, io);
113
55
  if (watch) {
114
- await buildIcons(varletConfig, io);
56
+ await build(varletConfig, io);
115
57
  chokidar.watch(io.entry, { ignoreInitial: true }).on('all', task);
116
58
  logger.info(`watching for ${io.entry} changes...`);
117
59
  return;
@@ -1,39 +1,11 @@
1
+ import { type VIConfig } from '@varlet/icon-builder';
1
2
  import { type CopyOptions } from '@varlet/vite-plugins';
2
- export interface VarletConfigIcons {
3
- /**
4
- * @default `varlet-icons`
5
- * Font name.
6
- */
7
- name?: string;
8
- /**
9
- * @default `var-icon`
10
- * Font name prefix.
11
- */
12
- namespace?: string;
13
- /**
14
- * @default `true`
15
- * Output base64
16
- */
17
- base64?: boolean;
18
- /**
19
- * @default `./svg`
20
- * SVG icons folder path.
21
- */
22
- entry?: string;
23
- /**
24
- * @default `./dist`
25
- * SVG icons folder path.
26
- */
27
- output?: string;
3
+ export interface VarletConfigIcons extends VIConfig {
28
4
  /**
29
5
  * @default true
30
6
  * Whether to generate png
31
7
  */
32
8
  genPng?: boolean;
33
- publicPath?: string;
34
- fontFamilyClassName?: string;
35
- fontWeight?: string;
36
- fontStyle?: string;
37
9
  }
38
10
  export interface VarletConfigEsbuild {
39
11
  target?: string | string[];
@@ -44,7 +44,5 @@ export declare const HL_ZH_TITLE_EVENTS_RE: RegExp;
44
44
  export declare const HL_ZH_TITLE_SLOTS_RE: RegExp;
45
45
  export declare const HL_ZH_MD = "zh-CN.md";
46
46
  export declare const HL_ZH_WEB_TYPES_JSON: string;
47
- export declare const ICONS_CSS_DIR_NAME = "css";
48
47
  export declare const ICONS_PNG_DIR_NAME = "png";
49
- export declare const ICONS_FONTS_DIR_NAME = "fonts";
50
48
  export declare const EXTENSION_ENTRY: string;
@@ -49,8 +49,6 @@ export const HL_ZH_TITLE_SLOTS_RE = /###\s*插槽(?:\r\n|\n)+/;
49
49
  export const HL_ZH_MD = 'zh-CN.md';
50
50
  export const HL_ZH_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.zh-CN.json');
51
51
  // icons
52
- export const ICONS_CSS_DIR_NAME = 'css';
53
52
  export const ICONS_PNG_DIR_NAME = 'png';
54
- export const ICONS_FONTS_DIR_NAME = 'fonts';
55
53
  // extension
56
54
  export const EXTENSION_ENTRY = resolve(CWD, 'src/extension.ts');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "3.1.4",
3
+ "version": "3.2.0-alpha.1710928822670",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@varlet/release": "^0.2.5",
38
+ "@varlet/icon-builder": "0.0.3",
38
39
  "@babel/core": "^7.22.5",
39
40
  "@babel/preset-typescript": "^7.22.5",
40
41
  "@vitejs/plugin-vue": "5.0.4",
@@ -63,9 +64,8 @@
63
64
  "sharp": "0.31.1",
64
65
  "slash": "^3.0.0",
65
66
  "typescript": "^5.1.5",
66
- "webfont": "11.2.26",
67
- "@varlet/shared": "3.1.4",
68
- "@varlet/vite-plugins": "3.1.4"
67
+ "@varlet/shared": "3.2.0-alpha.1710928822670",
68
+ "@varlet/vite-plugins": "3.2.0-alpha.1710928822670"
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.4",
84
- "@varlet/icons": "3.1.4",
85
- "@varlet/touch-emulator": "3.1.4"
83
+ "@varlet/icons": "3.2.0-alpha.1710928822670",
84
+ "@varlet/ui": "3.2.0-alpha.1710928822670",
85
+ "@varlet/touch-emulator": "3.2.0-alpha.1710928822670"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "@vue/runtime-core": "3.4.21",
@@ -95,9 +95,9 @@
95
95
  "lodash-es": "^4.17.21",
96
96
  "vue": "3.4.21",
97
97
  "vue-router": "4.2.0",
98
- "@varlet/ui": "3.1.4",
99
- "@varlet/icons": "3.1.4",
100
- "@varlet/touch-emulator": "3.1.4"
98
+ "@varlet/ui": "3.2.0-alpha.1710928822670",
99
+ "@varlet/icons": "3.2.0-alpha.1710928822670",
100
+ "@varlet/touch-emulator": "3.2.0-alpha.1710928822670"
101
101
  },
102
102
  "scripts": {
103
103
  "dev": "tsc --watch",