@iconify/tools 2.0.14 → 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 (309) 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 +41 -26
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +3 -1
  57. package/lib/download/git/reset.mjs +29 -5
  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 +20 -21
  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 +40 -53
  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 +7 -10
  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 +3 -11
  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 -44
  159. package/lib/index.mjs +83 -94
  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 +18 -15
  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 -14
  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 +99 -94
  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 -75
  251. package/lib/download/git/reset.js +0 -16
  252. package/lib/download/github/hash.js +0 -28
  253. package/lib/download/github/index.js +0 -116
  254. package/lib/download/github/types.js +0 -2
  255. package/lib/download/gitlab/hash.js +0 -27
  256. package/lib/download/gitlab/index.js +0 -115
  257. package/lib/download/gitlab/types.js +0 -7
  258. package/lib/download/helpers/untar.js +0 -14
  259. package/lib/download/helpers/unzip.js +0 -18
  260. package/lib/download/index.js +0 -27
  261. package/lib/download/npm/index.js +0 -91
  262. package/lib/download/npm/types.js +0 -2
  263. package/lib/download/npm/version.js +0 -27
  264. package/lib/download/types/modified.js +0 -2
  265. package/lib/download/types/sources.js +0 -2
  266. package/lib/export/directory.js +0 -52
  267. package/lib/export/helpers/custom-files.js +0 -32
  268. package/lib/export/helpers/prepare.js +0 -49
  269. package/lib/export/helpers/types-version.js +0 -12
  270. package/lib/export/icon-package.js +0 -77
  271. package/lib/export/json-package.js +0 -156
  272. package/lib/icon-set/index.js +0 -749
  273. package/lib/icon-set/match.js +0 -66
  274. package/lib/icon-set/merge.js +0 -90
  275. package/lib/icon-set/props.js +0 -34
  276. package/lib/icon-set/types.js +0 -2
  277. package/lib/import/directory.js +0 -59
  278. package/lib/import/figma/index.js +0 -90
  279. package/lib/import/figma/nodes.js +0 -106
  280. package/lib/import/figma/query.js +0 -244
  281. package/lib/import/figma/types/api.js +0 -12
  282. package/lib/import/figma/types/nodes.js +0 -2
  283. package/lib/import/figma/types/options.js +0 -2
  284. package/lib/import/figma/types/result.js +0 -2
  285. package/lib/index.js +0 -103
  286. package/lib/misc/bump-version.js +0 -19
  287. package/lib/misc/compare-dirs.js +0 -84
  288. package/lib/misc/exec.js +0 -26
  289. package/lib/misc/keyword.js +0 -31
  290. package/lib/misc/scan.js +0 -55
  291. package/lib/misc/write-json.js +0 -11
  292. package/lib/optimise/flags.js +0 -312
  293. package/lib/optimise/global-style.js +0 -185
  294. package/lib/optimise/scale.js +0 -42
  295. package/lib/optimise/svgo.js +0 -99
  296. package/lib/svg/analyse/error.js +0 -22
  297. package/lib/svg/analyse/types.js +0 -2
  298. package/lib/svg/analyse.js +0 -352
  299. package/lib/svg/cleanup/attribs.js +0 -51
  300. package/lib/svg/cleanup/bad-tags.js +0 -65
  301. package/lib/svg/cleanup/inline-style.js +0 -77
  302. package/lib/svg/cleanup/root-svg.js +0 -107
  303. package/lib/svg/cleanup/svgo-style.js +0 -35
  304. package/lib/svg/cleanup.js +0 -24
  305. package/lib/svg/data/attributes.js +0 -403
  306. package/lib/svg/data/tags.js +0 -188
  307. package/lib/svg/index.js +0 -134
  308. package/lib/svg/parse-style.js +0 -151
  309. package/lib/svg/parse.js +0 -49
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadGitRepo = void 0;
4
- const fs_1 = require("fs");
5
- const prepare_1 = require("../../export/helpers/prepare");
6
- const exec_1 = require("../../misc/exec");
7
- const branch_1 = require("./branch");
8
- const hash_1 = require("./hash");
9
- const reset_1 = require("./reset");
10
- async function downloadGitRepo(options) {
11
- const { remote, branch } = options;
12
- // Check for last commit
13
- const hasHashInTarget = options.target.indexOf('{hash}') !== -1;
14
- const ifModifiedSince = options.ifModifiedSince;
15
- if (ifModifiedSince || hasHashInTarget) {
16
- // Get actual hash
17
- const result = await (0, exec_1.execAsync)(`git ls-remote ${remote} --branch ${branch}`);
18
- const parts = result.stdout.split(/\s/);
19
- const latestHash = parts.shift();
20
- if (hasHashInTarget) {
21
- options.target = options.target.replace('{hash}', latestHash);
22
- }
23
- try {
24
- // Make sure correct branch is checked out. This will throw error if branch is not available
25
- await (0, branch_1.getGitRepoBranch)(options, branch);
26
- if (ifModifiedSince) {
27
- // Get expected hash
28
- const expectedHash = ifModifiedSince === true
29
- ? await (0, hash_1.getGitRepoHash)(options)
30
- : typeof ifModifiedSince === 'string'
31
- ? ifModifiedSince
32
- : ifModifiedSince.downloadType === 'git'
33
- ? ifModifiedSince.hash
34
- : null;
35
- if (latestHash === expectedHash) {
36
- // Reset contents before returning
37
- await (0, reset_1.resetGitRepoContents)(options.target);
38
- return 'not_modified';
39
- }
40
- }
41
- }
42
- catch (err) {
43
- // Cleanup on error
44
- options.cleanup = true;
45
- }
46
- }
47
- // Prepare target directory
48
- const target = (options.target = await (0, prepare_1.prepareDirectoryForExport)(options));
49
- // Check if directory is empty if directory wasn't cleaned up
50
- const files = options.cleanup ? [] : await fs_1.promises.readdir(target);
51
- if (!files.length) {
52
- if (options.log) {
53
- console.log(`Cloning ${remote}#${branch} to ${target}`);
54
- }
55
- await (0, exec_1.execAsync)(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
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
- }
66
- // Get latest hash and make sure correct branch is available
67
- const hash = await (0, hash_1.getGitRepoHash)(options);
68
- await (0, branch_1.getGitRepoBranch)(options, branch);
69
- return {
70
- downloadType: 'git',
71
- contentsDir: target,
72
- hash,
73
- };
74
- }
75
- exports.downloadGitRepo = downloadGitRepo;
@@ -1,16 +0,0 @@
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;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGitHubRepoHash = void 0;
4
- const api_1 = require("../api");
5
- /**
6
- * Get latest hash from GitHub using API
7
- */
8
- async function getGitHubRepoHash(options) {
9
- var _a;
10
- const uri = `https://api.github.com/repos/${options.user}/${options.repo}/branches/${options.branch}`;
11
- const data = await (0, api_1.sendAPIQuery)({
12
- uri,
13
- headers: {
14
- Accept: 'application/vnd.github.v3+json',
15
- Authorization: 'token ' + options.token,
16
- },
17
- });
18
- if (typeof data !== 'string') {
19
- throw new Error(`Error downloading data from GitHub API: ${data}`);
20
- }
21
- const content = JSON.parse(data);
22
- const hash = (_a = content === null || content === void 0 ? void 0 : content.commit) === null || _a === void 0 ? void 0 : _a.sha;
23
- if (typeof hash !== 'string') {
24
- throw new Error('Error parsing GitHub API response');
25
- }
26
- return hash;
27
- }
28
- exports.getGitHubRepoHash = getGitHubRepoHash;
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadGitHubRepo = void 0;
4
- const fs_1 = require("fs");
5
- const prepare_1 = require("../../export/helpers/prepare");
6
- const hash_1 = require("./hash");
7
- const download_1 = require("../api/download");
8
- const unzip_1 = require("../helpers/unzip");
9
- /**
10
- * Find matching directories
11
- */
12
- async function findMatchingDirs(rootDir, hash) {
13
- const matches = [];
14
- const files = await fs_1.promises.readdir(rootDir);
15
- for (let i = 0; i < files.length; i++) {
16
- const file = files[i];
17
- const lastChunk = file.split('-').pop();
18
- if (lastChunk.length < 4 ||
19
- lastChunk !== hash.slice(0, lastChunk.length)) {
20
- continue;
21
- }
22
- const stat = await fs_1.promises.stat(rootDir + '/' + file);
23
- if (stat.isDirectory()) {
24
- matches.push(file);
25
- }
26
- }
27
- return matches;
28
- }
29
- async function downloadGitHubRepo(options) {
30
- // Check for last commit
31
- const hash = await (0, hash_1.getGitHubRepoHash)(options);
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
- }
42
- }
43
- // Replace hash in target
44
- options.target = options.target.replace('{hash}', hash);
45
- // Prepare target directory
46
- const rootDir = (options.target = await (0, prepare_1.prepareDirectoryForExport)(options));
47
- // Archive name
48
- const archiveTarget = rootDir + '/' + hash + '.zip';
49
- // Check if archive exists
50
- let exists = false;
51
- try {
52
- const stat = await fs_1.promises.stat(archiveTarget);
53
- exists = stat.isFile();
54
- }
55
- catch (err) {
56
- //
57
- }
58
- // Download file
59
- if (!exists) {
60
- const uri = `https://api.github.com/repos/${options.user}/${options.repo}/zipball/${hash}`;
61
- // const uri = `https://codeload.github.com/${options.user}/${options.repo}/zip/${hash}`;
62
- await (0, download_1.downloadFile)({
63
- uri,
64
- headers: {
65
- Accept: 'application/vnd.github.v3+json',
66
- Authorization: 'token ' + options.token,
67
- },
68
- }, archiveTarget);
69
- }
70
- // Clean up old directories
71
- const files = await fs_1.promises.readdir(rootDir);
72
- const hashSearch = '-' + hash;
73
- for (let i = 0; i < files.length; i++) {
74
- const file = files[i];
75
- if (file === hash + '.zip') {
76
- continue;
77
- }
78
- const filename = rootDir + '/' + files[i];
79
- const stat = await fs_1.promises.lstat(filename);
80
- const isDir = stat.isDirectory();
81
- if (
82
- // Remove symbolic links
83
- stat.isSymbolicLink() ||
84
- // Remove if directory matches hash to avoid errors extracting zip
85
- (isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
86
- // Remove if directory and cleanupOldDirectories is not disabled
87
- (isDir && options.cleanupOldDirectories !== false) ||
88
- // Remove if file and cleanupOldFiles is enabled
89
- (!isDir && options.cleanupOldFiles)) {
90
- try {
91
- await fs_1.promises.rm(filename, {
92
- force: true,
93
- recursive: true,
94
- });
95
- }
96
- catch (err) {
97
- //
98
- }
99
- }
100
- }
101
- // Unpack it
102
- await (0, unzip_1.unzip)(archiveTarget, rootDir);
103
- // Get actual dir
104
- const matchingDirs = await findMatchingDirs(rootDir, hash);
105
- if (matchingDirs.length !== 1) {
106
- throw new Error(`Error unpacking ${hash}.zip`);
107
- }
108
- const contentsDir = rootDir + '/' + matchingDirs[0];
109
- return {
110
- downloadType: 'github',
111
- rootDir,
112
- contentsDir,
113
- hash,
114
- };
115
- }
116
- exports.downloadGitHubRepo = downloadGitHubRepo;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +0,0 @@
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;
@@ -1,115 +0,0 @@
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;
@@ -1,7 +0,0 @@
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';
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.untar = void 0;
4
- const tar_1 = require("tar");
5
- /**
6
- * Unpack .tgz archive
7
- */
8
- async function untar(file, path) {
9
- await (0, tar_1.x)({
10
- file,
11
- C: path,
12
- });
13
- }
14
- exports.untar = untar;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.unzip = void 0;
7
- const extract_zip_1 = __importDefault(require("extract-zip"));
8
- const fs_1 = require("fs");
9
- /**
10
- * Unzip archive
11
- */
12
- async function unzip(source, path) {
13
- const dir = await fs_1.promises.realpath(path);
14
- await (0, extract_zip_1.default)(source, {
15
- dir,
16
- });
17
- }
18
- exports.unzip = unzip;
@@ -1,27 +0,0 @@
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;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadNPMPackage = void 0;
4
- const fs_1 = require("fs");
5
- const prepare_1 = require("../../export/helpers/prepare");
6
- const download_1 = require("../api/download");
7
- const untar_1 = require("../helpers/untar");
8
- const version_1 = require("./version");
9
- async function downloadNPMPackage(options) {
10
- const rootDir = (options.target = (0, prepare_1.normalizeDir)(options.target));
11
- const contentsDir = rootDir + '/package';
12
- // Get latest location
13
- const versionInfo = await (0, version_1.getNPMVersion)(options);
14
- const version = versionInfo.version;
15
- // Check downloaded copy
16
- const ifModifiedSince = options.ifModifiedSince;
17
- if (ifModifiedSince) {
18
- try {
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
- }
37
- if (version === expectedVersion) {
38
- return 'not_modified';
39
- }
40
- }
41
- catch (err) {
42
- // Clean up on error
43
- options.cleanup = true;
44
- }
45
- }
46
- const archiveURL = versionInfo.file;
47
- if (!archiveURL) {
48
- throw new Error(`NPM registry did not provide link to package archive.`);
49
- }
50
- const archiveTarget = rootDir + '/' + version + '.tgz';
51
- // Prepare target directory
52
- await (0, prepare_1.prepareDirectoryForExport)(options);
53
- // Check if archive exists
54
- let archiveExists = false;
55
- try {
56
- const stat = await fs_1.promises.stat(archiveTarget);
57
- archiveExists = stat.isFile();
58
- }
59
- catch (err) {
60
- //
61
- }
62
- // Download file
63
- if (!archiveExists) {
64
- if (options.log) {
65
- console.log(`Downloading ${archiveURL}`);
66
- }
67
- await (0, download_1.downloadFile)({
68
- uri: archiveURL,
69
- headers: {
70
- Accept: 'application/tar+gzip',
71
- },
72
- }, archiveTarget);
73
- }
74
- // Remove old unpacked file
75
- await (0, prepare_1.prepareDirectoryForExport)({
76
- target: contentsDir,
77
- cleanup: true,
78
- });
79
- // Unpack file
80
- if (options.log) {
81
- console.log(`Unpacking ${archiveTarget}`);
82
- }
83
- await (0, untar_1.untar)(archiveTarget, rootDir);
84
- return {
85
- downloadType: 'npm',
86
- rootDir,
87
- contentsDir,
88
- version,
89
- };
90
- }
91
- exports.downloadNPMPackage = downloadNPMPackage;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPackageVersion = exports.getNPMVersion = void 0;
4
- const fs_1 = require("fs");
5
- const exec_1 = require("../../misc/exec");
6
- /**
7
- * Get version of package from NPM registry
8
- */
9
- async function getNPMVersion(options) {
10
- var _a;
11
- const tag = options.tag || 'latest';
12
- const result = await (0, exec_1.execAsync)(`npm view ${options.package}@${tag} --json`);
13
- const data = JSON.parse(result.stdout);
14
- return {
15
- version: data.version,
16
- file: (_a = data.dist) === null || _a === void 0 ? void 0 : _a.tarball,
17
- };
18
- }
19
- exports.getNPMVersion = getNPMVersion;
20
- /**
21
- * Get version of package from filename
22
- */
23
- async function getPackageVersion(target) {
24
- return JSON.parse(await fs_1.promises.readFile(target + '/package.json', 'utf8'))
25
- .version;
26
- }
27
- exports.getPackageVersion = getPackageVersion;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exportToDirectory = void 0;
4
- const fs_1 = require("fs");
5
- const prepare_1 = require("./helpers/prepare");
6
- /**
7
- * Export icon set to directory
8
- *
9
- * Returns list of stored files
10
- */
11
- async function exportToDirectory(iconSet, options) {
12
- // Normalise and prepare directory
13
- const dir = await (0, prepare_1.prepareDirectoryForExport)(options);
14
- const storedFiles = new Set();
15
- const customisations = options.autoHeight === false
16
- ? {
17
- height: '1em',
18
- }
19
- : {
20
- width: 'auto',
21
- height: 'auto',
22
- };
23
- // Function to save icon to file
24
- const store = async (name, target) => {
25
- const svg = iconSet.toString(name, customisations);
26
- if (!svg) {
27
- return;
28
- }
29
- await fs_1.promises.writeFile(target, svg, 'utf8');
30
- storedFiles.add(target);
31
- if (options.log) {
32
- console.log(`Saved ${target} (${svg.length} bytes)`);
33
- }
34
- };
35
- // Export characters first, in case if icon name conflicts with character name
36
- if (options.includeChars) {
37
- const chars = iconSet.chars();
38
- for (const char in chars) {
39
- const name = chars[char];
40
- await store(name, `${dir}/${char}.svg`);
41
- }
42
- }
43
- // Export all icons
44
- await iconSet.forEach(async (name, type) => {
45
- if (type === 'alias' && options.includeAliases === false) {
46
- return;
47
- }
48
- await store(name, `${dir}/${name}.svg`);
49
- });
50
- return Array.from(storedFiles);
51
- }
52
- exports.exportToDirectory = exportToDirectory;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exportCustomFiles = void 0;
4
- const fs_1 = require("fs");
5
- const write_json_1 = require("../../misc/write-json");
6
- /**
7
- * Write custom files
8
- */
9
- async function exportCustomFiles(dir, options, result) {
10
- const customFiles = options.customFiles || {};
11
- for (const filename in customFiles) {
12
- const content = customFiles[filename];
13
- if (content === null) {
14
- // Delete file, if exists
15
- try {
16
- await fs_1.promises.unlink(dir + '/' + filename);
17
- }
18
- catch (err) {
19
- //
20
- }
21
- continue;
22
- }
23
- if (typeof content === 'string') {
24
- await fs_1.promises.writeFile(dir + '/' + filename, content, 'utf8');
25
- }
26
- else if (typeof content === 'object') {
27
- await (0, write_json_1.writeJSONFile)(dir + '/' + filename, content);
28
- }
29
- result === null || result === void 0 ? void 0 : result.add(filename);
30
- }
31
- }
32
- exports.exportCustomFiles = exportCustomFiles;