@iconify/tools 2.0.1 → 2.0.5
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.
- package/lib/colors/parse.d.ts +1 -1
- package/lib/colors/parse.js +3 -1
- package/lib/colors/parse.mjs +2 -1
- package/lib/colors/validate.d.ts +11 -0
- package/lib/colors/validate.js +45 -0
- package/lib/colors/validate.mjs +33 -0
- package/lib/download/git/index.d.ts +7 -3
- package/lib/download/git/index.js +0 -3
- package/lib/download/github/index.d.ts +7 -3
- package/lib/download/github/index.js +18 -13
- package/lib/download/github/index.mjs +14 -10
- package/lib/download/helpers/untar.d.ts +4 -0
- package/lib/download/helpers/untar.js +14 -0
- package/lib/download/helpers/untar.mjs +11 -0
- package/lib/download/npm/index.d.ts +7 -3
- package/lib/download/npm/index.js +43 -15
- package/lib/download/npm/index.mjs +35 -9
- package/lib/export/helpers/types-version.mjs +26 -65
- package/lib/icon-set/index.js +1 -1
- package/lib/icon-set/merge.js +1 -1
- package/lib/import/figma/index.d.ts +3 -2
- package/lib/import/figma/index.js +0 -3
- package/lib/import/figma/query.d.ts +3 -2
- package/lib/import/figma/query.js +0 -3
- package/lib/import/figma/types/options.d.ts +4 -2
- package/lib/index.d.ts +9 -3
- package/lib/index.js +20 -6
- package/lib/index.mjs +16 -3
- package/lib/misc/bump-version.d.ts +4 -0
- package/lib/misc/bump-version.js +19 -0
- package/lib/misc/bump-version.mjs +15 -0
- package/lib/misc/compare-dirs.d.ts +9 -0
- package/lib/misc/compare-dirs.js +84 -0
- package/lib/misc/compare-dirs.mjs +71 -0
- package/lib/misc/scan.d.ts +4 -2
- package/lib/misc/scan.js +2 -2
- package/lib/misc/scan.mjs +2 -2
- package/lib/optimise/svgo.js +13 -3
- package/lib/optimise/svgo.mjs +8 -3
- package/lib/svg/cleanup/bad-tags.js +0 -2
- package/lib/svg/cleanup/bad-tags.mjs +0 -3
- package/lib/svg/data/tags.d.ts +0 -4
- package/lib/svg/data/tags.js +1 -9
- package/lib/svg/data/tags.mjs +0 -6
- package/package.json +23 -4
package/lib/colors/parse.d.ts
CHANGED
package/lib/colors/parse.js
CHANGED
|
@@ -245,13 +245,15 @@ async function parseColors(svg, options = {}) {
|
|
|
245
245
|
const color = getElementColor(prop, item);
|
|
246
246
|
if (color === attribs_1.defaultBlackColor) {
|
|
247
247
|
// Default black color: change it
|
|
248
|
-
result.hasUnsetColor = true;
|
|
249
248
|
if (defaultColor) {
|
|
250
249
|
// Add color to results and change attribute
|
|
251
250
|
findColor(defaultColor, true);
|
|
252
251
|
$element.attr(prop, (0, colors_1.colorToString)(defaultColor));
|
|
253
252
|
itemColors[prop] = defaultColor;
|
|
254
253
|
}
|
|
254
|
+
else {
|
|
255
|
+
result.hasUnsetColor = true;
|
|
256
|
+
}
|
|
255
257
|
}
|
|
256
258
|
}
|
|
257
259
|
}
|
package/lib/colors/parse.mjs
CHANGED
|
@@ -197,11 +197,12 @@ async function parseColors(svg, options = {}) {
|
|
|
197
197
|
const prop = requiredProps[i];
|
|
198
198
|
const color = getElementColor(prop, item);
|
|
199
199
|
if (color === defaultBlackColor) {
|
|
200
|
-
result.hasUnsetColor = true;
|
|
201
200
|
if (defaultColor) {
|
|
202
201
|
findColor(defaultColor, true);
|
|
203
202
|
$element.attr(prop, colorToString(defaultColor));
|
|
204
203
|
itemColors[prop] = defaultColor;
|
|
204
|
+
} else {
|
|
205
|
+
result.hasUnsetColor = true;
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SVG } from '../svg/index';
|
|
2
|
+
import { ParseColorsOptions } from './parse';
|
|
3
|
+
import type { FindColorsResult } from './parse';
|
|
4
|
+
/**
|
|
5
|
+
* Validate colors in icon
|
|
6
|
+
*
|
|
7
|
+
* If icon is monotone,
|
|
8
|
+
*
|
|
9
|
+
* Throws exception on error
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions): Promise<FindColorsResult>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateColors = void 0;
|
|
4
|
+
const colors_1 = require("@iconify/utils/lib/colors");
|
|
5
|
+
const parse_1 = require("./parse");
|
|
6
|
+
/**
|
|
7
|
+
* Validate colors in icon
|
|
8
|
+
*
|
|
9
|
+
* If icon is monotone,
|
|
10
|
+
*
|
|
11
|
+
* Throws exception on error
|
|
12
|
+
*/
|
|
13
|
+
async function validateColors(svg, expectMonotone, options) {
|
|
14
|
+
// Parse colors
|
|
15
|
+
const palette = await (0, parse_1.parseColors)(svg, options);
|
|
16
|
+
// Check palette
|
|
17
|
+
palette.colors.forEach((color) => {
|
|
18
|
+
if (typeof color === 'string') {
|
|
19
|
+
throw new Error('Unexpected color: ' + color);
|
|
20
|
+
}
|
|
21
|
+
switch (color.type) {
|
|
22
|
+
case 'none':
|
|
23
|
+
case 'transparent':
|
|
24
|
+
return;
|
|
25
|
+
// Monotone
|
|
26
|
+
case 'current':
|
|
27
|
+
if (!expectMonotone) {
|
|
28
|
+
throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
// Palette
|
|
32
|
+
case 'rgb':
|
|
33
|
+
case 'hsl':
|
|
34
|
+
if (expectMonotone) {
|
|
35
|
+
throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
// Do not allow other colors
|
|
39
|
+
default:
|
|
40
|
+
throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return palette;
|
|
44
|
+
}
|
|
45
|
+
exports.validateColors = validateColors;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/colors/validate.ts
|
|
2
|
+
import { colorToString } from "@iconify/utils/lib/colors";
|
|
3
|
+
import { parseColors } from "./parse.mjs";
|
|
4
|
+
async function validateColors(svg, expectMonotone, options) {
|
|
5
|
+
const palette = await parseColors(svg, options);
|
|
6
|
+
palette.colors.forEach((color) => {
|
|
7
|
+
if (typeof color === "string") {
|
|
8
|
+
throw new Error("Unexpected color: " + color);
|
|
9
|
+
}
|
|
10
|
+
switch (color.type) {
|
|
11
|
+
case "none":
|
|
12
|
+
case "transparent":
|
|
13
|
+
return;
|
|
14
|
+
case "current":
|
|
15
|
+
if (!expectMonotone) {
|
|
16
|
+
throw new Error("Unexpected color: " + colorToString(color));
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
case "rgb":
|
|
20
|
+
case "hsl":
|
|
21
|
+
if (expectMonotone) {
|
|
22
|
+
throw new Error("Unexpected color: " + colorToString(color));
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error("Unexpected color: " + colorToString(color));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return palette;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
validateColors
|
|
33
|
+
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ExportTargetOptions } from '../../export/helpers/prepare';
|
|
2
2
|
import type { DocumentNotModified } from '../types/modified';
|
|
3
|
+
interface IfModifiedSinceOption {
|
|
4
|
+
ifModifiedSince: string | true;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Options for downloadGitRepo()
|
|
5
8
|
*/
|
|
6
|
-
export interface DownloadGitRepoOptions extends ExportTargetOptions {
|
|
9
|
+
export interface DownloadGitRepoOptions extends ExportTargetOptions, Partial<IfModifiedSinceOption> {
|
|
7
10
|
remote: string;
|
|
8
11
|
branch: string;
|
|
9
|
-
ifModifiedSince?: string | true;
|
|
10
12
|
log?: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
@@ -19,4 +21,6 @@ export interface DownloadGitRepoResult {
|
|
|
19
21
|
/**
|
|
20
22
|
* Download Git repo
|
|
21
23
|
*/
|
|
22
|
-
export declare function downloadGitRepo(options:
|
|
24
|
+
export declare function downloadGitRepo<T extends IfModifiedSinceOption & DownloadGitRepoOptions>(options: T): Promise<DownloadGitRepoResult | DocumentNotModified>;
|
|
25
|
+
export declare function downloadGitRepo(options: DownloadGitRepoOptions): Promise<DownloadGitRepoResult>;
|
|
26
|
+
export {};
|
|
@@ -5,9 +5,6 @@ const fs_1 = require("fs");
|
|
|
5
5
|
const prepare_1 = require("../../export/helpers/prepare");
|
|
6
6
|
const exec_1 = require("../../misc/exec");
|
|
7
7
|
const hash_1 = require("./hash");
|
|
8
|
-
/**
|
|
9
|
-
* Download Git repo
|
|
10
|
-
*/
|
|
11
8
|
async function downloadGitRepo(options) {
|
|
12
9
|
const { remote, branch } = options;
|
|
13
10
|
// Check for last commit
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ExportTargetOptions } from '../../export/helpers/prepare';
|
|
2
2
|
import type { DocumentNotModified } from '../types/modified';
|
|
3
3
|
import type { GitHubAPIOptions } from './types';
|
|
4
|
+
interface IfModifiedSinceOption {
|
|
5
|
+
ifModifiedSince: string;
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
8
|
* Options for downloadGitRepo()
|
|
6
9
|
*/
|
|
7
|
-
export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAPIOptions {
|
|
8
|
-
ifModifiedSince?: string;
|
|
10
|
+
export interface DownloadGitHubRepoOptions extends ExportTargetOptions, GitHubAPIOptions, Partial<IfModifiedSinceOption> {
|
|
9
11
|
cleanupOldFiles?: boolean;
|
|
10
12
|
cleanupOldDirectories?: boolean;
|
|
11
13
|
log?: boolean;
|
|
@@ -21,4 +23,6 @@ export interface DownloadGitHubRepoResult {
|
|
|
21
23
|
/**
|
|
22
24
|
* Download GitHub repo using API
|
|
23
25
|
*/
|
|
24
|
-
export declare function downloadGitHubRepo(options:
|
|
26
|
+
export declare function downloadGitHubRepo<T extends IfModifiedSinceOption & DownloadGitHubRepoOptions>(options: T): Promise<DownloadGitHubRepoResult | DocumentNotModified>;
|
|
27
|
+
export declare function downloadGitHubRepo(options: DownloadGitHubRepoOptions): Promise<DownloadGitHubRepoResult>;
|
|
28
|
+
export {};
|
|
@@ -10,24 +10,22 @@ const unzip_1 = require("../helpers/unzip");
|
|
|
10
10
|
* Find matching directories
|
|
11
11
|
*/
|
|
12
12
|
async function findMatchingDirs(rootDir, hash) {
|
|
13
|
-
const search = '-' + hash;
|
|
14
13
|
const matches = [];
|
|
15
14
|
const files = await fs_1.promises.readdir(rootDir);
|
|
16
15
|
for (let i = 0; i < files.length; i++) {
|
|
17
16
|
const file = files[i];
|
|
18
|
-
|
|
17
|
+
const lastChunk = file.split('-').pop();
|
|
18
|
+
if (lastChunk.length < 4 ||
|
|
19
|
+
lastChunk !== hash.slice(0, lastChunk.length)) {
|
|
19
20
|
continue;
|
|
20
21
|
}
|
|
21
|
-
const stat = await fs_1.promises.
|
|
22
|
+
const stat = await fs_1.promises.stat(rootDir + '/' + file);
|
|
22
23
|
if (stat.isDirectory()) {
|
|
23
24
|
matches.push(file);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
return matches;
|
|
27
28
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Download GitHub repo using API
|
|
30
|
-
*/
|
|
31
29
|
async function downloadGitHubRepo(options) {
|
|
32
30
|
// Check for last commit
|
|
33
31
|
const hash = await (0, hash_1.getGitHubRepoHash)(options);
|
|
@@ -39,11 +37,11 @@ async function downloadGitHubRepo(options) {
|
|
|
39
37
|
// Prepare target directory
|
|
40
38
|
const rootDir = (options.target = await (0, prepare_1.prepareDirectoryForExport)(options));
|
|
41
39
|
// Archive name
|
|
42
|
-
const
|
|
40
|
+
const archiveTarget = rootDir + '/' + hash + '.zip';
|
|
43
41
|
// Check if archive exists
|
|
44
42
|
let exists = false;
|
|
45
43
|
try {
|
|
46
|
-
const stat = await fs_1.promises.
|
|
44
|
+
const stat = await fs_1.promises.stat(archiveTarget);
|
|
47
45
|
exists = stat.isFile();
|
|
48
46
|
}
|
|
49
47
|
catch (err) {
|
|
@@ -51,10 +49,15 @@ async function downloadGitHubRepo(options) {
|
|
|
51
49
|
}
|
|
52
50
|
// Download file
|
|
53
51
|
if (!exists) {
|
|
54
|
-
const uri = `https://
|
|
52
|
+
const uri = `https://api.github.com/repos/${options.user}/${options.repo}/zipball/${hash}`;
|
|
53
|
+
// const uri = `https://codeload.github.com/${options.user}/${options.repo}/zip/${hash}`;
|
|
55
54
|
await (0, download_1.downloadFile)({
|
|
56
55
|
uri,
|
|
57
|
-
|
|
56
|
+
headers: {
|
|
57
|
+
Accept: 'application/vnd.github.v3+json',
|
|
58
|
+
Authorization: 'token ' + options.token,
|
|
59
|
+
},
|
|
60
|
+
}, archiveTarget);
|
|
58
61
|
}
|
|
59
62
|
// Clean up old directories
|
|
60
63
|
const files = await fs_1.promises.readdir(rootDir);
|
|
@@ -68,8 +71,10 @@ async function downloadGitHubRepo(options) {
|
|
|
68
71
|
const stat = await fs_1.promises.lstat(filename);
|
|
69
72
|
const isDir = stat.isDirectory();
|
|
70
73
|
if (
|
|
71
|
-
// Remove
|
|
72
|
-
|
|
74
|
+
// Remove symbolic links
|
|
75
|
+
stat.isSymbolicLink() ||
|
|
76
|
+
// Remove if directory matches hash to avoid errors extracting zip
|
|
77
|
+
(isDir && filename.slice(0 - hashSearch.length) === hashSearch) ||
|
|
73
78
|
// Remove if directory and cleanupOldDirectories is not disabled
|
|
74
79
|
(isDir && options.cleanupOldDirectories !== false) ||
|
|
75
80
|
// Remove if file and cleanupOldFiles is enabled
|
|
@@ -86,7 +91,7 @@ async function downloadGitHubRepo(options) {
|
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
// Unpack it
|
|
89
|
-
await (0, unzip_1.unzip)(
|
|
94
|
+
await (0, unzip_1.unzip)(archiveTarget, rootDir);
|
|
90
95
|
// Get actual dir
|
|
91
96
|
const matchingDirs = await findMatchingDirs(rootDir, hash);
|
|
92
97
|
if (matchingDirs.length !== 1) {
|
|
@@ -7,15 +7,15 @@ import { getGitHubRepoHash } from "./hash.mjs";
|
|
|
7
7
|
import { downloadFile } from "../api/download.mjs";
|
|
8
8
|
import { unzip } from "../helpers/unzip.mjs";
|
|
9
9
|
async function findMatchingDirs(rootDir, hash) {
|
|
10
|
-
const search = "-" + hash;
|
|
11
10
|
const matches = [];
|
|
12
11
|
const files = await fs.readdir(rootDir);
|
|
13
12
|
for (let i = 0; i < files.length; i++) {
|
|
14
13
|
const file = files[i];
|
|
15
|
-
|
|
14
|
+
const lastChunk = file.split("-").pop();
|
|
15
|
+
if (lastChunk.length < 4 || lastChunk !== hash.slice(0, lastChunk.length)) {
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
|
-
const stat = await fs.
|
|
18
|
+
const stat = await fs.stat(rootDir + "/" + file);
|
|
19
19
|
if (stat.isDirectory()) {
|
|
20
20
|
matches.push(file);
|
|
21
21
|
}
|
|
@@ -29,18 +29,22 @@ async function downloadGitHubRepo(options) {
|
|
|
29
29
|
}
|
|
30
30
|
options.target = options.target.replace("{hash}", hash);
|
|
31
31
|
const rootDir = options.target = await prepareDirectoryForExport(options);
|
|
32
|
-
const
|
|
32
|
+
const archiveTarget = rootDir + "/" + hash + ".zip";
|
|
33
33
|
let exists = false;
|
|
34
34
|
try {
|
|
35
|
-
const stat = await fs.
|
|
35
|
+
const stat = await fs.stat(archiveTarget);
|
|
36
36
|
exists = stat.isFile();
|
|
37
37
|
} catch (err) {
|
|
38
38
|
}
|
|
39
39
|
if (!exists) {
|
|
40
|
-
const uri = `https://
|
|
40
|
+
const uri = `https://api.github.com/repos/${options.user}/${options.repo}/zipball/${hash}`;
|
|
41
41
|
await downloadFile({
|
|
42
|
-
uri
|
|
43
|
-
|
|
42
|
+
uri,
|
|
43
|
+
headers: {
|
|
44
|
+
Accept: "application/vnd.github.v3+json",
|
|
45
|
+
Authorization: "token " + options.token
|
|
46
|
+
}
|
|
47
|
+
}, archiveTarget);
|
|
44
48
|
}
|
|
45
49
|
const files = await fs.readdir(rootDir);
|
|
46
50
|
const hashSearch = "-" + hash;
|
|
@@ -52,7 +56,7 @@ async function downloadGitHubRepo(options) {
|
|
|
52
56
|
const filename = rootDir + "/" + files[i];
|
|
53
57
|
const stat = await fs.lstat(filename);
|
|
54
58
|
const isDir = stat.isDirectory();
|
|
55
|
-
if (isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
|
|
59
|
+
if (stat.isSymbolicLink() || isDir && filename.slice(0 - hashSearch.length) === hashSearch || isDir && options.cleanupOldDirectories !== false || !isDir && options.cleanupOldFiles) {
|
|
56
60
|
try {
|
|
57
61
|
await fs.rm(filename, {
|
|
58
62
|
force: true,
|
|
@@ -62,7 +66,7 @@ async function downloadGitHubRepo(options) {
|
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
|
-
await unzip(
|
|
69
|
+
await unzip(archiveTarget, rootDir);
|
|
66
70
|
const matchingDirs = await findMatchingDirs(rootDir, hash);
|
|
67
71
|
if (matchingDirs.length !== 1) {
|
|
68
72
|
throw new Error(`Error unpacking ${hash}.zip`);
|
|
@@ -0,0 +1,14 @@
|
|
|
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,12 +1,14 @@
|
|
|
1
1
|
import { ExportTargetOptions } from '../../export/helpers/prepare';
|
|
2
2
|
import type { DocumentNotModified } from '../types/modified';
|
|
3
|
+
interface IfModifiedSinceOption {
|
|
4
|
+
ifModifiedSince: string | true;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Options for downloadNPMPackage()
|
|
5
8
|
*/
|
|
6
|
-
export interface DownloadNPMPackageOptions extends ExportTargetOptions {
|
|
9
|
+
export interface DownloadNPMPackageOptions extends ExportTargetOptions, Partial<IfModifiedSinceOption> {
|
|
7
10
|
package: string;
|
|
8
11
|
tag?: string;
|
|
9
|
-
ifModifiedSince?: string | true;
|
|
10
12
|
log?: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
@@ -20,4 +22,6 @@ export interface DownloadNPMPackageResult {
|
|
|
20
22
|
/**
|
|
21
23
|
* Download NPM package
|
|
22
24
|
*/
|
|
23
|
-
export declare function downloadNPMPackage(options:
|
|
25
|
+
export declare function downloadNPMPackage<T extends IfModifiedSinceOption & DownloadNPMPackageOptions>(options: T): Promise<DownloadNPMPackageResult | DocumentNotModified>;
|
|
26
|
+
export declare function downloadNPMPackage(options: DownloadNPMPackageOptions): Promise<DownloadNPMPackageResult>;
|
|
27
|
+
export {};
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.downloadNPMPackage = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
4
5
|
const prepare_1 = require("../../export/helpers/prepare");
|
|
5
|
-
const
|
|
6
|
+
const download_1 = require("../api/download");
|
|
7
|
+
const untar_1 = require("../helpers/untar");
|
|
6
8
|
const version_1 = require("./version");
|
|
7
|
-
/**
|
|
8
|
-
* Download NPM package
|
|
9
|
-
*/
|
|
10
9
|
async function downloadNPMPackage(options) {
|
|
11
|
-
const packageName = options.package;
|
|
12
|
-
const tag = options.tag || 'latest';
|
|
13
10
|
const rootDir = (options.target = (0, prepare_1.normalizeDir)(options.target));
|
|
14
|
-
const actualDir = rootDir + '/
|
|
15
|
-
//
|
|
11
|
+
const actualDir = 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
16
|
if (options.ifModifiedSince) {
|
|
17
17
|
try {
|
|
18
18
|
const expectedVersion = options.ifModifiedSince === true
|
|
19
19
|
? await (0, version_1.getPackageVersion)(actualDir)
|
|
20
20
|
: options.ifModifiedSince;
|
|
21
|
-
|
|
22
|
-
if (latestVersion === expectedVersion) {
|
|
21
|
+
if (version === expectedVersion) {
|
|
23
22
|
return 'not_modified';
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -27,15 +26,44 @@ async function downloadNPMPackage(options) {
|
|
|
27
26
|
//
|
|
28
27
|
}
|
|
29
28
|
}
|
|
29
|
+
const archiveURL = versionInfo.file;
|
|
30
|
+
if (!archiveURL) {
|
|
31
|
+
throw new Error(`NPM registry did not provide link to package archive.`);
|
|
32
|
+
}
|
|
33
|
+
const archiveTarget = rootDir + '/' + version + '.tgz';
|
|
30
34
|
// Prepare target directory
|
|
31
35
|
await (0, prepare_1.prepareDirectoryForExport)(options);
|
|
32
|
-
// Check if
|
|
36
|
+
// Check if archive exists
|
|
37
|
+
let archiveExists = false;
|
|
38
|
+
try {
|
|
39
|
+
const stat = await fs_1.promises.stat(archiveTarget);
|
|
40
|
+
archiveExists = stat.isFile();
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
//
|
|
44
|
+
}
|
|
45
|
+
// Download file
|
|
46
|
+
if (!archiveExists) {
|
|
47
|
+
if (options.log) {
|
|
48
|
+
console.log(`Downloading ${archiveURL}`);
|
|
49
|
+
}
|
|
50
|
+
await (0, download_1.downloadFile)({
|
|
51
|
+
uri: archiveURL,
|
|
52
|
+
headers: {
|
|
53
|
+
Accept: 'application/tar+gzip',
|
|
54
|
+
},
|
|
55
|
+
}, archiveTarget);
|
|
56
|
+
}
|
|
57
|
+
// Remove old unpacked file
|
|
58
|
+
await (0, prepare_1.prepareDirectoryForExport)({
|
|
59
|
+
target: actualDir,
|
|
60
|
+
cleanup: true,
|
|
61
|
+
});
|
|
62
|
+
// Unpack file
|
|
33
63
|
if (options.log) {
|
|
34
|
-
console.log(`
|
|
64
|
+
console.log(`Unpacking ${archiveTarget}`);
|
|
35
65
|
}
|
|
36
|
-
await (0,
|
|
37
|
-
// Get latest version
|
|
38
|
-
const version = await (0, version_1.getPackageVersion)(actualDir);
|
|
66
|
+
await (0, untar_1.untar)(archiveTarget, rootDir);
|
|
39
67
|
return {
|
|
40
68
|
rootDir,
|
|
41
69
|
actualDir,
|
|
@@ -1,31 +1,57 @@
|
|
|
1
1
|
// src/download/npm/index.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
2
3
|
import {
|
|
3
4
|
normalizeDir,
|
|
4
5
|
prepareDirectoryForExport
|
|
5
6
|
} from "../../export/helpers/prepare.mjs";
|
|
6
|
-
import {
|
|
7
|
+
import { downloadFile } from "../api/download.mjs";
|
|
8
|
+
import { untar } from "../helpers/untar.mjs";
|
|
7
9
|
import { getNPMVersion, getPackageVersion } from "./version.mjs";
|
|
8
10
|
async function downloadNPMPackage(options) {
|
|
9
|
-
const packageName = options.package;
|
|
10
|
-
const tag = options.tag || "latest";
|
|
11
11
|
const rootDir = options.target = normalizeDir(options.target);
|
|
12
|
-
const actualDir = rootDir + "/
|
|
12
|
+
const actualDir = rootDir + "/package";
|
|
13
|
+
const versionInfo = await getNPMVersion(options);
|
|
14
|
+
const version = versionInfo.version;
|
|
13
15
|
if (options.ifModifiedSince) {
|
|
14
16
|
try {
|
|
15
17
|
const expectedVersion = options.ifModifiedSince === true ? await getPackageVersion(actualDir) : options.ifModifiedSince;
|
|
16
|
-
|
|
17
|
-
if (latestVersion === expectedVersion) {
|
|
18
|
+
if (version === expectedVersion) {
|
|
18
19
|
return "not_modified";
|
|
19
20
|
}
|
|
20
21
|
} catch (err) {
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
const archiveURL = versionInfo.file;
|
|
25
|
+
if (!archiveURL) {
|
|
26
|
+
throw new Error(`NPM registry did not provide link to package archive.`);
|
|
27
|
+
}
|
|
28
|
+
const archiveTarget = rootDir + "/" + version + ".tgz";
|
|
23
29
|
await prepareDirectoryForExport(options);
|
|
30
|
+
let archiveExists = false;
|
|
31
|
+
try {
|
|
32
|
+
const stat = await fs.stat(archiveTarget);
|
|
33
|
+
archiveExists = stat.isFile();
|
|
34
|
+
} catch (err) {
|
|
35
|
+
}
|
|
36
|
+
if (!archiveExists) {
|
|
37
|
+
if (options.log) {
|
|
38
|
+
console.log(`Downloading ${archiveURL}`);
|
|
39
|
+
}
|
|
40
|
+
await downloadFile({
|
|
41
|
+
uri: archiveURL,
|
|
42
|
+
headers: {
|
|
43
|
+
Accept: "application/tar+gzip"
|
|
44
|
+
}
|
|
45
|
+
}, archiveTarget);
|
|
46
|
+
}
|
|
47
|
+
await prepareDirectoryForExport({
|
|
48
|
+
target: actualDir,
|
|
49
|
+
cleanup: true
|
|
50
|
+
});
|
|
24
51
|
if (options.log) {
|
|
25
|
-
console.log(`
|
|
52
|
+
console.log(`Unpacking ${archiveTarget}`);
|
|
26
53
|
}
|
|
27
|
-
await
|
|
28
|
-
const version = await getPackageVersion(actualDir);
|
|
54
|
+
await untar(archiveTarget, rootDir);
|
|
29
55
|
return {
|
|
30
56
|
rootDir,
|
|
31
57
|
actualDir,
|
|
@@ -1,76 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
var __esm = (fn, res) => function __init() {
|
|
4
|
-
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
5
|
-
};
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
__markAsModule(target);
|
|
8
|
-
for (var name2 in all)
|
|
9
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
1
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
2
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
3
|
};
|
|
11
4
|
|
|
12
5
|
// ../../node_modules/@iconify/types/package.json
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
author = "Vjacheslav Trushkin";
|
|
37
|
-
license = "(Apache-2.0 OR GPL-2.0)";
|
|
38
|
-
main = "./index.js";
|
|
39
|
-
type = "module";
|
|
40
|
-
types = "./types.ts";
|
|
41
|
-
scripts = {
|
|
42
|
-
test: "tsc --noEmit --strict --typeRoots '[]' types.ts"
|
|
43
|
-
};
|
|
44
|
-
bugs = "https://github.com/iconify/iconify/issues";
|
|
45
|
-
homepage = "https://github.com/iconify/iconify";
|
|
46
|
-
repository = {
|
|
47
|
-
type: "git",
|
|
48
|
-
url: "https://github.com/iconify/iconify.git",
|
|
49
|
-
directory: "packages/types"
|
|
50
|
-
};
|
|
51
|
-
devDependencies = {
|
|
52
|
-
typescript: "^4.4.3"
|
|
53
|
-
};
|
|
54
|
-
package_default = {
|
|
55
|
-
name,
|
|
56
|
-
description,
|
|
57
|
-
version,
|
|
58
|
-
author,
|
|
59
|
-
license,
|
|
60
|
-
main,
|
|
61
|
-
type,
|
|
62
|
-
types,
|
|
63
|
-
scripts,
|
|
64
|
-
bugs,
|
|
65
|
-
homepage,
|
|
66
|
-
repository,
|
|
67
|
-
devDependencies
|
|
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
|
+
}
|
|
68
29
|
};
|
|
69
30
|
}
|
|
70
31
|
});
|
|
71
32
|
|
|
72
33
|
// src/export/helpers/types-version.ts
|
|
73
|
-
var pkg = (
|
|
34
|
+
var pkg = require_package();
|
|
74
35
|
function getTypesVersion() {
|
|
75
36
|
return pkg.version;
|
|
76
37
|
}
|