@iconify/tools 2.0.0-dev.3 → 2.0.2

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 (107) 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/css/parser/text.js +3 -6
  9. package/lib/css/parser/text.mjs +3 -3
  10. package/lib/{api → download/api}/cache.d.ts +0 -0
  11. package/lib/{api → download/api}/cache.js +1 -1
  12. package/lib/{api → download/api}/cache.mjs +2 -2
  13. package/lib/download/api/download.d.ts +5 -0
  14. package/lib/download/api/download.js +27 -0
  15. package/lib/download/api/download.mjs +21 -0
  16. package/lib/{api → download/api}/index.d.ts +0 -0
  17. package/lib/{api → download/api}/index.js +2 -2
  18. package/lib/{api → download/api}/index.mjs +3 -3
  19. package/lib/{api → download/api}/types.d.ts +0 -0
  20. package/lib/{api → download/api}/types.js +0 -0
  21. package/lib/{api → download/api}/types.mjs +0 -0
  22. package/lib/download/git/hash.d.ts +5 -0
  23. package/lib/download/git/hash.js +14 -0
  24. package/lib/download/git/hash.mjs +11 -0
  25. package/lib/download/git/index.d.ts +26 -0
  26. package/lib/download/git/index.js +52 -0
  27. package/lib/download/git/index.mjs +44 -0
  28. package/lib/download/github/hash.d.ts +5 -0
  29. package/lib/download/github/hash.js +28 -0
  30. package/lib/download/github/hash.mjs +25 -0
  31. package/lib/download/github/index.d.ts +28 -0
  32. package/lib/download/github/index.js +105 -0
  33. package/lib/download/github/index.mjs +83 -0
  34. package/lib/download/github/types.d.ts +9 -0
  35. package/lib/download/github/types.js +2 -0
  36. package/lib/download/github/types.mjs +0 -0
  37. package/lib/download/helpers/untar.d.ts +4 -0
  38. package/lib/download/helpers/untar.js +14 -0
  39. package/lib/download/helpers/untar.mjs +11 -0
  40. package/lib/download/helpers/unzip.d.ts +4 -0
  41. package/lib/download/helpers/unzip.js +18 -0
  42. package/lib/download/helpers/unzip.mjs +12 -0
  43. package/lib/download/npm/index.d.ts +27 -0
  44. package/lib/download/npm/index.js +73 -0
  45. package/lib/download/npm/index.mjs +63 -0
  46. package/lib/download/npm/types.d.ts +7 -0
  47. package/lib/download/npm/types.js +2 -0
  48. package/lib/download/npm/types.mjs +0 -0
  49. package/lib/download/npm/version.d.ts +13 -0
  50. package/lib/download/npm/version.js +27 -0
  51. package/lib/download/npm/version.mjs +20 -0
  52. package/lib/download/types/modified.d.ts +4 -0
  53. package/lib/download/types/modified.js +2 -0
  54. package/lib/download/types/modified.mjs +0 -0
  55. package/lib/export/directory.d.ts +2 -2
  56. package/lib/export/directory.js +2 -2
  57. package/lib/export/directory.mjs +2 -2
  58. package/lib/export/helpers/custom-files.d.ts +10 -0
  59. package/lib/export/helpers/custom-files.js +32 -0
  60. package/lib/export/helpers/custom-files.mjs +25 -0
  61. package/lib/export/{prepare.d.ts → helpers/prepare.d.ts} +4 -0
  62. package/lib/export/{prepare.js → helpers/prepare.js} +14 -5
  63. package/lib/export/{prepare.mjs → helpers/prepare.mjs} +9 -4
  64. package/lib/export/helpers/types-version.d.ts +4 -0
  65. package/lib/export/helpers/types-version.js +12 -0
  66. package/lib/export/helpers/types-version.mjs +40 -0
  67. package/lib/export/icon-package.d.ts +17 -0
  68. package/lib/export/icon-package.js +77 -0
  69. package/lib/export/icon-package.mjs +56 -0
  70. package/lib/export/json-package.d.ts +15 -0
  71. package/lib/export/json-package.js +151 -0
  72. package/lib/export/json-package.mjs +127 -0
  73. package/lib/icon-set/index.js +1 -2
  74. package/lib/icon-set/index.mjs +1 -1
  75. package/lib/import/figma/index.d.ts +5 -3
  76. package/lib/import/figma/index.js +0 -3
  77. package/lib/import/figma/query.d.ts +6 -4
  78. package/lib/import/figma/query.js +2 -5
  79. package/lib/import/figma/query.mjs +6 -2
  80. package/lib/import/figma/types/options.d.ts +4 -2
  81. package/lib/import/figma/types/result.d.ts +0 -4
  82. package/lib/index.d.ts +37 -0
  83. package/lib/index.js +89 -0
  84. package/lib/index.mjs +80 -0
  85. package/lib/misc/bump-version.d.ts +4 -0
  86. package/lib/misc/bump-version.js +19 -0
  87. package/lib/misc/bump-version.mjs +15 -0
  88. package/lib/misc/compare-dirs.d.ts +9 -0
  89. package/lib/misc/compare-dirs.js +84 -0
  90. package/lib/misc/compare-dirs.mjs +71 -0
  91. package/lib/misc/exec.d.ts +10 -0
  92. package/lib/misc/exec.js +26 -0
  93. package/lib/misc/exec.mjs +22 -0
  94. package/lib/misc/keyword.js +1 -1
  95. package/lib/misc/keyword.mjs +1 -1
  96. package/lib/misc/scan.d.ts +1 -1
  97. package/lib/misc/scan.js +14 -8
  98. package/lib/misc/scan.mjs +11 -6
  99. package/lib/misc/write-json.d.ts +4 -0
  100. package/lib/misc/write-json.js +11 -0
  101. package/lib/misc/write-json.mjs +8 -0
  102. package/lib/optimise/svgo.js +3 -1
  103. package/lib/optimise/svgo.mjs +2 -1
  104. package/lib/svg/index.d.ts +3 -0
  105. package/lib/svg/index.js +3 -0
  106. package/license.txt +21 -0
  107. package/package.json +138 -27
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareDirectoryForExport = void 0;
3
+ exports.prepareDirectoryForExport = exports.normalizeDir = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const pathe_1 = require("pathe");
6
+ /**
7
+ * Normalize directory
8
+ */
9
+ function normalizeDir(dir) {
10
+ // Normalise directory
11
+ dir = (0, pathe_1.normalize)(dir);
12
+ if (dir.slice(-1) === '/') {
13
+ dir = dir.slice(0, -1);
14
+ }
15
+ return dir;
16
+ }
17
+ exports.normalizeDir = normalizeDir;
6
18
  /**
7
19
  * Prepare directory for export
8
20
  *
@@ -10,10 +22,7 @@ const pathe_1 = require("pathe");
10
22
  */
11
23
  async function prepareDirectoryForExport(options) {
12
24
  // Normalise directory
13
- let dir = (0, pathe_1.normalize)(options.target);
14
- if (dir.slice(-1) === '/') {
15
- dir = dir.slice(0, dir.length - 1);
16
- }
25
+ const dir = normalizeDir(options.target);
17
26
  if (options.cleanup) {
18
27
  // Remove old files
19
28
  try {
@@ -1,11 +1,15 @@
1
- // src/export/prepare.ts
1
+ // src/export/helpers/prepare.ts
2
2
  import { promises as fs } from "fs";
3
3
  import { normalize } from "pathe";
4
- async function prepareDirectoryForExport(options) {
5
- let dir = normalize(options.target);
4
+ function normalizeDir(dir) {
5
+ dir = normalize(dir);
6
6
  if (dir.slice(-1) === "/") {
7
- dir = dir.slice(0, dir.length - 1);
7
+ dir = dir.slice(0, -1);
8
8
  }
9
+ return dir;
10
+ }
11
+ async function prepareDirectoryForExport(options) {
12
+ const dir = normalizeDir(options.target);
9
13
  if (options.cleanup) {
10
14
  try {
11
15
  await fs.rm(dir, {
@@ -24,5 +28,6 @@ async function prepareDirectoryForExport(options) {
24
28
  return dir;
25
29
  }
26
30
  export {
31
+ normalizeDir,
27
32
  prepareDirectoryForExport
28
33
  };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Get current version of Iconify Types package
3
+ */
4
+ export declare function getTypesVersion(): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypesVersion = void 0;
4
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
5
+ const pkg = require('@iconify/types/package.json');
6
+ /**
7
+ * Get current version of Iconify Types package
8
+ */
9
+ function getTypesVersion() {
10
+ return pkg.version;
11
+ }
12
+ exports.getTypesVersion = getTypesVersion;
@@ -0,0 +1,40 @@
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
+
33
+ // src/export/helpers/types-version.ts
34
+ var pkg = require_package();
35
+ function getTypesVersion() {
36
+ return pkg.version;
37
+ }
38
+ export {
39
+ getTypesVersion
40
+ };
@@ -0,0 +1,17 @@
1
+ import type { IconSet } from '../icon-set';
2
+ import type { ExportTargetOptions } from './helpers/prepare';
3
+ import { ExportOptionsWithCustomFiles } from './helpers/custom-files';
4
+ /**
5
+ * Options
6
+ */
7
+ export interface ExportIconPackageOptions extends ExportTargetOptions, ExportOptionsWithCustomFiles {
8
+ package?: Record<string, unknown>;
9
+ module?: boolean;
10
+ typesContent?: string;
11
+ }
12
+ /**
13
+ * Export icon set as single icon packages
14
+ *
15
+ * Used for exporting `@iconify-icons/{prefix}` packages
16
+ */
17
+ export declare function exportIconPackage(iconSet: IconSet, options: ExportIconPackageOptions): Promise<string[]>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportIconPackage = void 0;
4
+ const fs_1 = require("fs");
5
+ const prepare_1 = require("./helpers/prepare");
6
+ const write_json_1 = require("../misc/write-json");
7
+ const types_version_1 = require("./helpers/types-version");
8
+ const custom_files_1 = require("./helpers/custom-files");
9
+ /**
10
+ * Content for .d.ts files
11
+ */
12
+ const defaultTypesContent = `import type { IconifyIcon } from '@iconify/types';
13
+ declare const data: IconifyIcon;
14
+ export default data;
15
+ `;
16
+ /**
17
+ * Export icon set as single icon packages
18
+ *
19
+ * Used for exporting `@iconify-icons/{prefix}` packages
20
+ */
21
+ async function exportIconPackage(iconSet, options) {
22
+ const files = new Set();
23
+ const esm = options.module !== false;
24
+ // Normalise and prepare directory
25
+ const dir = await (0, prepare_1.prepareDirectoryForExport)(options);
26
+ // Write all icons
27
+ const typesContent = options.typesContent || defaultTypesContent;
28
+ await iconSet.forEach(async (name) => {
29
+ const data = iconSet.resolve(name, false);
30
+ if (!data) {
31
+ return;
32
+ }
33
+ // Store types
34
+ const typesFilename = name + '.d.ts';
35
+ await fs_1.promises.writeFile(`${dir}/${typesFilename}`, typesContent, 'utf8');
36
+ files.add(typesFilename);
37
+ // Generate content
38
+ let content = `const data = ` + JSON.stringify(data, null, '\t') + ';\n';
39
+ if (!esm) {
40
+ // CJS module
41
+ content += 'exports.__esModule = true;\nexports.default = data;\n';
42
+ }
43
+ else {
44
+ // ES module
45
+ content += 'export default data;\n';
46
+ }
47
+ const contentFilename = name + '.js';
48
+ await fs_1.promises.writeFile(`${dir}/${contentFilename}`, content, 'utf8');
49
+ files.add(contentFilename);
50
+ });
51
+ // Write custom files
52
+ await (0, custom_files_1.exportCustomFiles)(dir, options, files);
53
+ // Generate package.json
54
+ const info = iconSet.info;
55
+ const { name, description, version, dependencies, ...customPackageProps } = options.package || {};
56
+ const packageJSON = {
57
+ name: name ||
58
+ (esm
59
+ ? `@iconify-icons/${iconSet.prefix}`
60
+ : `@iconify/icons-${iconSet.prefix}`),
61
+ description: description ||
62
+ `Iconify icon components for ${info ? info.name : iconSet.prefix}`,
63
+ version,
64
+ type: esm ? 'module' : void 0,
65
+ iconSetInfo: info,
66
+ ...customPackageProps,
67
+ dependencies: dependencies || {
68
+ '@iconify/types': '^' + (0, types_version_1.getTypesVersion)(),
69
+ },
70
+ };
71
+ // Save package.json
72
+ await (0, write_json_1.writeJSONFile)(dir + '/package.json', packageJSON);
73
+ files.add('package.json');
74
+ // Return list of stored files as array
75
+ return Array.from(files);
76
+ }
77
+ exports.exportIconPackage = exportIconPackage;
@@ -0,0 +1,56 @@
1
+ // src/export/icon-package.ts
2
+ import { promises as fs } from "fs";
3
+ import { prepareDirectoryForExport } from "./helpers/prepare.mjs";
4
+ import { writeJSONFile } from "../misc/write-json.mjs";
5
+ import { getTypesVersion } from "./helpers/types-version.mjs";
6
+ import {
7
+ exportCustomFiles
8
+ } from "./helpers/custom-files.mjs";
9
+ var defaultTypesContent = `import type { IconifyIcon } from '@iconify/types';
10
+ declare const data: IconifyIcon;
11
+ export default data;
12
+ `;
13
+ async function exportIconPackage(iconSet, options) {
14
+ const files = new Set();
15
+ const esm = options.module !== false;
16
+ const dir = await prepareDirectoryForExport(options);
17
+ const typesContent = options.typesContent || defaultTypesContent;
18
+ await iconSet.forEach(async (name2) => {
19
+ const data = iconSet.resolve(name2, false);
20
+ if (!data) {
21
+ return;
22
+ }
23
+ const typesFilename = name2 + ".d.ts";
24
+ await fs.writeFile(`${dir}/${typesFilename}`, typesContent, "utf8");
25
+ files.add(typesFilename);
26
+ let content = `const data = ` + JSON.stringify(data, null, " ") + ";\n";
27
+ if (!esm) {
28
+ content += "exports.__esModule = true;\nexports.default = data;\n";
29
+ } else {
30
+ content += "export default data;\n";
31
+ }
32
+ const contentFilename = name2 + ".js";
33
+ await fs.writeFile(`${dir}/${contentFilename}`, content, "utf8");
34
+ files.add(contentFilename);
35
+ });
36
+ await exportCustomFiles(dir, options, files);
37
+ const info = iconSet.info;
38
+ const { name, description, version, dependencies, ...customPackageProps } = options.package || {};
39
+ const packageJSON = {
40
+ name: name || (esm ? `@iconify-icons/${iconSet.prefix}` : `@iconify/icons-${iconSet.prefix}`),
41
+ description: description || `Iconify icon components for ${info ? info.name : iconSet.prefix}`,
42
+ version,
43
+ type: esm ? "module" : void 0,
44
+ iconSetInfo: info,
45
+ ...customPackageProps,
46
+ dependencies: dependencies || {
47
+ "@iconify/types": "^" + getTypesVersion()
48
+ }
49
+ };
50
+ await writeJSONFile(dir + "/package.json", packageJSON);
51
+ files.add("package.json");
52
+ return Array.from(files);
53
+ }
54
+ export {
55
+ exportIconPackage
56
+ };
@@ -0,0 +1,15 @@
1
+ import type { IconSet } from '../icon-set';
2
+ import type { ExportTargetOptions } from './helpers/prepare';
3
+ import { ExportOptionsWithCustomFiles } from './helpers/custom-files';
4
+ /**
5
+ * Options
6
+ */
7
+ export interface ExportJSONPackageOptions extends ExportTargetOptions, ExportOptionsWithCustomFiles {
8
+ package?: Record<string, unknown>;
9
+ }
10
+ /**
11
+ * Export icon set as JSON package
12
+ *
13
+ * Used for exporting `@iconify-json/{prefix}` packages
14
+ */
15
+ export declare function exportJSONPackage(iconSet: IconSet, options: ExportJSONPackageOptions): Promise<string[]>;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportJSONPackage = void 0;
4
+ const fs_1 = require("fs");
5
+ const icon_1 = require("@iconify/utils/lib/icon");
6
+ const prepare_1 = require("./helpers/prepare");
7
+ const write_json_1 = require("../misc/write-json");
8
+ const types_version_1 = require("./helpers/types-version");
9
+ const custom_files_1 = require("./helpers/custom-files");
10
+ const exportTypes = {
11
+ icons: 'IconifyJSON',
12
+ info: 'IconifyInfo',
13
+ metadata: 'IconifyMetaData',
14
+ chars: 'IconifyChars',
15
+ };
16
+ const iconsKeys = ['aliases'].concat(Object.keys(icon_1.iconDefaults));
17
+ const metadataKeys = [
18
+ 'categories',
19
+ 'themes',
20
+ 'prefixes',
21
+ 'suffixes',
22
+ ];
23
+ /**
24
+ * Export icon set as JSON package
25
+ *
26
+ * Used for exporting `@iconify-json/{prefix}` packages
27
+ */
28
+ async function exportJSONPackage(iconSet, options) {
29
+ const files = new Set();
30
+ // Normalise and prepare directory
31
+ const dir = await (0, prepare_1.prepareDirectoryForExport)(options);
32
+ // Export icon set to IconifyJSON format
33
+ const exportedJSON = iconSet.export(true);
34
+ // Get icons
35
+ const icons = {
36
+ prefix: exportedJSON.prefix,
37
+ icons: exportedJSON.icons,
38
+ };
39
+ iconsKeys.forEach((attr) => {
40
+ if (exportedJSON[attr] !== void 0) {
41
+ icons[attr] = exportedJSON[attr];
42
+ }
43
+ });
44
+ // Get metadata
45
+ const metadata = {};
46
+ let hasMetadata = false;
47
+ metadataKeys.forEach((attr) => {
48
+ if (exportedJSON[attr]) {
49
+ metadata[attr] = exportedJSON[attr];
50
+ hasMetadata = true;
51
+ }
52
+ });
53
+ // Contents
54
+ const info = exportedJSON.info;
55
+ const contents = {
56
+ icons,
57
+ info,
58
+ metadata: hasMetadata ? metadata : void 0,
59
+ chars: exportedJSON.chars,
60
+ };
61
+ // Generate package.json
62
+ const { name, description, version, dependencies, ...customPackageProps } = options.package || {};
63
+ const packageJSONIconSet = {};
64
+ const packageJSONExports = {
65
+ './*': './*',
66
+ '.': {
67
+ require: './index.js',
68
+ import: './index.mjs',
69
+ },
70
+ };
71
+ const packageJSON = {
72
+ name: name || `@iconify-json/${iconSet.prefix}`,
73
+ description: description ||
74
+ `${info ? info.name : iconSet.prefix} icon set in Iconify JSON format`,
75
+ version,
76
+ iconSetVersion: info === null || info === void 0 ? void 0 : info.version,
77
+ main: 'index.js',
78
+ module: 'index.mjs',
79
+ types: 'index.d.ts',
80
+ ...customPackageProps,
81
+ exports: packageJSONExports,
82
+ iconSet: packageJSONIconSet,
83
+ dependencies: dependencies || {
84
+ '@iconify/types': '^' + (0, types_version_1.getTypesVersion)(),
85
+ },
86
+ };
87
+ // Save all files, generate exports
88
+ const dtsContent = [];
89
+ const cjsImports = [];
90
+ const cjsExports = [];
91
+ const mjsImports = [];
92
+ const mjsConsts = [];
93
+ const mjsExports = [];
94
+ for (const key in contents) {
95
+ const attr = key;
96
+ const data = contents[attr];
97
+ const type = exportTypes[attr];
98
+ const jsonFilename = attr + '.json';
99
+ const relativeFile = `./${jsonFilename}`;
100
+ // Add type
101
+ dtsContent.push(`export declare const ${attr}: ${type};`);
102
+ // Export variable
103
+ cjsExports.push(`exports.${attr} = ${attr};`);
104
+ mjsExports.push(attr);
105
+ if (data !== void 0) {
106
+ // Save JSON file
107
+ await (0, write_json_1.writeJSONFile)(`${dir}/${jsonFilename}`, data);
108
+ // Import data from JSON file
109
+ cjsImports.push(`const ${attr} = require('${relativeFile}');`);
110
+ mjsImports.push(`import ${attr} from '${relativeFile}';`);
111
+ // Add data to package.json
112
+ packageJSONIconSet[attr] = attr + '.json';
113
+ packageJSONExports[relativeFile] = relativeFile;
114
+ }
115
+ else {
116
+ // Create empty data
117
+ await (0, write_json_1.writeJSONFile)(`${dir}/${jsonFilename}`, {});
118
+ cjsImports.push(`const ${attr} = {};`);
119
+ mjsConsts.push(`const ${attr} = {};`);
120
+ }
121
+ files.add(jsonFilename);
122
+ }
123
+ // Generate CJS index file
124
+ const cjsContent = cjsImports.concat([''], cjsExports);
125
+ await fs_1.promises.writeFile(dir + '/index.js', cjsContent.join('\n') + '\n', 'utf8');
126
+ files.add('index.js');
127
+ // Generate MJS index file
128
+ const mjsContent = mjsImports.concat([''], mjsConsts, [
129
+ `export { ${mjsExports.join(', ')} };`,
130
+ ]);
131
+ await fs_1.promises.writeFile(dir + '/index.mjs', mjsContent.join('\n') + '\n', 'utf8');
132
+ files.add('index.mjs');
133
+ // Generate types file
134
+ const usedTypes = Object.values(exportTypes);
135
+ const typesData = [
136
+ `import type { ${usedTypes.join(', ')} } from '@iconify/types';`,
137
+ '',
138
+ `export { ${usedTypes.join(', ')} };`,
139
+ '',
140
+ ].concat(dtsContent);
141
+ await fs_1.promises.writeFile(dir + '/index.d.ts', typesData.join('\n') + '\n', 'utf8');
142
+ files.add('index.d.ts');
143
+ // Write custom files
144
+ await (0, custom_files_1.exportCustomFiles)(dir, options, files);
145
+ // Save package.json
146
+ await (0, write_json_1.writeJSONFile)(dir + '/package.json', packageJSON);
147
+ files.add('package.json');
148
+ // Return list of stored files as array
149
+ return Array.from(files);
150
+ }
151
+ exports.exportJSONPackage = exportJSONPackage;
@@ -0,0 +1,127 @@
1
+ // src/export/json-package.ts
2
+ import { promises as fs } from "fs";
3
+ import { iconDefaults } from "@iconify/utils/lib/icon";
4
+ import { prepareDirectoryForExport } from "./helpers/prepare.mjs";
5
+ import { writeJSONFile } from "../misc/write-json.mjs";
6
+ import { getTypesVersion } from "./helpers/types-version.mjs";
7
+ import {
8
+ exportCustomFiles
9
+ } from "./helpers/custom-files.mjs";
10
+ var exportTypes = {
11
+ icons: "IconifyJSON",
12
+ info: "IconifyInfo",
13
+ metadata: "IconifyMetaData",
14
+ chars: "IconifyChars"
15
+ };
16
+ var iconsKeys = ["aliases"].concat(Object.keys(iconDefaults));
17
+ var metadataKeys = [
18
+ "categories",
19
+ "themes",
20
+ "prefixes",
21
+ "suffixes"
22
+ ];
23
+ async function exportJSONPackage(iconSet, options) {
24
+ const files = new Set();
25
+ const dir = await prepareDirectoryForExport(options);
26
+ const exportedJSON = iconSet.export(true);
27
+ const icons = {
28
+ prefix: exportedJSON.prefix,
29
+ icons: exportedJSON.icons
30
+ };
31
+ iconsKeys.forEach((attr) => {
32
+ if (exportedJSON[attr] !== void 0) {
33
+ icons[attr] = exportedJSON[attr];
34
+ }
35
+ });
36
+ const metadata = {};
37
+ let hasMetadata = false;
38
+ metadataKeys.forEach((attr) => {
39
+ if (exportedJSON[attr]) {
40
+ metadata[attr] = exportedJSON[attr];
41
+ hasMetadata = true;
42
+ }
43
+ });
44
+ const info = exportedJSON.info;
45
+ const contents = {
46
+ icons,
47
+ info,
48
+ metadata: hasMetadata ? metadata : void 0,
49
+ chars: exportedJSON.chars
50
+ };
51
+ const { name, description, version, dependencies, ...customPackageProps } = options.package || {};
52
+ const packageJSONIconSet = {};
53
+ const packageJSONExports = {
54
+ "./*": "./*",
55
+ ".": {
56
+ require: "./index.js",
57
+ import: "./index.mjs"
58
+ }
59
+ };
60
+ const packageJSON = {
61
+ name: name || `@iconify-json/${iconSet.prefix}`,
62
+ description: description || `${info ? info.name : iconSet.prefix} icon set in Iconify JSON format`,
63
+ version,
64
+ iconSetVersion: info == null ? void 0 : info.version,
65
+ main: "index.js",
66
+ module: "index.mjs",
67
+ types: "index.d.ts",
68
+ ...customPackageProps,
69
+ exports: packageJSONExports,
70
+ iconSet: packageJSONIconSet,
71
+ dependencies: dependencies || {
72
+ "@iconify/types": "^" + getTypesVersion()
73
+ }
74
+ };
75
+ const dtsContent = [];
76
+ const cjsImports = [];
77
+ const cjsExports = [];
78
+ const mjsImports = [];
79
+ const mjsConsts = [];
80
+ const mjsExports = [];
81
+ for (const key in contents) {
82
+ const attr = key;
83
+ const data = contents[attr];
84
+ const type = exportTypes[attr];
85
+ const jsonFilename = attr + ".json";
86
+ const relativeFile = `./${jsonFilename}`;
87
+ dtsContent.push(`export declare const ${attr}: ${type};`);
88
+ cjsExports.push(`exports.${attr} = ${attr};`);
89
+ mjsExports.push(attr);
90
+ if (data !== void 0) {
91
+ await writeJSONFile(`${dir}/${jsonFilename}`, data);
92
+ cjsImports.push(`const ${attr} = require('${relativeFile}');`);
93
+ mjsImports.push(`import ${attr} from '${relativeFile}';`);
94
+ packageJSONIconSet[attr] = attr + ".json";
95
+ packageJSONExports[relativeFile] = relativeFile;
96
+ } else {
97
+ await writeJSONFile(`${dir}/${jsonFilename}`, {});
98
+ cjsImports.push(`const ${attr} = {};`);
99
+ mjsConsts.push(`const ${attr} = {};`);
100
+ }
101
+ files.add(jsonFilename);
102
+ }
103
+ const cjsContent = cjsImports.concat([""], cjsExports);
104
+ await fs.writeFile(dir + "/index.js", cjsContent.join("\n") + "\n", "utf8");
105
+ files.add("index.js");
106
+ const mjsContent = mjsImports.concat([""], mjsConsts, [
107
+ `export { ${mjsExports.join(", ")} };`
108
+ ]);
109
+ await fs.writeFile(dir + "/index.mjs", mjsContent.join("\n") + "\n", "utf8");
110
+ files.add("index.mjs");
111
+ const usedTypes = Object.values(exportTypes);
112
+ const typesData = [
113
+ `import type { ${usedTypes.join(", ")} } from '@iconify/types';`,
114
+ "",
115
+ `export { ${usedTypes.join(", ")} };`,
116
+ ""
117
+ ].concat(dtsContent);
118
+ await fs.writeFile(dir + "/index.d.ts", typesData.join("\n") + "\n", "utf8");
119
+ files.add("index.d.ts");
120
+ await exportCustomFiles(dir, options, files);
121
+ await writeJSONFile(dir + "/package.json", packageJSON);
122
+ files.add("package.json");
123
+ return Array.from(files);
124
+ }
125
+ export {
126
+ exportJSONPackage
127
+ };
@@ -130,8 +130,7 @@ class IconSet {
130
130
  // Prefix ending with with '-'
131
131
  const prefix = item.prefix;
132
132
  if (prefix.slice(-1) === '-') {
133
- prefixes[prefix.slice(0, prefix.length - 1)] =
134
- item.title;
133
+ prefixes[prefix.slice(0, -1)] = item.title;
135
134
  }
136
135
  }
137
136
  if (typeof item.suffix === 'string') {
@@ -98,7 +98,7 @@ var IconSet = class {
98
98
  if (typeof item.prefix === "string") {
99
99
  const prefix = item.prefix;
100
100
  if (prefix.slice(-1) === "-") {
101
- prefixes[prefix.slice(0, prefix.length - 1)] = item.title;
101
+ prefixes[prefix.slice(0, -1)] = item.title;
102
102
  }
103
103
  }
104
104
  if (typeof item.suffix === "string") {
@@ -1,6 +1,8 @@
1
- import type { FigmaImportOptions } from './types/options';
2
- import type { FigmaDocumentNotModified, FigmaImportResult } from './types/result';
1
+ import type { DocumentNotModified } from '../../download/types/modified';
2
+ import type { FigmaImportOptions, FigmaIfModifiedSinceOption } from './types/options';
3
+ import type { FigmaImportResult } from './types/result';
3
4
  /**
4
5
  * Import icon set from Figma
5
6
  */
6
- export declare function importFromFigma(options: FigmaImportOptions): Promise<FigmaImportResult | FigmaDocumentNotModified>;
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,11 +1,13 @@
1
- import type { APICacheOptions } from '../../api/types';
1
+ import type { APICacheOptions } from '../../download/api/types';
2
+ import type { DocumentNotModified } from '../../download/types/modified';
2
3
  import type { FigmaDocument } from './types/api';
3
- import type { FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
4
- import type { FigmaDocumentNotModified, FigmaNodesImportResult } from './types/result';
4
+ import type { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
5
+ import type { FigmaNodesImportResult } from './types/result';
5
6
  /**
6
7
  * Get Figma files
7
8
  */
8
- export declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument | FigmaDocumentNotModified>;
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>;
9
11
  /**
10
12
  * Generate all images
11
13
  */
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.figmaDownloadImages = exports.figmaImagesQuery = exports.figmaFilesQuery = void 0;
4
- const api_1 = require("../../api");
5
- const cache_1 = require("../../api/cache");
4
+ const api_1 = require("../../download/api");
5
+ const cache_1 = require("../../download/api/cache");
6
6
  /**
7
7
  * Compare last modified dates
8
8
  */
@@ -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) {
@@ -1,6 +1,10 @@
1
1
  // src/import/figma/query.ts
2
- import { sendAPIQuery } from "../../api/index.mjs";
3
- import { apiCacheKey, clearAPICache, getAPICache } from "../../api/cache.mjs";
2
+ import { sendAPIQuery } from "../../download/api/index.mjs";
3
+ import {
4
+ apiCacheKey,
5
+ clearAPICache,
6
+ getAPICache
7
+ } from "../../download/api/cache.mjs";
4
8
  function identicalDates(actual, expected) {
5
9
  if (typeof actual !== "string") {
6
10
  return false;