@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.
- package/lib/colors/attribs.cjs +30 -0
- package/lib/colors/attribs.d.ts +13 -10
- package/lib/colors/attribs.mjs +7 -13
- package/lib/colors/parse.cjs +269 -0
- package/lib/colors/parse.d.ts +15 -11
- package/lib/colors/parse.mjs +27 -31
- package/lib/colors/validate.cjs +52 -0
- package/lib/colors/validate.d.ts +11 -4
- package/lib/colors/validate.mjs +19 -6
- package/lib/css/parse.cjs +26 -0
- package/lib/css/parse.d.ts +3 -1
- package/lib/css/parse.mjs +8 -6
- package/lib/css/parser/error.cjs +25 -0
- package/lib/css/parser/error.d.ts +4 -2
- package/lib/css/parser/error.mjs +2 -4
- package/lib/css/parser/export.cjs +48 -0
- package/lib/css/parser/export.d.ts +5 -2
- package/lib/css/parser/export.mjs +4 -6
- package/lib/css/parser/strings.cjs +77 -0
- package/lib/css/parser/strings.d.ts +6 -3
- package/lib/css/parser/strings.mjs +4 -6
- package/lib/css/parser/text.cjs +135 -0
- package/lib/css/parser/text.d.ts +8 -5
- package/lib/css/parser/text.mjs +3 -8
- package/lib/css/parser/tokens.cjs +184 -0
- package/lib/css/parser/tokens.d.ts +6 -3
- package/lib/css/parser/tokens.mjs +7 -13
- package/lib/css/parser/tree.cjs +42 -0
- package/lib/css/parser/tree.d.ts +5 -2
- package/lib/css/parser/tree.mjs +2 -4
- package/lib/css/parser/types.cjs +2 -0
- package/lib/css/parser/types.d.ts +13 -11
- package/lib/css/parser/types.mjs +1 -0
- package/lib/download/api/cache.cjs +86 -0
- package/lib/download/api/cache.d.ts +8 -5
- package/lib/download/api/cache.mjs +14 -19
- package/lib/download/api/download.cjs +28 -0
- package/lib/download/api/download.d.ts +5 -2
- package/lib/download/api/download.mjs +8 -9
- package/lib/download/api/index.cjs +51 -0
- package/lib/download/api/index.d.ts +5 -2
- package/lib/download/api/index.mjs +8 -6
- package/lib/download/api/types.cjs +2 -0
- package/lib/download/api/types.d.ts +4 -2
- package/lib/download/api/types.mjs +1 -0
- package/lib/download/git/branch.cjs +22 -0
- package/lib/download/git/branch.d.ts +5 -2
- package/lib/download/git/branch.mjs +5 -5
- package/lib/download/git/hash.cjs +15 -0
- package/lib/download/git/hash.d.ts +5 -2
- package/lib/download/git/hash.mjs +5 -5
- package/lib/download/git/index.cjs +76 -0
- package/lib/download/git/index.d.ts +10 -8
- package/lib/download/git/index.mjs +41 -26
- package/lib/download/git/reset.cjs +41 -0
- package/lib/download/git/reset.d.ts +3 -1
- package/lib/download/git/reset.mjs +29 -5
- package/lib/download/github/hash.cjs +32 -0
- package/lib/download/github/hash.d.ts +5 -2
- package/lib/download/github/hash.mjs +10 -7
- package/lib/download/github/index.cjs +98 -0
- package/lib/download/github/index.d.ts +11 -9
- package/lib/download/github/index.mjs +23 -17
- package/lib/download/github/types.cjs +2 -0
- package/lib/download/github/types.d.ts +3 -1
- package/lib/download/github/types.mjs +1 -0
- package/lib/download/gitlab/hash.cjs +32 -0
- package/lib/download/gitlab/hash.d.ts +5 -2
- package/lib/download/gitlab/hash.mjs +10 -6
- package/lib/download/gitlab/index.cjs +98 -0
- package/lib/download/gitlab/index.d.ts +11 -9
- package/lib/download/gitlab/index.mjs +24 -18
- package/lib/download/gitlab/types.cjs +7 -0
- package/lib/download/gitlab/types.d.ts +4 -2
- package/lib/download/gitlab/types.mjs +3 -5
- package/lib/download/helpers/untar.cjs +14 -0
- package/lib/download/helpers/untar.d.ts +3 -1
- package/lib/download/helpers/untar.mjs +4 -5
- package/lib/download/helpers/unzip.cjs +19 -0
- package/lib/download/helpers/unzip.d.ts +3 -1
- package/lib/download/helpers/unzip.mjs +6 -7
- package/lib/download/index.cjs +64 -0
- package/lib/download/index.d.ts +18 -13
- package/lib/download/index.mjs +46 -19
- package/lib/download/npm/index.cjs +82 -0
- package/lib/download/npm/index.d.ts +10 -8
- package/lib/download/npm/index.mjs +16 -13
- package/lib/download/npm/types.cjs +2 -0
- package/lib/download/npm/types.d.ts +3 -1
- package/lib/download/npm/types.mjs +1 -0
- package/lib/download/npm/version.cjs +23 -0
- package/lib/download/npm/version.d.ts +7 -4
- package/lib/download/npm/version.mjs +8 -10
- package/lib/download/types/modified.cjs +2 -0
- package/lib/download/types/modified.d.ts +3 -1
- package/lib/download/types/modified.mjs +1 -0
- package/lib/download/types/sources.cjs +2 -0
- package/lib/download/types/sources.d.ts +4 -2
- package/lib/download/types/sources.mjs +1 -0
- package/lib/export/directory.cjs +45 -0
- package/lib/export/directory.d.ts +11 -4
- package/lib/export/directory.mjs +8 -8
- package/lib/export/helpers/custom-files.cjs +28 -0
- package/lib/export/helpers/custom-files.d.ts +4 -2
- package/lib/export/helpers/custom-files.mjs +8 -9
- package/lib/export/helpers/prepare.cjs +36 -0
- package/lib/export/helpers/prepare.d.ts +5 -3
- package/lib/export/helpers/prepare.mjs +7 -9
- package/lib/export/helpers/types-version.cjs +22 -0
- package/lib/export/helpers/types-version.d.ts +3 -1
- package/lib/export/helpers/types-version.mjs +15 -37
- package/lib/export/icon-package.cjs +59 -0
- package/lib/export/icon-package.d.ts +12 -5
- package/lib/export/icon-package.mjs +15 -16
- package/lib/export/json-package.cjs +133 -0
- package/lib/export/json-package.d.ts +12 -5
- package/lib/export/json-package.mjs +20 -21
- package/lib/icon-set/index.cjs +589 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +40 -53
- package/lib/icon-set/match.cjs +58 -0
- package/lib/icon-set/match.d.ts +10 -3
- package/lib/icon-set/match.mjs +5 -6
- package/lib/icon-set/merge.cjs +83 -0
- package/lib/icon-set/merge.d.ts +9 -2
- package/lib/icon-set/merge.mjs +15 -10
- package/lib/icon-set/props.cjs +28 -0
- package/lib/icon-set/props.d.ts +8 -4
- package/lib/icon-set/props.mjs +7 -10
- package/lib/icon-set/types.cjs +2 -0
- package/lib/icon-set/types.d.ts +19 -17
- package/lib/icon-set/types.mjs +1 -0
- package/lib/import/directory.cjs +76 -0
- package/lib/import/directory.d.ts +11 -5
- package/lib/import/directory.mjs +36 -11
- package/lib/import/figma/index.cjs +105 -0
- package/lib/import/figma/index.d.ts +15 -5
- package/lib/import/figma/index.mjs +40 -13
- package/lib/import/figma/nodes.cjs +86 -0
- package/lib/import/figma/nodes.d.ts +13 -4
- package/lib/import/figma/nodes.mjs +3 -11
- package/lib/import/figma/query.cjs +218 -0
- package/lib/import/figma/query.d.ts +18 -9
- package/lib/import/figma/query.mjs +9 -12
- package/lib/import/figma/types/api.cjs +2 -0
- package/lib/import/figma/types/api.d.ts +8 -7
- package/lib/import/figma/types/api.mjs +1 -0
- package/lib/import/figma/types/nodes.cjs +2 -0
- package/lib/import/figma/types/nodes.d.ts +16 -9
- package/lib/import/figma/types/nodes.mjs +1 -0
- package/lib/import/figma/types/options.cjs +2 -0
- package/lib/import/figma/types/options.d.ts +17 -10
- package/lib/import/figma/types/options.mjs +1 -0
- package/lib/import/figma/types/result.cjs +2 -0
- package/lib/import/figma/types/result.d.ts +12 -5
- package/lib/import/figma/types/result.mjs +1 -0
- package/lib/index.cjs +137 -0
- package/lib/index.d.ts +65 -44
- package/lib/index.mjs +83 -94
- package/lib/misc/bump-version.cjs +17 -0
- package/lib/misc/bump-version.d.ts +3 -1
- package/lib/misc/bump-version.mjs +2 -4
- package/lib/misc/compare-dirs.cjs +75 -0
- package/lib/misc/compare-dirs.d.ts +4 -2
- package/lib/misc/compare-dirs.mjs +12 -12
- package/lib/misc/exec.cjs +25 -0
- package/lib/misc/exec.d.ts +6 -4
- package/lib/misc/exec.mjs +4 -5
- package/lib/misc/keyword.cjs +19 -0
- package/lib/misc/keyword.d.ts +3 -1
- package/lib/misc/keyword.mjs +2 -4
- package/lib/misc/scan.cjs +51 -0
- package/lib/misc/scan.d.ts +7 -6
- package/lib/misc/scan.mjs +6 -7
- package/lib/misc/write-json.cjs +11 -0
- package/lib/misc/write-json.d.ts +3 -1
- package/lib/misc/write-json.mjs +5 -6
- package/lib/optimise/flags.cjs +252 -0
- package/lib/optimise/flags.d.ts +7 -2
- package/lib/optimise/flags.mjs +18 -19
- package/lib/optimise/global-style.cjs +154 -0
- package/lib/optimise/global-style.d.ts +7 -2
- package/lib/optimise/global-style.mjs +18 -15
- package/lib/optimise/scale.cjs +26 -0
- package/lib/optimise/scale.d.ts +7 -2
- package/lib/optimise/scale.mjs +5 -5
- package/lib/optimise/svgo.cjs +83 -0
- package/lib/optimise/svgo.d.ts +10 -6
- package/lib/optimise/svgo.mjs +6 -9
- package/lib/svg/analyse/error.cjs +18 -0
- package/lib/svg/analyse/error.d.ts +5 -2
- package/lib/svg/analyse/error.mjs +2 -4
- package/lib/svg/analyse/types.cjs +2 -0
- package/lib/svg/analyse/types.d.ts +11 -11
- package/lib/svg/analyse/types.mjs +1 -0
- package/lib/svg/analyse.cjs +291 -0
- package/lib/svg/analyse.d.ts +8 -3
- package/lib/svg/analyse.mjs +15 -30
- package/lib/svg/cleanup/attribs.cjs +41 -0
- package/lib/svg/cleanup/attribs.d.ts +7 -2
- package/lib/svg/cleanup/attribs.mjs +6 -12
- package/lib/svg/cleanup/bad-tags.cjs +51 -0
- package/lib/svg/cleanup/bad-tags.d.ts +7 -2
- package/lib/svg/cleanup/bad-tags.mjs +10 -25
- package/lib/svg/cleanup/inline-style.cjs +64 -0
- package/lib/svg/cleanup/inline-style.d.ts +7 -2
- package/lib/svg/cleanup/inline-style.mjs +14 -19
- package/lib/svg/cleanup/root-svg.cjs +81 -0
- package/lib/svg/cleanup/root-svg.d.ts +7 -2
- package/lib/svg/cleanup/root-svg.mjs +7 -18
- package/lib/svg/cleanup/svgo-style.cjs +38 -0
- package/lib/svg/cleanup/svgo-style.d.ts +7 -2
- package/lib/svg/cleanup/svgo-style.mjs +16 -11
- package/lib/svg/cleanup.cjs +32 -0
- package/lib/svg/cleanup.d.ts +7 -2
- package/lib/svg/cleanup.mjs +21 -9
- package/lib/svg/data/attributes.cjs +355 -0
- package/lib/svg/data/attributes.d.ts +27 -25
- package/lib/svg/data/attributes.mjs +90 -115
- package/lib/svg/data/tags.cjs +137 -0
- package/lib/svg/data/tags.d.ts +25 -23
- package/lib/svg/data/tags.mjs +25 -49
- package/lib/svg/index.cjs +130 -0
- package/lib/svg/index.d.ts +16 -5
- package/lib/svg/index.mjs +48 -14
- package/lib/svg/parse-style.cjs +134 -0
- package/lib/svg/parse-style.d.ts +12 -8
- package/lib/svg/parse-style.mjs +11 -9
- package/lib/svg/parse.cjs +42 -0
- package/lib/svg/parse.d.ts +11 -7
- package/lib/svg/parse.mjs +2 -4
- package/package.json +99 -94
- package/lib/colors/attribs.js +0 -26
- package/lib/colors/parse.js +0 -341
- package/lib/colors/validate.js +0 -48
- package/lib/css/parse.js +0 -23
- package/lib/css/parser/error.js +0 -27
- package/lib/css/parser/export.js +0 -69
- package/lib/css/parser/strings.js +0 -93
- package/lib/css/parser/text.js +0 -171
- package/lib/css/parser/tokens.js +0 -200
- package/lib/css/parser/tree.js +0 -44
- package/lib/css/parser/types.js +0 -2
- package/lib/download/api/cache.js +0 -108
- package/lib/download/api/download.js +0 -27
- package/lib/download/api/index.js +0 -52
- package/lib/download/api/types.js +0 -2
- package/lib/download/git/branch.js +0 -22
- package/lib/download/git/hash.js +0 -14
- package/lib/download/git/index.js +0 -75
- package/lib/download/git/reset.js +0 -16
- package/lib/download/github/hash.js +0 -28
- package/lib/download/github/index.js +0 -116
- package/lib/download/github/types.js +0 -2
- package/lib/download/gitlab/hash.js +0 -27
- package/lib/download/gitlab/index.js +0 -115
- package/lib/download/gitlab/types.js +0 -7
- package/lib/download/helpers/untar.js +0 -14
- package/lib/download/helpers/unzip.js +0 -18
- package/lib/download/index.js +0 -27
- package/lib/download/npm/index.js +0 -91
- package/lib/download/npm/types.js +0 -2
- package/lib/download/npm/version.js +0 -27
- package/lib/download/types/modified.js +0 -2
- package/lib/download/types/sources.js +0 -2
- package/lib/export/directory.js +0 -52
- package/lib/export/helpers/custom-files.js +0 -32
- package/lib/export/helpers/prepare.js +0 -49
- package/lib/export/helpers/types-version.js +0 -12
- package/lib/export/icon-package.js +0 -77
- package/lib/export/json-package.js +0 -156
- package/lib/icon-set/index.js +0 -749
- package/lib/icon-set/match.js +0 -66
- package/lib/icon-set/merge.js +0 -90
- package/lib/icon-set/props.js +0 -34
- package/lib/icon-set/types.js +0 -2
- package/lib/import/directory.js +0 -59
- package/lib/import/figma/index.js +0 -90
- package/lib/import/figma/nodes.js +0 -106
- package/lib/import/figma/query.js +0 -244
- package/lib/import/figma/types/api.js +0 -12
- package/lib/import/figma/types/nodes.js +0 -2
- package/lib/import/figma/types/options.js +0 -2
- package/lib/import/figma/types/result.js +0 -2
- package/lib/index.js +0 -103
- package/lib/misc/bump-version.js +0 -19
- package/lib/misc/compare-dirs.js +0 -84
- package/lib/misc/exec.js +0 -26
- package/lib/misc/keyword.js +0 -31
- package/lib/misc/scan.js +0 -55
- package/lib/misc/write-json.js +0 -11
- package/lib/optimise/flags.js +0 -312
- package/lib/optimise/global-style.js +0 -185
- package/lib/optimise/scale.js +0 -42
- package/lib/optimise/svgo.js +0 -99
- package/lib/svg/analyse/error.js +0 -22
- package/lib/svg/analyse/types.js +0 -2
- package/lib/svg/analyse.js +0 -352
- package/lib/svg/cleanup/attribs.js +0 -51
- package/lib/svg/cleanup/bad-tags.js +0 -65
- package/lib/svg/cleanup/inline-style.js +0 -77
- package/lib/svg/cleanup/root-svg.js +0 -107
- package/lib/svg/cleanup/svgo-style.js +0 -35
- package/lib/svg/cleanup.js +0 -24
- package/lib/svg/data/attributes.js +0 -403
- package/lib/svg/data/tags.js +0 -188
- package/lib/svg/index.js +0 -134
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
mergeTextTokens,
|
|
6
|
-
textTokensToRule,
|
|
7
|
-
textTokensToSelector
|
|
8
|
-
} from "./text.mjs";
|
|
1
|
+
import { styleParseError } from './error.mjs';
|
|
2
|
+
import { findEndOfQuotedString, findEndOfURL } from './strings.mjs';
|
|
3
|
+
import { textTokensToRule, mergeTextTokens, textTokensToSelector } from './text.mjs';
|
|
4
|
+
|
|
9
5
|
function findTokens(code, tokens) {
|
|
10
6
|
const list = [];
|
|
11
7
|
const lc = code.toLowerCase();
|
|
@@ -33,7 +29,6 @@ function getTokens(css) {
|
|
|
33
29
|
let depth = 0;
|
|
34
30
|
try {
|
|
35
31
|
const checkRule = (text) => {
|
|
36
|
-
var _a;
|
|
37
32
|
if (!textQueue.length) {
|
|
38
33
|
return;
|
|
39
34
|
}
|
|
@@ -46,7 +41,7 @@ function getTokens(css) {
|
|
|
46
41
|
if (!value.length) {
|
|
47
42
|
return;
|
|
48
43
|
}
|
|
49
|
-
throw styleParseError("Invalid css rule", css,
|
|
44
|
+
throw styleParseError("Invalid css rule", css, textQueue[0]?.index);
|
|
50
45
|
};
|
|
51
46
|
findTokens(css, ['"', "'", "/*", "{", "}", ";", "url(", "\\"]).forEach((token) => {
|
|
52
47
|
if (token.index < start) {
|
|
@@ -181,6 +176,5 @@ function getTokens(css) {
|
|
|
181
176
|
}
|
|
182
177
|
return items;
|
|
183
178
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
179
|
+
|
|
180
|
+
export { getTokens };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function tokensTree(tokens) {
|
|
6
|
+
const result = [];
|
|
7
|
+
let index = 0;
|
|
8
|
+
function parse(target) {
|
|
9
|
+
while (index < tokens.length) {
|
|
10
|
+
const token = tokens[index];
|
|
11
|
+
index++;
|
|
12
|
+
switch (token.type) {
|
|
13
|
+
case "close":
|
|
14
|
+
return;
|
|
15
|
+
case "selector":
|
|
16
|
+
case "at-rule": {
|
|
17
|
+
const newItem = {
|
|
18
|
+
...token,
|
|
19
|
+
children: []
|
|
20
|
+
};
|
|
21
|
+
target.push(newItem);
|
|
22
|
+
parse(newItem.children);
|
|
23
|
+
if (!newItem.children.length) {
|
|
24
|
+
const index2 = target.indexOf(newItem);
|
|
25
|
+
if (index2 !== -1) {
|
|
26
|
+
target.splice(index2, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
target.push(token);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
while (index < tokens.length) {
|
|
37
|
+
parse(result);
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.tokensTree = tokensTree;
|
package/lib/css/parser/tree.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CSSToken, CSSTreeToken } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Convert tokens list to tree
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function tokensTree(tokens: CSSToken[]): CSSTreeToken[];
|
|
7
|
+
|
|
8
|
+
export { tokensTree };
|
package/lib/css/parser/tree.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Text tokens, to be split combined into correct tokens later
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
interface TextToken {
|
|
5
5
|
type: 'chunk' | 'url' | 'quoted-string';
|
|
6
6
|
index: number;
|
|
7
7
|
text: string;
|
|
@@ -9,43 +9,45 @@ export interface TextToken {
|
|
|
9
9
|
/**
|
|
10
10
|
* Values
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
declare type CSSATValue = string | string[];
|
|
13
13
|
/**
|
|
14
14
|
* Tokens
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
interface CSSRuleToken {
|
|
17
17
|
type: 'rule';
|
|
18
18
|
index: number;
|
|
19
19
|
prop: string;
|
|
20
20
|
value: string;
|
|
21
21
|
important?: boolean;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
interface CSSSelectorToken {
|
|
24
24
|
type: 'selector';
|
|
25
25
|
index: number;
|
|
26
26
|
code: string;
|
|
27
27
|
selectors: string[];
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
interface CSSAtRuleToken {
|
|
30
30
|
type: 'at-rule';
|
|
31
31
|
index: number;
|
|
32
32
|
code: string;
|
|
33
33
|
atRule: string;
|
|
34
34
|
atValues: CSSATValue[];
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
interface CSSCloseToken {
|
|
37
37
|
type: 'close';
|
|
38
38
|
index: number;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
declare type CSSTokenWithSelector = CSSSelectorToken | CSSAtRuleToken;
|
|
41
|
+
declare type CSSToken = CSSRuleToken | CSSSelectorToken | CSSAtRuleToken | CSSCloseToken;
|
|
42
42
|
/**
|
|
43
43
|
* Tree tokens
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
interface CSSSelectorTreeToken extends CSSSelectorToken {
|
|
46
46
|
children: CSSTreeToken[];
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
interface CSSAtRuleTreeToken extends CSSAtRuleToken {
|
|
49
49
|
children: CSSTreeToken[];
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
declare type CSSTreeToken = CSSRuleToken | CSSSelectorTreeToken | CSSAtRuleTreeToken;
|
|
52
|
+
|
|
53
|
+
export { CSSATValue, CSSAtRuleToken, CSSAtRuleTreeToken, CSSCloseToken, CSSRuleToken, CSSSelectorToken, CSSSelectorTreeToken, CSSToken, CSSTokenWithSelector, CSSTreeToken, TextToken };
|
package/lib/css/parser/types.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
const misc_scan = require('../../misc/scan.cjs');
|
|
8
|
+
|
|
9
|
+
const cacheVersion = 1;
|
|
10
|
+
const storedFiles = /* @__PURE__ */ Object.create(null);
|
|
11
|
+
function apiCacheKey(query) {
|
|
12
|
+
const item = JSON.stringify({
|
|
13
|
+
uri: query.uri,
|
|
14
|
+
params: query.params?.toString(),
|
|
15
|
+
headers: query.headers
|
|
16
|
+
});
|
|
17
|
+
return crypto.createHash("md5").update(item).digest("hex");
|
|
18
|
+
}
|
|
19
|
+
async function storeAPICache(options, key, data) {
|
|
20
|
+
const expires = Date.now() + options.ttl * 1e3;
|
|
21
|
+
const filename = options.dir + "/" + key + "." + expires + ".json";
|
|
22
|
+
if (!storedFiles[options.dir]) {
|
|
23
|
+
await getStoredFiles(options.dir);
|
|
24
|
+
}
|
|
25
|
+
await fs.promises.writeFile(filename, JSON.stringify({
|
|
26
|
+
version: cacheVersion,
|
|
27
|
+
expires,
|
|
28
|
+
data
|
|
29
|
+
}, null, 4), "utf8");
|
|
30
|
+
storedFiles[options.dir][key] = {
|
|
31
|
+
filename,
|
|
32
|
+
expires
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function getAPICache(dir, key) {
|
|
36
|
+
if (!storedFiles[dir]) {
|
|
37
|
+
await getStoredFiles(dir);
|
|
38
|
+
}
|
|
39
|
+
const item = storedFiles[dir][key];
|
|
40
|
+
if (!item) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const time = Date.now();
|
|
44
|
+
try {
|
|
45
|
+
const content = JSON.parse(await fs.promises.readFile(item.filename, "utf8"));
|
|
46
|
+
return content.version === cacheVersion && content.expires > time ? content.data : null;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function clearAPICache(dir) {
|
|
52
|
+
return getStoredFiles(dir, true);
|
|
53
|
+
}
|
|
54
|
+
async function getStoredFiles(dir, clear = false) {
|
|
55
|
+
const storage = !clear && storedFiles[dir] || /* @__PURE__ */ Object.create(null);
|
|
56
|
+
const time = Date.now();
|
|
57
|
+
storedFiles[dir] = storage;
|
|
58
|
+
try {
|
|
59
|
+
await fs.promises.mkdir(dir, {
|
|
60
|
+
recursive: true
|
|
61
|
+
});
|
|
62
|
+
} catch (err) {
|
|
63
|
+
}
|
|
64
|
+
await misc_scan.scanDirectory(dir, async (ext, file, subdir, path) => {
|
|
65
|
+
if (ext !== ".json") {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const filename = path + subdir + file + ext;
|
|
69
|
+
const parts = file.split(".");
|
|
70
|
+
const expires = parseInt(parts.pop());
|
|
71
|
+
if (clear || expires < time || parts.length !== 1) {
|
|
72
|
+
await fs.promises.unlink(filename);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const cacheKey = parts[0];
|
|
76
|
+
storage[cacheKey] = {
|
|
77
|
+
filename,
|
|
78
|
+
expires
|
|
79
|
+
};
|
|
80
|
+
}, false);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.apiCacheKey = apiCacheKey;
|
|
84
|
+
exports.clearAPICache = clearAPICache;
|
|
85
|
+
exports.getAPICache = getAPICache;
|
|
86
|
+
exports.storeAPICache = storeAPICache;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { APIQueryParams, APICacheOptions } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Unique key
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function apiCacheKey(query: APIQueryParams): string;
|
|
6
7
|
/**
|
|
7
8
|
* Store cache
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare function storeAPICache(options: APICacheOptions, key: string, data: string): Promise<void>;
|
|
10
11
|
/**
|
|
11
12
|
* Get item from cache
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
declare function getAPICache(dir: string, key: string): Promise<string | null>;
|
|
14
15
|
/**
|
|
15
16
|
* Clear cache
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
declare function clearAPICache(dir: string): Promise<void>;
|
|
19
|
+
|
|
20
|
+
export { apiCacheKey, clearAPICache, getAPICache, storeAPICache };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { promises } from 'fs';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { scanDirectory } from '../../misc/scan.mjs';
|
|
4
|
+
|
|
5
|
+
const cacheVersion = 1;
|
|
6
|
+
const storedFiles = /* @__PURE__ */ Object.create(null);
|
|
7
7
|
function apiCacheKey(query) {
|
|
8
|
-
var _a;
|
|
9
8
|
const item = JSON.stringify({
|
|
10
9
|
uri: query.uri,
|
|
11
|
-
params:
|
|
10
|
+
params: query.params?.toString(),
|
|
12
11
|
headers: query.headers
|
|
13
12
|
});
|
|
14
13
|
return createHash("md5").update(item).digest("hex");
|
|
@@ -19,7 +18,7 @@ async function storeAPICache(options, key, data) {
|
|
|
19
18
|
if (!storedFiles[options.dir]) {
|
|
20
19
|
await getStoredFiles(options.dir);
|
|
21
20
|
}
|
|
22
|
-
await
|
|
21
|
+
await promises.writeFile(filename, JSON.stringify({
|
|
23
22
|
version: cacheVersion,
|
|
24
23
|
expires,
|
|
25
24
|
data
|
|
@@ -39,7 +38,7 @@ async function getAPICache(dir, key) {
|
|
|
39
38
|
}
|
|
40
39
|
const time = Date.now();
|
|
41
40
|
try {
|
|
42
|
-
const content = JSON.parse(await
|
|
41
|
+
const content = JSON.parse(await promises.readFile(item.filename, "utf8"));
|
|
43
42
|
return content.version === cacheVersion && content.expires > time ? content.data : null;
|
|
44
43
|
} catch (err) {
|
|
45
44
|
return null;
|
|
@@ -49,11 +48,11 @@ function clearAPICache(dir) {
|
|
|
49
48
|
return getStoredFiles(dir, true);
|
|
50
49
|
}
|
|
51
50
|
async function getStoredFiles(dir, clear = false) {
|
|
52
|
-
const storage = !clear && storedFiles[dir] || Object.create(null);
|
|
51
|
+
const storage = !clear && storedFiles[dir] || /* @__PURE__ */ Object.create(null);
|
|
53
52
|
const time = Date.now();
|
|
54
53
|
storedFiles[dir] = storage;
|
|
55
54
|
try {
|
|
56
|
-
await
|
|
55
|
+
await promises.mkdir(dir, {
|
|
57
56
|
recursive: true
|
|
58
57
|
});
|
|
59
58
|
} catch (err) {
|
|
@@ -66,7 +65,7 @@ async function getStoredFiles(dir, clear = false) {
|
|
|
66
65
|
const parts = file.split(".");
|
|
67
66
|
const expires = parseInt(parts.pop());
|
|
68
67
|
if (clear || expires < time || parts.length !== 1) {
|
|
69
|
-
await
|
|
68
|
+
await promises.unlink(filename);
|
|
70
69
|
return false;
|
|
71
70
|
}
|
|
72
71
|
const cacheKey = parts[0];
|
|
@@ -76,9 +75,5 @@ async function getStoredFiles(dir, clear = false) {
|
|
|
76
75
|
};
|
|
77
76
|
}, false);
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
clearAPICache,
|
|
82
|
-
getAPICache,
|
|
83
|
-
storeAPICache
|
|
84
|
-
};
|
|
78
|
+
|
|
79
|
+
export { apiCacheKey, clearAPICache, getAPICache, storeAPICache };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const fetch = require('node-fetch');
|
|
6
|
+
const util = require('util');
|
|
7
|
+
const stream = require('stream');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
11
|
+
|
|
12
|
+
const fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
13
|
+
|
|
14
|
+
const streamPipeline = util.promisify(stream.pipeline);
|
|
15
|
+
async function downloadFile(query, target) {
|
|
16
|
+
const params = query.params ? query.params.toString() : "";
|
|
17
|
+
const url = query.uri + (params ? "?" + params : "");
|
|
18
|
+
const headers = query.headers;
|
|
19
|
+
const response = await fetch__default(url, {
|
|
20
|
+
headers
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok || !response.body) {
|
|
23
|
+
throw new Error(`Error downloading ${url}: ${response.status}`);
|
|
24
|
+
}
|
|
25
|
+
await streamPipeline(response.body, fs.createWriteStream(target));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.downloadFile = downloadFile;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { APIQueryParams } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Download file
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function downloadFile(query: APIQueryParams, target: string): Promise<void>;
|
|
7
|
+
|
|
8
|
+
export { downloadFile };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { pipeline } from 'stream';
|
|
4
|
+
import { createWriteStream } from 'fs';
|
|
5
|
+
|
|
6
|
+
const streamPipeline = promisify(pipeline);
|
|
7
7
|
async function downloadFile(query, target) {
|
|
8
8
|
const params = query.params ? query.params.toString() : "";
|
|
9
9
|
const url = query.uri + (params ? "?" + params : "");
|
|
@@ -16,6 +16,5 @@ async function downloadFile(query, target) {
|
|
|
16
16
|
}
|
|
17
17
|
await streamPipeline(response.body, createWriteStream(target));
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
19
|
+
|
|
20
|
+
export { downloadFile };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const fetch = require('node-fetch');
|
|
6
|
+
const download_api_cache = require('./cache.cjs');
|
|
7
|
+
require('fs');
|
|
8
|
+
require('crypto');
|
|
9
|
+
require('../../misc/scan.cjs');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
12
|
+
|
|
13
|
+
const fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
14
|
+
|
|
15
|
+
async function sendAPIQuery(query, cache) {
|
|
16
|
+
const cacheKey = cache ? download_api_cache.apiCacheKey(query) : "";
|
|
17
|
+
if (cache) {
|
|
18
|
+
const cached = await download_api_cache.getAPICache(cache.dir, cacheKey);
|
|
19
|
+
if (cached) {
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const result = await sendQuery(query);
|
|
24
|
+
if (cache && typeof result !== "number") {
|
|
25
|
+
try {
|
|
26
|
+
await download_api_cache.storeAPICache(cache, cacheKey, result);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error("Error writing API cache");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async function sendQuery(query) {
|
|
34
|
+
const params = query.params ? query.params.toString() : "";
|
|
35
|
+
const url = query.uri + (params ? "?" + params : "");
|
|
36
|
+
console.log("Fetch:", url);
|
|
37
|
+
const headers = query.headers;
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch__default(url, {
|
|
40
|
+
headers
|
|
41
|
+
});
|
|
42
|
+
if (response.status >= 400) {
|
|
43
|
+
return response.status;
|
|
44
|
+
}
|
|
45
|
+
return await response.text();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
return 404;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.sendAPIQuery = sendAPIQuery;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { APIQueryParams, APICacheOptions } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Send API query
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function sendAPIQuery(query: APIQueryParams, cache?: APICacheOptions): Promise<number | string>;
|
|
7
|
+
|
|
8
|
+
export { sendAPIQuery };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { apiCacheKey, getAPICache, storeAPICache } from './cache.mjs';
|
|
3
|
+
import 'fs';
|
|
4
|
+
import 'crypto';
|
|
5
|
+
import '../../misc/scan.mjs';
|
|
6
|
+
|
|
4
7
|
async function sendAPIQuery(query, cache) {
|
|
5
8
|
const cacheKey = cache ? apiCacheKey(query) : "";
|
|
6
9
|
if (cache) {
|
|
@@ -36,6 +39,5 @@ async function sendQuery(query) {
|
|
|
36
39
|
return 404;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
+
|
|
43
|
+
export { sendAPIQuery };
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* API Cache
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
interface APICacheOptions {
|
|
5
5
|
dir: string;
|
|
6
6
|
ttl: number;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Params
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
interface APIQueryParams {
|
|
12
12
|
uri: string;
|
|
13
13
|
params?: URLSearchParams;
|
|
14
14
|
headers?: Record<string, string>;
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
export { APICacheOptions, APIQueryParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const misc_exec = require('../../misc/exec.cjs');
|
|
6
|
+
require('child_process');
|
|
7
|
+
|
|
8
|
+
async function getGitRepoBranch(options, checkout) {
|
|
9
|
+
const result = await misc_exec.execAsync("git branch --show-current", {
|
|
10
|
+
cwd: options.target
|
|
11
|
+
});
|
|
12
|
+
const branch = result.stdout.trim();
|
|
13
|
+
if (typeof checkout === "string" && branch !== checkout) {
|
|
14
|
+
await misc_exec.execAsync(`git checkout ${checkout}`, {
|
|
15
|
+
cwd: options.target
|
|
16
|
+
});
|
|
17
|
+
return await getGitRepoBranch(options);
|
|
18
|
+
}
|
|
19
|
+
return branch;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.getGitRepoBranch = getGitRepoBranch;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExportTargetOptions } from '../../export/helpers/prepare.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Get current branch from cloned git repo
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function getGitRepoBranch(options: ExportTargetOptions, checkout?: string): Promise<string>;
|
|
7
|
+
|
|
8
|
+
export { getGitRepoBranch };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { execAsync } from '../../misc/exec.mjs';
|
|
2
|
+
import 'child_process';
|
|
3
|
+
|
|
3
4
|
async function getGitRepoBranch(options, checkout) {
|
|
4
5
|
const result = await execAsync("git branch --show-current", {
|
|
5
6
|
cwd: options.target
|
|
@@ -13,6 +14,5 @@ async function getGitRepoBranch(options, checkout) {
|
|
|
13
14
|
}
|
|
14
15
|
return branch;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
17
|
+
|
|
18
|
+
export { getGitRepoBranch };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const misc_exec = require('../../misc/exec.cjs');
|
|
6
|
+
require('child_process');
|
|
7
|
+
|
|
8
|
+
async function getGitRepoHash(options) {
|
|
9
|
+
const result = await misc_exec.execAsync("git rev-parse HEAD", {
|
|
10
|
+
cwd: options.target
|
|
11
|
+
});
|
|
12
|
+
return result.stdout.trim();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.getGitRepoHash = getGitRepoHash;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExportTargetOptions } from '../../export/helpers/prepare.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Get latest hash from cloned git repo
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function getGitRepoHash(options: ExportTargetOptions): Promise<string>;
|
|
7
|
+
|
|
8
|
+
export { getGitRepoHash };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { execAsync } from '../../misc/exec.mjs';
|
|
2
|
+
import 'child_process';
|
|
3
|
+
|
|
3
4
|
async function getGitRepoHash(options) {
|
|
4
5
|
const result = await execAsync("git rev-parse HEAD", {
|
|
5
6
|
cwd: options.target
|
|
6
7
|
});
|
|
7
8
|
return result.stdout.trim();
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
10
|
+
|
|
11
|
+
export { getGitRepoHash };
|