@iconify/tools 2.0.0-dev.4 → 2.0.3

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.
Files changed (45) hide show
  1. package/README.md +90 -0
  2. package/lib/colors/parse.d.ts +1 -1
  3. package/lib/colors/parse.js +3 -1
  4. package/lib/colors/parse.mjs +2 -1
  5. package/lib/colors/validate.d.ts +11 -0
  6. package/lib/colors/validate.js +45 -0
  7. package/lib/colors/validate.mjs +33 -0
  8. package/lib/download/git/index.d.ts +7 -3
  9. package/lib/download/git/index.js +0 -3
  10. package/lib/download/github/index.d.ts +7 -3
  11. package/lib/download/github/index.js +13 -10
  12. package/lib/download/github/index.mjs +12 -8
  13. package/lib/download/helpers/untar.d.ts +4 -0
  14. package/lib/download/helpers/untar.js +14 -0
  15. package/lib/download/helpers/untar.mjs +11 -0
  16. package/lib/download/npm/index.d.ts +7 -3
  17. package/lib/download/npm/index.js +43 -15
  18. package/lib/download/npm/index.mjs +35 -9
  19. package/lib/export/helpers/types-version.js +3 -5
  20. package/lib/export/helpers/types-version.mjs +33 -1
  21. package/lib/import/figma/index.d.ts +3 -2
  22. package/lib/import/figma/index.js +0 -3
  23. package/lib/import/figma/query.d.ts +3 -2
  24. package/lib/import/figma/query.js +0 -3
  25. package/lib/import/figma/types/options.d.ts +4 -2
  26. package/lib/index.d.ts +37 -0
  27. package/lib/index.js +89 -0
  28. package/lib/index.mjs +80 -0
  29. package/lib/misc/bump-version.d.ts +4 -0
  30. package/lib/misc/bump-version.js +19 -0
  31. package/lib/misc/bump-version.mjs +15 -0
  32. package/lib/misc/compare-dirs.d.ts +9 -0
  33. package/lib/misc/compare-dirs.js +84 -0
  34. package/lib/misc/compare-dirs.mjs +71 -0
  35. package/lib/optimise/svgo.js +14 -3
  36. package/lib/optimise/svgo.mjs +9 -3
  37. package/lib/svg/cleanup/bad-tags.js +0 -2
  38. package/lib/svg/cleanup/bad-tags.mjs +0 -3
  39. package/lib/svg/data/tags.d.ts +0 -4
  40. package/lib/svg/data/tags.js +1 -9
  41. package/lib/svg/data/tags.mjs +0 -6
  42. package/lib/svg/index.d.ts +3 -0
  43. package/lib/svg/index.js +3 -0
  44. package/license.txt +21 -0
  45. package/package.json +36 -7
@@ -1,5 +1,37 @@
1
+ var __commonJS = (cb, mod) => function __require() {
2
+ return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
3
+ };
4
+
5
+ // ../../node_modules/@iconify/types/package.json
6
+ var require_package = __commonJS({
7
+ "../../node_modules/@iconify/types/package.json"(exports, module) {
8
+ module.exports = {
9
+ name: "@iconify/types",
10
+ description: "Types for Iconify data",
11
+ version: "1.0.12",
12
+ author: "Vjacheslav Trushkin",
13
+ license: "(Apache-2.0 OR GPL-2.0)",
14
+ main: "./index.js",
15
+ types: "./types.ts",
16
+ scripts: {
17
+ test: "tsc --noEmit --strict --typeRoots '[]' types.ts"
18
+ },
19
+ bugs: "https://github.com/iconify/iconify/issues",
20
+ homepage: "https://github.com/iconify/iconify",
21
+ repository: {
22
+ type: "git",
23
+ url: "https://github.com/iconify/iconify.git",
24
+ directory: "packages/types"
25
+ },
26
+ devDependencies: {
27
+ typescript: "^4.4.3"
28
+ }
29
+ };
30
+ }
31
+ });
32
+
1
33
  // src/export/helpers/types-version.ts
2
- import pkg from "@iconify/types/package.json";
34
+ var pkg = require_package();
3
35
  function getTypesVersion() {
4
36
  return pkg.version;
5
37
  }
@@ -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: FigmaImportOptions): Promise<FigmaImportResult | DocumentNotModified>;
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: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
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
  */
@@ -15,9 +15,6 @@ function identicalDates(actual, expected) {
15
15
  }
16
16
  return new Date(actual).toString() === new Date(expected).toString();
17
17
  }
18
- /**
19
- * Get Figma files
20
- */
21
18
  async function figmaFilesQuery(options, cache) {
22
19
  // Check token
23
20
  if (!options.token) {
@@ -17,8 +17,10 @@ interface FigmaImportCommonOptions {
17
17
  file: string;
18
18
  version?: string;
19
19
  }
20
- export interface FigmaFilesQueryOptions extends FigmaImportCommonOptions {
21
- ifModifiedSince?: string | Date | true;
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 ADDED
@@ -0,0 +1,37 @@
1
+ export { SVG } from './svg/index';
2
+ export { parseSVG } from './svg/parse';
3
+ export { parseSVGStyle } from './svg/parse-style';
4
+ export { cleanupSVG } from './svg/cleanup';
5
+ export { removeBadAttributes } from './svg/cleanup/attribs';
6
+ export { checkBadTags } from './svg/cleanup/bad-tags';
7
+ export { cleanupInlineStyle } from './svg/cleanup/inline-style';
8
+ export { cleanupSVGRoot } from './svg/cleanup/root-svg';
9
+ export { convertStyleToAttrs } from './svg/cleanup/svgo-style';
10
+ export { IconSet, blankIconSet } from './icon-set/index';
11
+ export { mergeIconSets } from './icon-set/merge';
12
+ export { importFromFigma } from './import/figma/index';
13
+ export { importDirectory } from './import/directory';
14
+ export { downloadGitRepo } from './download/git/index';
15
+ export { getGitRepoHash } from './download/git/hash';
16
+ export { downloadGitHubRepo } from './download/github/index';
17
+ export { getGitHubRepoHash } from './download/github/hash';
18
+ export { downloadNPMPackage } from './download/npm/index';
19
+ export { getNPMVersion, getPackageVersion } from './download/npm/version';
20
+ export { parseColors, isEmptyColor } from './colors/parse';
21
+ export { validateColors } from './colors/validate';
22
+ export { runSVGO } from './optimise/svgo';
23
+ export { deOptimisePaths } from './optimise/flags';
24
+ export { scaleSVG } from './optimise/scale';
25
+ export { exportToDirectory } from './export/directory';
26
+ export { exportIconPackage } from './export/icon-package';
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';
34
+ export { execAsync } from './misc/exec';
35
+ export { cleanupIconKeyword } from './misc/keyword';
36
+ export { bumpVersion } from './misc/bump-version';
37
+ export { sendAPIQuery } from './download/api/index';
package/lib/index.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ // SVG class and functions
5
+ var index_1 = require("./svg/index");
6
+ Object.defineProperty(exports, "SVG", { enumerable: true, get: function () { return index_1.SVG; } });
7
+ var parse_1 = require("./svg/parse");
8
+ Object.defineProperty(exports, "parseSVG", { enumerable: true, get: function () { return parse_1.parseSVG; } });
9
+ var parse_style_1 = require("./svg/parse-style");
10
+ Object.defineProperty(exports, "parseSVGStyle", { enumerable: true, get: function () { return parse_style_1.parseSVGStyle; } });
11
+ // SVG cleanup
12
+ var cleanup_1 = require("./svg/cleanup");
13
+ Object.defineProperty(exports, "cleanupSVG", { enumerable: true, get: function () { return cleanup_1.cleanupSVG; } });
14
+ var attribs_1 = require("./svg/cleanup/attribs");
15
+ Object.defineProperty(exports, "removeBadAttributes", { enumerable: true, get: function () { return attribs_1.removeBadAttributes; } });
16
+ var bad_tags_1 = require("./svg/cleanup/bad-tags");
17
+ Object.defineProperty(exports, "checkBadTags", { enumerable: true, get: function () { return bad_tags_1.checkBadTags; } });
18
+ var inline_style_1 = require("./svg/cleanup/inline-style");
19
+ Object.defineProperty(exports, "cleanupInlineStyle", { enumerable: true, get: function () { return inline_style_1.cleanupInlineStyle; } });
20
+ var root_svg_1 = require("./svg/cleanup/root-svg");
21
+ Object.defineProperty(exports, "cleanupSVGRoot", { enumerable: true, get: function () { return root_svg_1.cleanupSVGRoot; } });
22
+ var svgo_style_1 = require("./svg/cleanup/svgo-style");
23
+ Object.defineProperty(exports, "convertStyleToAttrs", { enumerable: true, get: function () { return svgo_style_1.convertStyleToAttrs; } });
24
+ // IconSet class
25
+ var index_2 = require("./icon-set/index");
26
+ Object.defineProperty(exports, "IconSet", { enumerable: true, get: function () { return index_2.IconSet; } });
27
+ Object.defineProperty(exports, "blankIconSet", { enumerable: true, get: function () { return index_2.blankIconSet; } });
28
+ var merge_1 = require("./icon-set/merge");
29
+ Object.defineProperty(exports, "mergeIconSets", { enumerable: true, get: function () { return merge_1.mergeIconSets; } });
30
+ // Import
31
+ var index_3 = require("./import/figma/index");
32
+ Object.defineProperty(exports, "importFromFigma", { enumerable: true, get: function () { return index_3.importFromFigma; } });
33
+ var directory_1 = require("./import/directory");
34
+ Object.defineProperty(exports, "importDirectory", { enumerable: true, get: function () { return directory_1.importDirectory; } });
35
+ // Download (for import)
36
+ var index_4 = require("./download/git/index");
37
+ Object.defineProperty(exports, "downloadGitRepo", { enumerable: true, get: function () { return index_4.downloadGitRepo; } });
38
+ var hash_1 = require("./download/git/hash");
39
+ Object.defineProperty(exports, "getGitRepoHash", { enumerable: true, get: function () { return hash_1.getGitRepoHash; } });
40
+ var index_5 = require("./download/github/index");
41
+ Object.defineProperty(exports, "downloadGitHubRepo", { enumerable: true, get: function () { return index_5.downloadGitHubRepo; } });
42
+ var hash_2 = require("./download/github/hash");
43
+ Object.defineProperty(exports, "getGitHubRepoHash", { enumerable: true, get: function () { return hash_2.getGitHubRepoHash; } });
44
+ var index_6 = require("./download/npm/index");
45
+ Object.defineProperty(exports, "downloadNPMPackage", { enumerable: true, get: function () { return index_6.downloadNPMPackage; } });
46
+ var version_1 = require("./download/npm/version");
47
+ Object.defineProperty(exports, "getNPMVersion", { enumerable: true, get: function () { return version_1.getNPMVersion; } });
48
+ Object.defineProperty(exports, "getPackageVersion", { enumerable: true, get: function () { return version_1.getPackageVersion; } });
49
+ // Manipulation
50
+ var parse_2 = require("./colors/parse");
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; } });
55
+ var svgo_1 = require("./optimise/svgo");
56
+ Object.defineProperty(exports, "runSVGO", { enumerable: true, get: function () { return svgo_1.runSVGO; } });
57
+ var flags_1 = require("./optimise/flags");
58
+ Object.defineProperty(exports, "deOptimisePaths", { enumerable: true, get: function () { return flags_1.deOptimisePaths; } });
59
+ var scale_1 = require("./optimise/scale");
60
+ Object.defineProperty(exports, "scaleSVG", { enumerable: true, get: function () { return scale_1.scaleSVG; } });
61
+ // Export
62
+ var directory_2 = require("./export/directory");
63
+ Object.defineProperty(exports, "exportToDirectory", { enumerable: true, get: function () { return directory_2.exportToDirectory; } });
64
+ var icon_package_1 = require("./export/icon-package");
65
+ Object.defineProperty(exports, "exportIconPackage", { enumerable: true, get: function () { return icon_package_1.exportIconPackage; } });
66
+ var json_package_1 = require("./export/json-package");
67
+ Object.defineProperty(exports, "exportJSONPackage", { enumerable: true, get: function () { return json_package_1.exportJSONPackage; } });
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
82
+ var exec_1 = require("./misc/exec");
83
+ Object.defineProperty(exports, "execAsync", { enumerable: true, get: function () { return exec_1.execAsync; } });
84
+ var keyword_1 = require("./misc/keyword");
85
+ Object.defineProperty(exports, "cleanupIconKeyword", { enumerable: true, get: function () { return keyword_1.cleanupIconKeyword; } });
86
+ var bump_version_1 = require("./misc/bump-version");
87
+ Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return bump_version_1.bumpVersion; } });
88
+ var index_7 = require("./download/api/index");
89
+ Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_7.sendAPIQuery; } });
package/lib/index.mjs ADDED
@@ -0,0 +1,80 @@
1
+ // src/index.ts
2
+ import { SVG } from "./svg/index.mjs";
3
+ import { parseSVG } from "./svg/parse.mjs";
4
+ import { parseSVGStyle } from "./svg/parse-style.mjs";
5
+ import { cleanupSVG } from "./svg/cleanup.mjs";
6
+ import { removeBadAttributes } from "./svg/cleanup/attribs.mjs";
7
+ import { checkBadTags } from "./svg/cleanup/bad-tags.mjs";
8
+ import { cleanupInlineStyle } from "./svg/cleanup/inline-style.mjs";
9
+ import { cleanupSVGRoot } from "./svg/cleanup/root-svg.mjs";
10
+ import { convertStyleToAttrs } from "./svg/cleanup/svgo-style.mjs";
11
+ import { IconSet, blankIconSet } from "./icon-set/index.mjs";
12
+ import { mergeIconSets } from "./icon-set/merge.mjs";
13
+ import { importFromFigma } from "./import/figma/index.mjs";
14
+ import { importDirectory } from "./import/directory.mjs";
15
+ import { downloadGitRepo } from "./download/git/index.mjs";
16
+ import { getGitRepoHash } from "./download/git/hash.mjs";
17
+ import { downloadGitHubRepo } from "./download/github/index.mjs";
18
+ import { getGitHubRepoHash } from "./download/github/hash.mjs";
19
+ import { downloadNPMPackage } from "./download/npm/index.mjs";
20
+ import { getNPMVersion, getPackageVersion } from "./download/npm/version.mjs";
21
+ import { parseColors, isEmptyColor } from "./colors/parse.mjs";
22
+ import { validateColors } from "./colors/validate.mjs";
23
+ import { runSVGO } from "./optimise/svgo.mjs";
24
+ import { deOptimisePaths } from "./optimise/flags.mjs";
25
+ import { scaleSVG } from "./optimise/scale.mjs";
26
+ import { exportToDirectory } from "./export/directory.mjs";
27
+ import { exportIconPackage } from "./export/icon-package.mjs";
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";
35
+ import { execAsync } from "./misc/exec.mjs";
36
+ import { cleanupIconKeyword } from "./misc/keyword.mjs";
37
+ import { bumpVersion } from "./misc/bump-version.mjs";
38
+ import { sendAPIQuery } from "./download/api/index.mjs";
39
+ export {
40
+ IconSet,
41
+ SVG,
42
+ blankIconSet,
43
+ bumpVersion,
44
+ checkBadTags,
45
+ cleanupIconKeyword,
46
+ cleanupInlineStyle,
47
+ cleanupSVG,
48
+ cleanupSVGRoot,
49
+ compareDirectories,
50
+ convertStyleToAttrs,
51
+ deOptimisePaths,
52
+ downloadGitHubRepo,
53
+ downloadGitRepo,
54
+ downloadNPMPackage,
55
+ execAsync,
56
+ exportIconPackage,
57
+ exportJSONPackage,
58
+ exportToDirectory,
59
+ getGitHubRepoHash,
60
+ getGitRepoHash,
61
+ getNPMVersion,
62
+ getPackageVersion,
63
+ importDirectory,
64
+ importFromFigma,
65
+ isEmptyColor,
66
+ mergeIconSets,
67
+ parseColors,
68
+ parseSVG,
69
+ parseSVGStyle,
70
+ prepareDirectoryForExport,
71
+ removeBadAttributes,
72
+ runSVGO,
73
+ scaleSVG,
74
+ scanDirectory,
75
+ sendAPIQuery,
76
+ untar,
77
+ unzip,
78
+ validateColors,
79
+ writeJSONFile
80
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Bump version number
3
+ */
4
+ export declare function bumpVersion(version: string): string;
@@ -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
+ };
@@ -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,7 +62,14 @@ async function runSVGO(svg, options = {}) {
60
62
  plugins = options.plugins;
61
63
  }
62
64
  else {
63
- plugins = exports.defaultSVGOPlugins.concat(options.keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
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',
@@ -79,10 +88,12 @@ 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)(svg.toString(), pluginOptions);
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
  }
86
- svg.load(result.data);
95
+ // Sometimes empty definitions are not removed: remove them
96
+ const content = result.data.replace(/<defs\/>/g, '');
97
+ svg.load(content);
87
98
  }
88
99
  exports.runSVGO = runSVGO;
@@ -44,12 +44,17 @@ 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
- plugins = defaultSVGOPlugins.concat(options.keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
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: {
@@ -62,11 +67,12 @@ async function runSVGO(svg, options = {}) {
62
67
  plugins,
63
68
  multipass
64
69
  };
65
- const result = optimize(svg.toString(), pluginOptions);
70
+ const result = optimize(code, pluginOptions);
66
71
  if (typeof result.error === "string") {
67
72
  throw new Error(result.error);
68
73
  }
69
- svg.load(result.data);
74
+ const content = result.data.replace(/<defs\/>/g, "");
75
+ svg.load(content);
70
76
  }
71
77
  export {
72
78
  defaultSVGOPlugins,
@@ -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) => {
@@ -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
  */