@fastkit/icon-font-gen 0.8.18 → 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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/icon-font-gen.cjs.js +21 -41
- package/dist/icon-font-gen.cjs.prod.js +21 -41
- package/package.json +17 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present, Ayumu Fujii (dadajam4) and Fastkit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -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,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastkit/icon-font-gen",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "A tool to generate icon web fonts and their definitions Type-safe for your application.",
|
|
5
5
|
"buildOptions": {
|
|
6
6
|
"name": "IconFont",
|
|
7
7
|
"formats": [
|
|
8
8
|
"cjs"
|
|
9
9
|
]
|
|
10
10
|
},
|
|
11
|
+
"_docs": {
|
|
12
|
+
"scope": "",
|
|
13
|
+
"feature": "icon",
|
|
14
|
+
"description": {
|
|
15
|
+
"en": "A tool to generate icon web fonts and their definitions Type-safe for your application.",
|
|
16
|
+
"ja": "アプリケーションのためにアイコンWebフォントとその定義をTypeセーフに生成するツール。"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
11
19
|
"main": "index.js",
|
|
12
20
|
"bin": {
|
|
13
21
|
"icon-font": "lib/cli.js"
|
|
@@ -24,7 +32,8 @@
|
|
|
24
32
|
"url": "git+https://github.com/dadajam4/fastkit.git"
|
|
25
33
|
},
|
|
26
34
|
"keywords": [
|
|
27
|
-
"fastkit"
|
|
35
|
+
"fastkit",
|
|
36
|
+
"icon"
|
|
28
37
|
],
|
|
29
38
|
"author": "dadajam4",
|
|
30
39
|
"license": "MIT",
|
|
@@ -33,13 +42,13 @@
|
|
|
33
42
|
},
|
|
34
43
|
"homepage": "https://github.com/dadajam4/fastkit/tree/main/packages/icon-font-gen#readme",
|
|
35
44
|
"dependencies": {
|
|
36
|
-
"@fastkit/ev": "0.
|
|
37
|
-
"@fastkit/icon-font": "0.
|
|
38
|
-
"@fastkit/node-util": "0.
|
|
39
|
-
"@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",
|
|
40
49
|
"cac": "^6.7.11",
|
|
41
50
|
"chokidar": "^3.5.0",
|
|
42
|
-
"fs-extra": "^
|
|
51
|
+
"fs-extra": "^11.1.0",
|
|
43
52
|
"webfont": "^11.2.26"
|
|
44
53
|
}
|
|
45
54
|
}
|