@iconify/tools 2.2.6 → 3.0.0-beta.1
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/README.md +8 -2
- package/lib/colors/detect.cjs +4 -4
- package/lib/colors/detect.d.ts +1 -1
- package/lib/colors/detect.mjs +5 -5
- package/lib/colors/parse.cjs +275 -129
- package/lib/colors/parse.d.ts +14 -5
- package/lib/colors/parse.mjs +278 -133
- package/lib/colors/validate.cjs +11 -2
- package/lib/colors/validate.d.ts +10 -2
- package/lib/colors/validate.mjs +12 -4
- package/lib/download/api/download.cjs +4 -4
- package/lib/download/api/download.mjs +4 -4
- package/lib/download/api/index.cjs +0 -1
- package/lib/download/api/index.mjs +0 -1
- package/lib/download/git/index.cjs +1 -1
- package/lib/download/git/index.mjs +1 -1
- package/lib/download/git/reset.cjs +1 -1
- package/lib/download/git/reset.mjs +1 -1
- package/lib/download/github/hash.cjs +0 -1
- package/lib/download/github/hash.mjs +0 -1
- package/lib/download/github/index.cjs +1 -1
- package/lib/download/github/index.mjs +1 -1
- package/lib/download/gitlab/hash.cjs +0 -1
- package/lib/download/gitlab/hash.mjs +0 -1
- package/lib/download/gitlab/index.cjs +1 -1
- package/lib/download/gitlab/index.mjs +1 -1
- package/lib/download/helpers/unzip.cjs +5 -1
- package/lib/download/index.cjs +1 -1
- package/lib/download/index.mjs +1 -1
- package/lib/download/npm/index.cjs +1 -1
- package/lib/download/npm/index.mjs +1 -1
- package/lib/icon-set/index.cjs +18 -0
- package/lib/icon-set/index.d.ts +7 -1
- package/lib/icon-set/index.mjs +18 -0
- package/lib/icon-set/tags.cjs +2 -2
- package/lib/icon-set/tags.d.ts +1 -1
- package/lib/icon-set/tags.mjs +2 -2
- package/lib/icon-set/types.d.ts +5 -4
- package/lib/import/directory.cjs +101 -28
- package/lib/import/directory.d.ts +12 -5
- package/lib/import/directory.mjs +103 -31
- package/lib/import/figma/index.cjs +1 -2
- package/lib/import/figma/index.mjs +1 -2
- package/lib/import/figma/query.cjs +0 -1
- package/lib/import/figma/query.mjs +0 -1
- package/lib/index.cjs +7 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.mjs +7 -7
- package/lib/misc/scan.cjs +61 -8
- package/lib/misc/scan.d.ts +12 -6
- package/lib/misc/scan.mjs +62 -10
- package/lib/svg/analyse.cjs +2 -2
- package/lib/svg/analyse.d.ts +1 -1
- package/lib/svg/analyse.mjs +4 -4
- package/lib/svg/cleanup/attribs.cjs +2 -2
- package/lib/svg/cleanup/attribs.d.ts +1 -1
- package/lib/svg/cleanup/attribs.mjs +3 -3
- package/lib/svg/cleanup/bad-tags.cjs +2 -2
- package/lib/svg/cleanup/bad-tags.d.ts +1 -1
- package/lib/svg/cleanup/bad-tags.mjs +3 -3
- package/lib/svg/cleanup/inline-style.cjs +2 -2
- package/lib/svg/cleanup/inline-style.d.ts +1 -1
- package/lib/svg/cleanup/inline-style.mjs +3 -3
- package/lib/svg/cleanup/root-style.cjs +1 -1
- package/lib/svg/cleanup/root-style.d.ts +1 -5
- package/lib/svg/cleanup/root-style.mjs +2 -2
- package/lib/svg/cleanup/svgo-style.cjs +2 -2
- package/lib/svg/cleanup/svgo-style.d.ts +1 -1
- package/lib/svg/cleanup/svgo-style.mjs +3 -3
- package/lib/svg/cleanup.cjs +6 -6
- package/lib/svg/cleanup.d.ts +1 -1
- package/lib/svg/cleanup.mjs +6 -6
- package/lib/svg/index.cjs +5 -1
- package/lib/svg/parse-style.cjs +149 -89
- package/lib/svg/parse-style.d.ts +6 -1
- package/lib/svg/parse-style.mjs +150 -91
- package/lib/svg/parse.cjs +56 -18
- package/lib/svg/parse.d.ts +8 -2
- package/lib/svg/parse.mjs +56 -19
- package/package.json +15 -17
|
@@ -13,7 +13,6 @@ require('@iconify/utils/lib/icon-set/minify');
|
|
|
13
13
|
require('@iconify/utils/lib/icon-set/convert-info');
|
|
14
14
|
require('../../icon-set/props.cjs');
|
|
15
15
|
require('@iconify/utils/lib/colors');
|
|
16
|
-
require('node-fetch');
|
|
17
16
|
require('fs');
|
|
18
17
|
require('crypto');
|
|
19
18
|
require('pathe');
|
|
@@ -26,6 +25,7 @@ require('@iconify/utils/lib/misc/objects');
|
|
|
26
25
|
require('child_process');
|
|
27
26
|
require('util');
|
|
28
27
|
require('stream');
|
|
28
|
+
require('fs/promises');
|
|
29
29
|
|
|
30
30
|
async function resetGitRepoContents(target) {
|
|
31
31
|
await misc_exec.execAsync("git add -A", {
|
|
@@ -11,7 +11,6 @@ import '@iconify/utils/lib/icon-set/minify';
|
|
|
11
11
|
import '@iconify/utils/lib/icon-set/convert-info';
|
|
12
12
|
import '../../icon-set/props.mjs';
|
|
13
13
|
import '@iconify/utils/lib/colors';
|
|
14
|
-
import 'node-fetch';
|
|
15
14
|
import 'fs';
|
|
16
15
|
import 'crypto';
|
|
17
16
|
import 'pathe';
|
|
@@ -24,6 +23,7 @@ import '@iconify/utils/lib/misc/objects';
|
|
|
24
23
|
import 'child_process';
|
|
25
24
|
import 'util';
|
|
26
25
|
import 'stream';
|
|
26
|
+
import 'fs/promises';
|
|
27
27
|
|
|
28
28
|
async function resetGitRepoContents(target) {
|
|
29
29
|
await execAsync("git add -A", {
|
|
@@ -7,12 +7,12 @@ const download_api_download = require('../api/download.cjs');
|
|
|
7
7
|
const download_helpers_unzip = require('../helpers/unzip.cjs');
|
|
8
8
|
require('pathe');
|
|
9
9
|
require('../api/index.cjs');
|
|
10
|
-
require('node-fetch');
|
|
11
10
|
require('../api/cache.cjs');
|
|
12
11
|
require('crypto');
|
|
13
12
|
require('../../misc/scan.cjs');
|
|
14
13
|
require('util');
|
|
15
14
|
require('stream');
|
|
15
|
+
require('fs/promises');
|
|
16
16
|
require('extract-zip');
|
|
17
17
|
|
|
18
18
|
async function findMatchingDirs(rootDir, hash) {
|
|
@@ -5,12 +5,12 @@ import { downloadFile } from '../api/download.mjs';
|
|
|
5
5
|
import { unzip } from '../helpers/unzip.mjs';
|
|
6
6
|
import 'pathe';
|
|
7
7
|
import '../api/index.mjs';
|
|
8
|
-
import 'node-fetch';
|
|
9
8
|
import '../api/cache.mjs';
|
|
10
9
|
import 'crypto';
|
|
11
10
|
import '../../misc/scan.mjs';
|
|
12
11
|
import 'util';
|
|
13
12
|
import 'stream';
|
|
13
|
+
import 'fs/promises';
|
|
14
14
|
import 'extract-zip';
|
|
15
15
|
|
|
16
16
|
async function findMatchingDirs(rootDir, hash) {
|
|
@@ -8,12 +8,12 @@ const download_api_download = require('../api/download.cjs');
|
|
|
8
8
|
const download_helpers_unzip = require('../helpers/unzip.cjs');
|
|
9
9
|
require('pathe');
|
|
10
10
|
require('../api/index.cjs');
|
|
11
|
-
require('node-fetch');
|
|
12
11
|
require('../api/cache.cjs');
|
|
13
12
|
require('crypto');
|
|
14
13
|
require('../../misc/scan.cjs');
|
|
15
14
|
require('util');
|
|
16
15
|
require('stream');
|
|
16
|
+
require('fs/promises');
|
|
17
17
|
require('extract-zip');
|
|
18
18
|
|
|
19
19
|
async function findMatchingDirs(rootDir, hash) {
|
|
@@ -6,12 +6,12 @@ import { downloadFile } from '../api/download.mjs';
|
|
|
6
6
|
import { unzip } from '../helpers/unzip.mjs';
|
|
7
7
|
import 'pathe';
|
|
8
8
|
import '../api/index.mjs';
|
|
9
|
-
import 'node-fetch';
|
|
10
9
|
import '../api/cache.mjs';
|
|
11
10
|
import 'crypto';
|
|
12
11
|
import '../../misc/scan.mjs';
|
|
13
12
|
import 'util';
|
|
14
13
|
import 'stream';
|
|
14
|
+
import 'fs/promises';
|
|
15
15
|
import 'extract-zip';
|
|
16
16
|
|
|
17
17
|
async function findMatchingDirs(rootDir, hash) {
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
const extract = require('extract-zip');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
|
|
6
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
7
|
+
|
|
8
|
+
const extract__default = /*#__PURE__*/_interopDefaultCompat(extract);
|
|
9
|
+
|
|
6
10
|
async function unzip(source, path) {
|
|
7
11
|
const dir = await fs.promises.realpath(path);
|
|
8
|
-
await
|
|
12
|
+
await extract__default(source, {
|
|
9
13
|
dir
|
|
10
14
|
});
|
|
11
15
|
}
|
package/lib/download/index.cjs
CHANGED
|
@@ -9,13 +9,13 @@ require('../export/helpers/prepare.cjs');
|
|
|
9
9
|
require('pathe');
|
|
10
10
|
require('./github/hash.cjs');
|
|
11
11
|
require('./api/index.cjs');
|
|
12
|
-
require('node-fetch');
|
|
13
12
|
require('./api/cache.cjs');
|
|
14
13
|
require('crypto');
|
|
15
14
|
require('../misc/scan.cjs');
|
|
16
15
|
require('./api/download.cjs');
|
|
17
16
|
require('util');
|
|
18
17
|
require('stream');
|
|
18
|
+
require('fs/promises');
|
|
19
19
|
require('./helpers/unzip.cjs');
|
|
20
20
|
require('extract-zip');
|
|
21
21
|
require('../misc/exec.cjs');
|
package/lib/download/index.mjs
CHANGED
|
@@ -7,13 +7,13 @@ import '../export/helpers/prepare.mjs';
|
|
|
7
7
|
import 'pathe';
|
|
8
8
|
import './github/hash.mjs';
|
|
9
9
|
import './api/index.mjs';
|
|
10
|
-
import 'node-fetch';
|
|
11
10
|
import './api/cache.mjs';
|
|
12
11
|
import 'crypto';
|
|
13
12
|
import '../misc/scan.mjs';
|
|
14
13
|
import './api/download.mjs';
|
|
15
14
|
import 'util';
|
|
16
15
|
import 'stream';
|
|
16
|
+
import 'fs/promises';
|
|
17
17
|
import './helpers/unzip.mjs';
|
|
18
18
|
import 'extract-zip';
|
|
19
19
|
import '../misc/exec.mjs';
|
|
@@ -6,9 +6,9 @@ const download_api_download = require('../api/download.cjs');
|
|
|
6
6
|
const download_helpers_untar = require('../helpers/untar.cjs');
|
|
7
7
|
const download_npm_version = require('./version.cjs');
|
|
8
8
|
require('pathe');
|
|
9
|
-
require('node-fetch');
|
|
10
9
|
require('util');
|
|
11
10
|
require('stream');
|
|
11
|
+
require('fs/promises');
|
|
12
12
|
require('tar');
|
|
13
13
|
require('../../misc/exec.cjs');
|
|
14
14
|
require('child_process');
|
|
@@ -4,9 +4,9 @@ import { downloadFile } from '../api/download.mjs';
|
|
|
4
4
|
import { untar } from '../helpers/untar.mjs';
|
|
5
5
|
import { getNPMVersion, getPackageVersion } from './version.mjs';
|
|
6
6
|
import 'pathe';
|
|
7
|
-
import 'node-fetch';
|
|
8
7
|
import 'util';
|
|
9
8
|
import 'stream';
|
|
9
|
+
import 'fs/promises';
|
|
10
10
|
import 'tar';
|
|
11
11
|
import '../../misc/exec.mjs';
|
|
12
12
|
import 'child_process';
|
package/lib/icon-set/index.cjs
CHANGED
|
@@ -172,6 +172,24 @@ class IconSet {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Synchronous version of forEach function to loop through all entries.
|
|
177
|
+
*
|
|
178
|
+
* Callback should return false to stop loop.
|
|
179
|
+
*/
|
|
180
|
+
forEachSync(callback, types = ["icon", "variation", "alias"]) {
|
|
181
|
+
const names = this.list(types);
|
|
182
|
+
for (let i = 0; i < names.length; i++) {
|
|
183
|
+
const name = names[i];
|
|
184
|
+
const item = this.entries[name];
|
|
185
|
+
if (item) {
|
|
186
|
+
const result = callback(name, item.type);
|
|
187
|
+
if (result === false) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
175
193
|
/**
|
|
176
194
|
* Get parent icons tree
|
|
177
195
|
*
|
package/lib/icon-set/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IconifyInfo, IconifyJSON } from '@iconify/types';
|
|
2
2
|
import { IconifyIconCustomisations } from '@iconify/utils/lib/customisations/defaults';
|
|
3
|
-
import { IconSetIconEntry, IconCategory, IconSetIconType, IconSetAsyncForEachCallback, ResolvedIconifyIcon, CommonIconProps, CheckThemeResult } from './types.js';
|
|
3
|
+
import { IconSetIconEntry, IconCategory, IconSetIconType, IconSetAsyncForEachCallback, IconSetSyncForEachCallback, ResolvedIconifyIcon, CommonIconProps, CheckThemeResult } from './types.js';
|
|
4
4
|
import { SVG } from '../svg/index.js';
|
|
5
5
|
import { ParentIconsTree } from '@iconify/utils/lib/icon-set/tree';
|
|
6
6
|
|
|
@@ -48,6 +48,12 @@ declare class IconSet {
|
|
|
48
48
|
* Callback should return false to stop loop.
|
|
49
49
|
*/
|
|
50
50
|
forEach(callback: IconSetAsyncForEachCallback, types?: IconSetIconType[]): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Synchronous version of forEach function to loop through all entries.
|
|
53
|
+
*
|
|
54
|
+
* Callback should return false to stop loop.
|
|
55
|
+
*/
|
|
56
|
+
forEachSync(callback: IconSetSyncForEachCallback, types?: IconSetIconType[]): void;
|
|
51
57
|
/**
|
|
52
58
|
* Get parent icons tree
|
|
53
59
|
*
|
package/lib/icon-set/index.mjs
CHANGED
|
@@ -170,6 +170,24 @@ class IconSet {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Synchronous version of forEach function to loop through all entries.
|
|
175
|
+
*
|
|
176
|
+
* Callback should return false to stop loop.
|
|
177
|
+
*/
|
|
178
|
+
forEachSync(callback, types = ["icon", "variation", "alias"]) {
|
|
179
|
+
const names = this.list(types);
|
|
180
|
+
for (let i = 0; i < names.length; i++) {
|
|
181
|
+
const name = names[i];
|
|
182
|
+
const item = this.entries[name];
|
|
183
|
+
if (item) {
|
|
184
|
+
const result = callback(name, item.type);
|
|
185
|
+
if (result === false) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
173
191
|
/**
|
|
174
192
|
* Get parent icons tree
|
|
175
193
|
*
|
package/lib/icon-set/tags.cjs
CHANGED
|
@@ -28,7 +28,7 @@ const sizeTags = {
|
|
|
28
28
|
gridPrefix: "Grid: ",
|
|
29
29
|
heightPrefix: "Height: "
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
function addTagsToIconSet(iconSet, customTags) {
|
|
32
32
|
const info = iconSet.info;
|
|
33
33
|
const tags = [];
|
|
34
34
|
const iconNames = Object.keys(iconSet.entries).filter((key) => {
|
|
@@ -44,7 +44,7 @@ async function addTagsToIconSet(iconSet, customTags) {
|
|
|
44
44
|
if (iconNames.length) {
|
|
45
45
|
let hasPalette = info?.palette;
|
|
46
46
|
if (hasPalette === void 0) {
|
|
47
|
-
hasPalette =
|
|
47
|
+
hasPalette = colors_detect.detectIconSetPalette(iconSet);
|
|
48
48
|
}
|
|
49
49
|
if (hasPalette === true) {
|
|
50
50
|
tags.push(paletteTags.palette);
|
package/lib/icon-set/tags.d.ts
CHANGED
|
@@ -17,6 +17,6 @@ declare const sizeTags: {
|
|
|
17
17
|
/**
|
|
18
18
|
* Add tags to icon set
|
|
19
19
|
*/
|
|
20
|
-
declare function addTagsToIconSet(iconSet: IconSet, customTags?: string[]):
|
|
20
|
+
declare function addTagsToIconSet(iconSet: IconSet, customTags?: string[]): string[];
|
|
21
21
|
|
|
22
22
|
export { addTagsToIconSet, paletteTags, sizeTags };
|
package/lib/icon-set/tags.mjs
CHANGED
|
@@ -26,7 +26,7 @@ const sizeTags = {
|
|
|
26
26
|
gridPrefix: "Grid: ",
|
|
27
27
|
heightPrefix: "Height: "
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
function addTagsToIconSet(iconSet, customTags) {
|
|
30
30
|
const info = iconSet.info;
|
|
31
31
|
const tags = [];
|
|
32
32
|
const iconNames = Object.keys(iconSet.entries).filter((key) => {
|
|
@@ -42,7 +42,7 @@ async function addTagsToIconSet(iconSet, customTags) {
|
|
|
42
42
|
if (iconNames.length) {
|
|
43
43
|
let hasPalette = info?.palette;
|
|
44
44
|
if (hasPalette === void 0) {
|
|
45
|
-
hasPalette =
|
|
45
|
+
hasPalette = detectIconSetPalette(iconSet);
|
|
46
46
|
}
|
|
47
47
|
if (hasPalette === true) {
|
|
48
48
|
tags.push(paletteTags.palette);
|
package/lib/icon-set/types.d.ts
CHANGED
|
@@ -64,11 +64,12 @@ interface CheckThemeResult {
|
|
|
64
64
|
invalid: string[];
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* Callback for
|
|
67
|
+
* Callback for forEach functions
|
|
68
68
|
*
|
|
69
69
|
* Return false to stop loop
|
|
70
70
|
*/
|
|
71
|
-
type
|
|
72
|
-
type IconSetAsyncForEachCallback = (name: string, type: IconSetIconEntry['type']) => Promise<
|
|
71
|
+
type IconSetForEachCallbackResult = void | false;
|
|
72
|
+
type IconSetAsyncForEachCallback = (name: string, type: IconSetIconEntry['type']) => Promise<IconSetForEachCallbackResult> | IconSetForEachCallbackResult;
|
|
73
|
+
type IconSetSyncForEachCallback = (name: string, type: IconSetIconEntry['type']) => IconSetForEachCallbackResult;
|
|
73
74
|
|
|
74
|
-
export { CheckThemeResult, CommonIconProps, ExtraIconProps, IconCategory, IconParentData, IconSetAsyncForEachCallback, IconSetIcon, IconSetIconAlias, IconSetIconEntry, IconSetIconType, IconSetIconVariation, IconWithCategories, IconWithChars, IconWithPropsData, ResolvedIconifyIcon };
|
|
75
|
+
export { CheckThemeResult, CommonIconProps, ExtraIconProps, IconCategory, IconParentData, IconSetAsyncForEachCallback, IconSetIcon, IconSetIconAlias, IconSetIconEntry, IconSetIconType, IconSetIconVariation, IconSetSyncForEachCallback, IconWithCategories, IconWithChars, IconWithPropsData, ResolvedIconifyIcon };
|
package/lib/import/directory.cjs
CHANGED
|
@@ -35,45 +35,118 @@ require('../optimise/svgo.cjs');
|
|
|
35
35
|
require('svgo');
|
|
36
36
|
require('@iconify/utils/lib/svg/id');
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
function importDir(iconSet, options, getKeyword, files, readFile, done) {
|
|
39
|
+
let i = 0;
|
|
40
|
+
const next = () => {
|
|
41
|
+
if (i >= files.length) {
|
|
42
|
+
return done(iconSet);
|
|
43
|
+
}
|
|
44
|
+
const file = files[i];
|
|
45
|
+
i++;
|
|
46
|
+
const defaultKeyword = misc_keyword.cleanupIconKeyword(file.file);
|
|
47
|
+
getKeyword([file, defaultKeyword, iconSet], (keyword) => {
|
|
48
|
+
if (typeof keyword !== "string" || !keyword.length) {
|
|
49
|
+
return next();
|
|
50
|
+
}
|
|
51
|
+
readFile(
|
|
52
|
+
file.path + file.subdir + file.file + file.ext,
|
|
53
|
+
(content) => {
|
|
54
|
+
try {
|
|
55
|
+
const svg = new svg_index.SVG(content);
|
|
56
|
+
svg_cleanup.cleanupSVG(svg);
|
|
57
|
+
iconSet.fromSVG(keyword, svg);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
if (options.ignoreImportErrors !== false) {
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
next();
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
next();
|
|
69
|
+
}
|
|
70
|
+
function isValidFile(item) {
|
|
71
|
+
return item.ext.toLowerCase() === ".svg";
|
|
72
|
+
}
|
|
73
|
+
function importDirectory(path, options = {}) {
|
|
74
|
+
return new Promise((fulfill, reject) => {
|
|
75
|
+
misc_scan.scanDirectory(path, (ext, file, subdir, path2) => {
|
|
41
76
|
const result = {
|
|
42
77
|
file,
|
|
43
78
|
ext,
|
|
44
79
|
subdir,
|
|
45
80
|
path: path2
|
|
46
81
|
};
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
82
|
+
return isValidFile(result) ? result : false;
|
|
83
|
+
}).then((files) => {
|
|
84
|
+
const iconSet = iconSet_index.blankIconSet(options.prefix || "");
|
|
85
|
+
try {
|
|
86
|
+
importDir(
|
|
87
|
+
iconSet,
|
|
88
|
+
options,
|
|
89
|
+
(params, done) => {
|
|
90
|
+
if (options.keyword) {
|
|
91
|
+
const result = options.keyword(...params);
|
|
92
|
+
if (result instanceof Promise) {
|
|
93
|
+
result.then(done).catch(reject);
|
|
94
|
+
} else {
|
|
95
|
+
done(result);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
done(params[1]);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
files,
|
|
102
|
+
(filename, done) => {
|
|
103
|
+
fs.promises.readFile(filename, "utf8").then(done).catch(reject);
|
|
104
|
+
},
|
|
105
|
+
fulfill
|
|
106
|
+
);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
reject(err);
|
|
109
|
+
}
|
|
110
|
+
}).catch(reject);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function importDirectorySync(path, options = {}) {
|
|
114
|
+
const files = misc_scan.scanDirectorySync(path, (ext, file, subdir, path2) => {
|
|
115
|
+
const result = {
|
|
116
|
+
file,
|
|
117
|
+
ext,
|
|
118
|
+
subdir,
|
|
119
|
+
path: path2
|
|
120
|
+
};
|
|
121
|
+
return isValidFile(result) ? result : false;
|
|
50
122
|
});
|
|
51
123
|
const iconSet = iconSet_index.blankIconSet(options.prefix || "");
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
keyword
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
throw err;
|
|
124
|
+
let isSync = true;
|
|
125
|
+
importDir(
|
|
126
|
+
iconSet,
|
|
127
|
+
options,
|
|
128
|
+
(params, done) => {
|
|
129
|
+
if (options.keyword) {
|
|
130
|
+
done(options.keyword(...params));
|
|
131
|
+
} else {
|
|
132
|
+
done(params[1]);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
files,
|
|
136
|
+
(filename, done) => {
|
|
137
|
+
done(fs.readFileSync(filename, "utf8"));
|
|
138
|
+
},
|
|
139
|
+
() => {
|
|
140
|
+
if (!isSync) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"importDirectorySync supposed to be synchronous"
|
|
143
|
+
);
|
|
73
144
|
}
|
|
74
145
|
}
|
|
75
|
-
|
|
146
|
+
);
|
|
147
|
+
isSync = false;
|
|
76
148
|
return iconSet;
|
|
77
149
|
}
|
|
78
150
|
|
|
79
151
|
exports.importDirectory = importDirectory;
|
|
152
|
+
exports.importDirectorySync = importDirectorySync;
|
|
@@ -24,19 +24,26 @@ interface ImportDirectoryFileEntry {
|
|
|
24
24
|
* Callback can be asynchronous
|
|
25
25
|
*/
|
|
26
26
|
type ImportDirectoryKeywordCallbackResult = string | undefined;
|
|
27
|
-
type
|
|
27
|
+
type Callback<T> = (file: ImportDirectoryFileEntry, defaultKeyword: string, iconSet: IconSet) => T;
|
|
28
|
+
type AsyncCallback<T> = Callback<T | Promise<T>>;
|
|
29
|
+
type ImportDirectoryKeywordCallback = AsyncCallback<ImportDirectoryKeywordCallbackResult>;
|
|
30
|
+
type ImportDirectoryKeywordSyncCallback = Callback<ImportDirectoryKeywordCallbackResult>;
|
|
28
31
|
/**
|
|
29
32
|
* Options
|
|
30
33
|
*/
|
|
31
|
-
interface ImportDirectoryOptions {
|
|
34
|
+
interface ImportDirectoryOptions<K> {
|
|
32
35
|
prefix?: string;
|
|
33
36
|
includeSubDirs?: boolean;
|
|
34
|
-
keyword?:
|
|
37
|
+
keyword?: K;
|
|
35
38
|
ignoreImportErrors?: boolean;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* Import all icons from directory
|
|
39
42
|
*/
|
|
40
|
-
declare function importDirectory(path: string, options?: ImportDirectoryOptions): Promise<IconSet>;
|
|
43
|
+
declare function importDirectory(path: string, options?: ImportDirectoryOptions<ImportDirectoryKeywordCallback>): Promise<IconSet>;
|
|
44
|
+
/**
|
|
45
|
+
* Import all icons from directory synchronously
|
|
46
|
+
*/
|
|
47
|
+
declare function importDirectorySync(path: string, options?: ImportDirectoryOptions<ImportDirectoryKeywordSyncCallback>): IconSet;
|
|
41
48
|
|
|
42
|
-
export { ImportDirectoryFileEntry, ImportDirectoryKeywordCallback, importDirectory };
|
|
49
|
+
export { ImportDirectoryFileEntry, ImportDirectoryKeywordCallback, ImportDirectoryKeywordSyncCallback, importDirectory, importDirectorySync };
|