@iconify/tools 2.0.12 → 2.0.15

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 (308) hide show
  1. package/lib/colors/attribs.cjs +30 -0
  2. package/lib/colors/attribs.d.ts +13 -10
  3. package/lib/colors/attribs.mjs +7 -13
  4. package/lib/colors/parse.cjs +269 -0
  5. package/lib/colors/parse.d.ts +15 -11
  6. package/lib/colors/parse.mjs +27 -31
  7. package/lib/colors/validate.cjs +52 -0
  8. package/lib/colors/validate.d.ts +11 -4
  9. package/lib/colors/validate.mjs +19 -6
  10. package/lib/css/parse.cjs +26 -0
  11. package/lib/css/parse.d.ts +3 -1
  12. package/lib/css/parse.mjs +8 -6
  13. package/lib/css/parser/error.cjs +25 -0
  14. package/lib/css/parser/error.d.ts +4 -2
  15. package/lib/css/parser/error.mjs +2 -4
  16. package/lib/css/parser/export.cjs +48 -0
  17. package/lib/css/parser/export.d.ts +5 -2
  18. package/lib/css/parser/export.mjs +4 -6
  19. package/lib/css/parser/strings.cjs +77 -0
  20. package/lib/css/parser/strings.d.ts +6 -3
  21. package/lib/css/parser/strings.mjs +4 -6
  22. package/lib/css/parser/text.cjs +135 -0
  23. package/lib/css/parser/text.d.ts +8 -5
  24. package/lib/css/parser/text.mjs +3 -8
  25. package/lib/css/parser/tokens.cjs +184 -0
  26. package/lib/css/parser/tokens.d.ts +6 -3
  27. package/lib/css/parser/tokens.mjs +7 -13
  28. package/lib/css/parser/tree.cjs +42 -0
  29. package/lib/css/parser/tree.d.ts +5 -2
  30. package/lib/css/parser/tree.mjs +2 -4
  31. package/lib/css/parser/types.cjs +2 -0
  32. package/lib/css/parser/types.d.ts +13 -11
  33. package/lib/css/parser/types.mjs +1 -0
  34. package/lib/download/api/cache.cjs +86 -0
  35. package/lib/download/api/cache.d.ts +8 -5
  36. package/lib/download/api/cache.mjs +14 -19
  37. package/lib/download/api/download.cjs +28 -0
  38. package/lib/download/api/download.d.ts +5 -2
  39. package/lib/download/api/download.mjs +8 -9
  40. package/lib/download/api/index.cjs +51 -0
  41. package/lib/download/api/index.d.ts +5 -2
  42. package/lib/download/api/index.mjs +8 -6
  43. package/lib/download/api/types.cjs +2 -0
  44. package/lib/download/api/types.d.ts +4 -2
  45. package/lib/download/api/types.mjs +1 -0
  46. package/lib/download/git/branch.cjs +22 -0
  47. package/lib/download/git/branch.d.ts +5 -2
  48. package/lib/download/git/branch.mjs +5 -5
  49. package/lib/download/git/hash.cjs +15 -0
  50. package/lib/download/git/hash.d.ts +5 -2
  51. package/lib/download/git/hash.mjs +5 -5
  52. package/lib/download/git/index.cjs +76 -0
  53. package/lib/download/git/index.d.ts +10 -8
  54. package/lib/download/git/index.mjs +42 -20
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +6 -0
  57. package/lib/download/git/reset.mjs +37 -0
  58. package/lib/download/github/hash.cjs +32 -0
  59. package/lib/download/github/hash.d.ts +5 -2
  60. package/lib/download/github/hash.mjs +10 -7
  61. package/lib/download/github/index.cjs +98 -0
  62. package/lib/download/github/index.d.ts +11 -9
  63. package/lib/download/github/index.mjs +23 -17
  64. package/lib/download/github/types.cjs +2 -0
  65. package/lib/download/github/types.d.ts +3 -1
  66. package/lib/download/github/types.mjs +1 -0
  67. package/lib/download/gitlab/hash.cjs +32 -0
  68. package/lib/download/gitlab/hash.d.ts +5 -2
  69. package/lib/download/gitlab/hash.mjs +10 -6
  70. package/lib/download/gitlab/index.cjs +98 -0
  71. package/lib/download/gitlab/index.d.ts +11 -9
  72. package/lib/download/gitlab/index.mjs +24 -18
  73. package/lib/download/gitlab/types.cjs +7 -0
  74. package/lib/download/gitlab/types.d.ts +4 -2
  75. package/lib/download/gitlab/types.mjs +3 -5
  76. package/lib/download/helpers/untar.cjs +14 -0
  77. package/lib/download/helpers/untar.d.ts +3 -1
  78. package/lib/download/helpers/untar.mjs +4 -5
  79. package/lib/download/helpers/unzip.cjs +19 -0
  80. package/lib/download/helpers/unzip.d.ts +3 -1
  81. package/lib/download/helpers/unzip.mjs +6 -7
  82. package/lib/download/index.cjs +64 -0
  83. package/lib/download/index.d.ts +18 -13
  84. package/lib/download/index.mjs +46 -19
  85. package/lib/download/npm/index.cjs +82 -0
  86. package/lib/download/npm/index.d.ts +10 -8
  87. package/lib/download/npm/index.mjs +16 -13
  88. package/lib/download/npm/types.cjs +2 -0
  89. package/lib/download/npm/types.d.ts +3 -1
  90. package/lib/download/npm/types.mjs +1 -0
  91. package/lib/download/npm/version.cjs +23 -0
  92. package/lib/download/npm/version.d.ts +7 -4
  93. package/lib/download/npm/version.mjs +8 -10
  94. package/lib/download/types/modified.cjs +2 -0
  95. package/lib/download/types/modified.d.ts +3 -1
  96. package/lib/download/types/modified.mjs +1 -0
  97. package/lib/download/types/sources.cjs +2 -0
  98. package/lib/download/types/sources.d.ts +4 -2
  99. package/lib/download/types/sources.mjs +1 -0
  100. package/lib/export/directory.cjs +45 -0
  101. package/lib/export/directory.d.ts +11 -4
  102. package/lib/export/directory.mjs +8 -8
  103. package/lib/export/helpers/custom-files.cjs +28 -0
  104. package/lib/export/helpers/custom-files.d.ts +4 -2
  105. package/lib/export/helpers/custom-files.mjs +8 -9
  106. package/lib/export/helpers/prepare.cjs +36 -0
  107. package/lib/export/helpers/prepare.d.ts +5 -3
  108. package/lib/export/helpers/prepare.mjs +7 -9
  109. package/lib/export/helpers/types-version.cjs +22 -0
  110. package/lib/export/helpers/types-version.d.ts +3 -1
  111. package/lib/export/helpers/types-version.mjs +15 -37
  112. package/lib/export/icon-package.cjs +59 -0
  113. package/lib/export/icon-package.d.ts +12 -5
  114. package/lib/export/icon-package.mjs +15 -16
  115. package/lib/export/json-package.cjs +133 -0
  116. package/lib/export/json-package.d.ts +12 -5
  117. package/lib/export/json-package.mjs +24 -22
  118. package/lib/icon-set/index.cjs +589 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +47 -57
  121. package/lib/icon-set/match.cjs +58 -0
  122. package/lib/icon-set/match.d.ts +10 -3
  123. package/lib/icon-set/match.mjs +5 -6
  124. package/lib/icon-set/merge.cjs +83 -0
  125. package/lib/icon-set/merge.d.ts +9 -2
  126. package/lib/icon-set/merge.mjs +15 -10
  127. package/lib/icon-set/props.cjs +28 -0
  128. package/lib/icon-set/props.d.ts +8 -4
  129. package/lib/icon-set/props.mjs +9 -12
  130. package/lib/icon-set/types.cjs +2 -0
  131. package/lib/icon-set/types.d.ts +19 -17
  132. package/lib/icon-set/types.mjs +1 -0
  133. package/lib/import/directory.cjs +76 -0
  134. package/lib/import/directory.d.ts +11 -5
  135. package/lib/import/directory.mjs +36 -11
  136. package/lib/import/figma/index.cjs +105 -0
  137. package/lib/import/figma/index.d.ts +15 -5
  138. package/lib/import/figma/index.mjs +40 -13
  139. package/lib/import/figma/nodes.cjs +86 -0
  140. package/lib/import/figma/nodes.d.ts +13 -4
  141. package/lib/import/figma/nodes.mjs +6 -16
  142. package/lib/import/figma/query.cjs +218 -0
  143. package/lib/import/figma/query.d.ts +18 -9
  144. package/lib/import/figma/query.mjs +9 -12
  145. package/lib/import/figma/types/api.cjs +2 -0
  146. package/lib/import/figma/types/api.d.ts +8 -7
  147. package/lib/import/figma/types/api.mjs +1 -0
  148. package/lib/import/figma/types/nodes.cjs +2 -0
  149. package/lib/import/figma/types/nodes.d.ts +16 -9
  150. package/lib/import/figma/types/nodes.mjs +1 -0
  151. package/lib/import/figma/types/options.cjs +2 -0
  152. package/lib/import/figma/types/options.d.ts +17 -10
  153. package/lib/import/figma/types/options.mjs +1 -0
  154. package/lib/import/figma/types/result.cjs +2 -0
  155. package/lib/import/figma/types/result.d.ts +12 -5
  156. package/lib/import/figma/types/result.mjs +1 -0
  157. package/lib/index.cjs +137 -0
  158. package/lib/index.d.ts +65 -43
  159. package/lib/index.mjs +83 -92
  160. package/lib/misc/bump-version.cjs +17 -0
  161. package/lib/misc/bump-version.d.ts +3 -1
  162. package/lib/misc/bump-version.mjs +2 -4
  163. package/lib/misc/compare-dirs.cjs +75 -0
  164. package/lib/misc/compare-dirs.d.ts +4 -2
  165. package/lib/misc/compare-dirs.mjs +12 -12
  166. package/lib/misc/exec.cjs +25 -0
  167. package/lib/misc/exec.d.ts +6 -4
  168. package/lib/misc/exec.mjs +4 -5
  169. package/lib/misc/keyword.cjs +19 -0
  170. package/lib/misc/keyword.d.ts +3 -1
  171. package/lib/misc/keyword.mjs +2 -4
  172. package/lib/misc/scan.cjs +51 -0
  173. package/lib/misc/scan.d.ts +7 -6
  174. package/lib/misc/scan.mjs +6 -7
  175. package/lib/misc/write-json.cjs +11 -0
  176. package/lib/misc/write-json.d.ts +3 -1
  177. package/lib/misc/write-json.mjs +5 -6
  178. package/lib/optimise/flags.cjs +252 -0
  179. package/lib/optimise/flags.d.ts +7 -2
  180. package/lib/optimise/flags.mjs +18 -19
  181. package/lib/optimise/global-style.cjs +154 -0
  182. package/lib/optimise/global-style.d.ts +7 -2
  183. package/lib/optimise/global-style.mjs +68 -47
  184. package/lib/optimise/scale.cjs +26 -0
  185. package/lib/optimise/scale.d.ts +7 -2
  186. package/lib/optimise/scale.mjs +5 -5
  187. package/lib/optimise/svgo.cjs +83 -0
  188. package/lib/optimise/svgo.d.ts +10 -6
  189. package/lib/optimise/svgo.mjs +6 -9
  190. package/lib/svg/analyse/error.cjs +18 -0
  191. package/lib/svg/analyse/error.d.ts +5 -2
  192. package/lib/svg/analyse/error.mjs +2 -4
  193. package/lib/svg/analyse/types.cjs +2 -0
  194. package/lib/svg/analyse/types.d.ts +11 -11
  195. package/lib/svg/analyse/types.mjs +1 -0
  196. package/lib/svg/analyse.cjs +291 -0
  197. package/lib/svg/analyse.d.ts +8 -3
  198. package/lib/svg/analyse.mjs +15 -30
  199. package/lib/svg/cleanup/attribs.cjs +41 -0
  200. package/lib/svg/cleanup/attribs.d.ts +7 -2
  201. package/lib/svg/cleanup/attribs.mjs +6 -12
  202. package/lib/svg/cleanup/bad-tags.cjs +51 -0
  203. package/lib/svg/cleanup/bad-tags.d.ts +7 -2
  204. package/lib/svg/cleanup/bad-tags.mjs +10 -25
  205. package/lib/svg/cleanup/inline-style.cjs +64 -0
  206. package/lib/svg/cleanup/inline-style.d.ts +7 -2
  207. package/lib/svg/cleanup/inline-style.mjs +14 -19
  208. package/lib/svg/cleanup/root-svg.cjs +81 -0
  209. package/lib/svg/cleanup/root-svg.d.ts +7 -2
  210. package/lib/svg/cleanup/root-svg.mjs +7 -18
  211. package/lib/svg/cleanup/svgo-style.cjs +38 -0
  212. package/lib/svg/cleanup/svgo-style.d.ts +7 -2
  213. package/lib/svg/cleanup/svgo-style.mjs +16 -11
  214. package/lib/svg/cleanup.cjs +32 -0
  215. package/lib/svg/cleanup.d.ts +7 -2
  216. package/lib/svg/cleanup.mjs +21 -9
  217. package/lib/svg/data/attributes.cjs +355 -0
  218. package/lib/svg/data/attributes.d.ts +27 -25
  219. package/lib/svg/data/attributes.mjs +90 -115
  220. package/lib/svg/data/tags.cjs +137 -0
  221. package/lib/svg/data/tags.d.ts +25 -23
  222. package/lib/svg/data/tags.mjs +25 -49
  223. package/lib/svg/index.cjs +130 -0
  224. package/lib/svg/index.d.ts +16 -5
  225. package/lib/svg/index.mjs +48 -11
  226. package/lib/svg/parse-style.cjs +134 -0
  227. package/lib/svg/parse-style.d.ts +12 -8
  228. package/lib/svg/parse-style.mjs +11 -9
  229. package/lib/svg/parse.cjs +42 -0
  230. package/lib/svg/parse.d.ts +11 -7
  231. package/lib/svg/parse.mjs +2 -4
  232. package/package.json +102 -93
  233. package/lib/colors/attribs.js +0 -26
  234. package/lib/colors/parse.js +0 -341
  235. package/lib/colors/validate.js +0 -48
  236. package/lib/css/parse.js +0 -23
  237. package/lib/css/parser/error.js +0 -27
  238. package/lib/css/parser/export.js +0 -69
  239. package/lib/css/parser/strings.js +0 -93
  240. package/lib/css/parser/text.js +0 -171
  241. package/lib/css/parser/tokens.js +0 -200
  242. package/lib/css/parser/tree.js +0 -44
  243. package/lib/css/parser/types.js +0 -2
  244. package/lib/download/api/cache.js +0 -108
  245. package/lib/download/api/download.js +0 -27
  246. package/lib/download/api/index.js +0 -52
  247. package/lib/download/api/types.js +0 -2
  248. package/lib/download/git/branch.js +0 -22
  249. package/lib/download/git/hash.js +0 -14
  250. package/lib/download/git/index.js +0 -63
  251. package/lib/download/github/hash.js +0 -28
  252. package/lib/download/github/index.js +0 -116
  253. package/lib/download/github/types.js +0 -2
  254. package/lib/download/gitlab/hash.js +0 -27
  255. package/lib/download/gitlab/index.js +0 -115
  256. package/lib/download/gitlab/types.js +0 -7
  257. package/lib/download/helpers/untar.js +0 -14
  258. package/lib/download/helpers/unzip.js +0 -18
  259. package/lib/download/index.js +0 -27
  260. package/lib/download/npm/index.js +0 -91
  261. package/lib/download/npm/types.js +0 -2
  262. package/lib/download/npm/version.js +0 -27
  263. package/lib/download/types/modified.js +0 -2
  264. package/lib/download/types/sources.js +0 -2
  265. package/lib/export/directory.js +0 -52
  266. package/lib/export/helpers/custom-files.js +0 -32
  267. package/lib/export/helpers/prepare.js +0 -49
  268. package/lib/export/helpers/types-version.js +0 -12
  269. package/lib/export/icon-package.js +0 -77
  270. package/lib/export/json-package.js +0 -151
  271. package/lib/icon-set/index.js +0 -746
  272. package/lib/icon-set/match.js +0 -66
  273. package/lib/icon-set/merge.js +0 -90
  274. package/lib/icon-set/props.js +0 -33
  275. package/lib/icon-set/types.js +0 -2
  276. package/lib/import/directory.js +0 -59
  277. package/lib/import/figma/index.js +0 -90
  278. package/lib/import/figma/nodes.js +0 -108
  279. package/lib/import/figma/query.js +0 -244
  280. package/lib/import/figma/types/api.js +0 -12
  281. package/lib/import/figma/types/nodes.js +0 -2
  282. package/lib/import/figma/types/options.js +0 -2
  283. package/lib/import/figma/types/result.js +0 -2
  284. package/lib/index.js +0 -101
  285. package/lib/misc/bump-version.js +0 -19
  286. package/lib/misc/compare-dirs.js +0 -84
  287. package/lib/misc/exec.js +0 -26
  288. package/lib/misc/keyword.js +0 -31
  289. package/lib/misc/scan.js +0 -55
  290. package/lib/misc/write-json.js +0 -11
  291. package/lib/optimise/flags.js +0 -312
  292. package/lib/optimise/global-style.js +0 -158
  293. package/lib/optimise/scale.js +0 -42
  294. package/lib/optimise/svgo.js +0 -99
  295. package/lib/svg/analyse/error.js +0 -22
  296. package/lib/svg/analyse/types.js +0 -2
  297. package/lib/svg/analyse.js +0 -352
  298. package/lib/svg/cleanup/attribs.js +0 -51
  299. package/lib/svg/cleanup/bad-tags.js +0 -65
  300. package/lib/svg/cleanup/inline-style.js +0 -77
  301. package/lib/svg/cleanup/root-svg.js +0 -107
  302. package/lib/svg/cleanup/svgo-style.js +0 -35
  303. package/lib/svg/cleanup.js +0 -24
  304. package/lib/svg/data/attributes.js +0 -403
  305. package/lib/svg/data/tags.js +0 -188
  306. package/lib/svg/index.js +0 -125
  307. package/lib/svg/parse-style.js +0 -151
  308. package/lib/svg/parse.js +0 -49
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const export_helpers_prepare = require('../../export/helpers/prepare.cjs');
6
+ const misc_exec = require('../../misc/exec.cjs');
7
+ const download_git_branch = require('./branch.cjs');
8
+ const download_git_hash = require('./hash.cjs');
9
+ const download_git_reset = require('./reset.cjs');
10
+ require('fs');
11
+ require('pathe');
12
+ require('child_process');
13
+ require('cheerio');
14
+ require('@iconify/utils');
15
+ require('@iconify/utils/lib/icon');
16
+ require('../../svg/data/attributes.cjs');
17
+ require('../../svg/data/tags.cjs');
18
+ require('../../svg/cleanup/bad-tags.cjs');
19
+ require('../../svg/parse.cjs');
20
+ require('svgo');
21
+ require('@iconify/utils/lib/svg/build');
22
+ require('@iconify/utils/lib/customisations');
23
+ require('@iconify/utils/lib/icon-set/minify');
24
+ require('@iconify/utils/lib/icon-set/convert-info');
25
+ require('../../icon-set/props.cjs');
26
+ require('node-fetch');
27
+ require('crypto');
28
+ require('../api/download.cjs');
29
+ require('util');
30
+ require('stream');
31
+ require('extract-zip');
32
+ require('tar');
33
+ require('@iconify/utils/lib/colors');
34
+ require('local-pkg');
35
+
36
+ async function downloadGitRepo(options) {
37
+ const { remote, branch } = options;
38
+ const hasHashInTarget = options.target.indexOf("{hash}") !== -1;
39
+ const ifModifiedSince = options.ifModifiedSince;
40
+ if (ifModifiedSince || hasHashInTarget) {
41
+ const result = await misc_exec.execAsync(`git ls-remote ${remote} --branch ${branch}`);
42
+ const parts = result.stdout.split(/\s/);
43
+ const latestHash = parts.shift();
44
+ if (hasHashInTarget) {
45
+ options.target = options.target.replace("{hash}", latestHash);
46
+ }
47
+ try {
48
+ await download_git_branch.getGitRepoBranch(options, branch);
49
+ if (ifModifiedSince) {
50
+ const expectedHash = ifModifiedSince === true ? await download_git_hash.getGitRepoHash(options) : typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "git" ? ifModifiedSince.hash : null;
51
+ if (latestHash === expectedHash) {
52
+ await download_git_reset.resetGitRepoContents(options.target);
53
+ return "not_modified";
54
+ }
55
+ }
56
+ } catch {
57
+ }
58
+ }
59
+ const target = options.target = await export_helpers_prepare.prepareDirectoryForExport({
60
+ ...options,
61
+ cleanup: true
62
+ });
63
+ if (options.log) {
64
+ console.log(`Cloning ${remote}#${branch} to ${target}`);
65
+ }
66
+ await misc_exec.execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
67
+ const hash = await download_git_hash.getGitRepoHash(options);
68
+ await download_git_branch.getGitRepoBranch(options, branch);
69
+ return {
70
+ downloadType: "git",
71
+ contentsDir: target,
72
+ hash
73
+ };
74
+ }
75
+
76
+ exports.downloadGitRepo = downloadGitRepo;
@@ -1,13 +1,14 @@
1
- import { ExportTargetOptions } from '../../export/helpers/prepare';
2
- import type { DocumentNotModified } from '../types/modified';
3
- import type { DownloadSourceMixin } from '../types/sources';
1
+ import { ExportTargetOptions } from '../../export/helpers/prepare.js';
2
+ import { DocumentNotModified } from '../types/modified.js';
3
+ import { DownloadSourceMixin } from '../types/sources.js';
4
+
4
5
  interface IfModifiedSinceOption {
5
6
  ifModifiedSince: string | true | DownloadGitRepoResult;
6
7
  }
7
8
  /**
8
9
  * Options for downloadGitRepo()
9
10
  */
10
- export interface DownloadGitRepoOptions extends ExportTargetOptions, Partial<IfModifiedSinceOption> {
11
+ interface DownloadGitRepoOptions extends ExportTargetOptions, Partial<IfModifiedSinceOption> {
11
12
  remote: string;
12
13
  branch: string;
13
14
  log?: boolean;
@@ -15,13 +16,14 @@ export interface DownloadGitRepoOptions extends ExportTargetOptions, Partial<IfM
15
16
  /**
16
17
  * Result
17
18
  */
18
- export interface DownloadGitRepoResult extends DownloadSourceMixin<'git'> {
19
+ interface DownloadGitRepoResult extends DownloadSourceMixin<'git'> {
19
20
  contentsDir: string;
20
21
  hash: string;
21
22
  }
22
23
  /**
23
24
  * Download Git repo
24
25
  */
25
- export declare function downloadGitRepo<T extends IfModifiedSinceOption & DownloadGitRepoOptions>(options: T): Promise<DownloadGitRepoResult | DocumentNotModified>;
26
- export declare function downloadGitRepo(options: DownloadGitRepoOptions): Promise<DownloadGitRepoResult>;
27
- export {};
26
+ declare function downloadGitRepo<T extends IfModifiedSinceOption & DownloadGitRepoOptions>(options: T): Promise<DownloadGitRepoResult | DocumentNotModified>;
27
+ declare function downloadGitRepo(options: DownloadGitRepoOptions): Promise<DownloadGitRepoResult>;
28
+
29
+ export { DownloadGitRepoOptions, DownloadGitRepoResult, downloadGitRepo };
@@ -1,11 +1,34 @@
1
- // src/download/git/index.ts
2
- import { promises as fs } from "fs";
3
- import {
4
- prepareDirectoryForExport
5
- } from "../../export/helpers/prepare.mjs";
6
- import { execAsync } from "../../misc/exec.mjs";
7
- import { getGitRepoBranch } from "./branch.mjs";
8
- import { getGitRepoHash } from "./hash.mjs";
1
+ import { prepareDirectoryForExport } from '../../export/helpers/prepare.mjs';
2
+ import { execAsync } from '../../misc/exec.mjs';
3
+ import { getGitRepoBranch } from './branch.mjs';
4
+ import { getGitRepoHash } from './hash.mjs';
5
+ import { resetGitRepoContents } from './reset.mjs';
6
+ import 'fs';
7
+ import 'pathe';
8
+ import 'child_process';
9
+ import 'cheerio';
10
+ import '@iconify/utils';
11
+ import '@iconify/utils/lib/icon';
12
+ import '../../svg/data/attributes.mjs';
13
+ import '../../svg/data/tags.mjs';
14
+ import '../../svg/cleanup/bad-tags.mjs';
15
+ import '../../svg/parse.mjs';
16
+ import 'svgo';
17
+ import '@iconify/utils/lib/svg/build';
18
+ import '@iconify/utils/lib/customisations';
19
+ import '@iconify/utils/lib/icon-set/minify';
20
+ import '@iconify/utils/lib/icon-set/convert-info';
21
+ import '../../icon-set/props.mjs';
22
+ import 'node-fetch';
23
+ import 'crypto';
24
+ import '../api/download.mjs';
25
+ import 'util';
26
+ import 'stream';
27
+ import 'extract-zip';
28
+ import 'tar';
29
+ import '@iconify/utils/lib/colors';
30
+ import 'local-pkg';
31
+
9
32
  async function downloadGitRepo(options) {
10
33
  const { remote, branch } = options;
11
34
  const hasHashInTarget = options.target.indexOf("{hash}") !== -1;
@@ -22,21 +45,21 @@ async function downloadGitRepo(options) {
22
45
  if (ifModifiedSince) {
23
46
  const expectedHash = ifModifiedSince === true ? await getGitRepoHash(options) : typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "git" ? ifModifiedSince.hash : null;
24
47
  if (latestHash === expectedHash) {
48
+ await resetGitRepoContents(options.target);
25
49
  return "not_modified";
26
50
  }
27
51
  }
28
- } catch (err) {
29
- options.cleanup = true;
52
+ } catch {
30
53
  }
31
54
  }
32
- const target = options.target = await prepareDirectoryForExport(options);
33
- const files = options.cleanup ? [] : await fs.readdir(target);
34
- if (!files.length) {
35
- if (options.log) {
36
- console.log(`Cloning ${remote}#${branch} to ${target}`);
37
- }
38
- await execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
55
+ const target = options.target = await prepareDirectoryForExport({
56
+ ...options,
57
+ cleanup: true
58
+ });
59
+ if (options.log) {
60
+ console.log(`Cloning ${remote}#${branch} to ${target}`);
39
61
  }
62
+ await execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
40
63
  const hash = await getGitRepoHash(options);
41
64
  await getGitRepoBranch(options, branch);
42
65
  return {
@@ -45,6 +68,5 @@ async function downloadGitRepo(options) {
45
68
  hash
46
69
  };
47
70
  }
48
- export {
49
- downloadGitRepo
50
- };
71
+
72
+ export { downloadGitRepo };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('cheerio');
6
+ require('@iconify/utils');
7
+ require('@iconify/utils/lib/icon');
8
+ require('../../svg/data/attributes.cjs');
9
+ require('../../svg/data/tags.cjs');
10
+ require('../../svg/cleanup/bad-tags.cjs');
11
+ require('svgo');
12
+ require('@iconify/utils/lib/svg/build');
13
+ require('@iconify/utils/lib/customisations');
14
+ require('@iconify/utils/lib/icon-set/minify');
15
+ require('@iconify/utils/lib/icon-set/convert-info');
16
+ require('../../icon-set/props.cjs');
17
+ require('node-fetch');
18
+ require('fs');
19
+ require('crypto');
20
+ require('pathe');
21
+ const misc_exec = require('../../misc/exec.cjs');
22
+ require('../api/download.cjs');
23
+ require('extract-zip');
24
+ require('tar');
25
+ require('@iconify/utils/lib/colors');
26
+ require('local-pkg');
27
+ require('../../svg/parse.cjs');
28
+ require('child_process');
29
+ require('util');
30
+ require('stream');
31
+
32
+ async function resetGitRepoContents(target) {
33
+ await misc_exec.execAsync("git add -A", {
34
+ cwd: target
35
+ });
36
+ await misc_exec.execAsync("git reset --hard --quiet", {
37
+ cwd: target
38
+ });
39
+ }
40
+
41
+ exports.resetGitRepoContents = resetGitRepoContents;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Reset Git repo contents
3
+ */
4
+ declare function resetGitRepoContents(target: string): Promise<void>;
5
+
6
+ export { resetGitRepoContents };
@@ -0,0 +1,37 @@
1
+ import 'cheerio';
2
+ import '@iconify/utils';
3
+ import '@iconify/utils/lib/icon';
4
+ import '../../svg/data/attributes.mjs';
5
+ import '../../svg/data/tags.mjs';
6
+ import '../../svg/cleanup/bad-tags.mjs';
7
+ import 'svgo';
8
+ import '@iconify/utils/lib/svg/build';
9
+ import '@iconify/utils/lib/customisations';
10
+ import '@iconify/utils/lib/icon-set/minify';
11
+ import '@iconify/utils/lib/icon-set/convert-info';
12
+ import '../../icon-set/props.mjs';
13
+ import 'node-fetch';
14
+ import 'fs';
15
+ import 'crypto';
16
+ import 'pathe';
17
+ import { execAsync } from '../../misc/exec.mjs';
18
+ import '../api/download.mjs';
19
+ import 'extract-zip';
20
+ import 'tar';
21
+ import '@iconify/utils/lib/colors';
22
+ import 'local-pkg';
23
+ import '../../svg/parse.mjs';
24
+ import 'child_process';
25
+ import 'util';
26
+ import 'stream';
27
+
28
+ async function resetGitRepoContents(target) {
29
+ await execAsync("git add -A", {
30
+ cwd: target
31
+ });
32
+ await execAsync("git reset --hard --quiet", {
33
+ cwd: target
34
+ });
35
+ }
36
+
37
+ export { resetGitRepoContents };
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const download_api_index = require('../api/index.cjs');
6
+ require('node-fetch');
7
+ require('../api/cache.cjs');
8
+ require('fs');
9
+ require('crypto');
10
+ require('../../misc/scan.cjs');
11
+
12
+ async function getGitHubRepoHash(options) {
13
+ const uri = `https://api.github.com/repos/${options.user}/${options.repo}/branches/${options.branch}`;
14
+ const data = await download_api_index.sendAPIQuery({
15
+ uri,
16
+ headers: {
17
+ Accept: "application/vnd.github.v3+json",
18
+ Authorization: "token " + options.token
19
+ }
20
+ });
21
+ if (typeof data !== "string") {
22
+ throw new Error(`Error downloading data from GitHub API: ${data}`);
23
+ }
24
+ const content = JSON.parse(data);
25
+ const hash = content?.commit?.sha;
26
+ if (typeof hash !== "string") {
27
+ throw new Error("Error parsing GitHub API response");
28
+ }
29
+ return hash;
30
+ }
31
+
32
+ exports.getGitHubRepoHash = getGitHubRepoHash;
@@ -1,5 +1,8 @@
1
- import type { GitHubAPIOptions } from './types';
1
+ import { GitHubAPIOptions } from './types.js';
2
+
2
3
  /**
3
4
  * Get latest hash from GitHub using API
4
5
  */
5
- export declare function getGitHubRepoHash(options: GitHubAPIOptions): Promise<string>;
6
+ declare function getGitHubRepoHash(options: GitHubAPIOptions): Promise<string>;
7
+
8
+ export { getGitHubRepoHash };
@@ -1,7 +1,11 @@
1
- // src/download/github/hash.ts
2
- import { sendAPIQuery } from "../api/index.mjs";
1
+ import { sendAPIQuery } from '../api/index.mjs';
2
+ import 'node-fetch';
3
+ import '../api/cache.mjs';
4
+ import 'fs';
5
+ import 'crypto';
6
+ import '../../misc/scan.mjs';
7
+
3
8
  async function getGitHubRepoHash(options) {
4
- var _a;
5
9
  const uri = `https://api.github.com/repos/${options.user}/${options.repo}/branches/${options.branch}`;
6
10
  const data = await sendAPIQuery({
7
11
  uri,
@@ -14,12 +18,11 @@ async function getGitHubRepoHash(options) {
14
18
  throw new Error(`Error downloading data from GitHub API: ${data}`);
15
19
  }
16
20
  const content = JSON.parse(data);
17
- const hash = (_a = content == null ? void 0 : content.commit) == null ? void 0 : _a.sha;
21
+ const hash = content?.commit?.sha;
18
22
  if (typeof hash !== "string") {
19
23
  throw new Error("Error parsing GitHub API response");
20
24
  }
21
25
  return hash;
22
26
  }
23
- export {
24
- getGitHubRepoHash
25
- };
27
+
28
+ export { getGitHubRepoHash };
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const fs = require('fs');
6
+ const export_helpers_prepare = require('../../export/helpers/prepare.cjs');
7
+ const download_github_hash = require('./hash.cjs');
8
+ const download_api_download = require('../api/download.cjs');
9
+ const download_helpers_unzip = require('../helpers/unzip.cjs');
10
+ require('pathe');
11
+ require('../api/index.cjs');
12
+ require('node-fetch');
13
+ require('../api/cache.cjs');
14
+ require('crypto');
15
+ require('../../misc/scan.cjs');
16
+ require('util');
17
+ require('stream');
18
+ require('extract-zip');
19
+
20
+ async function findMatchingDirs(rootDir, hash) {
21
+ const matches = [];
22
+ const files = await fs.promises.readdir(rootDir);
23
+ for (let i = 0; i < files.length; i++) {
24
+ const file = files[i];
25
+ const lastChunk = file.split("-").pop();
26
+ if (lastChunk.length < 4 || lastChunk !== hash.slice(0, lastChunk.length)) {
27
+ continue;
28
+ }
29
+ const stat = await fs.promises.stat(rootDir + "/" + file);
30
+ if (stat.isDirectory()) {
31
+ matches.push(file);
32
+ }
33
+ }
34
+ return matches;
35
+ }
36
+ async function downloadGitHubRepo(options) {
37
+ const hash = await download_github_hash.getGitHubRepoHash(options);
38
+ const ifModifiedSince = options.ifModifiedSince;
39
+ if (ifModifiedSince) {
40
+ const expectedHash = typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "github" ? ifModifiedSince.hash : null;
41
+ if (hash === expectedHash) {
42
+ return "not_modified";
43
+ }
44
+ }
45
+ options.target = options.target.replace("{hash}", hash);
46
+ const rootDir = options.target = await export_helpers_prepare.prepareDirectoryForExport(options);
47
+ const archiveTarget = rootDir + "/" + hash + ".zip";
48
+ let exists = false;
49
+ try {
50
+ const stat = await fs.promises.stat(archiveTarget);
51
+ exists = stat.isFile();
52
+ } catch (err) {
53
+ }
54
+ if (!exists) {
55
+ const uri = `https://api.github.com/repos/${options.user}/${options.repo}/zipball/${hash}`;
56
+ await download_api_download.downloadFile({
57
+ uri,
58
+ headers: {
59
+ Accept: "application/vnd.github.v3+json",
60
+ Authorization: "token " + options.token
61
+ }
62
+ }, archiveTarget);
63
+ }
64
+ const files = await fs.promises.readdir(rootDir);
65
+ const hashSearch = "-" + hash;
66
+ for (let i = 0; i < files.length; i++) {
67
+ const file = files[i];
68
+ if (file === hash + ".zip") {
69
+ continue;
70
+ }
71
+ const filename = rootDir + "/" + files[i];
72
+ const stat = await fs.promises.lstat(filename);
73
+ const isDir = stat.isDirectory();
74
+ if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
75
+ try {
76
+ await fs.promises.rm(filename, {
77
+ force: true,
78
+ recursive: true
79
+ });
80
+ } catch (err) {
81
+ }
82
+ }
83
+ }
84
+ await download_helpers_unzip.unzip(archiveTarget, rootDir);
85
+ const matchingDirs = await findMatchingDirs(rootDir, hash);
86
+ if (matchingDirs.length !== 1) {
87
+ throw new Error(`Error unpacking ${hash}.zip`);
88
+ }
89
+ const contentsDir = rootDir + "/" + matchingDirs[0];
90
+ return {
91
+ downloadType: "github",
92
+ rootDir,
93
+ contentsDir,
94
+ hash
95
+ };
96
+ }
97
+
98
+ exports.downloadGitHubRepo = downloadGitHubRepo;
@@ -1,14 +1,15 @@
1
- import { ExportTargetOptions } from '../../export/helpers/prepare';
2
- import type { DocumentNotModified } from '../types/modified';
3
- import type { GitHubAPIOptions } from './types';
4
- import type { DownloadSourceMixin } from '../types/sources';
1
+ import { ExportTargetOptions } from '../../export/helpers/prepare.js';
2
+ import { DocumentNotModified } from '../types/modified.js';
3
+ import { GitHubAPIOptions } from './types.js';
4
+ import { DownloadSourceMixin } from '../types/sources.js';
5
+
5
6
  interface IfModifiedSinceOption {
6
7
  ifModifiedSince: string | DownloadGitHubRepoResult;
7
8
  }
8
9
  /**
9
10
  * Options for downloadGitHubRepo()
10
11
  */
11
- export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAPIOptions, Partial<IfModifiedSinceOption> {
12
+ interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAPIOptions, Partial<IfModifiedSinceOption> {
12
13
  cleanupOldFiles?: boolean;
13
14
  cleanupOldDirectories?: boolean;
14
15
  log?: boolean;
@@ -16,7 +17,7 @@ export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAP
16
17
  /**
17
18
  * Result
18
19
  */
19
- export interface DownloadGitHubRepoResult extends DownloadSourceMixin<'github'> {
20
+ interface DownloadGitHubRepoResult extends DownloadSourceMixin<'github'> {
20
21
  rootDir: string;
21
22
  contentsDir: string;
22
23
  hash: string;
@@ -24,6 +25,7 @@ export interface DownloadGitHubRepoResult extends DownloadSourceMixin<'github'>
24
25
  /**
25
26
  * Download GitHub repo using API
26
27
  */
27
- export declare function downloadGitHubRepo<T extends IfModifiedSinceOption & DownloadGitHubRepoOptions>(options: T): Promise<DownloadGitHubRepoResult | DocumentNotModified>;
28
- export declare function downloadGitHubRepo(options: DownloadGitHubRepoOptions): Promise<DownloadGitHubRepoResult>;
29
- export {};
28
+ declare function downloadGitHubRepo<T extends IfModifiedSinceOption & DownloadGitHubRepoOptions>(options: T): Promise<DownloadGitHubRepoResult | DocumentNotModified>;
29
+ declare function downloadGitHubRepo(options: DownloadGitHubRepoOptions): Promise<DownloadGitHubRepoResult>;
30
+
31
+ export { DownloadGitHubRepoOptions, DownloadGitHubRepoResult, downloadGitHubRepo };
@@ -1,21 +1,28 @@
1
- // src/download/github/index.ts
2
- import { promises as fs } from "fs";
3
- import {
4
- prepareDirectoryForExport
5
- } from "../../export/helpers/prepare.mjs";
6
- import { getGitHubRepoHash } from "./hash.mjs";
7
- import { downloadFile } from "../api/download.mjs";
8
- import { unzip } from "../helpers/unzip.mjs";
1
+ import { promises } from 'fs';
2
+ import { prepareDirectoryForExport } from '../../export/helpers/prepare.mjs';
3
+ import { getGitHubRepoHash } from './hash.mjs';
4
+ import { downloadFile } from '../api/download.mjs';
5
+ import { unzip } from '../helpers/unzip.mjs';
6
+ import 'pathe';
7
+ import '../api/index.mjs';
8
+ import 'node-fetch';
9
+ import '../api/cache.mjs';
10
+ import 'crypto';
11
+ import '../../misc/scan.mjs';
12
+ import 'util';
13
+ import 'stream';
14
+ import 'extract-zip';
15
+
9
16
  async function findMatchingDirs(rootDir, hash) {
10
17
  const matches = [];
11
- const files = await fs.readdir(rootDir);
18
+ const files = await promises.readdir(rootDir);
12
19
  for (let i = 0; i < files.length; i++) {
13
20
  const file = files[i];
14
21
  const lastChunk = file.split("-").pop();
15
22
  if (lastChunk.length < 4 || lastChunk !== hash.slice(0, lastChunk.length)) {
16
23
  continue;
17
24
  }
18
- const stat = await fs.stat(rootDir + "/" + file);
25
+ const stat = await promises.stat(rootDir + "/" + file);
19
26
  if (stat.isDirectory()) {
20
27
  matches.push(file);
21
28
  }
@@ -36,7 +43,7 @@ async function downloadGitHubRepo(options) {
36
43
  const archiveTarget = rootDir + "/" + hash + ".zip";
37
44
  let exists = false;
38
45
  try {
39
- const stat = await fs.stat(archiveTarget);
46
+ const stat = await promises.stat(archiveTarget);
40
47
  exists = stat.isFile();
41
48
  } catch (err) {
42
49
  }
@@ -50,7 +57,7 @@ async function downloadGitHubRepo(options) {
50
57
  }
51
58
  }, archiveTarget);
52
59
  }
53
- const files = await fs.readdir(rootDir);
60
+ const files = await promises.readdir(rootDir);
54
61
  const hashSearch = "-" + hash;
55
62
  for (let i = 0; i < files.length; i++) {
56
63
  const file = files[i];
@@ -58,11 +65,11 @@ async function downloadGitHubRepo(options) {
58
65
  continue;
59
66
  }
60
67
  const filename = rootDir + "/" + files[i];
61
- const stat = await fs.lstat(filename);
68
+ const stat = await promises.lstat(filename);
62
69
  const isDir = stat.isDirectory();
63
70
  if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
64
71
  try {
65
- await fs.rm(filename, {
72
+ await promises.rm(filename, {
66
73
  force: true,
67
74
  recursive: true
68
75
  });
@@ -83,6 +90,5 @@ async function downloadGitHubRepo(options) {
83
90
  hash
84
91
  };
85
92
  }
86
- export {
87
- downloadGitHubRepo
88
- };
93
+
94
+ export { downloadGitHubRepo };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * API options
3
3
  */
4
- export interface GitHubAPIOptions {
4
+ interface GitHubAPIOptions {
5
5
  token: string;
6
6
  user: string;
7
7
  repo: string;
8
8
  branch: string;
9
9
  }
10
+
11
+ export { GitHubAPIOptions };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const download_api_index = require('../api/index.cjs');
6
+ const download_gitlab_types = require('./types.cjs');
7
+ require('node-fetch');
8
+ require('../api/cache.cjs');
9
+ require('fs');
10
+ require('crypto');
11
+ require('../../misc/scan.cjs');
12
+
13
+ async function getGitLabRepoHash(options) {
14
+ const uri = `${options.uri || download_gitlab_types.defaultGitLabBaseURI}/${options.project}/repository/branches/${options.branch}/`;
15
+ const data = await download_api_index.sendAPIQuery({
16
+ uri,
17
+ headers: {
18
+ Authorization: "token " + options.token
19
+ }
20
+ });
21
+ if (typeof data !== "string") {
22
+ throw new Error(`Error downloading data from GitLab API: ${data}`);
23
+ }
24
+ const content = JSON.parse(data);
25
+ const item = (content instanceof Array ? content : [content]).find((item2) => item2.name === options.branch && typeof item2.commit.id === "string");
26
+ if (!item) {
27
+ throw new Error("Error parsing GitLab API response");
28
+ }
29
+ return item.commit.id;
30
+ }
31
+
32
+ exports.getGitLabRepoHash = getGitLabRepoHash;
@@ -1,5 +1,8 @@
1
- import { GitLabAPIOptions } from './types';
1
+ import { GitLabAPIOptions } from './types.js';
2
+
2
3
  /**
3
4
  * Get latest hash from GitHub using API
4
5
  */
5
- export declare function getGitLabRepoHash(options: GitLabAPIOptions): Promise<string>;
6
+ declare function getGitLabRepoHash(options: GitLabAPIOptions): Promise<string>;
7
+
8
+ export { getGitLabRepoHash };