@iconify/tools 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +13 -10
- package/lib/download/github/index.mjs +12 -8
- 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/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/optimise/svgo.js +1 -0
- package/package.json +22 -3
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,12 +10,13 @@ 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
22
|
const stat = await fs_1.promises.lstat(rootDir + '/' + file);
|
|
@@ -25,9 +26,6 @@ async function findMatchingDirs(rootDir, hash) {
|
|
|
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.lstat(
|
|
44
|
+
const stat = await fs_1.promises.lstat(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);
|
|
@@ -86,7 +89,7 @@ async function downloadGitHubRepo(options) {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
// Unpack it
|
|
89
|
-
await (0, unzip_1.unzip)(
|
|
92
|
+
await (0, unzip_1.unzip)(archiveTarget, rootDir);
|
|
90
93
|
// Get actual dir
|
|
91
94
|
const matchingDirs = await findMatchingDirs(rootDir, hash);
|
|
92
95
|
if (matchingDirs.length !== 1) {
|
|
@@ -7,12 +7,12 @@ 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
18
|
const stat = await fs.lstat(rootDir + "/" + file);
|
|
@@ -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.lstat(
|
|
35
|
+
const stat = await fs.lstat(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;
|
|
@@ -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.lstat(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.lstat(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
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DocumentNotModified } from '../../download/types/modified';
|
|
2
|
-
import type { FigmaImportOptions } from './types/options';
|
|
2
|
+
import type { FigmaImportOptions, FigmaIfModifiedSinceOption } from './types/options';
|
|
3
3
|
import type { FigmaImportResult } from './types/result';
|
|
4
4
|
/**
|
|
5
5
|
* Import icon set from Figma
|
|
6
6
|
*/
|
|
7
|
-
export declare function importFromFigma(options:
|
|
7
|
+
export declare function importFromFigma<T extends FigmaIfModifiedSinceOption & FigmaImportOptions>(options: T): Promise<FigmaImportResult | DocumentNotModified>;
|
|
8
|
+
export declare function importFromFigma(options: FigmaImportOptions): Promise<FigmaImportResult>;
|
|
@@ -6,9 +6,6 @@ const svg_1 = require("../../svg");
|
|
|
6
6
|
const cleanup_1 = require("../../svg/cleanup");
|
|
7
7
|
const nodes_1 = require("./nodes");
|
|
8
8
|
const query_1 = require("./query");
|
|
9
|
-
/**
|
|
10
|
-
* Import icon set from Figma
|
|
11
|
-
*/
|
|
12
9
|
async function importFromFigma(options) {
|
|
13
10
|
const cacheOptions = options.cacheDir
|
|
14
11
|
? {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { APICacheOptions } from '../../download/api/types';
|
|
2
2
|
import type { DocumentNotModified } from '../../download/types/modified';
|
|
3
3
|
import type { FigmaDocument } from './types/api';
|
|
4
|
-
import type { FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
|
|
4
|
+
import type { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
|
|
5
5
|
import type { FigmaNodesImportResult } from './types/result';
|
|
6
6
|
/**
|
|
7
7
|
* Get Figma files
|
|
8
8
|
*/
|
|
9
|
-
export declare function figmaFilesQuery(options:
|
|
9
|
+
export declare function figmaFilesQuery<T extends FigmaIfModifiedSinceOption & FigmaFilesQueryOptions>(options: T, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
|
|
10
|
+
export declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument>;
|
|
10
11
|
/**
|
|
11
12
|
* Generate all images
|
|
12
13
|
*/
|
|
@@ -17,8 +17,10 @@ interface FigmaImportCommonOptions {
|
|
|
17
17
|
file: string;
|
|
18
18
|
version?: string;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
21
|
-
ifModifiedSince
|
|
20
|
+
export interface FigmaIfModifiedSinceOption {
|
|
21
|
+
ifModifiedSince: string | Date | true;
|
|
22
|
+
}
|
|
23
|
+
export interface FigmaFilesQueryOptions extends FigmaImportCommonOptions, Partial<FigmaIfModifiedSinceOption> {
|
|
22
24
|
ids?: string[];
|
|
23
25
|
depth?: number;
|
|
24
26
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,15 +17,21 @@ export { downloadGitHubRepo } from './download/github/index';
|
|
|
17
17
|
export { getGitHubRepoHash } from './download/github/hash';
|
|
18
18
|
export { downloadNPMPackage } from './download/npm/index';
|
|
19
19
|
export { getNPMVersion, getPackageVersion } from './download/npm/version';
|
|
20
|
-
export { parseColors } from './colors/parse';
|
|
20
|
+
export { parseColors, isEmptyColor } from './colors/parse';
|
|
21
|
+
export { validateColors } from './colors/validate';
|
|
21
22
|
export { runSVGO } from './optimise/svgo';
|
|
22
23
|
export { deOptimisePaths } from './optimise/flags';
|
|
23
24
|
export { scaleSVG } from './optimise/scale';
|
|
24
25
|
export { exportToDirectory } from './export/directory';
|
|
25
26
|
export { exportIconPackage } from './export/icon-package';
|
|
26
27
|
export { exportJSONPackage } from './export/json-package';
|
|
28
|
+
export { writeJSONFile } from './misc/write-json';
|
|
29
|
+
export { prepareDirectoryForExport } from './export/helpers/prepare';
|
|
30
|
+
export { scanDirectory } from './misc/scan';
|
|
31
|
+
export { compareDirectories } from './misc/compare-dirs';
|
|
32
|
+
export { unzip } from './download/helpers/unzip';
|
|
33
|
+
export { untar } from './download/helpers/untar';
|
|
27
34
|
export { execAsync } from './misc/exec';
|
|
28
35
|
export { cleanupIconKeyword } from './misc/keyword';
|
|
29
|
-
export {
|
|
30
|
-
export { writeJSONFile } from './misc/write-json';
|
|
36
|
+
export { bumpVersion } from './misc/bump-version';
|
|
31
37
|
export { sendAPIQuery } from './download/api/index';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendAPIQuery = exports.
|
|
3
|
+
exports.sendAPIQuery = exports.bumpVersion = exports.cleanupIconKeyword = exports.execAsync = exports.untar = exports.unzip = exports.compareDirectories = exports.scanDirectory = exports.prepareDirectoryForExport = exports.writeJSONFile = exports.exportJSONPackage = exports.exportIconPackage = exports.exportToDirectory = exports.scaleSVG = exports.deOptimisePaths = exports.runSVGO = exports.validateColors = exports.isEmptyColor = exports.parseColors = exports.getPackageVersion = exports.getNPMVersion = exports.downloadNPMPackage = exports.getGitHubRepoHash = exports.downloadGitHubRepo = exports.getGitRepoHash = exports.downloadGitRepo = exports.importDirectory = exports.importFromFigma = exports.mergeIconSets = exports.blankIconSet = exports.IconSet = exports.convertStyleToAttrs = exports.cleanupSVGRoot = exports.cleanupInlineStyle = exports.checkBadTags = exports.removeBadAttributes = exports.cleanupSVG = exports.parseSVGStyle = exports.parseSVG = exports.SVG = void 0;
|
|
4
4
|
// SVG class and functions
|
|
5
5
|
var index_1 = require("./svg/index");
|
|
6
6
|
Object.defineProperty(exports, "SVG", { enumerable: true, get: function () { return index_1.SVG; } });
|
|
@@ -49,6 +49,9 @@ Object.defineProperty(exports, "getPackageVersion", { enumerable: true, get: fun
|
|
|
49
49
|
// Manipulation
|
|
50
50
|
var parse_2 = require("./colors/parse");
|
|
51
51
|
Object.defineProperty(exports, "parseColors", { enumerable: true, get: function () { return parse_2.parseColors; } });
|
|
52
|
+
Object.defineProperty(exports, "isEmptyColor", { enumerable: true, get: function () { return parse_2.isEmptyColor; } });
|
|
53
|
+
var validate_1 = require("./colors/validate");
|
|
54
|
+
Object.defineProperty(exports, "validateColors", { enumerable: true, get: function () { return validate_1.validateColors; } });
|
|
52
55
|
var svgo_1 = require("./optimise/svgo");
|
|
53
56
|
Object.defineProperty(exports, "runSVGO", { enumerable: true, get: function () { return svgo_1.runSVGO; } });
|
|
54
57
|
var flags_1 = require("./optimise/flags");
|
|
@@ -62,14 +65,25 @@ var icon_package_1 = require("./export/icon-package");
|
|
|
62
65
|
Object.defineProperty(exports, "exportIconPackage", { enumerable: true, get: function () { return icon_package_1.exportIconPackage; } });
|
|
63
66
|
var json_package_1 = require("./export/json-package");
|
|
64
67
|
Object.defineProperty(exports, "exportJSONPackage", { enumerable: true, get: function () { return json_package_1.exportJSONPackage; } });
|
|
65
|
-
// Misc
|
|
68
|
+
// Misc: files, directories and archives
|
|
69
|
+
var write_json_1 = require("./misc/write-json");
|
|
70
|
+
Object.defineProperty(exports, "writeJSONFile", { enumerable: true, get: function () { return write_json_1.writeJSONFile; } });
|
|
71
|
+
var prepare_1 = require("./export/helpers/prepare");
|
|
72
|
+
Object.defineProperty(exports, "prepareDirectoryForExport", { enumerable: true, get: function () { return prepare_1.prepareDirectoryForExport; } });
|
|
73
|
+
var scan_1 = require("./misc/scan");
|
|
74
|
+
Object.defineProperty(exports, "scanDirectory", { enumerable: true, get: function () { return scan_1.scanDirectory; } });
|
|
75
|
+
var compare_dirs_1 = require("./misc/compare-dirs");
|
|
76
|
+
Object.defineProperty(exports, "compareDirectories", { enumerable: true, get: function () { return compare_dirs_1.compareDirectories; } });
|
|
77
|
+
var unzip_1 = require("./download/helpers/unzip");
|
|
78
|
+
Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return unzip_1.unzip; } });
|
|
79
|
+
var untar_1 = require("./download/helpers/untar");
|
|
80
|
+
Object.defineProperty(exports, "untar", { enumerable: true, get: function () { return untar_1.untar; } });
|
|
81
|
+
// Misc: other
|
|
66
82
|
var exec_1 = require("./misc/exec");
|
|
67
83
|
Object.defineProperty(exports, "execAsync", { enumerable: true, get: function () { return exec_1.execAsync; } });
|
|
68
84
|
var keyword_1 = require("./misc/keyword");
|
|
69
85
|
Object.defineProperty(exports, "cleanupIconKeyword", { enumerable: true, get: function () { return keyword_1.cleanupIconKeyword; } });
|
|
70
|
-
var
|
|
71
|
-
Object.defineProperty(exports, "
|
|
72
|
-
var write_json_1 = require("./misc/write-json");
|
|
73
|
-
Object.defineProperty(exports, "writeJSONFile", { enumerable: true, get: function () { return write_json_1.writeJSONFile; } });
|
|
86
|
+
var bump_version_1 = require("./misc/bump-version");
|
|
87
|
+
Object.defineProperty(exports, "bumpVersion", { enumerable: true, get: function () { return bump_version_1.bumpVersion; } });
|
|
74
88
|
var index_7 = require("./download/api/index");
|
|
75
89
|
Object.defineProperty(exports, "sendAPIQuery", { enumerable: true, get: function () { return index_7.sendAPIQuery; } });
|
package/lib/index.mjs
CHANGED
|
@@ -18,27 +18,35 @@ import { downloadGitHubRepo } from "./download/github/index.mjs";
|
|
|
18
18
|
import { getGitHubRepoHash } from "./download/github/hash.mjs";
|
|
19
19
|
import { downloadNPMPackage } from "./download/npm/index.mjs";
|
|
20
20
|
import { getNPMVersion, getPackageVersion } from "./download/npm/version.mjs";
|
|
21
|
-
import { parseColors } from "./colors/parse.mjs";
|
|
21
|
+
import { parseColors, isEmptyColor } from "./colors/parse.mjs";
|
|
22
|
+
import { validateColors } from "./colors/validate.mjs";
|
|
22
23
|
import { runSVGO } from "./optimise/svgo.mjs";
|
|
23
24
|
import { deOptimisePaths } from "./optimise/flags.mjs";
|
|
24
25
|
import { scaleSVG } from "./optimise/scale.mjs";
|
|
25
26
|
import { exportToDirectory } from "./export/directory.mjs";
|
|
26
27
|
import { exportIconPackage } from "./export/icon-package.mjs";
|
|
27
28
|
import { exportJSONPackage } from "./export/json-package.mjs";
|
|
29
|
+
import { writeJSONFile } from "./misc/write-json.mjs";
|
|
30
|
+
import { prepareDirectoryForExport } from "./export/helpers/prepare.mjs";
|
|
31
|
+
import { scanDirectory } from "./misc/scan.mjs";
|
|
32
|
+
import { compareDirectories } from "./misc/compare-dirs.mjs";
|
|
33
|
+
import { unzip } from "./download/helpers/unzip.mjs";
|
|
34
|
+
import { untar } from "./download/helpers/untar.mjs";
|
|
28
35
|
import { execAsync } from "./misc/exec.mjs";
|
|
29
36
|
import { cleanupIconKeyword } from "./misc/keyword.mjs";
|
|
30
|
-
import {
|
|
31
|
-
import { writeJSONFile } from "./misc/write-json.mjs";
|
|
37
|
+
import { bumpVersion } from "./misc/bump-version.mjs";
|
|
32
38
|
import { sendAPIQuery } from "./download/api/index.mjs";
|
|
33
39
|
export {
|
|
34
40
|
IconSet,
|
|
35
41
|
SVG,
|
|
36
42
|
blankIconSet,
|
|
43
|
+
bumpVersion,
|
|
37
44
|
checkBadTags,
|
|
38
45
|
cleanupIconKeyword,
|
|
39
46
|
cleanupInlineStyle,
|
|
40
47
|
cleanupSVG,
|
|
41
48
|
cleanupSVGRoot,
|
|
49
|
+
compareDirectories,
|
|
42
50
|
convertStyleToAttrs,
|
|
43
51
|
deOptimisePaths,
|
|
44
52
|
downloadGitHubRepo,
|
|
@@ -54,14 +62,19 @@ export {
|
|
|
54
62
|
getPackageVersion,
|
|
55
63
|
importDirectory,
|
|
56
64
|
importFromFigma,
|
|
65
|
+
isEmptyColor,
|
|
57
66
|
mergeIconSets,
|
|
58
67
|
parseColors,
|
|
59
68
|
parseSVG,
|
|
60
69
|
parseSVGStyle,
|
|
70
|
+
prepareDirectoryForExport,
|
|
61
71
|
removeBadAttributes,
|
|
62
72
|
runSVGO,
|
|
63
73
|
scaleSVG,
|
|
64
74
|
scanDirectory,
|
|
65
75
|
sendAPIQuery,
|
|
76
|
+
untar,
|
|
77
|
+
unzip,
|
|
78
|
+
validateColors,
|
|
66
79
|
writeJSONFile
|
|
67
80
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bumpVersion = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bump version number
|
|
6
|
+
*/
|
|
7
|
+
function bumpVersion(version) {
|
|
8
|
+
const versionParts = version.split('.');
|
|
9
|
+
const lastPart = versionParts.pop();
|
|
10
|
+
const num = parseInt(lastPart);
|
|
11
|
+
if (isNaN(num) || num + '' !== lastPart) {
|
|
12
|
+
versionParts.push(lastPart + '.1');
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
versionParts.push(num + 1 + '');
|
|
16
|
+
}
|
|
17
|
+
return versionParts.join('.');
|
|
18
|
+
}
|
|
19
|
+
exports.bumpVersion = bumpVersion;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/misc/bump-version.ts
|
|
2
|
+
function bumpVersion(version) {
|
|
3
|
+
const versionParts = version.split(".");
|
|
4
|
+
const lastPart = versionParts.pop();
|
|
5
|
+
const num = parseInt(lastPart);
|
|
6
|
+
if (isNaN(num) || num + "" !== lastPart) {
|
|
7
|
+
versionParts.push(lastPart + ".1");
|
|
8
|
+
} else {
|
|
9
|
+
versionParts.push(num + 1 + "");
|
|
10
|
+
}
|
|
11
|
+
return versionParts.join(".");
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
bumpVersion
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CompareDirectoriesOptions {
|
|
2
|
+
ignoreNewLine?: boolean;
|
|
3
|
+
ignoreVersions?: boolean;
|
|
4
|
+
textExtensions?: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Compare directories. Returns true if files are identical, false if different
|
|
8
|
+
*/
|
|
9
|
+
export declare function compareDirectories(dir1: string, dir2: string, options?: CompareDirectoriesOptions): Promise<boolean>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareDirectories = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const prepare_1 = require("../export/helpers/prepare");
|
|
6
|
+
const scan_1 = require("./scan");
|
|
7
|
+
/**
|
|
8
|
+
* Extensions that are treated as text
|
|
9
|
+
*/
|
|
10
|
+
const textFileExtensions = [
|
|
11
|
+
'json',
|
|
12
|
+
'ts',
|
|
13
|
+
'js',
|
|
14
|
+
'mjs',
|
|
15
|
+
'cjs',
|
|
16
|
+
'jsx',
|
|
17
|
+
'tsx',
|
|
18
|
+
'vue',
|
|
19
|
+
'svelte',
|
|
20
|
+
'svg',
|
|
21
|
+
'txt',
|
|
22
|
+
'md',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Compare directories. Returns true if files are identical, false if different
|
|
26
|
+
*/
|
|
27
|
+
async function compareDirectories(dir1, dir2, options) {
|
|
28
|
+
dir1 = (0, prepare_1.normalizeDir)(dir1);
|
|
29
|
+
dir2 = (0, prepare_1.normalizeDir)(dir2);
|
|
30
|
+
// Get all files
|
|
31
|
+
const files1 = await (0, scan_1.scanDirectory)(dir1);
|
|
32
|
+
const files2 = await (0, scan_1.scanDirectory)(dir2);
|
|
33
|
+
if (files1.length !== files2.length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Options
|
|
37
|
+
options = options || {};
|
|
38
|
+
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
39
|
+
const ignoreVersions = options.ignoreVersions !== false;
|
|
40
|
+
const textExtensions = new Set((options.textExtensions || []).concat(textFileExtensions));
|
|
41
|
+
// Check all files
|
|
42
|
+
for (let i = 0; i < files1.length; i++) {
|
|
43
|
+
const file = files1[i];
|
|
44
|
+
if (files2.indexOf(file) === -1) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const ext = file.split('.').pop().toLowerCase();
|
|
48
|
+
const isText = textExtensions.has(ext);
|
|
49
|
+
if (!isText) {
|
|
50
|
+
// Compare binary files
|
|
51
|
+
const content1 = await fs_1.promises.readFile(dir1 + '/' + file);
|
|
52
|
+
const content2 = await fs_1.promises.readFile(dir2 + '/' + file);
|
|
53
|
+
if (Buffer.compare(content1, content2) !== 0) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// Text files
|
|
59
|
+
let content1 = await fs_1.promises.readFile(dir1 + '/' + file, 'utf8');
|
|
60
|
+
let content2 = await fs_1.promises.readFile(dir2 + '/' + file, 'utf8');
|
|
61
|
+
if (content1 === content2) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ignoreNewLine) {
|
|
65
|
+
// Remove space before new line (\r\n -> \n), remove new line at the end
|
|
66
|
+
content1 = content1.replace(/\s+\n/g, '\n').trimRight();
|
|
67
|
+
content2 = content2.replace(/\s+\n/g, '\n').trimRight();
|
|
68
|
+
}
|
|
69
|
+
if (ignoreVersions && file.split('/').pop() === 'package.json') {
|
|
70
|
+
// Ignore versions in package.json
|
|
71
|
+
const data1 = JSON.parse(content1);
|
|
72
|
+
const data2 = JSON.parse(content2);
|
|
73
|
+
delete data1.version;
|
|
74
|
+
delete data2.version;
|
|
75
|
+
content1 = JSON.stringify(data1);
|
|
76
|
+
content2 = JSON.stringify(data2);
|
|
77
|
+
}
|
|
78
|
+
if (content1 !== content2) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
exports.compareDirectories = compareDirectories;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/misc/compare-dirs.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { normalizeDir } from "../export/helpers/prepare.mjs";
|
|
4
|
+
import { scanDirectory } from "./scan.mjs";
|
|
5
|
+
var textFileExtensions = [
|
|
6
|
+
"json",
|
|
7
|
+
"ts",
|
|
8
|
+
"js",
|
|
9
|
+
"mjs",
|
|
10
|
+
"cjs",
|
|
11
|
+
"jsx",
|
|
12
|
+
"tsx",
|
|
13
|
+
"vue",
|
|
14
|
+
"svelte",
|
|
15
|
+
"svg",
|
|
16
|
+
"txt",
|
|
17
|
+
"md"
|
|
18
|
+
];
|
|
19
|
+
async function compareDirectories(dir1, dir2, options) {
|
|
20
|
+
dir1 = normalizeDir(dir1);
|
|
21
|
+
dir2 = normalizeDir(dir2);
|
|
22
|
+
const files1 = await scanDirectory(dir1);
|
|
23
|
+
const files2 = await scanDirectory(dir2);
|
|
24
|
+
if (files1.length !== files2.length) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
options = options || {};
|
|
28
|
+
const ignoreNewLine = options.ignoreNewLine !== false;
|
|
29
|
+
const ignoreVersions = options.ignoreVersions !== false;
|
|
30
|
+
const textExtensions = new Set((options.textExtensions || []).concat(textFileExtensions));
|
|
31
|
+
for (let i = 0; i < files1.length; i++) {
|
|
32
|
+
const file = files1[i];
|
|
33
|
+
if (files2.indexOf(file) === -1) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const ext = file.split(".").pop().toLowerCase();
|
|
37
|
+
const isText = textExtensions.has(ext);
|
|
38
|
+
if (!isText) {
|
|
39
|
+
const content12 = await fs.readFile(dir1 + "/" + file);
|
|
40
|
+
const content22 = await fs.readFile(dir2 + "/" + file);
|
|
41
|
+
if (Buffer.compare(content12, content22) !== 0) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
let content1 = await fs.readFile(dir1 + "/" + file, "utf8");
|
|
47
|
+
let content2 = await fs.readFile(dir2 + "/" + file, "utf8");
|
|
48
|
+
if (content1 === content2) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (ignoreNewLine) {
|
|
52
|
+
content1 = content1.replace(/\s+\n/g, "\n").trimRight();
|
|
53
|
+
content2 = content2.replace(/\s+\n/g, "\n").trimRight();
|
|
54
|
+
}
|
|
55
|
+
if (ignoreVersions && file.split("/").pop() === "package.json") {
|
|
56
|
+
const data1 = JSON.parse(content1);
|
|
57
|
+
const data2 = JSON.parse(content2);
|
|
58
|
+
delete data1.version;
|
|
59
|
+
delete data2.version;
|
|
60
|
+
content1 = JSON.stringify(data1);
|
|
61
|
+
content2 = JSON.stringify(data2);
|
|
62
|
+
}
|
|
63
|
+
if (content1 !== content2) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
compareDirectories
|
|
71
|
+
};
|
package/lib/optimise/svgo.js
CHANGED
|
@@ -83,6 +83,7 @@ async function runSVGO(svg, options = {}) {
|
|
|
83
83
|
if (typeof result.error === 'string') {
|
|
84
84
|
throw new Error(result.error);
|
|
85
85
|
}
|
|
86
|
+
// Sometimes empty definitions are not removed: remove them
|
|
86
87
|
const content = result.data.replace(/<defs\/>/g, '');
|
|
87
88
|
svg.load(content);
|
|
88
89
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@iconify/tools",
|
|
3
3
|
"description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
|
|
4
4
|
"author": "Vjacheslav Trushkin",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.2",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
8
8
|
"homepage": "https://github.com/iconify/tools",
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
"test": "npm run test:jest && npm run test:jasmine"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@iconify/utils": "^1.0.
|
|
25
|
+
"@iconify/utils": "^1.0.20",
|
|
26
26
|
"@types/cheerio": "^0.22.30",
|
|
27
27
|
"@types/node-fetch": "^2.5.12",
|
|
28
|
+
"@types/svgo": "^2.6.0",
|
|
29
|
+
"@types/tar": "^6.1.0",
|
|
28
30
|
"cheerio": "^1.0.0-rc.10",
|
|
29
31
|
"extract-zip": "^2.0.1",
|
|
30
32
|
"node-fetch": "^2.6.6",
|
|
31
33
|
"pathe": "^0.2.0",
|
|
32
|
-
"svgo": "^2.7.0"
|
|
34
|
+
"svgo": "^2.7.0",
|
|
35
|
+
"tar": "^6.1.11"
|
|
33
36
|
},
|
|
34
37
|
"exports": {
|
|
35
38
|
"./*": "./*",
|
|
@@ -45,6 +48,10 @@
|
|
|
45
48
|
"require": "./lib/colors/parse.js",
|
|
46
49
|
"import": "./lib/colors/parse.mjs"
|
|
47
50
|
},
|
|
51
|
+
"./lib/colors/validate": {
|
|
52
|
+
"require": "./lib/colors/validate.js",
|
|
53
|
+
"import": "./lib/colors/validate.mjs"
|
|
54
|
+
},
|
|
48
55
|
"./lib/css/parse": {
|
|
49
56
|
"require": "./lib/css/parse.js",
|
|
50
57
|
"import": "./lib/css/parse.mjs"
|
|
@@ -125,6 +132,10 @@
|
|
|
125
132
|
"require": "./lib/download/github/types.js",
|
|
126
133
|
"import": "./lib/download/github/types.mjs"
|
|
127
134
|
},
|
|
135
|
+
"./lib/download/helpers/untar": {
|
|
136
|
+
"require": "./lib/download/helpers/untar.js",
|
|
137
|
+
"import": "./lib/download/helpers/untar.mjs"
|
|
138
|
+
},
|
|
128
139
|
"./lib/download/helpers/unzip": {
|
|
129
140
|
"require": "./lib/download/helpers/unzip.js",
|
|
130
141
|
"import": "./lib/download/helpers/unzip.mjs"
|
|
@@ -241,6 +252,14 @@
|
|
|
241
252
|
"require": "./lib/index.js",
|
|
242
253
|
"import": "./lib/index.mjs"
|
|
243
254
|
},
|
|
255
|
+
"./lib/misc/bump-version": {
|
|
256
|
+
"require": "./lib/misc/bump-version.js",
|
|
257
|
+
"import": "./lib/misc/bump-version.mjs"
|
|
258
|
+
},
|
|
259
|
+
"./lib/misc/compare-dirs": {
|
|
260
|
+
"require": "./lib/misc/compare-dirs.js",
|
|
261
|
+
"import": "./lib/misc/compare-dirs.mjs"
|
|
262
|
+
},
|
|
244
263
|
"./lib/misc/exec": {
|
|
245
264
|
"require": "./lib/misc/exec.js",
|
|
246
265
|
"import": "./lib/misc/exec.mjs"
|