@iconify/tools 2.0.1 → 2.0.5
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/lib/colors/parse.d.ts +1 -1
- package/lib/colors/parse.js +3 -1
- package/lib/colors/parse.mjs +2 -1
- package/lib/colors/validate.d.ts +11 -0
- package/lib/colors/validate.js +45 -0
- package/lib/colors/validate.mjs +33 -0
- package/lib/download/git/index.d.ts +7 -3
- package/lib/download/git/index.js +0 -3
- package/lib/download/github/index.d.ts +7 -3
- package/lib/download/github/index.js +18 -13
- package/lib/download/github/index.mjs +14 -10
- package/lib/download/helpers/untar.d.ts +4 -0
- package/lib/download/helpers/untar.js +14 -0
- package/lib/download/helpers/untar.mjs +11 -0
- package/lib/download/npm/index.d.ts +7 -3
- package/lib/download/npm/index.js +43 -15
- package/lib/download/npm/index.mjs +35 -9
- package/lib/export/helpers/types-version.mjs +26 -65
- package/lib/icon-set/index.js +1 -1
- package/lib/icon-set/merge.js +1 -1
- package/lib/import/figma/index.d.ts +3 -2
- package/lib/import/figma/index.js +0 -3
- package/lib/import/figma/query.d.ts +3 -2
- package/lib/import/figma/query.js +0 -3
- package/lib/import/figma/types/options.d.ts +4 -2
- package/lib/index.d.ts +9 -3
- package/lib/index.js +20 -6
- package/lib/index.mjs +16 -3
- package/lib/misc/bump-version.d.ts +4 -0
- package/lib/misc/bump-version.js +19 -0
- package/lib/misc/bump-version.mjs +15 -0
- package/lib/misc/compare-dirs.d.ts +9 -0
- package/lib/misc/compare-dirs.js +84 -0
- package/lib/misc/compare-dirs.mjs +71 -0
- package/lib/misc/scan.d.ts +4 -2
- package/lib/misc/scan.js +2 -2
- package/lib/misc/scan.mjs +2 -2
- package/lib/optimise/svgo.js +13 -3
- package/lib/optimise/svgo.mjs +8 -3
- package/lib/svg/cleanup/bad-tags.js +0 -2
- package/lib/svg/cleanup/bad-tags.mjs +0 -3
- package/lib/svg/data/tags.d.ts +0 -4
- package/lib/svg/data/tags.js +1 -9
- package/lib/svg/data/tags.mjs +0 -6
- package/package.json +23 -4
package/lib/icon-set/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const minify_1 = require("@iconify/utils/lib/icon-set/minify");
|
|
|
8
8
|
const convert_info_1 = require("@iconify/utils/lib/icon-set/convert-info");
|
|
9
9
|
const props_1 = require("./props");
|
|
10
10
|
const svg_1 = require("../svg");
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
12
|
function assertNever(v) {
|
|
13
13
|
//
|
|
14
14
|
}
|
package/lib/icon-set/merge.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeIconSets = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const match_1 = require("./match");
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
7
|
function assertNever(v) {
|
|
8
8
|
//
|
|
9
9
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DocumentNotModified } from '../../download/types/modified';
|
|
2
|
-
import type { FigmaImportOptions } from './types/options';
|
|
2
|
+
import type { FigmaImportOptions, FigmaIfModifiedSinceOption } from './types/options';
|
|
3
3
|
import type { FigmaImportResult } from './types/result';
|
|
4
4
|
/**
|
|
5
5
|
* Import icon set from Figma
|
|
6
6
|
*/
|
|
7
|
-
export declare function importFromFigma(options:
|
|
7
|
+
export declare function importFromFigma<T extends FigmaIfModifiedSinceOption & FigmaImportOptions>(options: T): Promise<FigmaImportResult | DocumentNotModified>;
|
|
8
|
+
export declare function importFromFigma(options: FigmaImportOptions): Promise<FigmaImportResult>;
|
|
@@ -6,9 +6,6 @@ const svg_1 = require("../../svg");
|
|
|
6
6
|
const cleanup_1 = require("../../svg/cleanup");
|
|
7
7
|
const nodes_1 = require("./nodes");
|
|
8
8
|
const query_1 = require("./query");
|
|
9
|
-
/**
|
|
10
|
-
* Import icon set from Figma
|
|
11
|
-
*/
|
|
12
9
|
async function importFromFigma(options) {
|
|
13
10
|
const cacheOptions = options.cacheDir
|
|
14
11
|
? {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { APICacheOptions } from '../../download/api/types';
|
|
2
2
|
import type { DocumentNotModified } from '../../download/types/modified';
|
|
3
3
|
import type { FigmaDocument } from './types/api';
|
|
4
|
-
import type { FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
|
|
4
|
+
import type { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
|
|
5
5
|
import type { FigmaNodesImportResult } from './types/result';
|
|
6
6
|
/**
|
|
7
7
|
* Get Figma files
|
|
8
8
|
*/
|
|
9
|
-
export declare function figmaFilesQuery(options:
|
|
9
|
+
export declare function figmaFilesQuery<T extends FigmaIfModifiedSinceOption & FigmaFilesQueryOptions>(options: T, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
|
|
10
|
+
export declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument>;
|
|
10
11
|
/**
|
|
11
12
|
* Generate all images
|
|
12
13
|
*/
|
|
@@ -17,8 +17,10 @@ interface FigmaImportCommonOptions {
|
|
|
17
17
|
file: string;
|
|
18
18
|
version?: string;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
21
|
-
ifModifiedSince
|
|
20
|
+
export interface FigmaIfModifiedSinceOption {
|
|
21
|
+
ifModifiedSince: string | Date | true;
|
|
22
|
+
}
|
|
23
|
+
export interface FigmaFilesQueryOptions extends FigmaImportCommonOptions, Partial<FigmaIfModifiedSinceOption> {
|
|
22
24
|
ids?: string[];
|
|
23
25
|
depth?: number;
|
|
24
26
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,15 +17,21 @@ export { downloadGitHubRepo } from './download/github/index';
|
|
|
17
17
|
export { getGitHubRepoHash } from './download/github/hash';
|
|
18
18
|
export { downloadNPMPackage } from './download/npm/index';
|
|
19
19
|
export { getNPMVersion, getPackageVersion } from './download/npm/version';
|
|
20
|
-
export { parseColors } from './colors/parse';
|
|
20
|
+
export { parseColors, isEmptyColor } from './colors/parse';
|
|
21
|
+
export { validateColors } from './colors/validate';
|
|
21
22
|
export { runSVGO } from './optimise/svgo';
|
|
22
23
|
export { deOptimisePaths } from './optimise/flags';
|
|
23
24
|
export { scaleSVG } from './optimise/scale';
|
|
24
25
|
export { exportToDirectory } from './export/directory';
|
|
25
26
|
export { exportIconPackage } from './export/icon-package';
|
|
26
27
|
export { exportJSONPackage } from './export/json-package';
|
|
28
|
+
export { writeJSONFile } from './misc/write-json';
|
|
29
|
+
export { prepareDirectoryForExport } from './export/helpers/prepare';
|
|
30
|
+
export { scanDirectory } from './misc/scan';
|
|
31
|
+
export { compareDirectories } from './misc/compare-dirs';
|
|
32
|
+
export { unzip } from './download/helpers/unzip';
|
|
33
|
+
export { untar } from './download/helpers/untar';
|
|
27
34
|
export { execAsync } from './misc/exec';
|
|
28
35
|
export { cleanupIconKeyword } from './misc/keyword';
|
|
29
|
-
export {
|
|
30
|
-
export { writeJSONFile } from './misc/write-json';
|
|
36
|
+
export { bumpVersion } from './misc/bump-version';
|
|
31
37
|
export { sendAPIQuery } from './download/api/index';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendAPIQuery = exports.
|
|
3
|
+
exports.sendAPIQuery = exports.bumpVersion = exports.cleanupIconKeyword = exports.execAsync = exports.untar = exports.unzip = exports.compareDirectories = exports.scanDirectory = exports.prepareDirectoryForExport = exports.writeJSONFile = exports.exportJSONPackage = exports.exportIconPackage = exports.exportToDirectory = exports.scaleSVG = exports.deOptimisePaths = exports.runSVGO = exports.validateColors = exports.isEmptyColor = exports.parseColors = exports.getPackageVersion = exports.getNPMVersion = exports.downloadNPMPackage = exports.getGitHubRepoHash = exports.downloadGitHubRepo = exports.getGitRepoHash = exports.downloadGitRepo = exports.importDirectory = exports.importFromFigma = exports.mergeIconSets = exports.blankIconSet = exports.IconSet = exports.convertStyleToAttrs = exports.cleanupSVGRoot = exports.cleanupInlineStyle = exports.checkBadTags = exports.removeBadAttributes = exports.cleanupSVG = exports.parseSVGStyle = exports.parseSVG = exports.SVG = void 0;
|
|
4
4
|
// SVG class and functions
|
|
5
5
|
var index_1 = require("./svg/index");
|
|
6
6
|
Object.defineProperty(exports, "SVG", { enumerable: true, get: function () { return index_1.SVG; } });
|
|
@@ -49,6 +49,9 @@ Object.defineProperty(exports, "getPackageVersion", { enumerable: true, get: fun
|
|
|
49
49
|
// Manipulation
|
|
50
50
|
var parse_2 = require("./colors/parse");
|
|
51
51
|
Object.defineProperty(exports, "parseColors", { enumerable: true, get: function () { return parse_2.parseColors; } });
|
|
52
|
+
Object.defineProperty(exports, "isEmptyColor", { enumerable: true, get: function () { return parse_2.isEmptyColor; } });
|
|
53
|
+
var validate_1 = require("./colors/validate");
|
|
54
|
+
Object.defineProperty(exports, "validateColors", { enumerable: true, get: function () { return validate_1.validateColors; } });
|
|
52
55
|
var svgo_1 = require("./optimise/svgo");
|
|
53
56
|
Object.defineProperty(exports, "runSVGO", { enumerable: true, get: function () { return svgo_1.runSVGO; } });
|
|
54
57
|
var flags_1 = require("./optimise/flags");
|
|
@@ -62,14 +65,25 @@ var icon_package_1 = require("./export/icon-package");
|
|
|
62
65
|
Object.defineProperty(exports, "exportIconPackage", { enumerable: true, get: function () { return icon_package_1.exportIconPackage; } });
|
|
63
66
|
var json_package_1 = require("./export/json-package");
|
|
64
67
|
Object.defineProperty(exports, "exportJSONPackage", { enumerable: true, get: function () { return json_package_1.exportJSONPackage; } });
|
|
65
|
-
// Misc
|
|
68
|
+
// Misc: files, directories and archives
|
|
69
|
+
var write_json_1 = require("./misc/write-json");
|
|
70
|
+
Object.defineProperty(exports, "writeJSONFile", { enumerable: true, get: function () { return write_json_1.writeJSONFile; } });
|
|
71
|
+
var prepare_1 = require("./export/helpers/prepare");
|
|
72
|
+
Object.defineProperty(exports, "prepareDirectoryForExport", { enumerable: true, get: function () { return prepare_1.prepareDirectoryForExport; } });
|
|
73
|
+
var scan_1 = require("./misc/scan");
|
|
74
|
+
Object.defineProperty(exports, "scanDirectory", { enumerable: true, get: function () { return scan_1.scanDirectory; } });
|
|
75
|
+
var compare_dirs_1 = require("./misc/compare-dirs");
|
|
76
|
+
Object.defineProperty(exports, "compareDirectories", { enumerable: true, get: function () { return compare_dirs_1.compareDirectories; } });
|
|
77
|
+
var unzip_1 = require("./download/helpers/unzip");
|
|
78
|
+
Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return unzip_1.unzip; } });
|
|
79
|
+
var untar_1 = require("./download/helpers/untar");
|
|
80
|
+
Object.defineProperty(exports, "untar", { enumerable: true, get: function () { return untar_1.untar; } });
|
|
81
|
+
// Misc: other
|
|
66
82
|
var exec_1 = require("./misc/exec");
|
|
67
83
|
Object.defineProperty(exports, "execAsync", { enumerable: true, get: function () { return exec_1.execAsync; } });
|
|
68
84
|
var keyword_1 = require("./misc/keyword");
|
|
69
85
|
Object.defineProperty(exports, "cleanupIconKeyword", { enumerable: true, get: function () { return keyword_1.cleanupIconKeyword; } });
|
|
70
|
-
var
|
|
71
|
-
Object.defineProperty(exports, "
|
|
72
|
-
var write_json_1 = require("./misc/write-json");
|
|
73
|
-
Object.defineProperty(exports, "writeJSONFile", { enumerable: true, get: function () { return write_json_1.writeJSONFile; } });
|
|
86
|
+
var bump_version_1 = require("./misc/bump-version");
|
|
87
|
+
Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return bump_version_1.bumpVersion; } });
|
|
74
88
|
var index_7 = require("./download/api/index");
|
|
75
89
|
Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_7.sendAPIQuery; } });
|
package/lib/index.mjs
CHANGED
|
@@ -18,27 +18,35 @@ import { downloadGitHubRepo } from "./download/github/index.mjs";
|
|
|
18
18
|
import { getGitHubRepoHash } from "./download/github/hash.mjs";
|
|
19
19
|
import { downloadNPMPackage } from "./download/npm/index.mjs";
|
|
20
20
|
import { getNPMVersion, getPackageVersion } from "./download/npm/version.mjs";
|
|
21
|
-
import { parseColors } from "./colors/parse.mjs";
|
|
21
|
+
import { parseColors, isEmptyColor } from "./colors/parse.mjs";
|
|
22
|
+
import { validateColors } from "./colors/validate.mjs";
|
|
22
23
|
import { runSVGO } from "./optimise/svgo.mjs";
|
|
23
24
|
import { deOptimisePaths } from "./optimise/flags.mjs";
|
|
24
25
|
import { scaleSVG } from "./optimise/scale.mjs";
|
|
25
26
|
import { exportToDirectory } from "./export/directory.mjs";
|
|
26
27
|
import { exportIconPackage } from "./export/icon-package.mjs";
|
|
27
28
|
import { exportJSONPackage } from "./export/json-package.mjs";
|
|
29
|
+
import { writeJSONFile } from "./misc/write-json.mjs";
|
|
30
|
+
import { prepareDirectoryForExport } from "./export/helpers/prepare.mjs";
|
|
31
|
+
import { scanDirectory } from "./misc/scan.mjs";
|
|
32
|
+
import { compareDirectories } from "./misc/compare-dirs.mjs";
|
|
33
|
+
import { unzip } from "./download/helpers/unzip.mjs";
|
|
34
|
+
import { untar } from "./download/helpers/untar.mjs";
|
|
28
35
|
import { execAsync } from "./misc/exec.mjs";
|
|
29
36
|
import { cleanupIconKeyword } from "./misc/keyword.mjs";
|
|
30
|
-
import {
|
|
31
|
-
import { writeJSONFile } from "./misc/write-json.mjs";
|
|
37
|
+
import { bumpVersion } from "./misc/bump-version.mjs";
|
|
32
38
|
import { sendAPIQuery } from "./download/api/index.mjs";
|
|
33
39
|
export {
|
|
34
40
|
IconSet,
|
|
35
41
|
SVG,
|
|
36
42
|
blankIconSet,
|
|
43
|
+
bumpVersion,
|
|
37
44
|
checkBadTags,
|
|
38
45
|
cleanupIconKeyword,
|
|
39
46
|
cleanupInlineStyle,
|
|
40
47
|
cleanupSVG,
|
|
41
48
|
cleanupSVGRoot,
|
|
49
|
+
compareDirectories,
|
|
42
50
|
convertStyleToAttrs,
|
|
43
51
|
deOptimisePaths,
|
|
44
52
|
downloadGitHubRepo,
|
|
@@ -54,14 +62,19 @@ export {
|
|
|
54
62
|
getPackageVersion,
|
|
55
63
|
importDirectory,
|
|
56
64
|
importFromFigma,
|
|
65
|
+
isEmptyColor,
|
|
57
66
|
mergeIconSets,
|
|
58
67
|
parseColors,
|
|
59
68
|
parseSVG,
|
|
60
69
|
parseSVGStyle,
|
|
70
|
+
prepareDirectoryForExport,
|
|
61
71
|
removeBadAttributes,
|
|
62
72
|
runSVGO,
|
|
63
73
|
scaleSVG,
|
|
64
74
|
scanDirectory,
|
|
65
75
|
sendAPIQuery,
|
|
76
|
+
untar,
|
|
77
|
+
unzip,
|
|
78
|
+
validateColors,
|
|
66
79
|
writeJSONFile
|
|
67
80
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bumpVersion = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bump version number
|
|
6
|
+
*/
|
|
7
|
+
function bumpVersion(version) {
|
|
8
|
+
const versionParts = version.split('.');
|
|
9
|
+
const lastPart = versionParts.pop();
|
|
10
|
+
const num = parseInt(lastPart);
|
|
11
|
+
if (isNaN(num) || num + '' !== lastPart) {
|
|
12
|
+
versionParts.push(lastPart + '.1');
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
versionParts.push(num + 1 + '');
|
|
16
|
+
}
|
|
17
|
+
return versionParts.join('.');
|
|
18
|
+
}
|
|
19
|
+
exports.bumpVersion = bumpVersion;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/misc/bump-version.ts
|
|
2
|
+
function bumpVersion(version) {
|
|
3
|
+
const versionParts = version.split(".");
|
|
4
|
+
const lastPart = versionParts.pop();
|
|
5
|
+
const num = parseInt(lastPart);
|
|
6
|
+
if (isNaN(num) || num + "" !== lastPart) {
|
|
7
|
+
versionParts.push(lastPart + ".1");
|
|
8
|
+
} else {
|
|
9
|
+
versionParts.push(num + 1 + "");
|
|
10
|
+
}
|
|
11
|
+
return versionParts.join(".");
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
bumpVersion
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CompareDirectoriesOptions {
|
|
2
|
+
ignoreNewLine?: boolean;
|
|
3
|
+
ignoreVersions?: boolean;
|
|
4
|
+
textExtensions?: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Compare directories. Returns true if files are identical, false if different
|
|
8
|
+
*/
|
|
9
|
+
export declare function compareDirectories(dir1: string, dir2: string, options?: CompareDirectoriesOptions): Promise<boolean>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareDirectories = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const prepare_1 = require("../export/helpers/prepare");
|
|
6
|
+
const scan_1 = require("./scan");
|
|
7
|
+
/**
|
|
8
|
+
* Extensions that are treated as text
|
|
9
|
+
*/
|
|
10
|
+
const textFileExtensions = [
|
|
11
|
+
'json',
|
|
12
|
+
'ts',
|
|
13
|
+
'js',
|
|
14
|
+
'mjs',
|
|
15
|
+
'cjs',
|
|
16
|
+
'jsx',
|
|
17
|
+
'tsx',
|
|
18
|
+
'vue',
|
|
19
|
+
'svelte',
|
|
20
|
+
'svg',
|
|
21
|
+
'txt',
|
|
22
|
+
'md',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Compare directories. Returns true if files are identical, false if different
|
|
26
|
+
*/
|
|
27
|
+
async function compareDirectories(dir1, dir2, options) {
|
|
28
|
+
dir1 = (0, prepare_1.normalizeDir)(dir1);
|
|
29
|
+
dir2 = (0, prepare_1.normalizeDir)(dir2);
|
|
30
|
+
// Get all files
|
|
31
|
+
const files1 = await (0, scan_1.scanDirectory)(dir1);
|
|
32
|
+
const files2 = await (0, scan_1.scanDirectory)(dir2);
|
|
33
|
+
if (files1.length !== files2.length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Options
|
|
37
|
+
options = options || {};
|
|
38
|
+
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
39
|
+
const ignoreVersions = options.ignoreVersions !== false;
|
|
40
|
+
const textExtensions = new Set((options.textExtensions || []).concat(textFileExtensions));
|
|
41
|
+
// Check all files
|
|
42
|
+
for (let i = 0; i < files1.length; i++) {
|
|
43
|
+
const file = files1[i];
|
|
44
|
+
if (files2.indexOf(file) === -1) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const ext = file.split('.').pop().toLowerCase();
|
|
48
|
+
const isText = textExtensions.has(ext);
|
|
49
|
+
if (!isText) {
|
|
50
|
+
// Compare binary files
|
|
51
|
+
const content1 = await fs_1.promises.readFile(dir1 + '/' + file);
|
|
52
|
+
const content2 = await fs_1.promises.readFile(dir2 + '/' + file);
|
|
53
|
+
if (Buffer.compare(content1, content2) !== 0) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// Text files
|
|
59
|
+
let content1 = await fs_1.promises.readFile(dir1 + '/' + file, 'utf8');
|
|
60
|
+
let content2 = await fs_1.promises.readFile(dir2 + '/' + file, 'utf8');
|
|
61
|
+
if (content1 === content2) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ignoreNewLine) {
|
|
65
|
+
// Remove space before new line (\r\n -> \n), remove new line at the end
|
|
66
|
+
content1 = content1.replace(/\s+\n/g, '\n').trimRight();
|
|
67
|
+
content2 = content2.replace(/\s+\n/g, '\n').trimRight();
|
|
68
|
+
}
|
|
69
|
+
if (ignoreVersions && file.split('/').pop() === 'package.json') {
|
|
70
|
+
// Ignore versions in package.json
|
|
71
|
+
const data1 = JSON.parse(content1);
|
|
72
|
+
const data2 = JSON.parse(content2);
|
|
73
|
+
delete data1.version;
|
|
74
|
+
delete data2.version;
|
|
75
|
+
content1 = JSON.stringify(data1);
|
|
76
|
+
content2 = JSON.stringify(data2);
|
|
77
|
+
}
|
|
78
|
+
if (content1 !== content2) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
exports.compareDirectories = compareDirectories;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/misc/compare-dirs.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { normalizeDir } from "../export/helpers/prepare.mjs";
|
|
4
|
+
import { scanDirectory } from "./scan.mjs";
|
|
5
|
+
var textFileExtensions = [
|
|
6
|
+
"json",
|
|
7
|
+
"ts",
|
|
8
|
+
"js",
|
|
9
|
+
"mjs",
|
|
10
|
+
"cjs",
|
|
11
|
+
"jsx",
|
|
12
|
+
"tsx",
|
|
13
|
+
"vue",
|
|
14
|
+
"svelte",
|
|
15
|
+
"svg",
|
|
16
|
+
"txt",
|
|
17
|
+
"md"
|
|
18
|
+
];
|
|
19
|
+
async function compareDirectories(dir1, dir2, options) {
|
|
20
|
+
dir1 = normalizeDir(dir1);
|
|
21
|
+
dir2 = normalizeDir(dir2);
|
|
22
|
+
const files1 = await scanDirectory(dir1);
|
|
23
|
+
const files2 = await scanDirectory(dir2);
|
|
24
|
+
if (files1.length !== files2.length) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
options = options || {};
|
|
28
|
+
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
29
|
+
const ignoreVersions = options.ignoreVersions !== false;
|
|
30
|
+
const textExtensions = new Set((options.textExtensions || []).concat(textFileExtensions));
|
|
31
|
+
for (let i = 0; i < files1.length; i++) {
|
|
32
|
+
const file = files1[i];
|
|
33
|
+
if (files2.indexOf(file) === -1) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const ext = file.split(".").pop().toLowerCase();
|
|
37
|
+
const isText = textExtensions.has(ext);
|
|
38
|
+
if (!isText) {
|
|
39
|
+
const content12 = await fs.readFile(dir1 + "/" + file);
|
|
40
|
+
const content22 = await fs.readFile(dir2 + "/" + file);
|
|
41
|
+
if (Buffer.compare(content12, content22) !== 0) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
let content1 = await fs.readFile(dir1 + "/" + file, "utf8");
|
|
47
|
+
let content2 = await fs.readFile(dir2 + "/" + file, "utf8");
|
|
48
|
+
if (content1 === content2) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (ignoreNewLine) {
|
|
52
|
+
content1 = content1.replace(/\s+\n/g, "\n").trimRight();
|
|
53
|
+
content2 = content2.replace(/\s+\n/g, "\n").trimRight();
|
|
54
|
+
}
|
|
55
|
+
if (ignoreVersions && file.split("/").pop() === "package.json") {
|
|
56
|
+
const data1 = JSON.parse(content1);
|
|
57
|
+
const data2 = JSON.parse(content2);
|
|
58
|
+
delete data1.version;
|
|
59
|
+
delete data2.version;
|
|
60
|
+
content1 = JSON.stringify(data1);
|
|
61
|
+
content2 = JSON.stringify(data2);
|
|
62
|
+
}
|
|
63
|
+
if (content1 !== content2) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
compareDirectories
|
|
71
|
+
};
|
package/lib/misc/scan.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Stats } from 'fs';
|
|
1
3
|
/**
|
|
2
4
|
* Callback
|
|
3
5
|
*
|
|
@@ -13,8 +15,8 @@
|
|
|
13
15
|
*/
|
|
14
16
|
declare type ScanDirectoryCallbackFalseResult = boolean | null | undefined;
|
|
15
17
|
declare type ScanDirectoryCallbackStringResult = ScanDirectoryCallbackFalseResult | string;
|
|
16
|
-
declare type ScanDirectoryCallbackAsString = (ext: string, file: string, subdir: string, path: string) => ScanDirectoryCallbackStringResult | Promise<ScanDirectoryCallbackStringResult>;
|
|
17
|
-
declare type ScanDirectoryCallbackAsCustom<T> = (ext: string, file: string, subdir: string, path: string) => T | ScanDirectoryCallbackFalseResult | Promise<T | ScanDirectoryCallbackFalseResult>;
|
|
18
|
+
declare type ScanDirectoryCallbackAsString = (ext: string, file: string, subdir: string, path: string, stat: Stats) => ScanDirectoryCallbackStringResult | Promise<ScanDirectoryCallbackStringResult>;
|
|
19
|
+
declare type ScanDirectoryCallbackAsCustom<T> = (ext: string, file: string, subdir: string, path: string, stat: Stats) => T | ScanDirectoryCallbackFalseResult | Promise<T | ScanDirectoryCallbackFalseResult>;
|
|
18
20
|
export declare type ScanDirectoryCallback = ScanDirectoryCallbackAsCustom<unknown> | ScanDirectoryCallbackAsString;
|
|
19
21
|
/**
|
|
20
22
|
* Find all files in directory
|
package/lib/misc/scan.js
CHANGED
|
@@ -15,7 +15,7 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
15
15
|
// Exclude hidden items
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
|
-
const stat = await fs_1.promises.
|
|
18
|
+
const stat = await fs_1.promises.stat(path + subdir + filename);
|
|
19
19
|
if (stat.isDirectory()) {
|
|
20
20
|
if (subdirs) {
|
|
21
21
|
await scan(subdir + filename + '/');
|
|
@@ -31,7 +31,7 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
31
31
|
// Callback
|
|
32
32
|
let callbackResult;
|
|
33
33
|
if (callback) {
|
|
34
|
-
callbackResult = callback(ext, file, subdir, path);
|
|
34
|
+
callbackResult = callback(ext, file, subdir, path, stat);
|
|
35
35
|
if (callbackResult instanceof Promise) {
|
|
36
36
|
callbackResult = await callbackResult;
|
|
37
37
|
}
|
package/lib/misc/scan.mjs
CHANGED
|
@@ -12,7 +12,7 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
12
12
|
if (filename.slice(0, 1) === ".") {
|
|
13
13
|
continue;
|
|
14
14
|
}
|
|
15
|
-
const stat = await fs.
|
|
15
|
+
const stat = await fs.stat(path + subdir + filename);
|
|
16
16
|
if (stat.isDirectory()) {
|
|
17
17
|
if (subdirs) {
|
|
18
18
|
await scan(subdir + filename + "/");
|
|
@@ -27,7 +27,7 @@ async function scanDirectory(path, callback, subdirs = true) {
|
|
|
27
27
|
const file = parts.join(".");
|
|
28
28
|
let callbackResult;
|
|
29
29
|
if (callback) {
|
|
30
|
-
callbackResult = callback(ext, file, subdir, path);
|
|
30
|
+
callbackResult = callback(ext, file, subdir, path, stat);
|
|
31
31
|
if (callbackResult instanceof Promise) {
|
|
32
32
|
callbackResult = await callbackResult;
|
|
33
33
|
}
|
package/lib/optimise/svgo.js
CHANGED
|
@@ -52,6 +52,8 @@ exports.shapeModifiyingSVGOPlugins = [
|
|
|
52
52
|
* Run SVGO on icon
|
|
53
53
|
*/
|
|
54
54
|
async function runSVGO(svg, options = {}) {
|
|
55
|
+
// Code
|
|
56
|
+
const code = svg.toString();
|
|
55
57
|
// Options
|
|
56
58
|
const multipass = options.multipass !== false;
|
|
57
59
|
// Plugins list
|
|
@@ -60,14 +62,21 @@ async function runSVGO(svg, options = {}) {
|
|
|
60
62
|
plugins = options.plugins;
|
|
61
63
|
}
|
|
62
64
|
else {
|
|
63
|
-
|
|
65
|
+
// Check for animations: convertShapeToPath and removeHiddenElems plugins currently might ruin animations
|
|
66
|
+
let keepShapes = options.keepShapes;
|
|
67
|
+
if (keepShapes === void 0 &&
|
|
68
|
+
(code.indexOf('<animate') !== -1 || code.indexOf('<set') !== -1)) {
|
|
69
|
+
// Do not check animations: just assume they might break
|
|
70
|
+
keepShapes = true;
|
|
71
|
+
}
|
|
72
|
+
plugins = exports.defaultSVGOPlugins.concat(keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
|
|
64
73
|
? [
|
|
65
74
|
{
|
|
66
75
|
name: 'cleanupIDs',
|
|
67
76
|
params: {
|
|
68
77
|
prefix: typeof options.cleanupIDs === 'string'
|
|
69
78
|
? options.cleanupIDs
|
|
70
|
-
: '
|
|
79
|
+
: 'svgID',
|
|
71
80
|
},
|
|
72
81
|
},
|
|
73
82
|
]
|
|
@@ -79,10 +88,11 @@ async function runSVGO(svg, options = {}) {
|
|
|
79
88
|
multipass,
|
|
80
89
|
};
|
|
81
90
|
// Load data (changing type because SVGO types do not include error ?????)
|
|
82
|
-
const result = (0, svgo_1.optimize)(
|
|
91
|
+
const result = (0, svgo_1.optimize)(code, pluginOptions);
|
|
83
92
|
if (typeof result.error === 'string') {
|
|
84
93
|
throw new Error(result.error);
|
|
85
94
|
}
|
|
95
|
+
// Sometimes empty definitions are not removed: remove them
|
|
86
96
|
const content = result.data.replace(/<defs\/>/g, '');
|
|
87
97
|
svg.load(content);
|
|
88
98
|
}
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -44,16 +44,21 @@ var shapeModifiyingSVGOPlugins = [
|
|
|
44
44
|
"reusePaths"
|
|
45
45
|
];
|
|
46
46
|
async function runSVGO(svg, options = {}) {
|
|
47
|
+
const code = svg.toString();
|
|
47
48
|
const multipass = options.multipass !== false;
|
|
48
49
|
let plugins;
|
|
49
50
|
if (options.plugins) {
|
|
50
51
|
plugins = options.plugins;
|
|
51
52
|
} else {
|
|
52
|
-
|
|
53
|
+
let keepShapes = options.keepShapes;
|
|
54
|
+
if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
|
|
55
|
+
keepShapes = true;
|
|
56
|
+
}
|
|
57
|
+
plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
|
|
53
58
|
{
|
|
54
59
|
name: "cleanupIDs",
|
|
55
60
|
params: {
|
|
56
|
-
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "
|
|
61
|
+
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
] : []);
|
|
@@ -62,7 +67,7 @@ async function runSVGO(svg, options = {}) {
|
|
|
62
67
|
plugins,
|
|
63
68
|
multipass
|
|
64
69
|
};
|
|
65
|
-
const result = optimize(
|
|
70
|
+
const result = optimize(code, pluginOptions);
|
|
66
71
|
if (typeof result.error === "string") {
|
|
67
72
|
throw new Error(result.error);
|
|
68
73
|
}
|
|
@@ -17,8 +17,6 @@ requiredParentTags.set(tags_1.filterTag, tags_1.filterChildTags);
|
|
|
17
17
|
requiredParentTags.set(tags_1.defsTag, tags_1.tagsInsideDefs);
|
|
18
18
|
// <stop> must be inside gradient
|
|
19
19
|
requiredParentTags.set(tags_1.gradientTags, tags_1.gradientChildTags);
|
|
20
|
-
// Animations must be inside shapes or filters
|
|
21
|
-
requiredParentTags.set(tags_1.tagsBeforeAnimation, tags_1.animateTags);
|
|
22
20
|
// <mpath> must be inside <animateMotion>
|
|
23
21
|
requiredParentTags.set(new Set(['animateMotion']), tags_1.animateMotionChildTags);
|
|
24
22
|
/**
|
|
@@ -3,7 +3,6 @@ import { parseSVG } from "../parse.mjs";
|
|
|
3
3
|
import {
|
|
4
4
|
allValidTags,
|
|
5
5
|
animateMotionChildTags,
|
|
6
|
-
animateTags,
|
|
7
6
|
badTags,
|
|
8
7
|
defsTag,
|
|
9
8
|
feComponentTransferChildTag,
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
filterTag,
|
|
15
14
|
gradientChildTags,
|
|
16
15
|
gradientTags,
|
|
17
|
-
tagsBeforeAnimation,
|
|
18
16
|
tagsInsideDefs,
|
|
19
17
|
unsupportedTags
|
|
20
18
|
} from "../data/tags.mjs";
|
|
@@ -25,7 +23,6 @@ requiredParentTags.set(feLightningTags, feLightningChildTags);
|
|
|
25
23
|
requiredParentTags.set(filterTag, filterChildTags);
|
|
26
24
|
requiredParentTags.set(defsTag, tagsInsideDefs);
|
|
27
25
|
requiredParentTags.set(gradientTags, gradientChildTags);
|
|
28
|
-
requiredParentTags.set(tagsBeforeAnimation, animateTags);
|
|
29
26
|
requiredParentTags.set(new Set(["animateMotion"]), animateMotionChildTags);
|
|
30
27
|
async function checkBadTags(svg) {
|
|
31
28
|
await parseSVG(svg, (item) => {
|
package/lib/svg/data/tags.d.ts
CHANGED
|
@@ -79,10 +79,6 @@ export declare const feMergeChildTags: Set<string>;
|
|
|
79
79
|
* Tags that can be used only inside <defs>
|
|
80
80
|
*/
|
|
81
81
|
export declare const tagsInsideDefs: Set<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Parent tags for animations
|
|
84
|
-
*/
|
|
85
|
-
export declare const tagsBeforeAnimation: Set<string>;
|
|
86
82
|
/**
|
|
87
83
|
* All supported tags
|
|
88
84
|
*/
|
package/lib/svg/data/tags.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Icons cannot have anything that requires external resources, anything that renders inconsistently.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.allValidTags = exports.
|
|
7
|
+
exports.allValidTags = exports.tagsInsideDefs = exports.feMergeChildTags = exports.feLightningChildTags = exports.feComponentTransferChildTag = exports.filterChildTags = exports.feLightningTags = exports.filterTag = exports.patternTag = exports.gradientChildTags = exports.gradientTags = exports.animateMotionChildTags = exports.animateTags = exports.markerTag = exports.groupTag = exports.useTag = exports.shapeTags = exports.maskAndSymbolTags = exports.defsTag = exports.styleTag = exports.unsupportedTags = exports.badTags = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* Bad tags
|
|
10
10
|
*
|
|
@@ -153,14 +153,6 @@ exports.tagsInsideDefs = new Set([
|
|
|
153
153
|
...exports.patternTag,
|
|
154
154
|
...exports.markerTag,
|
|
155
155
|
]);
|
|
156
|
-
/**
|
|
157
|
-
* Parent tags for animations
|
|
158
|
-
*/
|
|
159
|
-
exports.tagsBeforeAnimation = new Set([
|
|
160
|
-
...exports.shapeTags,
|
|
161
|
-
...exports.filterChildTags,
|
|
162
|
-
...exports.feComponentTransferChildTag,
|
|
163
|
-
]);
|
|
164
156
|
/**
|
|
165
157
|
* All supported tags
|
|
166
158
|
*/
|