@fastkit/icon-font-gen 0.9.0 → 0.10.0
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/dist/icon-font-gen.cjs.js +21 -41
- package/dist/icon-font-gen.cjs.prod.js +21 -41
- package/package.json +6 -6
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var path = require('path');
|
|
6
4
|
var nodeUtil = require('@fastkit/node-util');
|
|
7
5
|
var fs = require('fs-extra');
|
|
@@ -10,24 +8,6 @@ var ev = require('@fastkit/ev');
|
|
|
10
8
|
var tinyLogger = require('@fastkit/tiny-logger');
|
|
11
9
|
var cac = require('cac');
|
|
12
10
|
|
|
13
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
14
|
-
|
|
15
|
-
function _interopNamespace(e) {
|
|
16
|
-
if (e && e.__esModule) return e;
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
for (var k in e) {
|
|
20
|
-
n[k] = e[k];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
n["default"] = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
28
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
29
|
-
var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
|
|
30
|
-
|
|
31
11
|
const ICON_FONT_FORMATS = [
|
|
32
12
|
'eot',
|
|
33
13
|
'woff',
|
|
@@ -49,7 +29,7 @@ async function resolveRawIconFontEntry(rootDir, rawEntry) {
|
|
|
49
29
|
// mdi support
|
|
50
30
|
if (entry.src === '@mdi') {
|
|
51
31
|
const installedDir = await findOrInstallMDI();
|
|
52
|
-
entry.src =
|
|
32
|
+
entry.src = path.join(installedDir, 'svg');
|
|
53
33
|
if (entry.fontHeight == null) {
|
|
54
34
|
entry.fontHeight = 512;
|
|
55
35
|
}
|
|
@@ -60,9 +40,9 @@ async function resolveRawIconFontEntry(rootDir, rawEntry) {
|
|
|
60
40
|
entry.name = 'mdi';
|
|
61
41
|
}
|
|
62
42
|
}
|
|
63
|
-
const name = entry.name ||
|
|
43
|
+
const name = entry.name || path.basename(entry.src);
|
|
64
44
|
const fontName = entry.fontName || `${name}-icon`;
|
|
65
|
-
const dest =
|
|
45
|
+
const dest = path.join(rootDir, name);
|
|
66
46
|
const prefix = entry.disablePrefix ? '' : `${name}-`;
|
|
67
47
|
return {
|
|
68
48
|
...entry,
|
|
@@ -122,8 +102,8 @@ export const ICON_NAMES = registerIconNames([
|
|
|
122
102
|
export type { IconName, IconNameMap } from '@fastkit/icon-font';
|
|
123
103
|
`.trim();
|
|
124
104
|
const fileName = `${entry.name || 'icons'}.ts`;
|
|
125
|
-
const dest =
|
|
126
|
-
await
|
|
105
|
+
const dest = path.resolve(entry.dest, fileName);
|
|
106
|
+
await fs.writeFile(dest, code);
|
|
127
107
|
return {
|
|
128
108
|
fileName,
|
|
129
109
|
dest,
|
|
@@ -141,8 +121,8 @@ async function generateEntry(entry) {
|
|
|
141
121
|
logger.info(`Has not chaged files. Skip process. >>> ${options.src}`);
|
|
142
122
|
return { entry };
|
|
143
123
|
}
|
|
144
|
-
await
|
|
145
|
-
const webfont = await (
|
|
124
|
+
await fs.ensureDir(options.dest);
|
|
125
|
+
const { webfont } = await import('webfont');
|
|
146
126
|
// const { startUnicode = 0xea01 } = options;
|
|
147
127
|
const { startUnicode = 0xba01 } = options;
|
|
148
128
|
let i = startUnicode;
|
|
@@ -172,7 +152,7 @@ async function generateEntry(entry) {
|
|
|
172
152
|
}
|
|
173
153
|
});
|
|
174
154
|
await Promise.all(buildedFormats.map(({ format, code }) => {
|
|
175
|
-
return
|
|
155
|
+
return fs.writeFile(path.join(options.dest, `${options.name}.${format}`), code);
|
|
176
156
|
}));
|
|
177
157
|
const glyphs = [];
|
|
178
158
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -221,7 +201,7 @@ ${glyphs
|
|
|
221
201
|
})
|
|
222
202
|
.join('\n')}
|
|
223
203
|
`;
|
|
224
|
-
await
|
|
204
|
+
await fs.writeFile(path.join(options.dest, `${options.name}.css`), cssCode);
|
|
225
205
|
// const prefix = options.prefix ? `${options.prefix}-` : '';
|
|
226
206
|
const ids = glyphs.map(({ name }) => `${options.prefix}${name}`);
|
|
227
207
|
await generateTS(options, ids);
|
|
@@ -246,18 +226,18 @@ ${names
|
|
|
246
226
|
export type { IconName } from '@fastkit/icon-font';
|
|
247
227
|
export { ICON_NAMES } from '@fastkit/icon-font';
|
|
248
228
|
`.trim();
|
|
249
|
-
const tsDest =
|
|
250
|
-
await
|
|
229
|
+
const tsDest = path.join(dest, 'index.ts');
|
|
230
|
+
await fs.writeFile(tsDest, tsCode);
|
|
251
231
|
const cssCode = `
|
|
252
232
|
/* stylelint-disable */
|
|
253
233
|
${BANNER}
|
|
254
234
|
${names.map((name) => `@import './${name}/${name}.css';`).join('\n')}
|
|
255
235
|
`.trim();
|
|
256
|
-
const cssDest =
|
|
257
|
-
await
|
|
236
|
+
const cssDest = path.join(dest, 'index.css');
|
|
237
|
+
await fs.writeFile(cssDest, cssCode);
|
|
258
238
|
}
|
|
259
239
|
async function generate(opts) {
|
|
260
|
-
await
|
|
240
|
+
await fs.emptyDir(opts.dest);
|
|
261
241
|
const results = await Promise.all(opts.entries.map((entry) => resolveRawIconFontEntry(opts.dest, entry).then((entry) => generateEntry(entry))));
|
|
262
242
|
const entries = results.map(({ entry }) => entry);
|
|
263
243
|
await generateIndex(opts.dest, entries);
|
|
@@ -281,8 +261,8 @@ class IconFontRunnerItem extends ev.EV {
|
|
|
281
261
|
async run() {
|
|
282
262
|
const result = await this.build();
|
|
283
263
|
if (this.watchMode && !this._watcher) {
|
|
284
|
-
const watchDir =
|
|
285
|
-
this._watcher =
|
|
264
|
+
const watchDir = path.resolve(this.entry.src);
|
|
265
|
+
this._watcher = chokidar.watch(watchDir, { ignoreInitial: true });
|
|
286
266
|
this._watcher.on('all', this.build);
|
|
287
267
|
}
|
|
288
268
|
return result;
|
|
@@ -335,7 +315,7 @@ class IconFontRunner extends ev.EV {
|
|
|
335
315
|
return generateIndex(this.dest, entries);
|
|
336
316
|
}
|
|
337
317
|
async run() {
|
|
338
|
-
await
|
|
318
|
+
await fs.ensureDir(this.dest);
|
|
339
319
|
await Promise.all([
|
|
340
320
|
this.buildIndex(),
|
|
341
321
|
Promise.all(this.items.map((item) => item.run())),
|
|
@@ -354,10 +334,10 @@ function cli() {
|
|
|
354
334
|
const cli = cac.cac('icon-font');
|
|
355
335
|
cli
|
|
356
336
|
.option('-d, --dest <string>', 'Destination for generated fonts.', {
|
|
357
|
-
default:
|
|
337
|
+
default: path.join(process.cwd(), `${DEFAULT_DEST_DIRNAME}`),
|
|
358
338
|
})
|
|
359
339
|
.command('[config file path]', `
|
|
360
|
-
Path of the configuration file. (default: [your package directory]${
|
|
340
|
+
Path of the configuration file. (default: [your package directory]${path.sep}${DEFAULT_CONFIG_FILENAME})
|
|
361
341
|
You must export default <IconFontConfig>.
|
|
362
342
|
|
|
363
343
|
e.g.
|
|
@@ -373,9 +353,9 @@ Path of the configuration file. (default: [your package directory]${path__defaul
|
|
|
373
353
|
if (!pkgDir) {
|
|
374
354
|
throw new IconFontGenError('missing package directory.');
|
|
375
355
|
}
|
|
376
|
-
configPath =
|
|
356
|
+
configPath = path.join(pkgDir, DEFAULT_CONFIG_FILENAME);
|
|
377
357
|
}
|
|
378
|
-
const dest =
|
|
358
|
+
const dest = path.resolve(options.dest);
|
|
379
359
|
const mod = await nodeUtil.esbuildRequire(configPath);
|
|
380
360
|
const config = mod.exports.default;
|
|
381
361
|
await generate({
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var path = require('path');
|
|
6
4
|
var nodeUtil = require('@fastkit/node-util');
|
|
7
5
|
var fs = require('fs-extra');
|
|
@@ -10,24 +8,6 @@ var ev = require('@fastkit/ev');
|
|
|
10
8
|
var tinyLogger = require('@fastkit/tiny-logger');
|
|
11
9
|
var cac = require('cac');
|
|
12
10
|
|
|
13
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
14
|
-
|
|
15
|
-
function _interopNamespace(e) {
|
|
16
|
-
if (e && e.__esModule) return e;
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
for (var k in e) {
|
|
20
|
-
n[k] = e[k];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
n["default"] = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
28
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
29
|
-
var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
|
|
30
|
-
|
|
31
11
|
const ICON_FONT_FORMATS = [
|
|
32
12
|
'eot',
|
|
33
13
|
'woff',
|
|
@@ -49,7 +29,7 @@ async function resolveRawIconFontEntry(rootDir, rawEntry) {
|
|
|
49
29
|
// mdi support
|
|
50
30
|
if (entry.src === '@mdi') {
|
|
51
31
|
const installedDir = await findOrInstallMDI();
|
|
52
|
-
entry.src =
|
|
32
|
+
entry.src = path.join(installedDir, 'svg');
|
|
53
33
|
if (entry.fontHeight == null) {
|
|
54
34
|
entry.fontHeight = 512;
|
|
55
35
|
}
|
|
@@ -60,9 +40,9 @@ async function resolveRawIconFontEntry(rootDir, rawEntry) {
|
|
|
60
40
|
entry.name = 'mdi';
|
|
61
41
|
}
|
|
62
42
|
}
|
|
63
|
-
const name = entry.name ||
|
|
43
|
+
const name = entry.name || path.basename(entry.src);
|
|
64
44
|
const fontName = entry.fontName || `${name}-icon`;
|
|
65
|
-
const dest =
|
|
45
|
+
const dest = path.join(rootDir, name);
|
|
66
46
|
const prefix = entry.disablePrefix ? '' : `${name}-`;
|
|
67
47
|
return {
|
|
68
48
|
...entry,
|
|
@@ -122,8 +102,8 @@ export const ICON_NAMES = registerIconNames([
|
|
|
122
102
|
export type { IconName, IconNameMap } from '@fastkit/icon-font';
|
|
123
103
|
`.trim();
|
|
124
104
|
const fileName = `${entry.name || 'icons'}.ts`;
|
|
125
|
-
const dest =
|
|
126
|
-
await
|
|
105
|
+
const dest = path.resolve(entry.dest, fileName);
|
|
106
|
+
await fs.writeFile(dest, code);
|
|
127
107
|
return {
|
|
128
108
|
fileName,
|
|
129
109
|
dest,
|
|
@@ -141,8 +121,8 @@ async function generateEntry(entry) {
|
|
|
141
121
|
logger.info(`Has not chaged files. Skip process. >>> ${options.src}`);
|
|
142
122
|
return { entry };
|
|
143
123
|
}
|
|
144
|
-
await
|
|
145
|
-
const webfont = await (
|
|
124
|
+
await fs.ensureDir(options.dest);
|
|
125
|
+
const { webfont } = await import('webfont');
|
|
146
126
|
// const { startUnicode = 0xea01 } = options;
|
|
147
127
|
const { startUnicode = 0xba01 } = options;
|
|
148
128
|
let i = startUnicode;
|
|
@@ -172,7 +152,7 @@ async function generateEntry(entry) {
|
|
|
172
152
|
}
|
|
173
153
|
});
|
|
174
154
|
await Promise.all(buildedFormats.map(({ format, code }) => {
|
|
175
|
-
return
|
|
155
|
+
return fs.writeFile(path.join(options.dest, `${options.name}.${format}`), code);
|
|
176
156
|
}));
|
|
177
157
|
const glyphs = [];
|
|
178
158
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -221,7 +201,7 @@ ${glyphs
|
|
|
221
201
|
})
|
|
222
202
|
.join('\n')}
|
|
223
203
|
`;
|
|
224
|
-
await
|
|
204
|
+
await fs.writeFile(path.join(options.dest, `${options.name}.css`), cssCode);
|
|
225
205
|
// const prefix = options.prefix ? `${options.prefix}-` : '';
|
|
226
206
|
const ids = glyphs.map(({ name }) => `${options.prefix}${name}`);
|
|
227
207
|
await generateTS(options, ids);
|
|
@@ -246,18 +226,18 @@ ${names
|
|
|
246
226
|
export type { IconName } from '@fastkit/icon-font';
|
|
247
227
|
export { ICON_NAMES } from '@fastkit/icon-font';
|
|
248
228
|
`.trim();
|
|
249
|
-
const tsDest =
|
|
250
|
-
await
|
|
229
|
+
const tsDest = path.join(dest, 'index.ts');
|
|
230
|
+
await fs.writeFile(tsDest, tsCode);
|
|
251
231
|
const cssCode = `
|
|
252
232
|
/* stylelint-disable */
|
|
253
233
|
${BANNER}
|
|
254
234
|
${names.map((name) => `@import './${name}/${name}.css';`).join('\n')}
|
|
255
235
|
`.trim();
|
|
256
|
-
const cssDest =
|
|
257
|
-
await
|
|
236
|
+
const cssDest = path.join(dest, 'index.css');
|
|
237
|
+
await fs.writeFile(cssDest, cssCode);
|
|
258
238
|
}
|
|
259
239
|
async function generate(opts) {
|
|
260
|
-
await
|
|
240
|
+
await fs.emptyDir(opts.dest);
|
|
261
241
|
const results = await Promise.all(opts.entries.map((entry) => resolveRawIconFontEntry(opts.dest, entry).then((entry) => generateEntry(entry))));
|
|
262
242
|
const entries = results.map(({ entry }) => entry);
|
|
263
243
|
await generateIndex(opts.dest, entries);
|
|
@@ -281,8 +261,8 @@ class IconFontRunnerItem extends ev.EV {
|
|
|
281
261
|
async run() {
|
|
282
262
|
const result = await this.build();
|
|
283
263
|
if (this.watchMode && !this._watcher) {
|
|
284
|
-
const watchDir =
|
|
285
|
-
this._watcher =
|
|
264
|
+
const watchDir = path.resolve(this.entry.src);
|
|
265
|
+
this._watcher = chokidar.watch(watchDir, { ignoreInitial: true });
|
|
286
266
|
this._watcher.on('all', this.build);
|
|
287
267
|
}
|
|
288
268
|
return result;
|
|
@@ -335,7 +315,7 @@ class IconFontRunner extends ev.EV {
|
|
|
335
315
|
return generateIndex(this.dest, entries);
|
|
336
316
|
}
|
|
337
317
|
async run() {
|
|
338
|
-
await
|
|
318
|
+
await fs.ensureDir(this.dest);
|
|
339
319
|
await Promise.all([
|
|
340
320
|
this.buildIndex(),
|
|
341
321
|
Promise.all(this.items.map((item) => item.run())),
|
|
@@ -354,10 +334,10 @@ function cli() {
|
|
|
354
334
|
const cli = cac.cac('icon-font');
|
|
355
335
|
cli
|
|
356
336
|
.option('-d, --dest <string>', 'Destination for generated fonts.', {
|
|
357
|
-
default:
|
|
337
|
+
default: path.join(process.cwd(), `${DEFAULT_DEST_DIRNAME}`),
|
|
358
338
|
})
|
|
359
339
|
.command('[config file path]', `
|
|
360
|
-
Path of the configuration file. (default: [your package directory]${
|
|
340
|
+
Path of the configuration file. (default: [your package directory]${path.sep}${DEFAULT_CONFIG_FILENAME})
|
|
361
341
|
You must export default <IconFontConfig>.
|
|
362
342
|
|
|
363
343
|
e.g.
|
|
@@ -373,9 +353,9 @@ Path of the configuration file. (default: [your package directory]${path__defaul
|
|
|
373
353
|
if (!pkgDir) {
|
|
374
354
|
throw new IconFontGenError('missing package directory.');
|
|
375
355
|
}
|
|
376
|
-
configPath =
|
|
356
|
+
configPath = path.join(pkgDir, DEFAULT_CONFIG_FILENAME);
|
|
377
357
|
}
|
|
378
|
-
const dest =
|
|
358
|
+
const dest = path.resolve(options.dest);
|
|
379
359
|
const mod = await nodeUtil.esbuildRequire(configPath);
|
|
380
360
|
const config = mod.exports.default;
|
|
381
361
|
await generate({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastkit/icon-font-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "A tool to generate icon web fonts and their definitions Type-safe for your application.",
|
|
5
5
|
"buildOptions": {
|
|
6
6
|
"name": "IconFont",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen#readme",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@fastkit/ev": "0.
|
|
46
|
-
"@fastkit/icon-font": "0.
|
|
47
|
-
"@fastkit/node-util": "0.
|
|
48
|
-
"@fastkit/tiny-logger": "0.
|
|
45
|
+
"@fastkit/ev": "0.10.0",
|
|
46
|
+
"@fastkit/icon-font": "0.10.0",
|
|
47
|
+
"@fastkit/node-util": "0.10.0",
|
|
48
|
+
"@fastkit/tiny-logger": "0.10.0",
|
|
49
49
|
"cac": "^6.7.11",
|
|
50
50
|
"chokidar": "^3.5.0",
|
|
51
|
-
"fs-extra": "^
|
|
51
|
+
"fs-extra": "^11.1.0",
|
|
52
52
|
"webfont": "^11.2.26"
|
|
53
53
|
}
|
|
54
54
|
}
|