@varlet/icons 2.7.2 → 2.7.3-alpha.1675189320554

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.
Files changed (2) hide show
  1. package/package.json +4 -15
  2. package/lib/index.js +0 -137
package/package.json CHANGED
@@ -1,24 +1,19 @@
1
1
  {
2
2
  "name": "@varlet/icons",
3
- "version": "2.7.2",
3
+ "version": "2.7.3-alpha.1675189320554",
4
4
  "description": "Icons of varlet",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
- "bin": {
9
- "varlet-icons": "lib/index.js"
10
- },
11
8
  "keywords": [
12
9
  "icons",
13
10
  "svg",
14
- "builder",
15
11
  "varlet"
16
12
  ],
17
13
  "author": "haoziqaq <357229046@qq.com>",
18
14
  "license": "MIT",
19
15
  "files": [
20
- "dist",
21
- "lib"
16
+ "dist"
22
17
  ],
23
18
  "repository": {
24
19
  "type": "git",
@@ -27,16 +22,10 @@
27
22
  "bugs": {
28
23
  "url": "https://github.com/varletjs/varlet/issues"
29
24
  },
30
- "dependencies": {
31
- "commander": "^6.2.1",
32
- "fs-extra": "^9.0.1",
33
- "webfont": "^9.0.0",
34
- "sharp": "0.31.3"
35
- },
36
25
  "devDependencies": {
37
- "@types/node": "^18.7.20"
26
+ "@varlet/cli": "2.7.3-alpha.1675189320554"
38
27
  },
39
28
  "scripts": {
40
- "build": "varlet-icons build"
29
+ "build": "varlet-cli build:icons"
41
30
  }
42
31
  }
package/lib/index.js DELETED
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env node
2
- import webfont from 'webfont'
3
- import commander from 'commander'
4
- import fse from 'fs-extra'
5
- import sharp from 'sharp'
6
- import { resolve, parse } from 'path'
7
- import { pathToFileURL } from 'url'
8
-
9
- const { writeFile, ensureDir, removeSync, readdirSync } = fse
10
-
11
- const CWD = process.cwd()
12
- const SVG_DIR = resolve(CWD, 'svg')
13
- const DIST_DIR = resolve(CWD, 'dist')
14
- const FONTS_DIR = resolve(DIST_DIR, 'fonts')
15
- const CSS_DIR = resolve(DIST_DIR, 'css')
16
- const PNG_DIR = resolve(DIST_DIR, 'png')
17
- const formats = ['ttf']
18
-
19
- async function resetDistDir() {
20
- removeSync(DIST_DIR)
21
- await Promise.all([ensureDir(FONTS_DIR), ensureDir(CSS_DIR), ensureDir(PNG_DIR)])
22
- }
23
-
24
- async function buildPNG(svgFiles) {
25
- await Promise.all(
26
- svgFiles.map((svg) => {
27
- return new Promise((done) => {
28
- const { name } = parse(svg)
29
- resolve(SVG_DIR, svg)
30
-
31
- sharp(resolve(SVG_DIR, svg))
32
- .resize({ height: 100 })
33
- .toBuffer()
34
- .then((buffer) => {
35
- sharp({
36
- create: {
37
- width: 100,
38
- height: 100,
39
- channels: 4,
40
- background: '#4a7afe',
41
- },
42
- })
43
- .composite([
44
- {
45
- input: buffer,
46
- blend: 'dest-in',
47
- },
48
- ])
49
- .png()
50
- .toFile(resolve(PNG_DIR, `${name}.png`))
51
- .then(() => {
52
- done()
53
- })
54
- })
55
- })
56
- })
57
- )
58
- }
59
-
60
- async function build() {
61
- const { default: config } = await import(pathToFileURL(resolve(CWD, 'varlet-icons.config.js')))
62
- const { base64, publicPath, namespace, fontName, fileName, fontWeight = 'normal', fontStyle = 'normal' } = config
63
-
64
- await resetDistDir()
65
- const svgFiles = readdirSync(SVG_DIR)
66
-
67
- const [{ ttf }] = await Promise.all([
68
- webfont.default({
69
- files: `${SVG_DIR}/*.svg`,
70
- fontName,
71
- formats,
72
- fontHeight: 512,
73
- descent: 64,
74
- }),
75
- buildPNG(svgFiles),
76
- ])
77
-
78
- const icons = svgFiles.map((svgName) => {
79
- const i = svgName.indexOf('-')
80
- const extIndex = svgName.lastIndexOf('.')
81
-
82
- return {
83
- name: svgName.slice(i + 1, extIndex),
84
- pointCode: svgName.slice(1, i),
85
- }
86
- })
87
-
88
- const iconNames = icons.map((iconName) => ` '${iconName.name}'`)
89
-
90
- const indexTemplate = `\
91
- export const pointCodes = {
92
- ${icons.map(({ pointCode, name }) => `'${name}': '${pointCode}'`).join(',\n ')}
93
- }
94
-
95
- export default [
96
- ${iconNames.join(',\n')}
97
- ]
98
- `
99
-
100
- const cssTemplate = `\
101
- @font-face {
102
- font-family: "${fontName}";
103
- src: url("${
104
- base64
105
- ? `data:font/truetype;charset=utf-8;base64,${ttf.toString('base64')}`
106
- : `${publicPath}${fileName}-webfont.ttf`
107
- }") format("truetype");
108
- font-weight: ${fontWeight};
109
- font-style: ${fontStyle};
110
- }
111
-
112
- .${namespace}--set {
113
- font-family: "${fontName}";
114
- }
115
-
116
- ${icons
117
- .map((icon) => {
118
- return `.${namespace}-${icon.name}::before {
119
- content: "\\${icon.pointCode}";
120
- }`
121
- })
122
- .join('\n\n')}
123
- `
124
-
125
- await Promise.all([
126
- writeFile(resolve(FONTS_DIR, `${fileName}-webfont.ttf`), ttf),
127
- writeFile(resolve(CSS_DIR, `${fileName}.css`), cssTemplate),
128
- writeFile(resolve(CSS_DIR, `${fileName}.less`), cssTemplate),
129
- writeFile(resolve(DIST_DIR, 'index.js'), indexTemplate),
130
- ])
131
-
132
- console.log('build success!')
133
- }
134
-
135
- commander.command('build').description('Build varlet icons from svg').action(build)
136
-
137
- commander.parse()