@iconify/tools 2.0.12 → 2.0.13

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.
@@ -6,6 +6,7 @@ const prepare_1 = require("../../export/helpers/prepare");
6
6
  const exec_1 = require("../../misc/exec");
7
7
  const branch_1 = require("./branch");
8
8
  const hash_1 = require("./hash");
9
+ const reset_1 = require("./reset");
9
10
  async function downloadGitRepo(options) {
10
11
  const { remote, branch } = options;
11
12
  // Check for last commit
@@ -32,6 +33,8 @@ async function downloadGitRepo(options) {
32
33
  ? ifModifiedSince.hash
33
34
  : null;
34
35
  if (latestHash === expectedHash) {
36
+ // Reset contents before returning
37
+ await (0, reset_1.resetGitRepoContents)(options.target);
35
38
  return 'not_modified';
36
39
  }
37
40
  }
@@ -51,6 +54,15 @@ async function downloadGitRepo(options) {
51
54
  }
52
55
  await (0, exec_1.execAsync)(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
53
56
  }
57
+ else {
58
+ // Attempt to reset contents
59
+ try {
60
+ await (0, reset_1.resetGitRepoContents)(options.target);
61
+ }
62
+ catch (err) {
63
+ //
64
+ }
65
+ }
54
66
  // Get latest hash and make sure correct branch is available
55
67
  const hash = await (0, hash_1.getGitRepoHash)(options);
56
68
  await (0, branch_1.getGitRepoBranch)(options, branch);
@@ -6,6 +6,7 @@ import {
6
6
  import { execAsync } from "../../misc/exec.mjs";
7
7
  import { getGitRepoBranch } from "./branch.mjs";
8
8
  import { getGitRepoHash } from "./hash.mjs";
9
+ import { resetGitRepoContents } from "./reset.mjs";
9
10
  async function downloadGitRepo(options) {
10
11
  const { remote, branch } = options;
11
12
  const hasHashInTarget = options.target.indexOf("{hash}") !== -1;
@@ -22,6 +23,7 @@ async function downloadGitRepo(options) {
22
23
  if (ifModifiedSince) {
23
24
  const expectedHash = ifModifiedSince === true ? await getGitRepoHash(options) : typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "git" ? ifModifiedSince.hash : null;
24
25
  if (latestHash === expectedHash) {
26
+ await resetGitRepoContents(options.target);
25
27
  return "not_modified";
26
28
  }
27
29
  }
@@ -36,6 +38,11 @@ async function downloadGitRepo(options) {
36
38
  console.log(`Cloning ${remote}#${branch} to ${target}`);
37
39
  }
38
40
  await execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
41
+ } else {
42
+ try {
43
+ await resetGitRepoContents(options.target);
44
+ } catch (err) {
45
+ }
39
46
  }
40
47
  const hash = await getGitRepoHash(options);
41
48
  await getGitRepoBranch(options, branch);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reset Git repo contents
3
+ */
4
+ export declare function resetGitRepoContents(target: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resetGitRepoContents = void 0;
4
+ const __1 = require("../..");
5
+ /**
6
+ * Reset Git repo contents
7
+ */
8
+ async function resetGitRepoContents(target) {
9
+ await (0, __1.execAsync)('git add -A', {
10
+ cwd: target,
11
+ });
12
+ await (0, __1.execAsync)('git reset --hard --quiet', {
13
+ cwd: target,
14
+ });
15
+ }
16
+ exports.resetGitRepoContents = resetGitRepoContents;
@@ -0,0 +1,13 @@
1
+ // src/download/git/reset.ts
2
+ import { execAsync } from "../../index.mjs";
3
+ async function resetGitRepoContents(target) {
4
+ await execAsync("git add -A", {
5
+ cwd: target
6
+ });
7
+ await execAsync("git reset --hard --quiet", {
8
+ cwd: target
9
+ });
10
+ }
11
+ export {
12
+ resetGitRepoContents
13
+ };
@@ -51,7 +51,12 @@ async function exportJSONPackage(iconSet, options) {
51
51
  }
52
52
  });
53
53
  // Contents
54
- const info = exportedJSON.info;
54
+ const info = exportedJSON.info
55
+ ? {
56
+ prefix: iconSet.prefix,
57
+ ...exportedJSON.info,
58
+ }
59
+ : void 0;
55
60
  const contents = {
56
61
  icons,
57
62
  info,
@@ -41,7 +41,10 @@ async function exportJSONPackage(iconSet, options) {
41
41
  hasMetadata = true;
42
42
  }
43
43
  });
44
- const info = exportedJSON.info;
44
+ const info = exportedJSON.info ? {
45
+ prefix: iconSet.prefix,
46
+ ...exportedJSON.info
47
+ } : void 0;
45
48
  const contents = {
46
49
  icons,
47
50
  info,
@@ -42,7 +42,7 @@ class IconSet {
42
42
  load(data) {
43
43
  this.prefix = data.prefix;
44
44
  // Defaults
45
- const defaultProps = (0, props_1.filterProps)(data);
45
+ const defaultProps = (0, props_1.filterProps)(data, true);
46
46
  // Add icons
47
47
  this.entries = Object.create(null);
48
48
  const entries = this.entries;
@@ -51,7 +51,10 @@ class IconSet {
51
51
  const entry = {
52
52
  type: 'icon',
53
53
  body: item.body,
54
- props: { ...defaultProps, ...(0, props_1.filterProps)(item) },
54
+ props: (0, props_1.filterProps)({
55
+ ...defaultProps,
56
+ ...item,
57
+ }, true),
55
58
  chars: new Set(),
56
59
  categories: new Set(),
57
60
  };
@@ -62,7 +65,7 @@ class IconSet {
62
65
  for (const name in data.aliases) {
63
66
  const item = data.aliases[name];
64
67
  const parent = item.parent;
65
- const props = (0, props_1.filterProps)(item);
68
+ const props = (0, props_1.filterProps)(item, false);
66
69
  const chars = new Set();
67
70
  if (Object.keys(props).length) {
68
71
  // Variation
@@ -599,7 +602,7 @@ class IconSet {
599
602
  return this.setItem(name, {
600
603
  type: 'icon',
601
604
  body: icon.body,
602
- props: (0, props_1.filterProps)(icon),
605
+ props: (0, props_1.filterProps)(icon, true),
603
606
  chars: new Set(),
604
607
  categories: new Set(),
605
608
  });
@@ -21,7 +21,7 @@ var IconSet = class {
21
21
  }
22
22
  load(data) {
23
23
  this.prefix = data.prefix;
24
- const defaultProps = filterProps(data);
24
+ const defaultProps = filterProps(data, true);
25
25
  this.entries = Object.create(null);
26
26
  const entries = this.entries;
27
27
  for (const name in data.icons) {
@@ -29,7 +29,10 @@ var IconSet = class {
29
29
  const entry = {
30
30
  type: "icon",
31
31
  body: item.body,
32
- props: { ...defaultProps, ...filterProps(item) },
32
+ props: filterProps({
33
+ ...defaultProps,
34
+ ...item
35
+ }, true),
33
36
  chars: new Set(),
34
37
  categories: new Set()
35
38
  };
@@ -39,7 +42,7 @@ var IconSet = class {
39
42
  for (const name in data.aliases) {
40
43
  const item = data.aliases[name];
41
44
  const parent = item.parent;
42
- const props = filterProps(item);
45
+ const props = filterProps(item, false);
43
46
  const chars = new Set();
44
47
  if (Object.keys(props).length) {
45
48
  const entry = {
@@ -473,7 +476,7 @@ var IconSet = class {
473
476
  return this.setItem(name, {
474
477
  type: "icon",
475
478
  body: icon.body,
476
- props: filterProps(icon),
479
+ props: filterProps(icon, true),
477
480
  chars: new Set(),
478
481
  categories: new Set()
479
482
  });
@@ -7,4 +7,4 @@ export declare const defaultCommonProps: Required<CommonIconProps>;
7
7
  /**
8
8
  * Filter icon props: copies properties, removing undefined and default entries
9
9
  */
10
- export declare function filterProps(data: CommonIconProps): CommonIconProps;
10
+ export declare function filterProps(data: CommonIconProps, compareDefaultValues: boolean): CommonIconProps;
@@ -19,12 +19,13 @@ const props = Object.keys(exports.defaultCommonProps);
19
19
  /**
20
20
  * Filter icon props: copies properties, removing undefined and default entries
21
21
  */
22
- function filterProps(data) {
22
+ function filterProps(data, compareDefaultValues) {
23
23
  const result = {};
24
24
  props.forEach((attr) => {
25
25
  const value = data[attr];
26
26
  if (value !== void 0 &&
27
- value !== exports.defaultCommonProps[attr]) {
27
+ (!compareDefaultValues ||
28
+ value !== exports.defaultCommonProps[attr])) {
28
29
  result[attr] = value;
29
30
  }
30
31
  });
@@ -8,11 +8,11 @@ var defaultCommonProps = {
8
8
  ...extraDefaultProps
9
9
  };
10
10
  var props = Object.keys(defaultCommonProps);
11
- function filterProps(data) {
11
+ function filterProps(data, compareDefaultValues) {
12
12
  const result = {};
13
13
  props.forEach((attr) => {
14
14
  const value = data[attr];
15
- if (value !== void 0 && value !== defaultCommonProps[attr]) {
15
+ if (value !== void 0 && (!compareDefaultValues || value !== defaultCommonProps[attr])) {
16
16
  result[attr] = value;
17
17
  }
18
18
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFigmaIconNodes = void 0;
4
- // eslint-disable-next-line @typescript-eslint/no-unused-vars-experimental, @typescript-eslint/no-unused-vars
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
5
  function assertNever(v) {
6
6
  //
7
7
  }
@@ -24,9 +24,8 @@ async function getFigmaIconNodes(document, options) {
24
24
  if (iconNode.absoluteBoundingBox) {
25
25
  const box = iconNode.absoluteBoundingBox;
26
26
  const item = {
27
- id: node.id,
27
+ ...node,
28
28
  type: iconNodeType,
29
- name: node.name,
30
29
  width: box.width,
31
30
  height: box.height,
32
31
  parents,
@@ -70,9 +69,8 @@ async function getFigmaIconNodes(document, options) {
70
69
  case 'FRAME':
71
70
  case 'GROUP': {
72
71
  const parentItem = {
73
- id: node.id,
72
+ ...node,
74
73
  type: parentNodeType,
75
- name: node.name,
76
74
  };
77
75
  const newParents = parents.concat([parentItem]);
78
76
  if (!parents.length && options.pages) {
@@ -16,9 +16,8 @@ async function getFigmaIconNodes(document, options) {
16
16
  if (iconNode.absoluteBoundingBox) {
17
17
  const box = iconNode.absoluteBoundingBox;
18
18
  const item = {
19
- id: node.id,
19
+ ...node,
20
20
  type: iconNodeType,
21
- name: node.name,
22
21
  width: box.width,
23
22
  height: box.height,
24
23
  parents
@@ -57,9 +56,8 @@ async function getFigmaIconNodes(document, options) {
57
56
  case "FRAME":
58
57
  case "GROUP": {
59
58
  const parentItem = {
60
- id: node.id,
61
- type: parentNodeType,
62
- name: node.name
59
+ ...node,
60
+ type: parentNodeType
63
61
  };
64
62
  const newParents = parents.concat([parentItem]);
65
63
  if (!parents.length && options.pages) {
package/lib/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export { importDirectory } from './import/directory';
15
15
  export { downloadGitRepo } from './download/git/index';
16
16
  export { getGitRepoHash } from './download/git/hash';
17
17
  export { getGitRepoBranch } from './download/git/branch';
18
+ export { resetGitRepoContents } from './download/git/reset';
18
19
  export { downloadGitHubRepo } from './download/github/index';
19
20
  export { getGitHubRepoHash } from './download/github/hash';
20
21
  export { downloadGitLabRepo } from './download/gitlab/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.bumpVersion = exports.cleanupIconKeyword = exports.execAsync = exports.untar = exports.unzip = exports.compareDirectories = exports.scanDirectory = exports.prepareDirectoryForExport = exports.writeJSONFile = exports.exportJSONPackage = exports.exportIconPackage = exports.exportToDirectory = exports.cleanupGlobalStyle = 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.analyseSVGStructure = 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.cleanupGlobalStyle = 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.resetGitRepoContents = 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.analyseSVGStructure = 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; } });
@@ -41,6 +41,8 @@ var hash_1 = require("./download/git/hash");
41
41
  Object.defineProperty(exports, "getGitRepoHash", { enumerable: true, get: function () { return hash_1.getGitRepoHash; } });
42
42
  var branch_1 = require("./download/git/branch");
43
43
  Object.defineProperty(exports, "getGitRepoBranch", { enumerable: true, get: function () { return branch_1.getGitRepoBranch; } });
44
+ var reset_1 = require("./download/git/reset");
45
+ Object.defineProperty(exports, "resetGitRepoContents", { enumerable: true, get: function () { return reset_1.resetGitRepoContents; } });
44
46
  var index_5 = require("./download/github/index");
45
47
  Object.defineProperty(exports, "downloadGitHubRepo", { enumerable: true, get: function () { return index_5.downloadGitHubRepo; } });
46
48
  var hash_2 = require("./download/github/hash");
package/lib/index.mjs CHANGED
@@ -16,6 +16,7 @@ import { importDirectory } from "./import/directory.mjs";
16
16
  import { downloadGitRepo } from "./download/git/index.mjs";
17
17
  import { getGitRepoHash } from "./download/git/hash.mjs";
18
18
  import { getGitRepoBranch } from "./download/git/branch.mjs";
19
+ import { resetGitRepoContents } from "./download/git/reset.mjs";
19
20
  import { downloadGitHubRepo } from "./download/github/index.mjs";
20
21
  import { getGitHubRepoHash } from "./download/github/hash.mjs";
21
22
  import { downloadGitLabRepo } from "./download/gitlab/index.mjs";
@@ -81,6 +82,7 @@ export {
81
82
  parseSVGStyle,
82
83
  prepareDirectoryForExport,
83
84
  removeBadAttributes,
85
+ resetGitRepoContents,
84
86
  runSVGO,
85
87
  scaleSVG,
86
88
  scanDirectory,
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.12",
5
+ "version": "2.0.13",
6
6
  "license": "MIT",
7
7
  "bugs": "https://github.com/iconify/tools/issues",
8
8
  "homepage": "https://github.com/iconify/tools",
@@ -120,6 +120,10 @@
120
120
  "require": "./lib/download/git/index.js",
121
121
  "import": "./lib/download/git/index.mjs"
122
122
  },
123
+ "./lib/download/git/reset": {
124
+ "require": "./lib/download/git/reset.js",
125
+ "import": "./lib/download/git/reset.mjs"
126
+ },
123
127
  "./lib/download/github/hash": {
124
128
  "require": "./lib/download/github/hash.js",
125
129
  "import": "./lib/download/github/hash.mjs"