@iconify/tools 2.2.5 → 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 +9 -1
- package/lib/index.d.ts +7 -6
- package/lib/index.mjs +8 -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/optimise/origin.cjs +23 -0
- package/lib/optimise/origin.d.ts +10 -0
- package/lib/optimise/origin.mjs +21 -0
- package/lib/optimise/scale.cjs +17 -15
- package/lib/optimise/scale.mjs +17 -15
- 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 +23 -20
package/lib/import/directory.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { promises } from 'fs';
|
|
1
|
+
import { promises, readFileSync } from 'fs';
|
|
2
2
|
import { blankIconSet } from '../icon-set/index.mjs';
|
|
3
3
|
import { cleanupIconKeyword } from '../misc/keyword.mjs';
|
|
4
|
-
import { scanDirectory } from '../misc/scan.mjs';
|
|
4
|
+
import { scanDirectory, scanDirectorySync } from '../misc/scan.mjs';
|
|
5
5
|
import { SVG } from '../svg/index.mjs';
|
|
6
6
|
import { cleanupSVG } from '../svg/cleanup.mjs';
|
|
7
7
|
import '@iconify/utils/lib/icon/defaults';
|
|
@@ -33,45 +33,117 @@ import '../optimise/svgo.mjs';
|
|
|
33
33
|
import 'svgo';
|
|
34
34
|
import '@iconify/utils/lib/svg/id';
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
function importDir(iconSet, options, getKeyword, files, readFile, done) {
|
|
37
|
+
let i = 0;
|
|
38
|
+
const next = () => {
|
|
39
|
+
if (i >= files.length) {
|
|
40
|
+
return done(iconSet);
|
|
41
|
+
}
|
|
42
|
+
const file = files[i];
|
|
43
|
+
i++;
|
|
44
|
+
const defaultKeyword = cleanupIconKeyword(file.file);
|
|
45
|
+
getKeyword([file, defaultKeyword, iconSet], (keyword) => {
|
|
46
|
+
if (typeof keyword !== "string" || !keyword.length) {
|
|
47
|
+
return next();
|
|
48
|
+
}
|
|
49
|
+
readFile(
|
|
50
|
+
file.path + file.subdir + file.file + file.ext,
|
|
51
|
+
(content) => {
|
|
52
|
+
try {
|
|
53
|
+
const svg = new SVG(content);
|
|
54
|
+
cleanupSVG(svg);
|
|
55
|
+
iconSet.fromSVG(keyword, svg);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (options.ignoreImportErrors !== false) {
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
next();
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
next();
|
|
67
|
+
}
|
|
68
|
+
function isValidFile(item) {
|
|
69
|
+
return item.ext.toLowerCase() === ".svg";
|
|
70
|
+
}
|
|
71
|
+
function importDirectory(path, options = {}) {
|
|
72
|
+
return new Promise((fulfill, reject) => {
|
|
73
|
+
scanDirectory(path, (ext, file, subdir, path2) => {
|
|
39
74
|
const result = {
|
|
40
75
|
file,
|
|
41
76
|
ext,
|
|
42
77
|
subdir,
|
|
43
78
|
path: path2
|
|
44
79
|
};
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
|
|
80
|
+
return isValidFile(result) ? result : false;
|
|
81
|
+
}).then((files) => {
|
|
82
|
+
const iconSet = blankIconSet(options.prefix || "");
|
|
83
|
+
try {
|
|
84
|
+
importDir(
|
|
85
|
+
iconSet,
|
|
86
|
+
options,
|
|
87
|
+
(params, done) => {
|
|
88
|
+
if (options.keyword) {
|
|
89
|
+
const result = options.keyword(...params);
|
|
90
|
+
if (result instanceof Promise) {
|
|
91
|
+
result.then(done).catch(reject);
|
|
92
|
+
} else {
|
|
93
|
+
done(result);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
done(params[1]);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
files,
|
|
100
|
+
(filename, done) => {
|
|
101
|
+
promises.readFile(filename, "utf8").then(done).catch(reject);
|
|
102
|
+
},
|
|
103
|
+
fulfill
|
|
104
|
+
);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
reject(err);
|
|
107
|
+
}
|
|
108
|
+
}).catch(reject);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function importDirectorySync(path, options = {}) {
|
|
112
|
+
const files = scanDirectorySync(path, (ext, file, subdir, path2) => {
|
|
113
|
+
const result = {
|
|
114
|
+
file,
|
|
115
|
+
ext,
|
|
116
|
+
subdir,
|
|
117
|
+
path: path2
|
|
118
|
+
};
|
|
119
|
+
return isValidFile(result) ? result : false;
|
|
48
120
|
});
|
|
49
121
|
const iconSet = blankIconSet(options.prefix || "");
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
keyword
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
throw err;
|
|
122
|
+
let isSync = true;
|
|
123
|
+
importDir(
|
|
124
|
+
iconSet,
|
|
125
|
+
options,
|
|
126
|
+
(params, done) => {
|
|
127
|
+
if (options.keyword) {
|
|
128
|
+
done(options.keyword(...params));
|
|
129
|
+
} else {
|
|
130
|
+
done(params[1]);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
files,
|
|
134
|
+
(filename, done) => {
|
|
135
|
+
done(readFileSync(filename, "utf8"));
|
|
136
|
+
},
|
|
137
|
+
() => {
|
|
138
|
+
if (!isSync) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"importDirectorySync supposed to be synchronous"
|
|
141
|
+
);
|
|
71
142
|
}
|
|
72
143
|
}
|
|
73
|
-
|
|
144
|
+
);
|
|
145
|
+
isSync = false;
|
|
74
146
|
return iconSet;
|
|
75
147
|
}
|
|
76
148
|
|
|
77
|
-
export { importDirectory };
|
|
149
|
+
export { importDirectory, importDirectorySync };
|
|
@@ -34,7 +34,6 @@ require('../../optimise/svgo.cjs');
|
|
|
34
34
|
require('svgo');
|
|
35
35
|
require('@iconify/utils/lib/svg/id');
|
|
36
36
|
require('../../download/api/index.cjs');
|
|
37
|
-
require('node-fetch');
|
|
38
37
|
require('../../download/api/cache.cjs');
|
|
39
38
|
require('fs');
|
|
40
39
|
require('crypto');
|
|
@@ -81,7 +80,7 @@ async function importFromFigma(options) {
|
|
|
81
80
|
}
|
|
82
81
|
try {
|
|
83
82
|
const svg = new svg_index.SVG(item.content);
|
|
84
|
-
|
|
83
|
+
svg_cleanup.cleanupSVG(svg);
|
|
85
84
|
iconSet.fromSVG(item.keyword, svg);
|
|
86
85
|
} catch (err) {
|
|
87
86
|
missing.push(item);
|
|
@@ -32,7 +32,6 @@ import '../../optimise/svgo.mjs';
|
|
|
32
32
|
import 'svgo';
|
|
33
33
|
import '@iconify/utils/lib/svg/id';
|
|
34
34
|
import '../../download/api/index.mjs';
|
|
35
|
-
import 'node-fetch';
|
|
36
35
|
import '../../download/api/cache.mjs';
|
|
37
36
|
import 'fs';
|
|
38
37
|
import 'crypto';
|
|
@@ -79,7 +78,7 @@ async function importFromFigma(options) {
|
|
|
79
78
|
}
|
|
80
79
|
try {
|
|
81
80
|
const svg = new SVG(item.content);
|
|
82
|
-
|
|
81
|
+
cleanupSVG(svg);
|
|
83
82
|
iconSet.fromSVG(item.keyword, svg);
|
|
84
83
|
} catch (err) {
|
|
85
84
|
missing.push(item);
|
package/lib/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ const colors_validate = require('./colors/validate.cjs');
|
|
|
33
33
|
const colors_detect = require('./colors/detect.cjs');
|
|
34
34
|
const optimise_svgo = require('./optimise/svgo.cjs');
|
|
35
35
|
const optimise_flags = require('./optimise/flags.cjs');
|
|
36
|
+
const optimise_origin = require('./optimise/origin.cjs');
|
|
36
37
|
const optimise_scale = require('./optimise/scale.cjs');
|
|
37
38
|
const optimise_globalStyle = require('./optimise/global-style.cjs');
|
|
38
39
|
const export_directory = require('./export/directory.cjs');
|
|
@@ -77,11 +78,11 @@ require('./import/figma/query.cjs');
|
|
|
77
78
|
require('./download/api/cache.cjs');
|
|
78
79
|
require('fs');
|
|
79
80
|
require('crypto');
|
|
80
|
-
require('node-fetch');
|
|
81
81
|
require('pathe');
|
|
82
82
|
require('child_process');
|
|
83
83
|
require('util');
|
|
84
84
|
require('stream');
|
|
85
|
+
require('fs/promises');
|
|
85
86
|
require('extract-zip');
|
|
86
87
|
require('tar');
|
|
87
88
|
require('./download/gitlab/types.cjs');
|
|
@@ -91,7 +92,9 @@ require('./export/helpers/custom-files.cjs');
|
|
|
91
92
|
|
|
92
93
|
exports.SVG = svg_index.SVG;
|
|
93
94
|
exports.parseSVG = svg_parse.parseSVG;
|
|
95
|
+
exports.parseSVGSync = svg_parse.parseSVGSync;
|
|
94
96
|
exports.parseSVGStyle = svg_parseStyle.parseSVGStyle;
|
|
97
|
+
exports.parseSVGStyleSync = svg_parseStyle.parseSVGStyleSync;
|
|
95
98
|
exports.analyseSVGStructure = svg_analyse.analyseSVGStructure;
|
|
96
99
|
exports.cleanupSVG = svg_cleanup.cleanupSVG;
|
|
97
100
|
exports.removeBadAttributes = svg_cleanup_attribs.removeBadAttributes;
|
|
@@ -106,6 +109,7 @@ exports.mergeIconSets = iconSet_merge.mergeIconSets;
|
|
|
106
109
|
exports.addTagsToIconSet = iconSet_tags.addTagsToIconSet;
|
|
107
110
|
exports.importFromFigma = import_figma_index.importFromFigma;
|
|
108
111
|
exports.importDirectory = import_directory.importDirectory;
|
|
112
|
+
exports.importDirectorySync = import_directory.importDirectorySync;
|
|
109
113
|
exports.downloadGitRepo = download_git_index.downloadGitRepo;
|
|
110
114
|
exports.getGitRepoHash = download_git_hash.getGitRepoHash;
|
|
111
115
|
exports.getGitRepoBranch = download_git_branch.getGitRepoBranch;
|
|
@@ -121,10 +125,13 @@ exports.downloadPackage = download_index.downloadPackage;
|
|
|
121
125
|
exports.downloadFile = download_api_download.downloadFile;
|
|
122
126
|
exports.isEmptyColor = colors_parse.isEmptyColor;
|
|
123
127
|
exports.parseColors = colors_parse.parseColors;
|
|
128
|
+
exports.parseColorsSync = colors_parse.parseColorsSync;
|
|
124
129
|
exports.validateColors = colors_validate.validateColors;
|
|
130
|
+
exports.validateColorsSync = colors_validate.validateColorsSync;
|
|
125
131
|
exports.detectIconSetPalette = colors_detect.detectIconSetPalette;
|
|
126
132
|
exports.runSVGO = optimise_svgo.runSVGO;
|
|
127
133
|
exports.deOptimisePaths = optimise_flags.deOptimisePaths;
|
|
134
|
+
exports.resetSVGOrigin = optimise_origin.resetSVGOrigin;
|
|
128
135
|
exports.scaleSVG = optimise_scale.scaleSVG;
|
|
129
136
|
exports.cleanupGlobalStyle = optimise_globalStyle.cleanupGlobalStyle;
|
|
130
137
|
exports.exportToDirectory = export_directory.exportToDirectory;
|
|
@@ -133,6 +140,7 @@ exports.exportJSONPackage = export_jsonPackage.exportJSONPackage;
|
|
|
133
140
|
exports.writeJSONFile = misc_writeJson.writeJSONFile;
|
|
134
141
|
exports.prepareDirectoryForExport = export_helpers_prepare.prepareDirectoryForExport;
|
|
135
142
|
exports.scanDirectory = misc_scan.scanDirectory;
|
|
143
|
+
exports.scanDirectorySync = misc_scan.scanDirectorySync;
|
|
136
144
|
exports.compareDirectories = misc_compareDirs.compareDirectories;
|
|
137
145
|
exports.unzip = download_helpers_unzip.unzip;
|
|
138
146
|
exports.untar = download_helpers_untar.untar;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { SVG } from './svg/index.js';
|
|
2
|
-
export { parseSVG } from './svg/parse.js';
|
|
3
|
-
export { parseSVGStyle } from './svg/parse-style.js';
|
|
2
|
+
export { parseSVG, parseSVGSync } from './svg/parse.js';
|
|
3
|
+
export { parseSVGStyle, parseSVGStyleSync } from './svg/parse-style.js';
|
|
4
4
|
export { analyseSVGStructure } from './svg/analyse.js';
|
|
5
5
|
export { cleanupSVG } from './svg/cleanup.js';
|
|
6
6
|
export { removeBadAttributes } from './svg/cleanup/attribs.js';
|
|
@@ -13,7 +13,7 @@ export { IconSet, blankIconSet } from './icon-set/index.js';
|
|
|
13
13
|
export { mergeIconSets } from './icon-set/merge.js';
|
|
14
14
|
export { addTagsToIconSet } from './icon-set/tags.js';
|
|
15
15
|
export { importFromFigma } from './import/figma/index.js';
|
|
16
|
-
export { importDirectory } from './import/directory.js';
|
|
16
|
+
export { importDirectory, importDirectorySync } from './import/directory.js';
|
|
17
17
|
export { downloadGitRepo } from './download/git/index.js';
|
|
18
18
|
export { getGitRepoHash } from './download/git/hash.js';
|
|
19
19
|
export { getGitRepoBranch } from './download/git/branch.js';
|
|
@@ -26,11 +26,12 @@ export { downloadNPMPackage } from './download/npm/index.js';
|
|
|
26
26
|
export { getNPMVersion, getPackageVersion } from './download/npm/version.js';
|
|
27
27
|
export { downloadPackage } from './download/index.js';
|
|
28
28
|
export { downloadFile } from './download/api/download.js';
|
|
29
|
-
export { isEmptyColor, parseColors } from './colors/parse.js';
|
|
30
|
-
export { validateColors } from './colors/validate.js';
|
|
29
|
+
export { isEmptyColor, parseColors, parseColorsSync } from './colors/parse.js';
|
|
30
|
+
export { validateColors, validateColorsSync } from './colors/validate.js';
|
|
31
31
|
export { detectIconSetPalette } from './colors/detect.js';
|
|
32
32
|
export { runSVGO } from './optimise/svgo.js';
|
|
33
33
|
export { deOptimisePaths } from './optimise/flags.js';
|
|
34
|
+
export { resetSVGOrigin } from './optimise/origin.js';
|
|
34
35
|
export { scaleSVG } from './optimise/scale.js';
|
|
35
36
|
export { cleanupGlobalStyle } from './optimise/global-style.js';
|
|
36
37
|
export { exportToDirectory } from './export/directory.js';
|
|
@@ -38,7 +39,7 @@ export { exportIconPackage } from './export/icon-package.js';
|
|
|
38
39
|
export { exportJSONPackage } from './export/json-package.js';
|
|
39
40
|
export { writeJSONFile } from './misc/write-json.js';
|
|
40
41
|
export { prepareDirectoryForExport } from './export/helpers/prepare.js';
|
|
41
|
-
export { scanDirectory } from './misc/scan.js';
|
|
42
|
+
export { scanDirectory, scanDirectorySync } from './misc/scan.js';
|
|
42
43
|
export { compareDirectories } from './misc/compare-dirs.js';
|
|
43
44
|
export { unzip } from './download/helpers/unzip.js';
|
|
44
45
|
export { untar } from './download/helpers/untar.js';
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { SVG } from './svg/index.mjs';
|
|
2
|
-
export { parseSVG } from './svg/parse.mjs';
|
|
3
|
-
export { parseSVGStyle } from './svg/parse-style.mjs';
|
|
2
|
+
export { parseSVG, parseSVGSync } from './svg/parse.mjs';
|
|
3
|
+
export { parseSVGStyle, parseSVGStyleSync } from './svg/parse-style.mjs';
|
|
4
4
|
export { analyseSVGStructure } from './svg/analyse.mjs';
|
|
5
5
|
export { cleanupSVG } from './svg/cleanup.mjs';
|
|
6
6
|
export { removeBadAttributes } from './svg/cleanup/attribs.mjs';
|
|
@@ -13,7 +13,7 @@ export { IconSet, blankIconSet } from './icon-set/index.mjs';
|
|
|
13
13
|
export { mergeIconSets } from './icon-set/merge.mjs';
|
|
14
14
|
export { addTagsToIconSet } from './icon-set/tags.mjs';
|
|
15
15
|
export { importFromFigma } from './import/figma/index.mjs';
|
|
16
|
-
export { importDirectory } from './import/directory.mjs';
|
|
16
|
+
export { importDirectory, importDirectorySync } from './import/directory.mjs';
|
|
17
17
|
export { downloadGitRepo } from './download/git/index.mjs';
|
|
18
18
|
export { getGitRepoHash } from './download/git/hash.mjs';
|
|
19
19
|
export { getGitRepoBranch } from './download/git/branch.mjs';
|
|
@@ -26,11 +26,12 @@ export { downloadNPMPackage } from './download/npm/index.mjs';
|
|
|
26
26
|
export { getNPMVersion, getPackageVersion } from './download/npm/version.mjs';
|
|
27
27
|
export { downloadPackage } from './download/index.mjs';
|
|
28
28
|
export { downloadFile } from './download/api/download.mjs';
|
|
29
|
-
export { isEmptyColor, parseColors } from './colors/parse.mjs';
|
|
30
|
-
export { validateColors } from './colors/validate.mjs';
|
|
29
|
+
export { isEmptyColor, parseColors, parseColorsSync } from './colors/parse.mjs';
|
|
30
|
+
export { validateColors, validateColorsSync } from './colors/validate.mjs';
|
|
31
31
|
export { detectIconSetPalette } from './colors/detect.mjs';
|
|
32
32
|
export { runSVGO } from './optimise/svgo.mjs';
|
|
33
33
|
export { deOptimisePaths } from './optimise/flags.mjs';
|
|
34
|
+
export { resetSVGOrigin } from './optimise/origin.mjs';
|
|
34
35
|
export { scaleSVG } from './optimise/scale.mjs';
|
|
35
36
|
export { cleanupGlobalStyle } from './optimise/global-style.mjs';
|
|
36
37
|
export { exportToDirectory } from './export/directory.mjs';
|
|
@@ -38,7 +39,7 @@ export { exportIconPackage } from './export/icon-package.mjs';
|
|
|
38
39
|
export { exportJSONPackage } from './export/json-package.mjs';
|
|
39
40
|
export { writeJSONFile } from './misc/write-json.mjs';
|
|
40
41
|
export { prepareDirectoryForExport } from './export/helpers/prepare.mjs';
|
|
41
|
-
export { scanDirectory } from './misc/scan.mjs';
|
|
42
|
+
export { scanDirectory, scanDirectorySync } from './misc/scan.mjs';
|
|
42
43
|
export { compareDirectories } from './misc/compare-dirs.mjs';
|
|
43
44
|
export { unzip } from './download/helpers/unzip.mjs';
|
|
44
45
|
export { untar } from './download/helpers/untar.mjs';
|
|
@@ -75,11 +76,11 @@ import './import/figma/query.mjs';
|
|
|
75
76
|
import './download/api/cache.mjs';
|
|
76
77
|
import 'fs';
|
|
77
78
|
import 'crypto';
|
|
78
|
-
import 'node-fetch';
|
|
79
79
|
import 'pathe';
|
|
80
80
|
import 'child_process';
|
|
81
81
|
import 'util';
|
|
82
82
|
import 'stream';
|
|
83
|
+
import 'fs/promises';
|
|
83
84
|
import 'extract-zip';
|
|
84
85
|
import 'tar';
|
|
85
86
|
import './download/gitlab/types.mjs';
|
package/lib/misc/scan.cjs
CHANGED
|
@@ -2,16 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const results = [];
|
|
5
|
+
function cleanPath(path) {
|
|
7
6
|
if (path.length && path.slice(-1) !== "/") {
|
|
8
|
-
path
|
|
7
|
+
return path + "/";
|
|
9
8
|
}
|
|
9
|
+
return path;
|
|
10
|
+
}
|
|
11
|
+
function isHidden(filename) {
|
|
12
|
+
return filename.slice(0, 1) === ".";
|
|
13
|
+
}
|
|
14
|
+
function split(filename) {
|
|
15
|
+
const parts = filename.split(".");
|
|
16
|
+
const ext = parts.length > 1 ? "." + parts.pop() : "";
|
|
17
|
+
const file = parts.join(".");
|
|
18
|
+
return { ext, file };
|
|
19
|
+
}
|
|
20
|
+
function isIgnoredResult(result) {
|
|
21
|
+
return result === void 0 || result === false || result === null;
|
|
22
|
+
}
|
|
23
|
+
async function scanDirectory(path, callback, subdirs = true) {
|
|
24
|
+
const results = [];
|
|
25
|
+
path = cleanPath(path);
|
|
10
26
|
async function scan(subdir) {
|
|
11
27
|
const files = await fs.promises.readdir(path + subdir);
|
|
12
28
|
for (let i = 0; i < files.length; i++) {
|
|
13
29
|
const filename = files[i];
|
|
14
|
-
if (filename
|
|
30
|
+
if (isHidden(filename)) {
|
|
15
31
|
continue;
|
|
16
32
|
}
|
|
17
33
|
const stat = await fs.promises.stat(path + subdir + filename);
|
|
@@ -24,16 +40,14 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
24
40
|
if (!stat.isFile()) {
|
|
25
41
|
continue;
|
|
26
42
|
}
|
|
27
|
-
const
|
|
28
|
-
const ext = parts.length > 1 ? "." + parts.pop() : "";
|
|
29
|
-
const file = parts.join(".");
|
|
43
|
+
const { ext, file } = split(filename);
|
|
30
44
|
let callbackResult;
|
|
31
45
|
if (callback) {
|
|
32
46
|
callbackResult = callback(ext, file, subdir, path, stat);
|
|
33
47
|
if (callbackResult instanceof Promise) {
|
|
34
48
|
callbackResult = await callbackResult;
|
|
35
49
|
}
|
|
36
|
-
if (callbackResult
|
|
50
|
+
if (isIgnoredResult(callbackResult)) {
|
|
37
51
|
continue;
|
|
38
52
|
}
|
|
39
53
|
} else {
|
|
@@ -47,5 +61,44 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
47
61
|
await scan("");
|
|
48
62
|
return results;
|
|
49
63
|
}
|
|
64
|
+
function scanDirectorySync(path, callback, subdirs = true) {
|
|
65
|
+
const results = [];
|
|
66
|
+
path = cleanPath(path);
|
|
67
|
+
function scan(subdir) {
|
|
68
|
+
const files = fs.readdirSync(path + subdir);
|
|
69
|
+
for (let i = 0; i < files.length; i++) {
|
|
70
|
+
const filename = files[i];
|
|
71
|
+
if (isHidden(filename)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const stat = fs.statSync(path + subdir + filename);
|
|
75
|
+
if (stat.isDirectory()) {
|
|
76
|
+
if (subdirs) {
|
|
77
|
+
scan(subdir + filename + "/");
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!stat.isFile()) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const { ext, file } = split(filename);
|
|
85
|
+
let callbackResult;
|
|
86
|
+
if (callback) {
|
|
87
|
+
callbackResult = callback(ext, file, subdir, path, stat);
|
|
88
|
+
if (isIgnoredResult(callbackResult)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
callbackResult = true;
|
|
93
|
+
}
|
|
94
|
+
results.push(
|
|
95
|
+
callbackResult === true ? subdir + filename : callbackResult
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
scan("");
|
|
100
|
+
return results;
|
|
101
|
+
}
|
|
50
102
|
|
|
51
103
|
exports.scanDirectory = scanDirectory;
|
|
104
|
+
exports.scanDirectorySync = scanDirectorySync;
|
package/lib/misc/scan.d.ts
CHANGED
|
@@ -15,13 +15,19 @@ import { Stats } from 'fs';
|
|
|
15
15
|
*/
|
|
16
16
|
type ScanDirectoryCallbackFalseResult = boolean | null | undefined;
|
|
17
17
|
type ScanDirectoryCallbackStringResult = ScanDirectoryCallbackFalseResult | string;
|
|
18
|
-
type
|
|
19
|
-
type
|
|
20
|
-
type ScanDirectoryCallback =
|
|
18
|
+
type Callback<T> = (ext: string, file: string, subdir: string, path: string, stat: Stats) => T;
|
|
19
|
+
type AsyncCallback<T> = Callback<T | Promise<T>>;
|
|
20
|
+
type ScanDirectoryCallback = AsyncCallback<ScanDirectoryCallbackStringResult | unknown>;
|
|
21
|
+
type ScanDirectorySyncCallback = Callback<ScanDirectoryCallbackStringResult | unknown>;
|
|
21
22
|
/**
|
|
22
23
|
* Find all files in directory
|
|
23
24
|
*/
|
|
24
|
-
declare function scanDirectory(path: string, callback?:
|
|
25
|
-
declare function scanDirectory<T>(path: string, callback:
|
|
25
|
+
declare function scanDirectory(path: string, callback?: AsyncCallback<ScanDirectoryCallbackStringResult>, subdirs?: boolean): Promise<string[]>;
|
|
26
|
+
declare function scanDirectory<T>(path: string, callback: AsyncCallback<T | ScanDirectoryCallbackFalseResult>, subdirs?: boolean): Promise<T[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Find all files in directory, synchronously
|
|
29
|
+
*/
|
|
30
|
+
declare function scanDirectorySync(path: string, callback?: Callback<ScanDirectoryCallbackStringResult>, subdirs?: boolean): string[];
|
|
31
|
+
declare function scanDirectorySync<T>(path: string, callback: Callback<T | ScanDirectoryCallbackFalseResult>, subdirs?: boolean): T[];
|
|
26
32
|
|
|
27
|
-
export { ScanDirectoryCallback, scanDirectory };
|
|
33
|
+
export { ScanDirectoryCallback, ScanDirectorySyncCallback, scanDirectory, scanDirectorySync };
|
package/lib/misc/scan.mjs
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import { promises } from 'fs';
|
|
1
|
+
import { promises, readdirSync, statSync } from 'fs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const results = [];
|
|
3
|
+
function cleanPath(path) {
|
|
5
4
|
if (path.length && path.slice(-1) !== "/") {
|
|
6
|
-
path
|
|
5
|
+
return path + "/";
|
|
7
6
|
}
|
|
7
|
+
return path;
|
|
8
|
+
}
|
|
9
|
+
function isHidden(filename) {
|
|
10
|
+
return filename.slice(0, 1) === ".";
|
|
11
|
+
}
|
|
12
|
+
function split(filename) {
|
|
13
|
+
const parts = filename.split(".");
|
|
14
|
+
const ext = parts.length > 1 ? "." + parts.pop() : "";
|
|
15
|
+
const file = parts.join(".");
|
|
16
|
+
return { ext, file };
|
|
17
|
+
}
|
|
18
|
+
function isIgnoredResult(result) {
|
|
19
|
+
return result === void 0 || result === false || result === null;
|
|
20
|
+
}
|
|
21
|
+
async function scanDirectory(path, callback, subdirs = true) {
|
|
22
|
+
const results = [];
|
|
23
|
+
path = cleanPath(path);
|
|
8
24
|
async function scan(subdir) {
|
|
9
25
|
const files = await promises.readdir(path + subdir);
|
|
10
26
|
for (let i = 0; i < files.length; i++) {
|
|
11
27
|
const filename = files[i];
|
|
12
|
-
if (filename
|
|
28
|
+
if (isHidden(filename)) {
|
|
13
29
|
continue;
|
|
14
30
|
}
|
|
15
31
|
const stat = await promises.stat(path + subdir + filename);
|
|
@@ -22,16 +38,14 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
22
38
|
if (!stat.isFile()) {
|
|
23
39
|
continue;
|
|
24
40
|
}
|
|
25
|
-
const
|
|
26
|
-
const ext = parts.length > 1 ? "." + parts.pop() : "";
|
|
27
|
-
const file = parts.join(".");
|
|
41
|
+
const { ext, file } = split(filename);
|
|
28
42
|
let callbackResult;
|
|
29
43
|
if (callback) {
|
|
30
44
|
callbackResult = callback(ext, file, subdir, path, stat);
|
|
31
45
|
if (callbackResult instanceof Promise) {
|
|
32
46
|
callbackResult = await callbackResult;
|
|
33
47
|
}
|
|
34
|
-
if (callbackResult
|
|
48
|
+
if (isIgnoredResult(callbackResult)) {
|
|
35
49
|
continue;
|
|
36
50
|
}
|
|
37
51
|
} else {
|
|
@@ -45,5 +59,43 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
45
59
|
await scan("");
|
|
46
60
|
return results;
|
|
47
61
|
}
|
|
62
|
+
function scanDirectorySync(path, callback, subdirs = true) {
|
|
63
|
+
const results = [];
|
|
64
|
+
path = cleanPath(path);
|
|
65
|
+
function scan(subdir) {
|
|
66
|
+
const files = readdirSync(path + subdir);
|
|
67
|
+
for (let i = 0; i < files.length; i++) {
|
|
68
|
+
const filename = files[i];
|
|
69
|
+
if (isHidden(filename)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const stat = statSync(path + subdir + filename);
|
|
73
|
+
if (stat.isDirectory()) {
|
|
74
|
+
if (subdirs) {
|
|
75
|
+
scan(subdir + filename + "/");
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!stat.isFile()) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const { ext, file } = split(filename);
|
|
83
|
+
let callbackResult;
|
|
84
|
+
if (callback) {
|
|
85
|
+
callbackResult = callback(ext, file, subdir, path, stat);
|
|
86
|
+
if (isIgnoredResult(callbackResult)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
callbackResult = true;
|
|
91
|
+
}
|
|
92
|
+
results.push(
|
|
93
|
+
callbackResult === true ? subdir + filename : callbackResult
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
scan("");
|
|
98
|
+
return results;
|
|
99
|
+
}
|
|
48
100
|
|
|
49
|
-
export { scanDirectory };
|
|
101
|
+
export { scanDirectory, scanDirectorySync };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const optimise_svgo = require('./svgo.cjs');
|
|
4
|
+
require('svgo');
|
|
5
|
+
require('@iconify/utils/lib/svg/id');
|
|
6
|
+
|
|
7
|
+
function resetSVGOrigin(svg) {
|
|
8
|
+
const viewBox = svg.viewBox;
|
|
9
|
+
if (viewBox.left !== 0 || viewBox.top !== 0) {
|
|
10
|
+
const content = `<svg width="${viewBox.width}" height="${viewBox.height}" viewBox="0 0 ${viewBox.width} ${viewBox.height}"><g transform="translate(${0 - viewBox.left} ${0 - viewBox.top})">${svg.getBody()}</g></svg>`;
|
|
11
|
+
svg.load(content);
|
|
12
|
+
optimise_svgo.runSVGO(svg, {
|
|
13
|
+
plugins: [
|
|
14
|
+
"collapseGroups",
|
|
15
|
+
"convertTransform",
|
|
16
|
+
"convertPathData",
|
|
17
|
+
"sortAttrs"
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.resetSVGOrigin = resetSVGOrigin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { runSVGO } from './svgo.mjs';
|
|
2
|
+
import 'svgo';
|
|
3
|
+
import '@iconify/utils/lib/svg/id';
|
|
4
|
+
|
|
5
|
+
function resetSVGOrigin(svg) {
|
|
6
|
+
const viewBox = svg.viewBox;
|
|
7
|
+
if (viewBox.left !== 0 || viewBox.top !== 0) {
|
|
8
|
+
const content = `<svg width="${viewBox.width}" height="${viewBox.height}" viewBox="0 0 ${viewBox.width} ${viewBox.height}"><g transform="translate(${0 - viewBox.left} ${0 - viewBox.top})">${svg.getBody()}</g></svg>`;
|
|
9
|
+
svg.load(content);
|
|
10
|
+
runSVGO(svg, {
|
|
11
|
+
plugins: [
|
|
12
|
+
"collapseGroups",
|
|
13
|
+
"convertTransform",
|
|
14
|
+
"convertPathData",
|
|
15
|
+
"sortAttrs"
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { resetSVGOrigin };
|