@iconify/tools 2.0.6 → 2.0.10

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 (42) hide show
  1. package/lib/colors/parse.d.ts +10 -1
  2. package/lib/colors/parse.js +10 -3
  3. package/lib/colors/parse.mjs +7 -3
  4. package/lib/colors/validate.js +5 -2
  5. package/lib/colors/validate.mjs +3 -1
  6. package/lib/download/git/branch.d.ts +5 -0
  7. package/lib/download/git/branch.js +22 -0
  8. package/lib/download/git/branch.mjs +18 -0
  9. package/lib/download/git/index.d.ts +4 -3
  10. package/lib/download/git/index.js +21 -10
  11. package/lib/download/git/index.mjs +12 -6
  12. package/lib/download/github/index.d.ts +5 -4
  13. package/lib/download/github/index.js +13 -4
  14. package/lib/download/github/index.mjs +9 -4
  15. package/lib/download/gitlab/hash.d.ts +5 -0
  16. package/lib/download/gitlab/hash.js +27 -0
  17. package/lib/download/gitlab/hash.mjs +24 -0
  18. package/lib/download/gitlab/index.d.ts +29 -0
  19. package/lib/download/gitlab/index.js +115 -0
  20. package/lib/download/gitlab/index.mjs +88 -0
  21. package/lib/download/gitlab/types.d.ts +13 -0
  22. package/lib/download/gitlab/types.js +7 -0
  23. package/lib/download/gitlab/types.mjs +5 -0
  24. package/lib/download/index.d.ts +43 -0
  25. package/lib/download/index.js +27 -0
  26. package/lib/download/index.mjs +33 -0
  27. package/lib/download/npm/index.d.ts +4 -3
  28. package/lib/download/npm/index.js +26 -8
  29. package/lib/download/npm/index.mjs +17 -5
  30. package/lib/download/types/sources.d.ts +10 -0
  31. package/lib/download/types/sources.js +2 -0
  32. package/lib/download/types/sources.mjs +0 -0
  33. package/lib/icon-set/index.js +1 -0
  34. package/lib/icon-set/index.mjs +1 -0
  35. package/lib/index.d.ts +4 -0
  36. package/lib/index.js +13 -5
  37. package/lib/index.mjs +8 -0
  38. package/lib/optimise/svgo.js +1 -1
  39. package/lib/optimise/svgo.mjs +0 -1
  40. package/lib/svg/cleanup/root-svg.js +1 -1
  41. package/lib/svg/cleanup/root-svg.mjs +1 -1
  42. package/package.json +34 -2
@@ -1,5 +1,6 @@
1
1
  import type { Color } from '@iconify/utils/lib/colors/types';
2
2
  import type { SVG } from '../svg';
3
+ import { ParseSVGCallbackItem } from '../svg/parse';
3
4
  import { ColorAttributes } from './attribs';
4
5
  /**
5
6
  * Result
@@ -23,9 +24,17 @@ declare type ParseColorsCallback = (attr: ColorAttributes, colorString: string,
23
24
  /**
24
25
  * Options
25
26
  */
27
+ export declare type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedParseSVGCallbackItem) => Color;
26
28
  export interface ParseColorsOptions {
27
29
  callback?: ParseColorsCallback;
28
- defaultColor?: Color | string;
30
+ defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
31
+ }
32
+ /**
33
+ * Extend properties for item
34
+ */
35
+ declare type ItemColors = Partial<Record<ColorAttributes, Color | string>>;
36
+ export interface ExtendedParseSVGCallbackItem extends ParseSVGCallbackItem {
37
+ colors?: ItemColors;
29
38
  }
30
39
  /**
31
40
  * Find colors in icon
@@ -95,6 +95,10 @@ async function parseColors(svg, options = {}) {
95
95
  // Resolve color
96
96
  const parsedColor = (0, colors_1.stringToColor)(value);
97
97
  const defaultValue = parsedColor || value;
98
+ // Ignore url()
99
+ if ((parsedColor === null || parsedColor === void 0 ? void 0 : parsedColor.type) === 'function' && parsedColor.func === 'url') {
100
+ return value;
101
+ }
98
102
  // Check if callback exists
99
103
  if (!options.callback) {
100
104
  addColorToItem(prop, defaultValue, item);
@@ -246,10 +250,13 @@ async function parseColors(svg, options = {}) {
246
250
  if (color === attribs_1.defaultBlackColor) {
247
251
  // Default black color: change it
248
252
  if (defaultColor) {
253
+ const defaultColorValue = typeof defaultColor === 'function'
254
+ ? defaultColor(prop, item)
255
+ : defaultColor;
249
256
  // Add color to results and change attribute
250
- findColor(defaultColor, true);
251
- $element.attr(prop, (0, colors_1.colorToString)(defaultColor));
252
- itemColors[prop] = defaultColor;
257
+ findColor(defaultColorValue, true);
258
+ $element.attr(prop, (0, colors_1.colorToString)(defaultColorValue));
259
+ itemColors[prop] = defaultColorValue;
253
260
  }
254
261
  else {
255
262
  result.hasUnsetColor = true;
@@ -77,6 +77,9 @@ async function parseColors(svg, options = {}) {
77
77
  }
78
78
  const parsedColor = stringToColor(value);
79
79
  const defaultValue = parsedColor || value;
80
+ if ((parsedColor == null ? void 0 : parsedColor.type) === "function" && parsedColor.func === "url") {
81
+ return value;
82
+ }
80
83
  if (!options.callback) {
81
84
  addColorToItem(prop, defaultValue, item);
82
85
  return value;
@@ -198,9 +201,10 @@ async function parseColors(svg, options = {}) {
198
201
  const color = getElementColor(prop, item);
199
202
  if (color === defaultBlackColor) {
200
203
  if (defaultColor) {
201
- findColor(defaultColor, true);
202
- $element.attr(prop, colorToString(defaultColor));
203
- itemColors[prop] = defaultColor;
204
+ const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, item) : defaultColor;
205
+ findColor(defaultColorValue, true);
206
+ $element.attr(prop, colorToString(defaultColorValue));
207
+ itemColors[prop] = defaultColorValue;
204
208
  } else {
205
209
  result.hasUnsetColor = true;
206
210
  }
@@ -35,9 +35,12 @@ async function validateColors(svg, expectMonotone, options) {
35
35
  throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
36
36
  }
37
37
  return;
38
- // Do not allow other colors
39
38
  default:
40
- throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
39
+ // Allow url()
40
+ if (color.type !== 'function' || color.func !== 'url') {
41
+ // Do not allow other colors
42
+ throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
43
+ }
41
44
  }
42
45
  });
43
46
  return palette;
@@ -23,7 +23,9 @@ async function validateColors(svg, expectMonotone, options) {
23
23
  }
24
24
  return;
25
25
  default:
26
- throw new Error("Unexpected color: " + colorToString(color));
26
+ if (color.type !== "function" || color.func !== "url") {
27
+ throw new Error("Unexpected color: " + colorToString(color));
28
+ }
27
29
  }
28
30
  });
29
31
  return palette;
@@ -0,0 +1,5 @@
1
+ import type { ExportTargetOptions } from '../../export/helpers/prepare';
2
+ /**
3
+ * Get current branch from cloned git repo
4
+ */
5
+ export declare function getGitRepoBranch(options: ExportTargetOptions, checkout?: string): Promise<string>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGitRepoBranch = void 0;
4
+ const exec_1 = require("../../misc/exec");
5
+ /**
6
+ * Get current branch from cloned git repo
7
+ */
8
+ async function getGitRepoBranch(options, checkout) {
9
+ const result = await (0, exec_1.execAsync)('git branch --show-current', {
10
+ cwd: options.target,
11
+ });
12
+ const branch = result.stdout.trim();
13
+ if (typeof checkout === 'string' && branch !== checkout) {
14
+ // Checkout correct branch
15
+ await (0, exec_1.execAsync)(`git checkout ${checkout}`, {
16
+ cwd: options.target,
17
+ });
18
+ return await getGitRepoBranch(options);
19
+ }
20
+ return branch;
21
+ }
22
+ exports.getGitRepoBranch = getGitRepoBranch;
@@ -0,0 +1,18 @@
1
+ // src/download/git/branch.ts
2
+ import { execAsync } from "../../misc/exec.mjs";
3
+ async function getGitRepoBranch(options, checkout) {
4
+ const result = await execAsync("git branch --show-current", {
5
+ cwd: options.target
6
+ });
7
+ const branch = result.stdout.trim();
8
+ if (typeof checkout === "string" && branch !== checkout) {
9
+ await execAsync(`git checkout ${checkout}`, {
10
+ cwd: options.target
11
+ });
12
+ return await getGitRepoBranch(options);
13
+ }
14
+ return branch;
15
+ }
16
+ export {
17
+ getGitRepoBranch
18
+ };
@@ -1,7 +1,8 @@
1
1
  import { ExportTargetOptions } from '../../export/helpers/prepare';
2
2
  import type { DocumentNotModified } from '../types/modified';
3
+ import type { DownloadSourceMixin } from '../types/sources';
3
4
  interface IfModifiedSinceOption {
4
- ifModifiedSince: string | true;
5
+ ifModifiedSince: string | true | DownloadGitRepoResult;
5
6
  }
6
7
  /**
7
8
  * Options for downloadGitRepo()
@@ -14,8 +15,8 @@ export interface DownloadGitRepoOptions extends ExportTargetOptions, Partial<IfM
14
15
  /**
15
16
  * Result
16
17
  */
17
- export interface DownloadGitRepoResult {
18
- target: string;
18
+ export interface DownloadGitRepoResult extends DownloadSourceMixin<'git'> {
19
+ contentsDir: string;
19
20
  hash: string;
20
21
  }
21
22
  /**
@@ -4,12 +4,14 @@ exports.downloadGitRepo = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const prepare_1 = require("../../export/helpers/prepare");
6
6
  const exec_1 = require("../../misc/exec");
7
+ const branch_1 = require("./branch");
7
8
  const hash_1 = require("./hash");
8
9
  async function downloadGitRepo(options) {
9
10
  const { remote, branch } = options;
10
11
  // Check for last commit
11
12
  const hasHashInTarget = options.target.indexOf('{hash}') !== -1;
12
- if (options.ifModifiedSince || hasHashInTarget) {
13
+ const ifModifiedSince = options.ifModifiedSince;
14
+ if (ifModifiedSince || hasHashInTarget) {
13
15
  // Get actual hash
14
16
  const result = await (0, exec_1.execAsync)(`git ls-remote ${remote} --branch ${branch}`);
15
17
  const parts = result.stdout.split(/\s/);
@@ -17,19 +19,26 @@ async function downloadGitRepo(options) {
17
19
  if (hasHashInTarget) {
18
20
  options.target = options.target.replace('{hash}', latestHash);
19
21
  }
20
- if (options.ifModifiedSince) {
21
- try {
22
+ try {
23
+ // Make sure correct branch is checked out. This will throw error if branch is not available
24
+ await (0, branch_1.getGitRepoBranch)(options, branch);
25
+ if (ifModifiedSince) {
22
26
  // Get expected hash
23
- const expectedHash = options.ifModifiedSince === true
27
+ const expectedHash = ifModifiedSince === true
24
28
  ? await (0, hash_1.getGitRepoHash)(options)
25
- : options.ifModifiedSince;
29
+ : typeof ifModifiedSince === 'string'
30
+ ? ifModifiedSince
31
+ : ifModifiedSince.downloadType === 'git'
32
+ ? ifModifiedSince.hash
33
+ : null;
26
34
  if (latestHash === expectedHash) {
27
35
  return 'not_modified';
28
36
  }
29
37
  }
30
- catch (err) {
31
- //
32
- }
38
+ }
39
+ catch (err) {
40
+ // Cleanup on error
41
+ options.cleanup = true;
33
42
  }
34
43
  }
35
44
  // Prepare target directory
@@ -42,10 +51,12 @@ async function downloadGitRepo(options) {
42
51
  }
43
52
  await (0, exec_1.execAsync)(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
44
53
  }
45
- // Get latest hash
54
+ // Get latest hash and make sure correct branch is available
46
55
  const hash = await (0, hash_1.getGitRepoHash)(options);
56
+ await (0, branch_1.getGitRepoBranch)(options, branch);
47
57
  return {
48
- target,
58
+ downloadType: 'git',
59
+ contentsDir: target,
49
60
  hash,
50
61
  };
51
62
  }
@@ -4,25 +4,29 @@ import {
4
4
  prepareDirectoryForExport
5
5
  } from "../../export/helpers/prepare.mjs";
6
6
  import { execAsync } from "../../misc/exec.mjs";
7
+ import { getGitRepoBranch } from "./branch.mjs";
7
8
  import { getGitRepoHash } from "./hash.mjs";
8
9
  async function downloadGitRepo(options) {
9
10
  const { remote, branch } = options;
10
11
  const hasHashInTarget = options.target.indexOf("{hash}") !== -1;
11
- if (options.ifModifiedSince || hasHashInTarget) {
12
+ const ifModifiedSince = options.ifModifiedSince;
13
+ if (ifModifiedSince || hasHashInTarget) {
12
14
  const result = await execAsync(`git ls-remote ${remote} --branch ${branch}`);
13
15
  const parts = result.stdout.split(/\s/);
14
16
  const latestHash = parts.shift();
15
17
  if (hasHashInTarget) {
16
18
  options.target = options.target.replace("{hash}", latestHash);
17
19
  }
18
- if (options.ifModifiedSince) {
19
- try {
20
- const expectedHash = options.ifModifiedSince === true ? await getGitRepoHash(options) : options.ifModifiedSince;
20
+ try {
21
+ await getGitRepoBranch(options, branch);
22
+ if (ifModifiedSince) {
23
+ const expectedHash = ifModifiedSince === true ? await getGitRepoHash(options) : typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "git" ? ifModifiedSince.hash : null;
21
24
  if (latestHash === expectedHash) {
22
25
  return "not_modified";
23
26
  }
24
- } catch (err) {
25
27
  }
28
+ } catch (err) {
29
+ options.cleanup = true;
26
30
  }
27
31
  }
28
32
  const target = options.target = await prepareDirectoryForExport(options);
@@ -34,8 +38,10 @@ async function downloadGitRepo(options) {
34
38
  await execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
35
39
  }
36
40
  const hash = await getGitRepoHash(options);
41
+ await getGitRepoBranch(options, branch);
37
42
  return {
38
- target,
43
+ downloadType: "git",
44
+ contentsDir: target,
39
45
  hash
40
46
  };
41
47
  }
@@ -1,11 +1,12 @@
1
1
  import { ExportTargetOptions } from '../../export/helpers/prepare';
2
2
  import type { DocumentNotModified } from '../types/modified';
3
3
  import type { GitHubAPIOptions } from './types';
4
+ import type { DownloadSourceMixin } from '../types/sources';
4
5
  interface IfModifiedSinceOption {
5
- ifModifiedSince: string;
6
+ ifModifiedSince: string | DownloadGitHubRepoResult;
6
7
  }
7
8
  /**
8
- * Options for downloadGitRepo()
9
+ * Options for downloadGitHubRepo()
9
10
  */
10
11
  export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAPIOptions, Partial<IfModifiedSinceOption> {
11
12
  cleanupOldFiles?: boolean;
@@ -15,9 +16,9 @@ export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAP
15
16
  /**
16
17
  * Result
17
18
  */
18
- export interface DownloadGitHubRepoResult {
19
+ export interface DownloadGitHubRepoResult extends DownloadSourceMixin<'github'> {
19
20
  rootDir: string;
20
- actualDir: string;
21
+ contentsDir: string;
21
22
  hash: string;
22
23
  }
23
24
  /**
@@ -29,8 +29,16 @@ async function findMatchingDirs(rootDir, hash) {
29
29
  async function downloadGitHubRepo(options) {
30
30
  // Check for last commit
31
31
  const hash = await (0, hash_1.getGitHubRepoHash)(options);
32
- if (options.ifModifiedSince && hash === options.ifModifiedSince) {
33
- return 'not_modified';
32
+ const ifModifiedSince = options.ifModifiedSince;
33
+ if (ifModifiedSince) {
34
+ const expectedHash = typeof ifModifiedSince === 'string'
35
+ ? ifModifiedSince
36
+ : ifModifiedSince.downloadType === 'github'
37
+ ? ifModifiedSince.hash
38
+ : null;
39
+ if (hash === expectedHash) {
40
+ return 'not_modified';
41
+ }
34
42
  }
35
43
  // Replace hash in target
36
44
  options.target = options.target.replace('{hash}', hash);
@@ -97,10 +105,11 @@ async function downloadGitHubRepo(options) {
97
105
  if (matchingDirs.length !== 1) {
98
106
  throw new Error(`Error unpacking ${hash}.zip`);
99
107
  }
100
- const actualDir = rootDir + '/' + matchingDirs[0];
108
+ const contentsDir = rootDir + '/' + matchingDirs[0];
101
109
  return {
110
+ downloadType: 'github',
102
111
  rootDir,
103
- actualDir,
112
+ contentsDir,
104
113
  hash,
105
114
  };
106
115
  }
@@ -24,8 +24,12 @@ async function findMatchingDirs(rootDir, hash) {
24
24
  }
25
25
  async function downloadGitHubRepo(options) {
26
26
  const hash = await getGitHubRepoHash(options);
27
- if (options.ifModifiedSince && hash === options.ifModifiedSince) {
28
- return "not_modified";
27
+ const ifModifiedSince = options.ifModifiedSince;
28
+ if (ifModifiedSince) {
29
+ const expectedHash = typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "github" ? ifModifiedSince.hash : null;
30
+ if (hash === expectedHash) {
31
+ return "not_modified";
32
+ }
29
33
  }
30
34
  options.target = options.target.replace("{hash}", hash);
31
35
  const rootDir = options.target = await prepareDirectoryForExport(options);
@@ -71,10 +75,11 @@ async function downloadGitHubRepo(options) {
71
75
  if (matchingDirs.length !== 1) {
72
76
  throw new Error(`Error unpacking ${hash}.zip`);
73
77
  }
74
- const actualDir = rootDir + "/" + matchingDirs[0];
78
+ const contentsDir = rootDir + "/" + matchingDirs[0];
75
79
  return {
80
+ downloadType: "github",
76
81
  rootDir,
77
- actualDir,
82
+ contentsDir,
78
83
  hash
79
84
  };
80
85
  }
@@ -0,0 +1,5 @@
1
+ import { GitLabAPIOptions } from './types';
2
+ /**
3
+ * Get latest hash from GitHub using API
4
+ */
5
+ export declare function getGitLabRepoHash(options: GitLabAPIOptions): Promise<string>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGitLabRepoHash = void 0;
4
+ const api_1 = require("../api");
5
+ const types_1 = require("./types");
6
+ /**
7
+ * Get latest hash from GitHub using API
8
+ */
9
+ async function getGitLabRepoHash(options) {
10
+ const uri = `${options.uri || types_1.defaultGitLabBaseURI}/${options.project}/repository/branches/${options.branch}/`;
11
+ const data = await (0, api_1.sendAPIQuery)({
12
+ uri,
13
+ headers: {
14
+ Authorization: 'token ' + options.token,
15
+ },
16
+ });
17
+ if (typeof data !== 'string') {
18
+ throw new Error(`Error downloading data from GitLab API: ${data}`);
19
+ }
20
+ const content = JSON.parse(data);
21
+ const item = (content instanceof Array ? content : [content]).find((item) => item.name === options.branch && typeof item.commit.id === 'string');
22
+ if (!item) {
23
+ throw new Error('Error parsing GitLab API response');
24
+ }
25
+ return item.commit.id;
26
+ }
27
+ exports.getGitLabRepoHash = getGitLabRepoHash;
@@ -0,0 +1,24 @@
1
+ // src/download/gitlab/hash.ts
2
+ import { sendAPIQuery } from "../api/index.mjs";
3
+ import { defaultGitLabBaseURI } from "./types.mjs";
4
+ async function getGitLabRepoHash(options) {
5
+ const uri = `${options.uri || defaultGitLabBaseURI}/${options.project}/repository/branches/${options.branch}/`;
6
+ const data = await sendAPIQuery({
7
+ uri,
8
+ headers: {
9
+ Authorization: "token " + options.token
10
+ }
11
+ });
12
+ if (typeof data !== "string") {
13
+ throw new Error(`Error downloading data from GitLab API: ${data}`);
14
+ }
15
+ const content = JSON.parse(data);
16
+ const item = (content instanceof Array ? content : [content]).find((item2) => item2.name === options.branch && typeof item2.commit.id === "string");
17
+ if (!item) {
18
+ throw new Error("Error parsing GitLab API response");
19
+ }
20
+ return item.commit.id;
21
+ }
22
+ export {
23
+ getGitLabRepoHash
24
+ };
@@ -0,0 +1,29 @@
1
+ import { ExportTargetOptions } from '../../export/helpers/prepare';
2
+ import type { DocumentNotModified } from '../types/modified';
3
+ import { GitLabAPIOptions } from './types';
4
+ import type { DownloadSourceMixin } from '../types/sources';
5
+ interface IfModifiedSinceOption {
6
+ ifModifiedSince: string | DownloadGitLabRepoResult;
7
+ }
8
+ /**
9
+ * Options for downloadGitLabRepo()
10
+ */
11
+ export interface DownloadGitLabRepoOptions extends ExportTargetOptions, GitLabAPIOptions, Partial<IfModifiedSinceOption> {
12
+ cleanupOldFiles?: boolean;
13
+ cleanupOldDirectories?: boolean;
14
+ log?: boolean;
15
+ }
16
+ /**
17
+ * Result
18
+ */
19
+ export interface DownloadGitLabRepoResult extends DownloadSourceMixin<'gitlab'> {
20
+ rootDir: string;
21
+ contentsDir: string;
22
+ hash: string;
23
+ }
24
+ /**
25
+ * Download GitLab repo using API
26
+ */
27
+ export declare function downloadGitLabRepo<T extends IfModifiedSinceOption & DownloadGitLabRepoOptions>(options: T): Promise<DownloadGitLabRepoResult | DocumentNotModified>;
28
+ export declare function downloadGitLabRepo(options: DownloadGitLabRepoOptions): Promise<DownloadGitLabRepoResult>;
29
+ export {};
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadGitLabRepo = void 0;
4
+ const fs_1 = require("fs");
5
+ const prepare_1 = require("../../export/helpers/prepare");
6
+ const hash_1 = require("./hash");
7
+ const types_1 = require("./types");
8
+ const download_1 = require("../api/download");
9
+ const unzip_1 = require("../helpers/unzip");
10
+ /**
11
+ * Find matching directories
12
+ */
13
+ async function findMatchingDirs(rootDir, hash) {
14
+ const matches = [];
15
+ const files = await fs_1.promises.readdir(rootDir);
16
+ for (let i = 0; i < files.length; i++) {
17
+ const file = files[i];
18
+ const lastChunk = file.split('-').pop();
19
+ if (lastChunk.length < 4 ||
20
+ lastChunk !== hash.slice(0, lastChunk.length)) {
21
+ continue;
22
+ }
23
+ const stat = await fs_1.promises.stat(rootDir + '/' + file);
24
+ if (stat.isDirectory()) {
25
+ matches.push(file);
26
+ }
27
+ }
28
+ return matches;
29
+ }
30
+ async function downloadGitLabRepo(options) {
31
+ // Check for last commit
32
+ const hash = await (0, hash_1.getGitLabRepoHash)(options);
33
+ const ifModifiedSince = options.ifModifiedSince;
34
+ if (ifModifiedSince) {
35
+ const expectedHash = typeof ifModifiedSince === 'string'
36
+ ? ifModifiedSince
37
+ : ifModifiedSince.downloadType === 'gitlab'
38
+ ? ifModifiedSince.hash
39
+ : null;
40
+ if (hash === expectedHash) {
41
+ return 'not_modified';
42
+ }
43
+ }
44
+ // Replace hash in target
45
+ options.target = options.target.replace('{hash}', hash);
46
+ // Prepare target directory
47
+ const rootDir = (options.target = await (0, prepare_1.prepareDirectoryForExport)(options));
48
+ // Archive name
49
+ const archiveTarget = rootDir + '/' + hash + '.zip';
50
+ // Check if archive exists
51
+ let exists = false;
52
+ try {
53
+ const stat = await fs_1.promises.stat(archiveTarget);
54
+ exists = stat.isFile();
55
+ }
56
+ catch (err) {
57
+ //
58
+ }
59
+ // Download file
60
+ if (!exists) {
61
+ const uri = `${options.uri || types_1.defaultGitLabBaseURI}/${options.project}/repository/archive.zip?sha=${hash}`;
62
+ await (0, download_1.downloadFile)({
63
+ uri,
64
+ headers: {
65
+ Authorization: 'token ' + options.token,
66
+ },
67
+ }, archiveTarget);
68
+ }
69
+ // Clean up old directories
70
+ const files = await fs_1.promises.readdir(rootDir);
71
+ const hashSearch = '-' + hash;
72
+ for (let i = 0; i < files.length; i++) {
73
+ const file = files[i];
74
+ if (file === hash + '.zip') {
75
+ continue;
76
+ }
77
+ const filename = rootDir + '/' + files[i];
78
+ const stat = await fs_1.promises.lstat(filename);
79
+ const isDir = stat.isDirectory();
80
+ if (
81
+ // Remove symbolic links
82
+ stat.isSymbolicLink() ||
83
+ // Remove if directory matches hash to avoid errors extracting zip
84
+ (isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
85
+ // Remove if directory and cleanupOldDirectories is not disabled
86
+ (isDir && options.cleanupOldDirectories !== false) ||
87
+ // Remove if file and cleanupOldFiles is enabled
88
+ (!isDir && options.cleanupOldFiles)) {
89
+ try {
90
+ await fs_1.promises.rm(filename, {
91
+ force: true,
92
+ recursive: true,
93
+ });
94
+ }
95
+ catch (err) {
96
+ //
97
+ }
98
+ }
99
+ }
100
+ // Unpack it
101
+ await (0, unzip_1.unzip)(archiveTarget, rootDir);
102
+ // Get actual dir
103
+ const matchingDirs = await findMatchingDirs(rootDir, hash);
104
+ if (matchingDirs.length !== 1) {
105
+ throw new Error(`Error unpacking ${hash}.zip`);
106
+ }
107
+ const contentsDir = rootDir + '/' + matchingDirs[0];
108
+ return {
109
+ downloadType: 'gitlab',
110
+ rootDir,
111
+ contentsDir,
112
+ hash,
113
+ };
114
+ }
115
+ exports.downloadGitLabRepo = downloadGitLabRepo;
@@ -0,0 +1,88 @@
1
+ // src/download/gitlab/index.ts
2
+ import { promises as fs } from "fs";
3
+ import {
4
+ prepareDirectoryForExport
5
+ } from "../../export/helpers/prepare.mjs";
6
+ import { getGitLabRepoHash } from "./hash.mjs";
7
+ import { defaultGitLabBaseURI } from "./types.mjs";
8
+ import { downloadFile } from "../api/download.mjs";
9
+ import { unzip } from "../helpers/unzip.mjs";
10
+ async function findMatchingDirs(rootDir, hash) {
11
+ const matches = [];
12
+ const files = await fs.readdir(rootDir);
13
+ for (let i = 0; i < files.length; i++) {
14
+ const file = files[i];
15
+ const lastChunk = file.split("-").pop();
16
+ if (lastChunk.length < 4 || lastChunk !== hash.slice(0, lastChunk.length)) {
17
+ continue;
18
+ }
19
+ const stat = await fs.stat(rootDir + "/" + file);
20
+ if (stat.isDirectory()) {
21
+ matches.push(file);
22
+ }
23
+ }
24
+ return matches;
25
+ }
26
+ async function downloadGitLabRepo(options) {
27
+ const hash = await getGitLabRepoHash(options);
28
+ const ifModifiedSince = options.ifModifiedSince;
29
+ if (ifModifiedSince) {
30
+ const expectedHash = typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "gitlab" ? ifModifiedSince.hash : null;
31
+ if (hash === expectedHash) {
32
+ return "not_modified";
33
+ }
34
+ }
35
+ options.target = options.target.replace("{hash}", hash);
36
+ const rootDir = options.target = await prepareDirectoryForExport(options);
37
+ const archiveTarget = rootDir + "/" + hash + ".zip";
38
+ let exists = false;
39
+ try {
40
+ const stat = await fs.stat(archiveTarget);
41
+ exists = stat.isFile();
42
+ } catch (err) {
43
+ }
44
+ if (!exists) {
45
+ const uri = `${options.uri || defaultGitLabBaseURI}/${options.project}/repository/archive.zip?sha=${hash}`;
46
+ await downloadFile({
47
+ uri,
48
+ headers: {
49
+ Authorization: "token " + options.token
50
+ }
51
+ }, archiveTarget);
52
+ }
53
+ const files = await fs.readdir(rootDir);
54
+ const hashSearch = "-" + hash;
55
+ for (let i = 0; i < files.length; i++) {
56
+ const file = files[i];
57
+ if (file === hash + ".zip") {
58
+ continue;
59
+ }
60
+ const filename = rootDir + "/" + files[i];
61
+ const stat = await fs.lstat(filename);
62
+ const isDir = stat.isDirectory();
63
+ if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
64
+ try {
65
+ await fs.rm(filename, {
66
+ force: true,
67
+ recursive: true
68
+ });
69
+ } catch (err) {
70
+ }
71
+ }
72
+ }
73
+ await unzip(archiveTarget, rootDir);
74
+ const matchingDirs = await findMatchingDirs(rootDir, hash);
75
+ if (matchingDirs.length !== 1) {
76
+ throw new Error(`Error unpacking ${hash}.zip`);
77
+ }
78
+ const contentsDir = rootDir + "/" + matchingDirs[0];
79
+ return {
80
+ downloadType: "gitlab",
81
+ rootDir,
82
+ contentsDir,
83
+ hash
84
+ };
85
+ }
86
+ export {
87
+ downloadGitLabRepo
88
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * API options
3
+ */
4
+ export interface GitLabAPIOptions {
5
+ uri?: string;
6
+ token: string;
7
+ project: string;
8
+ branch: string;
9
+ }
10
+ /**
11
+ * Default base URI for GitLab API
12
+ */
13
+ export declare const defaultGitLabBaseURI = "https://gitlab.com/api/v4/projects";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultGitLabBaseURI = void 0;
4
+ /**
5
+ * Default base URI for GitLab API
6
+ */
7
+ exports.defaultGitLabBaseURI = 'https://gitlab.com/api/v4/projects';
@@ -0,0 +1,5 @@
1
+ // src/download/gitlab/types.ts
2
+ var defaultGitLabBaseURI = "https://gitlab.com/api/v4/projects";
3
+ export {
4
+ defaultGitLabBaseURI
5
+ };
@@ -0,0 +1,43 @@
1
+ import { DownloadGitHubRepoOptions, DownloadGitHubRepoResult } from './github';
2
+ import { DownloadGitRepoOptions, DownloadGitRepoResult } from './git';
3
+ import { DownloadNPMPackageOptions, DownloadNPMPackageResult } from './npm';
4
+ import type { DocumentNotModified } from './types/modified';
5
+ import type { DownloadSourceMixin, DownloadSourceType } from './types/sources';
6
+ import { DownloadGitLabRepoOptions, DownloadGitLabRepoResult } from './gitlab';
7
+ /**
8
+ * Options and result combinations
9
+ */
10
+ interface DownloadGitRepo {
11
+ options: DownloadGitRepoOptions & DownloadSourceMixin<'git'>;
12
+ result: DownloadGitRepoResult;
13
+ }
14
+ interface DownloadGitHubRepo {
15
+ options: DownloadGitHubRepoOptions & DownloadSourceMixin<'github'>;
16
+ result: DownloadGitHubRepoResult;
17
+ }
18
+ interface DownloadGitLabRepo {
19
+ options: DownloadGitLabRepoOptions & DownloadSourceMixin<'gitlab'>;
20
+ result: DownloadGitLabRepoResult;
21
+ }
22
+ interface DownloadNPMPackage {
23
+ options: DownloadNPMPackageOptions & DownloadSourceMixin<'npm'>;
24
+ result: DownloadNPMPackageResult;
25
+ }
26
+ /**
27
+ * Combinations based on type
28
+ */
29
+ export declare type DownloadParamsMixin<T extends DownloadSourceType> = T extends 'git' ? DownloadGitRepo : T extends 'github' ? DownloadGitHubRepo : T extends 'gitlab' ? DownloadGitLabRepo : T extends 'npm' ? DownloadNPMPackage : never;
30
+ /**
31
+ * Combinations
32
+ */
33
+ export declare type DownloadParams = DownloadGitRepo | DownloadGitHubRepo | DownloadGitLabRepo | DownloadNPMPackage;
34
+ /**
35
+ * Pick options or result from combinations
36
+ */
37
+ declare type DownloadOptions<T extends DownloadSourceType> = DownloadParamsMixin<T>['options'];
38
+ declare type DownloadResult<T extends DownloadSourceType> = Promise<DocumentNotModified | DownloadParamsMixin<T>['result']>;
39
+ export declare function downloadPackage<T extends 'git'>(options: DownloadOptions<T>): DownloadResult<T>;
40
+ export declare function downloadPackage<T extends 'github'>(options: DownloadOptions<T>): DownloadResult<T>;
41
+ export declare function downloadPackage<T extends 'gitlab'>(options: DownloadOptions<T>): DownloadResult<T>;
42
+ export declare function downloadPackage<T extends 'npm'>(options: DownloadOptions<T>): DownloadResult<T>;
43
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadPackage = void 0;
4
+ const github_1 = require("./github");
5
+ const git_1 = require("./git");
6
+ const npm_1 = require("./npm");
7
+ const gitlab_1 = require("./gitlab");
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ function assertNever(v) {
10
+ //
11
+ }
12
+ function downloadPackage(options) {
13
+ switch (options.downloadType) {
14
+ case 'git':
15
+ return (0, git_1.downloadGitRepo)(options);
16
+ case 'github':
17
+ return (0, github_1.downloadGitHubRepo)(options);
18
+ case 'gitlab':
19
+ return (0, gitlab_1.downloadGitLabRepo)(options);
20
+ case 'npm':
21
+ return (0, npm_1.downloadNPMPackage)(options);
22
+ default:
23
+ assertNever(options);
24
+ throw new Error(`Invalid download type: ${options.downloadType}`);
25
+ }
26
+ }
27
+ exports.downloadPackage = downloadPackage;
@@ -0,0 +1,33 @@
1
+ // src/download/index.ts
2
+ import {
3
+ downloadGitHubRepo
4
+ } from "./github/index.mjs";
5
+ import {
6
+ downloadGitRepo
7
+ } from "./git/index.mjs";
8
+ import {
9
+ downloadNPMPackage
10
+ } from "./npm/index.mjs";
11
+ import {
12
+ downloadGitLabRepo
13
+ } from "./gitlab/index.mjs";
14
+ function assertNever(v) {
15
+ }
16
+ function downloadPackage(options) {
17
+ switch (options.downloadType) {
18
+ case "git":
19
+ return downloadGitRepo(options);
20
+ case "github":
21
+ return downloadGitHubRepo(options);
22
+ case "gitlab":
23
+ return downloadGitLabRepo(options);
24
+ case "npm":
25
+ return downloadNPMPackage(options);
26
+ default:
27
+ assertNever(options);
28
+ throw new Error(`Invalid download type: ${options.downloadType}`);
29
+ }
30
+ }
31
+ export {
32
+ downloadPackage
33
+ };
@@ -1,7 +1,8 @@
1
1
  import { ExportTargetOptions } from '../../export/helpers/prepare';
2
2
  import type { DocumentNotModified } from '../types/modified';
3
+ import type { DownloadSourceMixin } from '../types/sources';
3
4
  interface IfModifiedSinceOption {
4
- ifModifiedSince: string | true;
5
+ ifModifiedSince: string | true | DownloadNPMPackageResult;
5
6
  }
6
7
  /**
7
8
  * Options for downloadNPMPackage()
@@ -14,9 +15,9 @@ export interface DownloadNPMPackageOptions extends ExportTargetOptions, Partial<
14
15
  /**
15
16
  * Result
16
17
  */
17
- export interface DownloadNPMPackageResult {
18
+ export interface DownloadNPMPackageResult extends DownloadSourceMixin<'npm'> {
18
19
  rootDir: string;
19
- actualDir: string;
20
+ contentsDir: string;
20
21
  version: string;
21
22
  }
22
23
  /**
@@ -8,22 +8,39 @@ const untar_1 = require("../helpers/untar");
8
8
  const version_1 = require("./version");
9
9
  async function downloadNPMPackage(options) {
10
10
  const rootDir = (options.target = (0, prepare_1.normalizeDir)(options.target));
11
- const actualDir = rootDir + '/package';
11
+ const contentsDir = rootDir + '/package';
12
12
  // Get latest location
13
13
  const versionInfo = await (0, version_1.getNPMVersion)(options);
14
14
  const version = versionInfo.version;
15
15
  // Check downloaded copy
16
- if (options.ifModifiedSince) {
16
+ const ifModifiedSince = options.ifModifiedSince;
17
+ if (ifModifiedSince) {
17
18
  try {
18
- const expectedVersion = options.ifModifiedSince === true
19
- ? await (0, version_1.getPackageVersion)(actualDir)
20
- : options.ifModifiedSince;
19
+ let expectedVersion;
20
+ if (typeof ifModifiedSince === 'object') {
21
+ // Make sure result object matches
22
+ if (ifModifiedSince.downloadType === 'npm' &&
23
+ ifModifiedSince.rootDir === rootDir &&
24
+ ifModifiedSince.contentsDir === contentsDir) {
25
+ expectedVersion = ifModifiedSince.version;
26
+ }
27
+ else {
28
+ expectedVersion = null;
29
+ }
30
+ }
31
+ else {
32
+ expectedVersion =
33
+ ifModifiedSince === true
34
+ ? await (0, version_1.getPackageVersion)(contentsDir)
35
+ : ifModifiedSince;
36
+ }
21
37
  if (version === expectedVersion) {
22
38
  return 'not_modified';
23
39
  }
24
40
  }
25
41
  catch (err) {
26
- //
42
+ // Clean up on error
43
+ options.cleanup = true;
27
44
  }
28
45
  }
29
46
  const archiveURL = versionInfo.file;
@@ -56,7 +73,7 @@ async function downloadNPMPackage(options) {
56
73
  }
57
74
  // Remove old unpacked file
58
75
  await (0, prepare_1.prepareDirectoryForExport)({
59
- target: actualDir,
76
+ target: contentsDir,
60
77
  cleanup: true,
61
78
  });
62
79
  // Unpack file
@@ -65,8 +82,9 @@ async function downloadNPMPackage(options) {
65
82
  }
66
83
  await (0, untar_1.untar)(archiveTarget, rootDir);
67
84
  return {
85
+ downloadType: 'npm',
68
86
  rootDir,
69
- actualDir,
87
+ contentsDir,
70
88
  version,
71
89
  };
72
90
  }
@@ -9,16 +9,27 @@ import { untar } from "../helpers/untar.mjs";
9
9
  import { getNPMVersion, getPackageVersion } from "./version.mjs";
10
10
  async function downloadNPMPackage(options) {
11
11
  const rootDir = options.target = normalizeDir(options.target);
12
- const actualDir = rootDir + "/package";
12
+ const contentsDir = rootDir + "/package";
13
13
  const versionInfo = await getNPMVersion(options);
14
14
  const version = versionInfo.version;
15
- if (options.ifModifiedSince) {
15
+ const ifModifiedSince = options.ifModifiedSince;
16
+ if (ifModifiedSince) {
16
17
  try {
17
- const expectedVersion = options.ifModifiedSince === true ? await getPackageVersion(actualDir) : options.ifModifiedSince;
18
+ let expectedVersion;
19
+ if (typeof ifModifiedSince === "object") {
20
+ if (ifModifiedSince.downloadType === "npm" && ifModifiedSince.rootDir === rootDir && ifModifiedSince.contentsDir === contentsDir) {
21
+ expectedVersion = ifModifiedSince.version;
22
+ } else {
23
+ expectedVersion = null;
24
+ }
25
+ } else {
26
+ expectedVersion = ifModifiedSince === true ? await getPackageVersion(contentsDir) : ifModifiedSince;
27
+ }
18
28
  if (version === expectedVersion) {
19
29
  return "not_modified";
20
30
  }
21
31
  } catch (err) {
32
+ options.cleanup = true;
22
33
  }
23
34
  }
24
35
  const archiveURL = versionInfo.file;
@@ -45,7 +56,7 @@ async function downloadNPMPackage(options) {
45
56
  }, archiveTarget);
46
57
  }
47
58
  await prepareDirectoryForExport({
48
- target: actualDir,
59
+ target: contentsDir,
49
60
  cleanup: true
50
61
  });
51
62
  if (options.log) {
@@ -53,8 +64,9 @@ async function downloadNPMPackage(options) {
53
64
  }
54
65
  await untar(archiveTarget, rootDir);
55
66
  return {
67
+ downloadType: "npm",
56
68
  rootDir,
57
- actualDir,
69
+ contentsDir,
58
70
  version
59
71
  };
60
72
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Download types
3
+ */
4
+ export declare type DownloadSourceType = 'git' | 'github' | 'gitlab' | 'npm';
5
+ /**
6
+ * Type in other objects
7
+ */
8
+ export interface DownloadSourceMixin<T extends DownloadSourceType> {
9
+ downloadType: T;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -342,6 +342,7 @@ class IconSet {
342
342
  .forEach((item) => {
343
343
  const names = this.listCategory(item);
344
344
  if (names) {
345
+ names.sort((a, b) => a.localeCompare(b));
345
346
  categories[item.title] = names;
346
347
  }
347
348
  });
@@ -271,6 +271,7 @@ var IconSet = class {
271
271
  Array.from(this.categories).sort((a, b) => a.title.localeCompare(b.title)).forEach((item) => {
272
272
  const names2 = this.listCategory(item);
273
273
  if (names2) {
274
+ names2.sort((a, b) => a.localeCompare(b));
274
275
  categories[item.title] = names2;
275
276
  }
276
277
  });
package/lib/index.d.ts CHANGED
@@ -13,10 +13,14 @@ export { importFromFigma } from './import/figma/index';
13
13
  export { importDirectory } from './import/directory';
14
14
  export { downloadGitRepo } from './download/git/index';
15
15
  export { getGitRepoHash } from './download/git/hash';
16
+ export { getGitRepoBranch } from './download/git/branch';
16
17
  export { downloadGitHubRepo } from './download/github/index';
17
18
  export { getGitHubRepoHash } from './download/github/hash';
19
+ export { downloadGitLabRepo } from './download/gitlab/index';
20
+ export { getGitLabRepoHash } from './download/gitlab/hash';
18
21
  export { downloadNPMPackage } from './download/npm/index';
19
22
  export { getNPMVersion, getPackageVersion } from './download/npm/version';
23
+ export { downloadPackage } from './download/index';
20
24
  export { parseColors, isEmptyColor } from './colors/parse';
21
25
  export { validateColors } from './colors/validate';
22
26
  export { runSVGO } from './optimise/svgo';
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.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;
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.downloadPackage = exports.getPackageVersion = exports.getNPMVersion = exports.downloadNPMPackage = exports.getGitLabRepoHash = exports.downloadGitLabRepo = exports.getGitHubRepoHash = exports.downloadGitHubRepo = exports.getGitRepoBranch = 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; } });
@@ -37,15 +37,23 @@ var index_4 = require("./download/git/index");
37
37
  Object.defineProperty(exports, "downloadGitRepo", { enumerable: true, get: function () { return index_4.downloadGitRepo; } });
38
38
  var hash_1 = require("./download/git/hash");
39
39
  Object.defineProperty(exports, "getGitRepoHash", { enumerable: true, get: function () { return hash_1.getGitRepoHash; } });
40
+ var branch_1 = require("./download/git/branch");
41
+ Object.defineProperty(exports, "getGitRepoBranch", { enumerable: true, get: function () { return branch_1.getGitRepoBranch; } });
40
42
  var index_5 = require("./download/github/index");
41
43
  Object.defineProperty(exports, "downloadGitHubRepo", { enumerable: true, get: function () { return index_5.downloadGitHubRepo; } });
42
44
  var hash_2 = require("./download/github/hash");
43
45
  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 index_6 = require("./download/gitlab/index");
47
+ Object.defineProperty(exports, "downloadGitLabRepo", { enumerable: true, get: function () { return index_6.downloadGitLabRepo; } });
48
+ var hash_3 = require("./download/gitlab/hash");
49
+ Object.defineProperty(exports, "getGitLabRepoHash", { enumerable: true, get: function () { return hash_3.getGitLabRepoHash; } });
50
+ var index_7 = require("./download/npm/index");
51
+ Object.defineProperty(exports, "downloadNPMPackage", { enumerable: true, get: function () { return index_7.downloadNPMPackage; } });
46
52
  var version_1 = require("./download/npm/version");
47
53
  Object.defineProperty(exports, "getNPMVersion", { enumerable: true, get: function () { return version_1.getNPMVersion; } });
48
54
  Object.defineProperty(exports, "getPackageVersion", { enumerable: true, get: function () { return version_1.getPackageVersion; } });
55
+ var index_8 = require("./download/index");
56
+ Object.defineProperty(exports, "downloadPackage", { enumerable: true, get: function () { return index_8.downloadPackage; } });
49
57
  // Manipulation
50
58
  var parse_2 = require("./colors/parse");
51
59
  Object.defineProperty(exports, "parseColors", { enumerable: true, get: function () { return parse_2.parseColors; } });
@@ -85,5 +93,5 @@ var keyword_1 = require("./misc/keyword");
85
93
  Object.defineProperty(exports, "cleanupIconKeyword", { enumerable: true, get: function () { return keyword_1.cleanupIconKeyword; } });
86
94
  var bump_version_1 = require("./misc/bump-version");
87
95
  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; } });
96
+ var index_9 = require("./download/api/index");
97
+ Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_9.sendAPIQuery; } });
package/lib/index.mjs CHANGED
@@ -14,10 +14,14 @@ import { importFromFigma } from "./import/figma/index.mjs";
14
14
  import { importDirectory } from "./import/directory.mjs";
15
15
  import { downloadGitRepo } from "./download/git/index.mjs";
16
16
  import { getGitRepoHash } from "./download/git/hash.mjs";
17
+ import { getGitRepoBranch } from "./download/git/branch.mjs";
17
18
  import { downloadGitHubRepo } from "./download/github/index.mjs";
18
19
  import { getGitHubRepoHash } from "./download/github/hash.mjs";
20
+ import { downloadGitLabRepo } from "./download/gitlab/index.mjs";
21
+ import { getGitLabRepoHash } from "./download/gitlab/hash.mjs";
19
22
  import { downloadNPMPackage } from "./download/npm/index.mjs";
20
23
  import { getNPMVersion, getPackageVersion } from "./download/npm/version.mjs";
24
+ import { downloadPackage } from "./download/index.mjs";
21
25
  import { parseColors, isEmptyColor } from "./colors/parse.mjs";
22
26
  import { validateColors } from "./colors/validate.mjs";
23
27
  import { runSVGO } from "./optimise/svgo.mjs";
@@ -50,13 +54,17 @@ export {
50
54
  convertStyleToAttrs,
51
55
  deOptimisePaths,
52
56
  downloadGitHubRepo,
57
+ downloadGitLabRepo,
53
58
  downloadGitRepo,
54
59
  downloadNPMPackage,
60
+ downloadPackage,
55
61
  execAsync,
56
62
  exportIconPackage,
57
63
  exportJSONPackage,
58
64
  exportToDirectory,
59
65
  getGitHubRepoHash,
66
+ getGitLabRepoHash,
67
+ getGitRepoBranch,
60
68
  getGitRepoHash,
61
69
  getNPMVersion,
62
70
  getPackageVersion,
@@ -45,7 +45,7 @@ exports.shapeModifiyingSVGOPlugins = [
45
45
  noSpaceAfterFlags: true,
46
46
  },
47
47
  },
48
- 'removeOffCanvasPaths',
48
+ // 'removeOffCanvasPaths', // bugged for some icons
49
49
  'reusePaths',
50
50
  ];
51
51
  /**
@@ -40,7 +40,6 @@ var shapeModifiyingSVGOPlugins = [
40
40
  noSpaceAfterFlags: true
41
41
  }
42
42
  },
43
- "removeOffCanvasPaths",
44
43
  "reusePaths"
45
44
  ];
46
45
  async function runSVGO(svg, options = {}) {
@@ -77,7 +77,7 @@ async function cleanupSVGRoot(svg) {
77
77
  $root.removeAttr(attr);
78
78
  return;
79
79
  }
80
- console.log(`Removing unexpected attribute on SVG: ${attr}`);
80
+ console.warn(`Removing unexpected attribute on SVG: ${attr}`);
81
81
  $root.removeAttr(attr);
82
82
  });
83
83
  if (Object.keys(moveToChildren).length) {
@@ -60,7 +60,7 @@ async function cleanupSVGRoot(svg) {
60
60
  $root.removeAttr(attr);
61
61
  return;
62
62
  }
63
- console.log(`Removing unexpected attribute on SVG: ${attr}`);
63
+ console.warn(`Removing unexpected attribute on SVG: ${attr}`);
64
64
  $root.removeAttr(attr);
65
65
  });
66
66
  if (Object.keys(moveToChildren).length) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@iconify/tools",
3
3
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
4
4
  "author": "Vjacheslav Trushkin",
5
- "version": "2.0.6",
5
+ "version": "2.0.10",
6
6
  "license": "MIT",
7
7
  "bugs": "https://github.com/iconify/tools/issues",
8
8
  "homepage": "https://github.com/iconify/tools",
@@ -22,7 +22,7 @@
22
22
  "test": "npm run test:jest && npm run test:jasmine"
23
23
  },
24
24
  "dependencies": {
25
- "@iconify/utils": "^1.0.21",
25
+ "@iconify/utils": "^1.0.22",
26
26
  "@types/cheerio": "^0.22.30",
27
27
  "@types/node-fetch": "^2.5.12",
28
28
  "@types/svgo": "^2.6.0",
@@ -104,6 +104,10 @@
104
104
  "require": "./lib/download/api/types.js",
105
105
  "import": "./lib/download/api/types.mjs"
106
106
  },
107
+ "./lib/download/git/branch": {
108
+ "require": "./lib/download/git/branch.js",
109
+ "import": "./lib/download/git/branch.mjs"
110
+ },
107
111
  "./lib/download/git/hash": {
108
112
  "require": "./lib/download/git/hash.js",
109
113
  "import": "./lib/download/git/hash.mjs"
@@ -132,6 +136,22 @@
132
136
  "require": "./lib/download/github/types.js",
133
137
  "import": "./lib/download/github/types.mjs"
134
138
  },
139
+ "./lib/download/gitlab/hash": {
140
+ "require": "./lib/download/gitlab/hash.js",
141
+ "import": "./lib/download/gitlab/hash.mjs"
142
+ },
143
+ "./lib/download/gitlab": {
144
+ "require": "./lib/download/gitlab/index.js",
145
+ "import": "./lib/download/gitlab/index.mjs"
146
+ },
147
+ "./lib/download/gitlab/index": {
148
+ "require": "./lib/download/gitlab/index.js",
149
+ "import": "./lib/download/gitlab/index.mjs"
150
+ },
151
+ "./lib/download/gitlab/types": {
152
+ "require": "./lib/download/gitlab/types.js",
153
+ "import": "./lib/download/gitlab/types.mjs"
154
+ },
135
155
  "./lib/download/helpers/untar": {
136
156
  "require": "./lib/download/helpers/untar.js",
137
157
  "import": "./lib/download/helpers/untar.mjs"
@@ -140,6 +160,14 @@
140
160
  "require": "./lib/download/helpers/unzip.js",
141
161
  "import": "./lib/download/helpers/unzip.mjs"
142
162
  },
163
+ "./lib/download": {
164
+ "require": "./lib/download/index.js",
165
+ "import": "./lib/download/index.mjs"
166
+ },
167
+ "./lib/download/index": {
168
+ "require": "./lib/download/index.js",
169
+ "import": "./lib/download/index.mjs"
170
+ },
143
171
  "./lib/download/npm": {
144
172
  "require": "./lib/download/npm/index.js",
145
173
  "import": "./lib/download/npm/index.mjs"
@@ -160,6 +188,10 @@
160
188
  "require": "./lib/download/types/modified.js",
161
189
  "import": "./lib/download/types/modified.mjs"
162
190
  },
191
+ "./lib/download/types/sources": {
192
+ "require": "./lib/download/types/sources.js",
193
+ "import": "./lib/download/types/sources.mjs"
194
+ },
163
195
  "./lib/export/directory": {
164
196
  "require": "./lib/export/directory.js",
165
197
  "import": "./lib/export/directory.mjs"