@varlet/cli 2.20.3 → 2.20.4-alpha.1703144664203
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.
|
@@ -3,18 +3,18 @@ import sharp from 'sharp';
|
|
|
3
3
|
import webfont from 'webfont';
|
|
4
4
|
import logger from '../shared/logger.js';
|
|
5
5
|
import { parse, resolve } from 'path';
|
|
6
|
-
import {
|
|
6
|
+
import { ICONS_CSS_DIR_NAME, ICONS_FONTS_DIR_NAME, ICONS_PNG_DIR_NAME, CWD } from '../shared/constant.js';
|
|
7
7
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
8
8
|
import { get } from 'lodash-es';
|
|
9
9
|
const { removeSync, ensureDir, writeFile, readdirSync } = fse;
|
|
10
|
-
async function removeDir() {
|
|
11
|
-
removeSync(
|
|
12
|
-
await Promise.all([ensureDir(
|
|
10
|
+
async function removeDir(output, fontsDir, cssDir, pngDir) {
|
|
11
|
+
removeSync(output);
|
|
12
|
+
await Promise.all([ensureDir(fontsDir), ensureDir(cssDir), ensureDir(pngDir)]);
|
|
13
13
|
}
|
|
14
|
-
async function buildPNG(svgFiles) {
|
|
14
|
+
async function buildPNG(entry, pngDir, svgFiles) {
|
|
15
15
|
await Promise.all(svgFiles.map((svg) => new Promise((done) => {
|
|
16
16
|
const { name } = parse(svg);
|
|
17
|
-
sharp(resolve(
|
|
17
|
+
sharp(resolve(entry, svg))
|
|
18
18
|
.resize({ height: 100 })
|
|
19
19
|
.toBuffer()
|
|
20
20
|
.then((buffer) => {
|
|
@@ -33,16 +33,16 @@ async function buildPNG(svgFiles) {
|
|
|
33
33
|
},
|
|
34
34
|
])
|
|
35
35
|
.png()
|
|
36
|
-
.toFile(resolve(
|
|
36
|
+
.toFile(resolve(pngDir, `${name}.png`))
|
|
37
37
|
.then(() => {
|
|
38
38
|
done();
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
})));
|
|
42
42
|
}
|
|
43
|
-
function buildWebFont(name) {
|
|
43
|
+
function buildWebFont(name, entry) {
|
|
44
44
|
return webfont.default({
|
|
45
|
-
files: `${
|
|
45
|
+
files: `${entry}/*.svg`,
|
|
46
46
|
fontName: name,
|
|
47
47
|
formats: ['ttf'],
|
|
48
48
|
fontHeight: 512,
|
|
@@ -51,10 +51,20 @@ function buildWebFont(name) {
|
|
|
51
51
|
}
|
|
52
52
|
export async function icons() {
|
|
53
53
|
const varletConfig = await getVarletConfig();
|
|
54
|
-
const { name, namespace, base64, publicPath, fontFamilyClassName, fontWeight, fontStyle } = get(varletConfig, 'icons');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const { name, namespace, base64, publicPath, fontFamilyClassName, fontWeight, fontStyle, genPng = true, entry = './svg', output = './dist', } = get(varletConfig, 'icons');
|
|
55
|
+
const io = {
|
|
56
|
+
entry: resolve(CWD, entry),
|
|
57
|
+
output: resolve(CWD, output),
|
|
58
|
+
};
|
|
59
|
+
const fontsDir = resolve(io.output, ICONS_FONTS_DIR_NAME);
|
|
60
|
+
const cssDir = resolve(io.output, ICONS_CSS_DIR_NAME);
|
|
61
|
+
const pngDir = resolve(io.output, ICONS_PNG_DIR_NAME);
|
|
62
|
+
await removeDir(io.output, fontsDir, cssDir, pngDir);
|
|
63
|
+
const svgFiles = readdirSync(io.entry).filter((svgFile) => svgFile.startsWith('u') && svgFile.endsWith('.svg'));
|
|
64
|
+
const [{ ttf }] = await Promise.all([
|
|
65
|
+
buildWebFont(name, io.entry),
|
|
66
|
+
genPng ? buildPNG(io.entry, pngDir, svgFiles) : Promise.resolve(),
|
|
67
|
+
]);
|
|
58
68
|
const icons = svgFiles.map((svgName) => {
|
|
59
69
|
const i = svgName.indexOf('-');
|
|
60
70
|
const extIndex = svgName.lastIndexOf('.');
|
|
@@ -92,10 +102,10 @@ ${icons
|
|
|
92
102
|
.join('\n\n')}
|
|
93
103
|
`;
|
|
94
104
|
await Promise.all([
|
|
95
|
-
writeFile(resolve(
|
|
96
|
-
writeFile(resolve(
|
|
97
|
-
writeFile(resolve(
|
|
98
|
-
writeFile(resolve(
|
|
105
|
+
writeFile(resolve(fontsDir, `${name}-webfont.ttf`), ttf),
|
|
106
|
+
writeFile(resolve(cssDir, `${name}.css`), cssTemplate),
|
|
107
|
+
writeFile(resolve(cssDir, `${name}.less`), cssTemplate),
|
|
108
|
+
writeFile(resolve(io.output, 'index.js'), indexTemplate),
|
|
99
109
|
]);
|
|
100
110
|
logger.success('build success!');
|
|
101
111
|
}
|
|
@@ -15,6 +15,21 @@ export interface VarletConfigIcons {
|
|
|
15
15
|
* Output base64
|
|
16
16
|
*/
|
|
17
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;
|
|
28
|
+
/**
|
|
29
|
+
* @default true
|
|
30
|
+
* Whether to generate png
|
|
31
|
+
*/
|
|
32
|
+
genPng?: boolean;
|
|
18
33
|
publicPath?: string;
|
|
19
34
|
fontFamilyClassName?: string;
|
|
20
35
|
fontWeight?: string;
|
|
@@ -44,9 +44,7 @@ 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
|
|
48
|
-
export declare const
|
|
49
|
-
export declare const
|
|
50
|
-
export declare const ICONS_FONTS_DIR: string;
|
|
51
|
-
export declare const ICONS_SVG_DIR: string;
|
|
47
|
+
export declare const ICONS_CSS_DIR_NAME = "css";
|
|
48
|
+
export declare const ICONS_PNG_DIR_NAME = "png";
|
|
49
|
+
export declare const ICONS_FONTS_DIR_NAME = "fonts";
|
|
52
50
|
export declare const EXTENSION_ENTRY: string;
|
|
@@ -49,10 +49,8 @@ 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
|
|
53
|
-
export const
|
|
54
|
-
export const
|
|
55
|
-
export const ICONS_FONTS_DIR = resolve(ICONS_DIST_DIR, 'fonts');
|
|
56
|
-
export const ICONS_SVG_DIR = resolve(CWD, 'svg');
|
|
52
|
+
export const ICONS_CSS_DIR_NAME = 'css';
|
|
53
|
+
export const ICONS_PNG_DIR_NAME = 'png';
|
|
54
|
+
export const ICONS_FONTS_DIR_NAME = 'fonts';
|
|
57
55
|
// extension
|
|
58
56
|
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": "2.20.
|
|
3
|
+
"version": "2.20.4-alpha.1703144664203",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"typescript": "^5.1.5",
|
|
64
64
|
"vite": "4.3.5",
|
|
65
65
|
"vue": "3.3.4",
|
|
66
|
-
"webfont": "
|
|
67
|
-
"@varlet/
|
|
68
|
-
"@varlet/
|
|
66
|
+
"webfont": "11.2.26",
|
|
67
|
+
"@varlet/vite-plugins": "2.20.4-alpha.1703144664203",
|
|
68
|
+
"@varlet/shared": "2.20.4-alpha.1703144664203"
|
|
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/
|
|
84
|
-
"@varlet/
|
|
85
|
-
"@varlet/
|
|
83
|
+
"@varlet/icons": "2.20.4-alpha.1703144664203",
|
|
84
|
+
"@varlet/ui": "2.20.4-alpha.1703144664203",
|
|
85
|
+
"@varlet/touch-emulator": "2.20.4-alpha.1703144664203"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"@vue/runtime-core": "3.3.4",
|
|
@@ -95,9 +95,9 @@
|
|
|
95
95
|
"lodash-es": "^4.17.21",
|
|
96
96
|
"vue": "3.3.4",
|
|
97
97
|
"vue-router": "4.2.0",
|
|
98
|
-
"@varlet/ui": "2.20.
|
|
99
|
-
"@varlet/icons": "2.20.
|
|
100
|
-
"@varlet/touch-emulator": "2.20.
|
|
98
|
+
"@varlet/ui": "2.20.4-alpha.1703144664203",
|
|
99
|
+
"@varlet/icons": "2.20.4-alpha.1703144664203",
|
|
100
|
+
"@varlet/touch-emulator": "2.20.4-alpha.1703144664203"
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
103
|
"dev": "tsc --watch",
|