@_davideast/stitch-mcp 0.4.0 → 0.5.0
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/dist/chunk-25wakzyb.js +137 -0
- package/dist/chunk-25wakzyb.js.map +10 -0
- package/dist/chunk-2cetsfw4.js +16531 -0
- package/dist/chunk-2cetsfw4.js.map +95 -0
- package/dist/chunk-2fcdwvrm.js +54 -0
- package/dist/chunk-2fcdwvrm.js.map +10 -0
- package/dist/chunk-2k7n0w2x.js +3980 -0
- package/dist/chunk-2k7n0w2x.js.map +16 -0
- package/dist/chunk-2kyqsrg2.js +403 -0
- package/dist/chunk-2kyqsrg2.js.map +10 -0
- package/dist/chunk-384jmtpy.js +11057 -0
- package/dist/chunk-384jmtpy.js.map +238 -0
- package/dist/chunk-3at4pjgn.js +22 -0
- package/dist/chunk-3at4pjgn.js.map +9 -0
- package/dist/chunk-3sfn889r.js +492 -0
- package/dist/chunk-3sfn889r.js.map +13 -0
- package/dist/chunk-45wx7tn7.js +94 -0
- package/dist/chunk-45wx7tn7.js.map +10 -0
- package/dist/chunk-48d17n29.js +10 -0
- package/dist/chunk-48d17n29.js.map +9 -0
- package/dist/chunk-4jwmvjb4.js +839 -0
- package/dist/chunk-4jwmvjb4.js.map +11 -0
- package/dist/chunk-4jygt4d6.js +14 -0
- package/dist/chunk-4jygt4d6.js.map +10 -0
- package/dist/chunk-4vxy1qce.js +68 -0
- package/dist/chunk-4vxy1qce.js.map +10 -0
- package/dist/chunk-7tx0wn04.js +11 -0
- package/dist/chunk-7tx0wn04.js.map +9 -0
- package/dist/chunk-7xh1y383.js +45188 -0
- package/dist/chunk-7xh1y383.js.map +258 -0
- package/dist/chunk-8yrtq2qs.js +18 -0
- package/dist/chunk-8yrtq2qs.js.map +9 -0
- package/dist/chunk-985f11w6.js +21 -0
- package/dist/chunk-985f11w6.js.map +9 -0
- package/dist/chunk-9tvppjaf.js +250 -0
- package/dist/chunk-9tvppjaf.js.map +14 -0
- package/dist/chunk-9wyra8hs.js +32 -0
- package/dist/chunk-9wyra8hs.js.map +9 -0
- package/dist/chunk-cwkb2wbe.js +733 -0
- package/dist/chunk-cwkb2wbe.js.map +16 -0
- package/dist/chunk-djhzzcgj.js +362 -0
- package/dist/chunk-djhzzcgj.js.map +13 -0
- package/dist/chunk-edp6faw2.js +7 -0
- package/dist/chunk-edp6faw2.js.map +9 -0
- package/dist/chunk-ezmw2j8c.js +14 -0
- package/dist/chunk-ezmw2j8c.js.map +9 -0
- package/dist/chunk-f2hq6bfv.js +22 -0
- package/dist/chunk-f2hq6bfv.js.map +10 -0
- package/dist/chunk-fwb4fnkp.js +31 -0
- package/dist/chunk-fwb4fnkp.js.map +10 -0
- package/dist/chunk-h18jrqed.js +9517 -0
- package/dist/chunk-h18jrqed.js.map +99 -0
- package/dist/chunk-hb3c6f6a.js +42 -0
- package/dist/chunk-hb3c6f6a.js.map +9 -0
- package/dist/chunk-jy2d17pr.js +252 -0
- package/dist/chunk-jy2d17pr.js.map +11 -0
- package/dist/chunk-kbtqrkwh.js +24 -0
- package/dist/chunk-kbtqrkwh.js.map +10 -0
- package/dist/chunk-knbnsf6s.js +92 -0
- package/dist/chunk-knbnsf6s.js.map +10 -0
- package/dist/chunk-mv9ssgmx.js +446 -0
- package/dist/chunk-mv9ssgmx.js.map +17 -0
- package/dist/chunk-nq68kghz.js +1647 -0
- package/dist/chunk-nq68kghz.js.map +10 -0
- package/dist/chunk-nthabjd9.js +3138 -0
- package/dist/chunk-nthabjd9.js.map +34 -0
- package/dist/chunk-nxpzt33t.js +278 -0
- package/dist/chunk-nxpzt33t.js.map +10 -0
- package/dist/chunk-pfyjtfex.js +172 -0
- package/dist/chunk-pfyjtfex.js.map +10 -0
- package/dist/chunk-q1nd6g0y.js +392 -0
- package/dist/chunk-q1nd6g0y.js.map +20 -0
- package/dist/chunk-q4js8r0z.js +4708 -0
- package/dist/chunk-q4js8r0z.js.map +29 -0
- package/dist/chunk-qv44tmn6.js +289 -0
- package/dist/chunk-qv44tmn6.js.map +13 -0
- package/dist/chunk-r2sg2nxa.js +20 -0
- package/dist/chunk-r2sg2nxa.js.map +9 -0
- package/dist/chunk-rp8wjzht.js +16959 -0
- package/dist/chunk-rp8wjzht.js.map +26 -0
- package/dist/chunk-rpxnm86e.js +372 -0
- package/dist/chunk-rpxnm86e.js.map +17 -0
- package/dist/chunk-sdp429xd.js +914 -0
- package/dist/chunk-sdp429xd.js.map +24 -0
- package/dist/chunk-t85nbjjb.js +113 -0
- package/dist/chunk-t85nbjjb.js.map +10 -0
- package/dist/chunk-tz7wnw4s.js +211 -0
- package/dist/chunk-tz7wnw4s.js.map +11 -0
- package/dist/chunk-v7117ywx.js +1477 -0
- package/dist/chunk-v7117ywx.js.map +23 -0
- package/dist/chunk-w8q7nsm7.js +2098 -0
- package/dist/chunk-w8q7nsm7.js.map +44 -0
- package/dist/chunk-wa64nz8b.js +47 -0
- package/dist/chunk-wa64nz8b.js.map +10 -0
- package/dist/chunk-wz8d5vzb.js +234 -0
- package/dist/chunk-wz8d5vzb.js.map +11 -0
- package/dist/chunk-ycfxp056.js +677 -0
- package/dist/chunk-ycfxp056.js.map +17 -0
- package/dist/chunk-z9d2xc83.js +3256 -0
- package/dist/chunk-z9d2xc83.js.map +84 -0
- package/dist/cli.js +111 -126055
- package/dist/cli.js.map +19 -0
- package/dist/commands/autoload.d.ts +2 -0
- package/dist/commands/doctor/command.d.ts +2 -1
- package/dist/commands/doctor/command.js +82 -0
- package/dist/commands/doctor/command.js.map +11 -0
- package/dist/commands/doctor/spec.d.ts +16 -8
- package/dist/commands/init/command.d.ts +2 -1
- package/dist/commands/init/command.js +98 -0
- package/dist/commands/init/command.js.map +11 -0
- package/dist/commands/init/spec.d.ts +29 -9
- package/dist/commands/logout/command.d.ts +2 -1
- package/dist/commands/logout/command.js +79 -0
- package/dist/commands/logout/command.js.map +11 -0
- package/dist/commands/logout/spec.d.ts +11 -0
- package/dist/commands/proxy/command.d.ts +2 -1
- package/dist/commands/proxy/command.js +56 -0
- package/dist/commands/proxy/command.js.map +11 -0
- package/dist/commands/proxy/spec.d.ts +15 -0
- package/dist/commands/screens/command.d.ts +2 -1
- package/dist/commands/screens/command.js +61 -0
- package/dist/commands/screens/command.js.map +11 -0
- package/dist/commands/screens/spec.d.ts +9 -0
- package/dist/commands/serve/command.d.ts +2 -1
- package/dist/commands/serve/command.js +65 -0
- package/dist/commands/serve/command.js.map +11 -0
- package/dist/commands/serve/spec.d.ts +9 -0
- package/dist/commands/site/command.d.ts +2 -1
- package/dist/commands/site/command.js +53 -0
- package/dist/commands/site/command.js.map +11 -0
- package/dist/commands/site/spec.d.ts +15 -0
- package/dist/commands/snapshot/command.d.ts +2 -1
- package/dist/commands/snapshot/command.js +59 -0
- package/dist/commands/snapshot/command.js.map +11 -0
- package/dist/commands/tool/command.d.ts +2 -1
- package/dist/commands/tool/command.js +79 -0
- package/dist/commands/tool/command.js.map +11 -0
- package/dist/commands/tool/handler.d.ts +17 -0
- package/dist/commands/tool/spec.d.ts +17 -0
- package/dist/commands/view/command.d.ts +2 -1
- package/dist/commands/view/command.js +52 -0
- package/dist/commands/view/command.js.map +11 -0
- package/dist/commands/view/spec.d.ts +24 -0
- package/dist/framework/CommandDefinition.d.ts +2 -2
- package/dist/index.js +26 -21607
- package/dist/index.js.map +9 -0
- package/dist/lib/services/site/schemas.d.ts +8 -8
- package/dist/services/config/handler.d.ts +12 -0
- package/dist/services/config/spec.d.ts +82 -0
- package/dist/services/gcloud/auth.d.ts +28 -0
- package/dist/services/gcloud/core.d.ts +21 -0
- package/dist/services/gcloud/handler.d.ts +6 -18
- package/dist/services/gcloud/install.d.ts +23 -0
- package/dist/services/gcloud/projects.d.ts +15 -0
- package/dist/services/gcloud/spec.d.ts +32 -24
- package/dist/services/mcp-client/client.d.ts +0 -5
- package/dist/services/mcp-client/spec.d.ts +6 -6
- package/dist/services/mcp-config/spec.d.ts +12 -12
- package/dist/services/project/spec.d.ts +4 -4
- package/dist/services/proxy/spec.d.ts +3 -3
- package/dist/services/stitch/api.d.ts +10 -0
- package/dist/services/stitch/connection.d.ts +5 -0
- package/dist/services/stitch/handler.d.ts +5 -3
- package/dist/services/stitch/iam.d.ts +11 -0
- package/dist/services/stitch/spec.d.ts +6 -6
- package/dist/services/view/spec.d.ts +7 -7
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/commands/doctor/handler.d.ts +9 -0
- package/dist/src/commands/doctor/handler.test.d.ts +1 -0
- package/dist/src/commands/doctor/spec.d.ts +130 -0
- package/dist/src/commands/doctor/spec.test.d.ts +1 -0
- package/dist/src/commands/init/handler.d.ts +17 -0
- package/dist/src/commands/init/handler.test.d.ts +1 -0
- package/dist/src/commands/init/spec.d.ts +88 -0
- package/dist/src/commands/init/spec.test.d.ts +1 -0
- package/dist/src/commands/proxy/handler.d.ts +7 -0
- package/dist/src/commands/proxy/handler.test.d.ts +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/platform/detector.d.ts +29 -0
- package/dist/src/platform/paths.d.ts +20 -0
- package/dist/src/platform/shell.d.ts +26 -0
- package/dist/src/services/gcloud/handler.d.ts +48 -0
- package/dist/src/services/gcloud/handler.test.d.ts +1 -0
- package/dist/src/services/gcloud/spec.d.ts +405 -0
- package/dist/src/services/mcp-config/handler.d.ts +12 -0
- package/dist/src/services/mcp-config/handler.test.d.ts +1 -0
- package/dist/src/services/mcp-config/spec.d.ts +88 -0
- package/dist/src/services/mcp-config/spec.test.d.ts +1 -0
- package/dist/src/services/project/handler.d.ts +11 -0
- package/dist/src/services/project/handler.test.d.ts +1 -0
- package/dist/src/services/project/spec.d.ts +86 -0
- package/dist/src/services/project/spec.test.d.ts +1 -0
- package/dist/src/services/proxy/handler.d.ts +15 -0
- package/dist/src/services/proxy/handler.test.d.ts +1 -0
- package/dist/src/services/proxy/spec.d.ts +83 -0
- package/dist/src/services/proxy/spec.test.d.ts +1 -0
- package/dist/src/services/stitch/handler.d.ts +15 -0
- package/dist/src/services/stitch/handler.test.d.ts +1 -0
- package/dist/src/services/stitch/spec.d.ts +262 -0
- package/dist/src/services/stitch/spec.test.d.ts +1 -0
- package/dist/src/ui/spinner.d.ts +11 -0
- package/dist/src/ui/theme.d.ts +18 -0
- package/dist/src/ui/wizard.d.ts +24 -0
- package/dist/tests/mocks/shell.d.ts +2 -0
- package/dist/ui/JsonTree.d.ts +1 -1
- package/package.json +2 -2
- package/dist/commands/registry.d.ts +0 -2
- package/dist/ui/copy-behaviors/index.d.ts +0 -8
- package/dist/ui/serve-behaviors/index.d.ts +0 -7
- /package/dist/ui/navigation-behaviors/{index.d.ts → handler.d.ts} +0 -0
|
@@ -0,0 +1,3138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
theme
|
|
3
|
+
} from "./chunk-kbtqrkwh.js";
|
|
4
|
+
import {
|
|
5
|
+
exports_external
|
|
6
|
+
} from "./chunk-2k7n0w2x.js";
|
|
7
|
+
import {
|
|
8
|
+
__commonJS,
|
|
9
|
+
__require,
|
|
10
|
+
__toESM
|
|
11
|
+
} from "./chunk-9wyra8hs.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/adm-zip/util/constants.js
|
|
14
|
+
var require_constants = __commonJS((exports, module) => {
|
|
15
|
+
module.exports = {
|
|
16
|
+
LOCHDR: 30,
|
|
17
|
+
LOCSIG: 67324752,
|
|
18
|
+
LOCVER: 4,
|
|
19
|
+
LOCFLG: 6,
|
|
20
|
+
LOCHOW: 8,
|
|
21
|
+
LOCTIM: 10,
|
|
22
|
+
LOCCRC: 14,
|
|
23
|
+
LOCSIZ: 18,
|
|
24
|
+
LOCLEN: 22,
|
|
25
|
+
LOCNAM: 26,
|
|
26
|
+
LOCEXT: 28,
|
|
27
|
+
EXTSIG: 134695760,
|
|
28
|
+
EXTHDR: 16,
|
|
29
|
+
EXTCRC: 4,
|
|
30
|
+
EXTSIZ: 8,
|
|
31
|
+
EXTLEN: 12,
|
|
32
|
+
CENHDR: 46,
|
|
33
|
+
CENSIG: 33639248,
|
|
34
|
+
CENVEM: 4,
|
|
35
|
+
CENVER: 6,
|
|
36
|
+
CENFLG: 8,
|
|
37
|
+
CENHOW: 10,
|
|
38
|
+
CENTIM: 12,
|
|
39
|
+
CENCRC: 16,
|
|
40
|
+
CENSIZ: 20,
|
|
41
|
+
CENLEN: 24,
|
|
42
|
+
CENNAM: 28,
|
|
43
|
+
CENEXT: 30,
|
|
44
|
+
CENCOM: 32,
|
|
45
|
+
CENDSK: 34,
|
|
46
|
+
CENATT: 36,
|
|
47
|
+
CENATX: 38,
|
|
48
|
+
CENOFF: 42,
|
|
49
|
+
ENDHDR: 22,
|
|
50
|
+
ENDSIG: 101010256,
|
|
51
|
+
ENDSUB: 8,
|
|
52
|
+
ENDTOT: 10,
|
|
53
|
+
ENDSIZ: 12,
|
|
54
|
+
ENDOFF: 16,
|
|
55
|
+
ENDCOM: 20,
|
|
56
|
+
END64HDR: 20,
|
|
57
|
+
END64SIG: 117853008,
|
|
58
|
+
END64START: 4,
|
|
59
|
+
END64OFF: 8,
|
|
60
|
+
END64NUMDISKS: 16,
|
|
61
|
+
ZIP64SIG: 101075792,
|
|
62
|
+
ZIP64HDR: 56,
|
|
63
|
+
ZIP64LEAD: 12,
|
|
64
|
+
ZIP64SIZE: 4,
|
|
65
|
+
ZIP64VEM: 12,
|
|
66
|
+
ZIP64VER: 14,
|
|
67
|
+
ZIP64DSK: 16,
|
|
68
|
+
ZIP64DSKDIR: 20,
|
|
69
|
+
ZIP64SUB: 24,
|
|
70
|
+
ZIP64TOT: 32,
|
|
71
|
+
ZIP64SIZB: 40,
|
|
72
|
+
ZIP64OFF: 48,
|
|
73
|
+
ZIP64EXTRA: 56,
|
|
74
|
+
STORED: 0,
|
|
75
|
+
SHRUNK: 1,
|
|
76
|
+
REDUCED1: 2,
|
|
77
|
+
REDUCED2: 3,
|
|
78
|
+
REDUCED3: 4,
|
|
79
|
+
REDUCED4: 5,
|
|
80
|
+
IMPLODED: 6,
|
|
81
|
+
DEFLATED: 8,
|
|
82
|
+
ENHANCED_DEFLATED: 9,
|
|
83
|
+
PKWARE: 10,
|
|
84
|
+
BZIP2: 12,
|
|
85
|
+
LZMA: 14,
|
|
86
|
+
IBM_TERSE: 18,
|
|
87
|
+
IBM_LZ77: 19,
|
|
88
|
+
AES_ENCRYPT: 99,
|
|
89
|
+
FLG_ENC: 1,
|
|
90
|
+
FLG_COMP1: 2,
|
|
91
|
+
FLG_COMP2: 4,
|
|
92
|
+
FLG_DESC: 8,
|
|
93
|
+
FLG_ENH: 16,
|
|
94
|
+
FLG_PATCH: 32,
|
|
95
|
+
FLG_STR: 64,
|
|
96
|
+
FLG_EFS: 2048,
|
|
97
|
+
FLG_MSK: 4096,
|
|
98
|
+
FILE: 2,
|
|
99
|
+
BUFFER: 1,
|
|
100
|
+
NONE: 0,
|
|
101
|
+
EF_ID: 0,
|
|
102
|
+
EF_SIZE: 2,
|
|
103
|
+
ID_ZIP64: 1,
|
|
104
|
+
ID_AVINFO: 7,
|
|
105
|
+
ID_PFS: 8,
|
|
106
|
+
ID_OS2: 9,
|
|
107
|
+
ID_NTFS: 10,
|
|
108
|
+
ID_OPENVMS: 12,
|
|
109
|
+
ID_UNIX: 13,
|
|
110
|
+
ID_FORK: 14,
|
|
111
|
+
ID_PATCH: 15,
|
|
112
|
+
ID_X509_PKCS7: 20,
|
|
113
|
+
ID_X509_CERTID_F: 21,
|
|
114
|
+
ID_X509_CERTID_C: 22,
|
|
115
|
+
ID_STRONGENC: 23,
|
|
116
|
+
ID_RECORD_MGT: 24,
|
|
117
|
+
ID_X509_PKCS7_RL: 25,
|
|
118
|
+
ID_IBM1: 101,
|
|
119
|
+
ID_IBM2: 102,
|
|
120
|
+
ID_POSZIP: 18064,
|
|
121
|
+
EF_ZIP64_OR_32: 4294967295,
|
|
122
|
+
EF_ZIP64_OR_16: 65535,
|
|
123
|
+
EF_ZIP64_SUNCOMP: 0,
|
|
124
|
+
EF_ZIP64_SCOMP: 8,
|
|
125
|
+
EF_ZIP64_RHO: 16,
|
|
126
|
+
EF_ZIP64_DSN: 24
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// node_modules/adm-zip/util/errors.js
|
|
131
|
+
var require_errors = __commonJS((exports) => {
|
|
132
|
+
var errors = {
|
|
133
|
+
INVALID_LOC: "Invalid LOC header (bad signature)",
|
|
134
|
+
INVALID_CEN: "Invalid CEN header (bad signature)",
|
|
135
|
+
INVALID_END: "Invalid END header (bad signature)",
|
|
136
|
+
DESCRIPTOR_NOT_EXIST: "No descriptor present",
|
|
137
|
+
DESCRIPTOR_UNKNOWN: "Unknown descriptor format",
|
|
138
|
+
DESCRIPTOR_FAULTY: "Descriptor data is malformed",
|
|
139
|
+
NO_DATA: "Nothing to decompress",
|
|
140
|
+
BAD_CRC: "CRC32 checksum failed {0}",
|
|
141
|
+
FILE_IN_THE_WAY: "There is a file in the way: {0}",
|
|
142
|
+
UNKNOWN_METHOD: "Invalid/unsupported compression method",
|
|
143
|
+
AVAIL_DATA: "inflate::Available inflate data did not terminate",
|
|
144
|
+
INVALID_DISTANCE: "inflate::Invalid literal/length or distance code in fixed or dynamic block",
|
|
145
|
+
TO_MANY_CODES: "inflate::Dynamic block code description: too many length or distance codes",
|
|
146
|
+
INVALID_REPEAT_LEN: "inflate::Dynamic block code description: repeat more than specified lengths",
|
|
147
|
+
INVALID_REPEAT_FIRST: "inflate::Dynamic block code description: repeat lengths with no first length",
|
|
148
|
+
INCOMPLETE_CODES: "inflate::Dynamic block code description: code lengths codes incomplete",
|
|
149
|
+
INVALID_DYN_DISTANCE: "inflate::Dynamic block code description: invalid distance code lengths",
|
|
150
|
+
INVALID_CODES_LEN: "inflate::Dynamic block code description: invalid literal/length code lengths",
|
|
151
|
+
INVALID_STORE_BLOCK: "inflate::Stored block length did not match one's complement",
|
|
152
|
+
INVALID_BLOCK_TYPE: "inflate::Invalid block type (type == 3)",
|
|
153
|
+
CANT_EXTRACT_FILE: "Could not extract the file",
|
|
154
|
+
CANT_OVERRIDE: "Target file already exists",
|
|
155
|
+
DISK_ENTRY_TOO_LARGE: "Number of disk entries is too large",
|
|
156
|
+
NO_ZIP: "No zip file was loaded",
|
|
157
|
+
NO_ENTRY: "Entry doesn't exist",
|
|
158
|
+
DIRECTORY_CONTENT_ERROR: "A directory cannot have content",
|
|
159
|
+
FILE_NOT_FOUND: 'File not found: "{0}"',
|
|
160
|
+
NOT_IMPLEMENTED: "Not implemented",
|
|
161
|
+
INVALID_FILENAME: "Invalid filename",
|
|
162
|
+
INVALID_FORMAT: "Invalid or unsupported zip format. No END header found",
|
|
163
|
+
INVALID_PASS_PARAM: "Incompatible password parameter",
|
|
164
|
+
WRONG_PASSWORD: "Wrong Password",
|
|
165
|
+
COMMENT_TOO_LONG: "Comment is too long",
|
|
166
|
+
EXTRA_FIELD_PARSE_ERROR: "Extra field parsing error"
|
|
167
|
+
};
|
|
168
|
+
function E(message) {
|
|
169
|
+
return function(...args) {
|
|
170
|
+
if (args.length) {
|
|
171
|
+
message = message.replace(/\{(\d)\}/g, (_, n) => args[n] || "");
|
|
172
|
+
}
|
|
173
|
+
return new Error("ADM-ZIP: " + message);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
for (const msg of Object.keys(errors)) {
|
|
177
|
+
exports[msg] = E(errors[msg]);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// node_modules/adm-zip/util/utils.js
|
|
182
|
+
var require_utils = __commonJS((exports, module) => {
|
|
183
|
+
var fsystem = __require("fs");
|
|
184
|
+
var pth = __require("path");
|
|
185
|
+
var Constants = require_constants();
|
|
186
|
+
var Errors = require_errors();
|
|
187
|
+
var isWin = typeof process === "object" && process.platform === "win32";
|
|
188
|
+
var is_Obj = (obj) => typeof obj === "object" && obj !== null;
|
|
189
|
+
var crcTable = new Uint32Array(256).map((t, c) => {
|
|
190
|
+
for (let k = 0;k < 8; k++) {
|
|
191
|
+
if ((c & 1) !== 0) {
|
|
192
|
+
c = 3988292384 ^ c >>> 1;
|
|
193
|
+
} else {
|
|
194
|
+
c >>>= 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return c >>> 0;
|
|
198
|
+
});
|
|
199
|
+
function Utils(opts) {
|
|
200
|
+
this.sep = pth.sep;
|
|
201
|
+
this.fs = fsystem;
|
|
202
|
+
if (is_Obj(opts)) {
|
|
203
|
+
if (is_Obj(opts.fs) && typeof opts.fs.statSync === "function") {
|
|
204
|
+
this.fs = opts.fs;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
module.exports = Utils;
|
|
209
|
+
Utils.prototype.makeDir = function(folder) {
|
|
210
|
+
const self = this;
|
|
211
|
+
function mkdirSync(fpath) {
|
|
212
|
+
let resolvedPath = fpath.split(self.sep)[0];
|
|
213
|
+
fpath.split(self.sep).forEach(function(name) {
|
|
214
|
+
if (!name || name.substr(-1, 1) === ":")
|
|
215
|
+
return;
|
|
216
|
+
resolvedPath += self.sep + name;
|
|
217
|
+
var stat;
|
|
218
|
+
try {
|
|
219
|
+
stat = self.fs.statSync(resolvedPath);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
self.fs.mkdirSync(resolvedPath);
|
|
222
|
+
}
|
|
223
|
+
if (stat && stat.isFile())
|
|
224
|
+
throw Errors.FILE_IN_THE_WAY(`"${resolvedPath}"`);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
mkdirSync(folder);
|
|
228
|
+
};
|
|
229
|
+
Utils.prototype.writeFileTo = function(path2, content, overwrite, attr) {
|
|
230
|
+
const self = this;
|
|
231
|
+
if (self.fs.existsSync(path2)) {
|
|
232
|
+
if (!overwrite)
|
|
233
|
+
return false;
|
|
234
|
+
var stat = self.fs.statSync(path2);
|
|
235
|
+
if (stat.isDirectory()) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
var folder = pth.dirname(path2);
|
|
240
|
+
if (!self.fs.existsSync(folder)) {
|
|
241
|
+
self.makeDir(folder);
|
|
242
|
+
}
|
|
243
|
+
var fd;
|
|
244
|
+
try {
|
|
245
|
+
fd = self.fs.openSync(path2, "w", 438);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
self.fs.chmodSync(path2, 438);
|
|
248
|
+
fd = self.fs.openSync(path2, "w", 438);
|
|
249
|
+
}
|
|
250
|
+
if (fd) {
|
|
251
|
+
try {
|
|
252
|
+
self.fs.writeSync(fd, content, 0, content.length, 0);
|
|
253
|
+
} finally {
|
|
254
|
+
self.fs.closeSync(fd);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
self.fs.chmodSync(path2, attr || 438);
|
|
258
|
+
return true;
|
|
259
|
+
};
|
|
260
|
+
Utils.prototype.writeFileToAsync = function(path2, content, overwrite, attr, callback) {
|
|
261
|
+
if (typeof attr === "function") {
|
|
262
|
+
callback = attr;
|
|
263
|
+
attr = undefined;
|
|
264
|
+
}
|
|
265
|
+
const self = this;
|
|
266
|
+
self.fs.exists(path2, function(exist) {
|
|
267
|
+
if (exist && !overwrite)
|
|
268
|
+
return callback(false);
|
|
269
|
+
self.fs.stat(path2, function(err, stat) {
|
|
270
|
+
if (exist && stat.isDirectory()) {
|
|
271
|
+
return callback(false);
|
|
272
|
+
}
|
|
273
|
+
var folder = pth.dirname(path2);
|
|
274
|
+
self.fs.exists(folder, function(exists) {
|
|
275
|
+
if (!exists)
|
|
276
|
+
self.makeDir(folder);
|
|
277
|
+
self.fs.open(path2, "w", 438, function(err2, fd) {
|
|
278
|
+
if (err2) {
|
|
279
|
+
self.fs.chmod(path2, 438, function() {
|
|
280
|
+
self.fs.open(path2, "w", 438, function(err3, fd2) {
|
|
281
|
+
self.fs.write(fd2, content, 0, content.length, 0, function() {
|
|
282
|
+
self.fs.close(fd2, function() {
|
|
283
|
+
self.fs.chmod(path2, attr || 438, function() {
|
|
284
|
+
callback(true);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
} else if (fd) {
|
|
291
|
+
self.fs.write(fd, content, 0, content.length, 0, function() {
|
|
292
|
+
self.fs.close(fd, function() {
|
|
293
|
+
self.fs.chmod(path2, attr || 438, function() {
|
|
294
|
+
callback(true);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
self.fs.chmod(path2, attr || 438, function() {
|
|
300
|
+
callback(true);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
Utils.prototype.findFiles = function(path2) {
|
|
309
|
+
const self = this;
|
|
310
|
+
function findSync(dir, pattern, recursive) {
|
|
311
|
+
if (typeof pattern === "boolean") {
|
|
312
|
+
recursive = pattern;
|
|
313
|
+
pattern = undefined;
|
|
314
|
+
}
|
|
315
|
+
let files = [];
|
|
316
|
+
self.fs.readdirSync(dir).forEach(function(file) {
|
|
317
|
+
const path3 = pth.join(dir, file);
|
|
318
|
+
const stat = self.fs.statSync(path3);
|
|
319
|
+
if (!pattern || pattern.test(path3)) {
|
|
320
|
+
files.push(pth.normalize(path3) + (stat.isDirectory() ? self.sep : ""));
|
|
321
|
+
}
|
|
322
|
+
if (stat.isDirectory() && recursive)
|
|
323
|
+
files = files.concat(findSync(path3, pattern, recursive));
|
|
324
|
+
});
|
|
325
|
+
return files;
|
|
326
|
+
}
|
|
327
|
+
return findSync(path2, undefined, true);
|
|
328
|
+
};
|
|
329
|
+
Utils.prototype.findFilesAsync = function(dir, cb) {
|
|
330
|
+
const self = this;
|
|
331
|
+
let results = [];
|
|
332
|
+
self.fs.readdir(dir, function(err, list) {
|
|
333
|
+
if (err)
|
|
334
|
+
return cb(err);
|
|
335
|
+
let list_length = list.length;
|
|
336
|
+
if (!list_length)
|
|
337
|
+
return cb(null, results);
|
|
338
|
+
list.forEach(function(file) {
|
|
339
|
+
file = pth.join(dir, file);
|
|
340
|
+
self.fs.stat(file, function(err2, stat) {
|
|
341
|
+
if (err2)
|
|
342
|
+
return cb(err2);
|
|
343
|
+
if (stat) {
|
|
344
|
+
results.push(pth.normalize(file) + (stat.isDirectory() ? self.sep : ""));
|
|
345
|
+
if (stat.isDirectory()) {
|
|
346
|
+
self.findFilesAsync(file, function(err3, res) {
|
|
347
|
+
if (err3)
|
|
348
|
+
return cb(err3);
|
|
349
|
+
results = results.concat(res);
|
|
350
|
+
if (!--list_length)
|
|
351
|
+
cb(null, results);
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
if (!--list_length)
|
|
355
|
+
cb(null, results);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
Utils.prototype.getAttributes = function() {};
|
|
363
|
+
Utils.prototype.setAttributes = function() {};
|
|
364
|
+
Utils.crc32update = function(crc, byte) {
|
|
365
|
+
return crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
366
|
+
};
|
|
367
|
+
Utils.crc32 = function(buf) {
|
|
368
|
+
if (typeof buf === "string") {
|
|
369
|
+
buf = Buffer.from(buf, "utf8");
|
|
370
|
+
}
|
|
371
|
+
let len = buf.length;
|
|
372
|
+
let crc = ~0;
|
|
373
|
+
for (let off = 0;off < len; )
|
|
374
|
+
crc = Utils.crc32update(crc, buf[off++]);
|
|
375
|
+
return ~crc >>> 0;
|
|
376
|
+
};
|
|
377
|
+
Utils.methodToString = function(method) {
|
|
378
|
+
switch (method) {
|
|
379
|
+
case Constants.STORED:
|
|
380
|
+
return "STORED (" + method + ")";
|
|
381
|
+
case Constants.DEFLATED:
|
|
382
|
+
return "DEFLATED (" + method + ")";
|
|
383
|
+
default:
|
|
384
|
+
return "UNSUPPORTED (" + method + ")";
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
Utils.canonical = function(path2) {
|
|
388
|
+
if (!path2)
|
|
389
|
+
return "";
|
|
390
|
+
const safeSuffix = pth.posix.normalize("/" + path2.split("\\").join("/"));
|
|
391
|
+
return pth.join(".", safeSuffix);
|
|
392
|
+
};
|
|
393
|
+
Utils.zipnamefix = function(path2) {
|
|
394
|
+
if (!path2)
|
|
395
|
+
return "";
|
|
396
|
+
const safeSuffix = pth.posix.normalize("/" + path2.split("\\").join("/"));
|
|
397
|
+
return pth.posix.join(".", safeSuffix);
|
|
398
|
+
};
|
|
399
|
+
Utils.findLast = function(arr, callback) {
|
|
400
|
+
if (!Array.isArray(arr))
|
|
401
|
+
throw new TypeError("arr is not array");
|
|
402
|
+
const len = arr.length >>> 0;
|
|
403
|
+
for (let i = len - 1;i >= 0; i--) {
|
|
404
|
+
if (callback(arr[i], i, arr)) {
|
|
405
|
+
return arr[i];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return;
|
|
409
|
+
};
|
|
410
|
+
Utils.sanitize = function(prefix, name) {
|
|
411
|
+
prefix = pth.resolve(pth.normalize(prefix));
|
|
412
|
+
var parts = name.split("/");
|
|
413
|
+
for (var i = 0, l = parts.length;i < l; i++) {
|
|
414
|
+
var path2 = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
|
|
415
|
+
if (path2.indexOf(prefix) === 0) {
|
|
416
|
+
return path2;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return pth.normalize(pth.join(prefix, pth.basename(name)));
|
|
420
|
+
};
|
|
421
|
+
Utils.toBuffer = function toBuffer(input, encoder) {
|
|
422
|
+
if (Buffer.isBuffer(input)) {
|
|
423
|
+
return input;
|
|
424
|
+
} else if (input instanceof Uint8Array) {
|
|
425
|
+
return Buffer.from(input);
|
|
426
|
+
} else {
|
|
427
|
+
return typeof input === "string" ? encoder(input) : Buffer.alloc(0);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
Utils.readBigUInt64LE = function(buffer, index) {
|
|
431
|
+
var slice = Buffer.from(buffer.slice(index, index + 8));
|
|
432
|
+
slice.swap64();
|
|
433
|
+
return parseInt(`0x${slice.toString("hex")}`);
|
|
434
|
+
};
|
|
435
|
+
Utils.fromDOS2Date = function(val) {
|
|
436
|
+
return new Date((val >> 25 & 127) + 1980, Math.max((val >> 21 & 15) - 1, 0), Math.max(val >> 16 & 31, 1), val >> 11 & 31, val >> 5 & 63, (val & 31) << 1);
|
|
437
|
+
};
|
|
438
|
+
Utils.fromDate2DOS = function(val) {
|
|
439
|
+
let date = 0;
|
|
440
|
+
let time = 0;
|
|
441
|
+
if (val.getFullYear() > 1979) {
|
|
442
|
+
date = (val.getFullYear() - 1980 & 127) << 9 | val.getMonth() + 1 << 5 | val.getDate();
|
|
443
|
+
time = val.getHours() << 11 | val.getMinutes() << 5 | val.getSeconds() >> 1;
|
|
444
|
+
}
|
|
445
|
+
return date << 16 | time;
|
|
446
|
+
};
|
|
447
|
+
Utils.isWin = isWin;
|
|
448
|
+
Utils.crcTable = crcTable;
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// node_modules/adm-zip/util/fattr.js
|
|
452
|
+
var require_fattr = __commonJS((exports, module) => {
|
|
453
|
+
var pth = __require("path");
|
|
454
|
+
module.exports = function(path2, { fs: fs2 }) {
|
|
455
|
+
var _path = path2 || "", _obj = newAttr(), _stat = null;
|
|
456
|
+
function newAttr() {
|
|
457
|
+
return {
|
|
458
|
+
directory: false,
|
|
459
|
+
readonly: false,
|
|
460
|
+
hidden: false,
|
|
461
|
+
executable: false,
|
|
462
|
+
mtime: 0,
|
|
463
|
+
atime: 0
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
if (_path && fs2.existsSync(_path)) {
|
|
467
|
+
_stat = fs2.statSync(_path);
|
|
468
|
+
_obj.directory = _stat.isDirectory();
|
|
469
|
+
_obj.mtime = _stat.mtime;
|
|
470
|
+
_obj.atime = _stat.atime;
|
|
471
|
+
_obj.executable = (73 & _stat.mode) !== 0;
|
|
472
|
+
_obj.readonly = (128 & _stat.mode) === 0;
|
|
473
|
+
_obj.hidden = pth.basename(_path)[0] === ".";
|
|
474
|
+
} else {
|
|
475
|
+
console.warn("Invalid path: " + _path);
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
get directory() {
|
|
479
|
+
return _obj.directory;
|
|
480
|
+
},
|
|
481
|
+
get readOnly() {
|
|
482
|
+
return _obj.readonly;
|
|
483
|
+
},
|
|
484
|
+
get hidden() {
|
|
485
|
+
return _obj.hidden;
|
|
486
|
+
},
|
|
487
|
+
get mtime() {
|
|
488
|
+
return _obj.mtime;
|
|
489
|
+
},
|
|
490
|
+
get atime() {
|
|
491
|
+
return _obj.atime;
|
|
492
|
+
},
|
|
493
|
+
get executable() {
|
|
494
|
+
return _obj.executable;
|
|
495
|
+
},
|
|
496
|
+
decodeAttributes: function() {},
|
|
497
|
+
encodeAttributes: function() {},
|
|
498
|
+
toJSON: function() {
|
|
499
|
+
return {
|
|
500
|
+
path: _path,
|
|
501
|
+
isDirectory: _obj.directory,
|
|
502
|
+
isReadOnly: _obj.readonly,
|
|
503
|
+
isHidden: _obj.hidden,
|
|
504
|
+
isExecutable: _obj.executable,
|
|
505
|
+
mTime: _obj.mtime,
|
|
506
|
+
aTime: _obj.atime
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
toString: function() {
|
|
510
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// node_modules/adm-zip/util/decoder.js
|
|
517
|
+
var require_decoder = __commonJS((exports, module) => {
|
|
518
|
+
module.exports = {
|
|
519
|
+
efs: true,
|
|
520
|
+
encode: (data) => Buffer.from(data, "utf8"),
|
|
521
|
+
decode: (data) => data.toString("utf8")
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
// node_modules/adm-zip/util/index.js
|
|
526
|
+
var require_util = __commonJS((exports, module) => {
|
|
527
|
+
module.exports = require_utils();
|
|
528
|
+
module.exports.Constants = require_constants();
|
|
529
|
+
module.exports.Errors = require_errors();
|
|
530
|
+
module.exports.FileAttr = require_fattr();
|
|
531
|
+
module.exports.decoder = require_decoder();
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
// node_modules/adm-zip/headers/entryHeader.js
|
|
535
|
+
var require_entryHeader = __commonJS((exports, module) => {
|
|
536
|
+
var Utils = require_util();
|
|
537
|
+
var Constants = Utils.Constants;
|
|
538
|
+
module.exports = function() {
|
|
539
|
+
var _verMade = 20, _version = 10, _flags = 0, _method = 0, _time = 0, _crc = 0, _compressedSize = 0, _size = 0, _fnameLen = 0, _extraLen = 0, _comLen = 0, _diskStart = 0, _inattr = 0, _attr = 0, _offset = 0;
|
|
540
|
+
_verMade |= Utils.isWin ? 2560 : 768;
|
|
541
|
+
_flags |= Constants.FLG_EFS;
|
|
542
|
+
const _localHeader = {
|
|
543
|
+
extraLen: 0
|
|
544
|
+
};
|
|
545
|
+
const uint32 = (val) => Math.max(0, val) >>> 0;
|
|
546
|
+
const uint16 = (val) => Math.max(0, val) & 65535;
|
|
547
|
+
const uint8 = (val) => Math.max(0, val) & 255;
|
|
548
|
+
_time = Utils.fromDate2DOS(new Date);
|
|
549
|
+
return {
|
|
550
|
+
get made() {
|
|
551
|
+
return _verMade;
|
|
552
|
+
},
|
|
553
|
+
set made(val) {
|
|
554
|
+
_verMade = val;
|
|
555
|
+
},
|
|
556
|
+
get version() {
|
|
557
|
+
return _version;
|
|
558
|
+
},
|
|
559
|
+
set version(val) {
|
|
560
|
+
_version = val;
|
|
561
|
+
},
|
|
562
|
+
get flags() {
|
|
563
|
+
return _flags;
|
|
564
|
+
},
|
|
565
|
+
set flags(val) {
|
|
566
|
+
_flags = val;
|
|
567
|
+
},
|
|
568
|
+
get flags_efs() {
|
|
569
|
+
return (_flags & Constants.FLG_EFS) > 0;
|
|
570
|
+
},
|
|
571
|
+
set flags_efs(val) {
|
|
572
|
+
if (val) {
|
|
573
|
+
_flags |= Constants.FLG_EFS;
|
|
574
|
+
} else {
|
|
575
|
+
_flags &= ~Constants.FLG_EFS;
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
get flags_desc() {
|
|
579
|
+
return (_flags & Constants.FLG_DESC) > 0;
|
|
580
|
+
},
|
|
581
|
+
set flags_desc(val) {
|
|
582
|
+
if (val) {
|
|
583
|
+
_flags |= Constants.FLG_DESC;
|
|
584
|
+
} else {
|
|
585
|
+
_flags &= ~Constants.FLG_DESC;
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
get method() {
|
|
589
|
+
return _method;
|
|
590
|
+
},
|
|
591
|
+
set method(val) {
|
|
592
|
+
switch (val) {
|
|
593
|
+
case Constants.STORED:
|
|
594
|
+
this.version = 10;
|
|
595
|
+
case Constants.DEFLATED:
|
|
596
|
+
default:
|
|
597
|
+
this.version = 20;
|
|
598
|
+
}
|
|
599
|
+
_method = val;
|
|
600
|
+
},
|
|
601
|
+
get time() {
|
|
602
|
+
return Utils.fromDOS2Date(this.timeval);
|
|
603
|
+
},
|
|
604
|
+
set time(val) {
|
|
605
|
+
this.timeval = Utils.fromDate2DOS(val);
|
|
606
|
+
},
|
|
607
|
+
get timeval() {
|
|
608
|
+
return _time;
|
|
609
|
+
},
|
|
610
|
+
set timeval(val) {
|
|
611
|
+
_time = uint32(val);
|
|
612
|
+
},
|
|
613
|
+
get timeHighByte() {
|
|
614
|
+
return uint8(_time >>> 8);
|
|
615
|
+
},
|
|
616
|
+
get crc() {
|
|
617
|
+
return _crc;
|
|
618
|
+
},
|
|
619
|
+
set crc(val) {
|
|
620
|
+
_crc = uint32(val);
|
|
621
|
+
},
|
|
622
|
+
get compressedSize() {
|
|
623
|
+
return _compressedSize;
|
|
624
|
+
},
|
|
625
|
+
set compressedSize(val) {
|
|
626
|
+
_compressedSize = uint32(val);
|
|
627
|
+
},
|
|
628
|
+
get size() {
|
|
629
|
+
return _size;
|
|
630
|
+
},
|
|
631
|
+
set size(val) {
|
|
632
|
+
_size = uint32(val);
|
|
633
|
+
},
|
|
634
|
+
get fileNameLength() {
|
|
635
|
+
return _fnameLen;
|
|
636
|
+
},
|
|
637
|
+
set fileNameLength(val) {
|
|
638
|
+
_fnameLen = val;
|
|
639
|
+
},
|
|
640
|
+
get extraLength() {
|
|
641
|
+
return _extraLen;
|
|
642
|
+
},
|
|
643
|
+
set extraLength(val) {
|
|
644
|
+
_extraLen = val;
|
|
645
|
+
},
|
|
646
|
+
get extraLocalLength() {
|
|
647
|
+
return _localHeader.extraLen;
|
|
648
|
+
},
|
|
649
|
+
set extraLocalLength(val) {
|
|
650
|
+
_localHeader.extraLen = val;
|
|
651
|
+
},
|
|
652
|
+
get commentLength() {
|
|
653
|
+
return _comLen;
|
|
654
|
+
},
|
|
655
|
+
set commentLength(val) {
|
|
656
|
+
_comLen = val;
|
|
657
|
+
},
|
|
658
|
+
get diskNumStart() {
|
|
659
|
+
return _diskStart;
|
|
660
|
+
},
|
|
661
|
+
set diskNumStart(val) {
|
|
662
|
+
_diskStart = uint32(val);
|
|
663
|
+
},
|
|
664
|
+
get inAttr() {
|
|
665
|
+
return _inattr;
|
|
666
|
+
},
|
|
667
|
+
set inAttr(val) {
|
|
668
|
+
_inattr = uint32(val);
|
|
669
|
+
},
|
|
670
|
+
get attr() {
|
|
671
|
+
return _attr;
|
|
672
|
+
},
|
|
673
|
+
set attr(val) {
|
|
674
|
+
_attr = uint32(val);
|
|
675
|
+
},
|
|
676
|
+
get fileAttr() {
|
|
677
|
+
return (_attr || 0) >> 16 & 4095;
|
|
678
|
+
},
|
|
679
|
+
get offset() {
|
|
680
|
+
return _offset;
|
|
681
|
+
},
|
|
682
|
+
set offset(val) {
|
|
683
|
+
_offset = uint32(val);
|
|
684
|
+
},
|
|
685
|
+
get encrypted() {
|
|
686
|
+
return (_flags & Constants.FLG_ENC) === Constants.FLG_ENC;
|
|
687
|
+
},
|
|
688
|
+
get centralHeaderSize() {
|
|
689
|
+
return Constants.CENHDR + _fnameLen + _extraLen + _comLen;
|
|
690
|
+
},
|
|
691
|
+
get realDataOffset() {
|
|
692
|
+
return _offset + Constants.LOCHDR + _localHeader.fnameLen + _localHeader.extraLen;
|
|
693
|
+
},
|
|
694
|
+
get localHeader() {
|
|
695
|
+
return _localHeader;
|
|
696
|
+
},
|
|
697
|
+
loadLocalHeaderFromBinary: function(input) {
|
|
698
|
+
var data = input.slice(_offset, _offset + Constants.LOCHDR);
|
|
699
|
+
if (data.readUInt32LE(0) !== Constants.LOCSIG) {
|
|
700
|
+
throw Utils.Errors.INVALID_LOC();
|
|
701
|
+
}
|
|
702
|
+
_localHeader.version = data.readUInt16LE(Constants.LOCVER);
|
|
703
|
+
_localHeader.flags = data.readUInt16LE(Constants.LOCFLG);
|
|
704
|
+
_localHeader.method = data.readUInt16LE(Constants.LOCHOW);
|
|
705
|
+
_localHeader.time = data.readUInt32LE(Constants.LOCTIM);
|
|
706
|
+
_localHeader.crc = data.readUInt32LE(Constants.LOCCRC);
|
|
707
|
+
_localHeader.compressedSize = data.readUInt32LE(Constants.LOCSIZ);
|
|
708
|
+
_localHeader.size = data.readUInt32LE(Constants.LOCLEN);
|
|
709
|
+
_localHeader.fnameLen = data.readUInt16LE(Constants.LOCNAM);
|
|
710
|
+
_localHeader.extraLen = data.readUInt16LE(Constants.LOCEXT);
|
|
711
|
+
const extraStart = _offset + Constants.LOCHDR + _localHeader.fnameLen;
|
|
712
|
+
const extraEnd = extraStart + _localHeader.extraLen;
|
|
713
|
+
return input.slice(extraStart, extraEnd);
|
|
714
|
+
},
|
|
715
|
+
loadFromBinary: function(data) {
|
|
716
|
+
if (data.length !== Constants.CENHDR || data.readUInt32LE(0) !== Constants.CENSIG) {
|
|
717
|
+
throw Utils.Errors.INVALID_CEN();
|
|
718
|
+
}
|
|
719
|
+
_verMade = data.readUInt16LE(Constants.CENVEM);
|
|
720
|
+
_version = data.readUInt16LE(Constants.CENVER);
|
|
721
|
+
_flags = data.readUInt16LE(Constants.CENFLG);
|
|
722
|
+
_method = data.readUInt16LE(Constants.CENHOW);
|
|
723
|
+
_time = data.readUInt32LE(Constants.CENTIM);
|
|
724
|
+
_crc = data.readUInt32LE(Constants.CENCRC);
|
|
725
|
+
_compressedSize = data.readUInt32LE(Constants.CENSIZ);
|
|
726
|
+
_size = data.readUInt32LE(Constants.CENLEN);
|
|
727
|
+
_fnameLen = data.readUInt16LE(Constants.CENNAM);
|
|
728
|
+
_extraLen = data.readUInt16LE(Constants.CENEXT);
|
|
729
|
+
_comLen = data.readUInt16LE(Constants.CENCOM);
|
|
730
|
+
_diskStart = data.readUInt16LE(Constants.CENDSK);
|
|
731
|
+
_inattr = data.readUInt16LE(Constants.CENATT);
|
|
732
|
+
_attr = data.readUInt32LE(Constants.CENATX);
|
|
733
|
+
_offset = data.readUInt32LE(Constants.CENOFF);
|
|
734
|
+
},
|
|
735
|
+
localHeaderToBinary: function() {
|
|
736
|
+
var data = Buffer.alloc(Constants.LOCHDR);
|
|
737
|
+
data.writeUInt32LE(Constants.LOCSIG, 0);
|
|
738
|
+
data.writeUInt16LE(_version, Constants.LOCVER);
|
|
739
|
+
data.writeUInt16LE(_flags, Constants.LOCFLG);
|
|
740
|
+
data.writeUInt16LE(_method, Constants.LOCHOW);
|
|
741
|
+
data.writeUInt32LE(_time, Constants.LOCTIM);
|
|
742
|
+
data.writeUInt32LE(_crc, Constants.LOCCRC);
|
|
743
|
+
data.writeUInt32LE(_compressedSize, Constants.LOCSIZ);
|
|
744
|
+
data.writeUInt32LE(_size, Constants.LOCLEN);
|
|
745
|
+
data.writeUInt16LE(_fnameLen, Constants.LOCNAM);
|
|
746
|
+
data.writeUInt16LE(_localHeader.extraLen, Constants.LOCEXT);
|
|
747
|
+
return data;
|
|
748
|
+
},
|
|
749
|
+
centralHeaderToBinary: function() {
|
|
750
|
+
var data = Buffer.alloc(Constants.CENHDR + _fnameLen + _extraLen + _comLen);
|
|
751
|
+
data.writeUInt32LE(Constants.CENSIG, 0);
|
|
752
|
+
data.writeUInt16LE(_verMade, Constants.CENVEM);
|
|
753
|
+
data.writeUInt16LE(_version, Constants.CENVER);
|
|
754
|
+
data.writeUInt16LE(_flags, Constants.CENFLG);
|
|
755
|
+
data.writeUInt16LE(_method, Constants.CENHOW);
|
|
756
|
+
data.writeUInt32LE(_time, Constants.CENTIM);
|
|
757
|
+
data.writeUInt32LE(_crc, Constants.CENCRC);
|
|
758
|
+
data.writeUInt32LE(_compressedSize, Constants.CENSIZ);
|
|
759
|
+
data.writeUInt32LE(_size, Constants.CENLEN);
|
|
760
|
+
data.writeUInt16LE(_fnameLen, Constants.CENNAM);
|
|
761
|
+
data.writeUInt16LE(_extraLen, Constants.CENEXT);
|
|
762
|
+
data.writeUInt16LE(_comLen, Constants.CENCOM);
|
|
763
|
+
data.writeUInt16LE(_diskStart, Constants.CENDSK);
|
|
764
|
+
data.writeUInt16LE(_inattr, Constants.CENATT);
|
|
765
|
+
data.writeUInt32LE(_attr, Constants.CENATX);
|
|
766
|
+
data.writeUInt32LE(_offset, Constants.CENOFF);
|
|
767
|
+
return data;
|
|
768
|
+
},
|
|
769
|
+
toJSON: function() {
|
|
770
|
+
const bytes = function(nr) {
|
|
771
|
+
return nr + " bytes";
|
|
772
|
+
};
|
|
773
|
+
return {
|
|
774
|
+
made: _verMade,
|
|
775
|
+
version: _version,
|
|
776
|
+
flags: _flags,
|
|
777
|
+
method: Utils.methodToString(_method),
|
|
778
|
+
time: this.time,
|
|
779
|
+
crc: "0x" + _crc.toString(16).toUpperCase(),
|
|
780
|
+
compressedSize: bytes(_compressedSize),
|
|
781
|
+
size: bytes(_size),
|
|
782
|
+
fileNameLength: bytes(_fnameLen),
|
|
783
|
+
extraLength: bytes(_extraLen),
|
|
784
|
+
commentLength: bytes(_comLen),
|
|
785
|
+
diskNumStart: _diskStart,
|
|
786
|
+
inAttr: _inattr,
|
|
787
|
+
attr: _attr,
|
|
788
|
+
offset: _offset,
|
|
789
|
+
centralHeaderSize: bytes(Constants.CENHDR + _fnameLen + _extraLen + _comLen)
|
|
790
|
+
};
|
|
791
|
+
},
|
|
792
|
+
toString: function() {
|
|
793
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
// node_modules/adm-zip/headers/mainHeader.js
|
|
800
|
+
var require_mainHeader = __commonJS((exports, module) => {
|
|
801
|
+
var Utils = require_util();
|
|
802
|
+
var Constants = Utils.Constants;
|
|
803
|
+
module.exports = function() {
|
|
804
|
+
var _volumeEntries = 0, _totalEntries = 0, _size = 0, _offset = 0, _commentLength = 0;
|
|
805
|
+
return {
|
|
806
|
+
get diskEntries() {
|
|
807
|
+
return _volumeEntries;
|
|
808
|
+
},
|
|
809
|
+
set diskEntries(val) {
|
|
810
|
+
_volumeEntries = _totalEntries = val;
|
|
811
|
+
},
|
|
812
|
+
get totalEntries() {
|
|
813
|
+
return _totalEntries;
|
|
814
|
+
},
|
|
815
|
+
set totalEntries(val) {
|
|
816
|
+
_totalEntries = _volumeEntries = val;
|
|
817
|
+
},
|
|
818
|
+
get size() {
|
|
819
|
+
return _size;
|
|
820
|
+
},
|
|
821
|
+
set size(val) {
|
|
822
|
+
_size = val;
|
|
823
|
+
},
|
|
824
|
+
get offset() {
|
|
825
|
+
return _offset;
|
|
826
|
+
},
|
|
827
|
+
set offset(val) {
|
|
828
|
+
_offset = val;
|
|
829
|
+
},
|
|
830
|
+
get commentLength() {
|
|
831
|
+
return _commentLength;
|
|
832
|
+
},
|
|
833
|
+
set commentLength(val) {
|
|
834
|
+
_commentLength = val;
|
|
835
|
+
},
|
|
836
|
+
get mainHeaderSize() {
|
|
837
|
+
return Constants.ENDHDR + _commentLength;
|
|
838
|
+
},
|
|
839
|
+
loadFromBinary: function(data) {
|
|
840
|
+
if ((data.length !== Constants.ENDHDR || data.readUInt32LE(0) !== Constants.ENDSIG) && (data.length < Constants.ZIP64HDR || data.readUInt32LE(0) !== Constants.ZIP64SIG)) {
|
|
841
|
+
throw Utils.Errors.INVALID_END();
|
|
842
|
+
}
|
|
843
|
+
if (data.readUInt32LE(0) === Constants.ENDSIG) {
|
|
844
|
+
_volumeEntries = data.readUInt16LE(Constants.ENDSUB);
|
|
845
|
+
_totalEntries = data.readUInt16LE(Constants.ENDTOT);
|
|
846
|
+
_size = data.readUInt32LE(Constants.ENDSIZ);
|
|
847
|
+
_offset = data.readUInt32LE(Constants.ENDOFF);
|
|
848
|
+
_commentLength = data.readUInt16LE(Constants.ENDCOM);
|
|
849
|
+
} else {
|
|
850
|
+
_volumeEntries = Utils.readBigUInt64LE(data, Constants.ZIP64SUB);
|
|
851
|
+
_totalEntries = Utils.readBigUInt64LE(data, Constants.ZIP64TOT);
|
|
852
|
+
_size = Utils.readBigUInt64LE(data, Constants.ZIP64SIZE);
|
|
853
|
+
_offset = Utils.readBigUInt64LE(data, Constants.ZIP64OFF);
|
|
854
|
+
_commentLength = 0;
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
toBinary: function() {
|
|
858
|
+
var b = Buffer.alloc(Constants.ENDHDR + _commentLength);
|
|
859
|
+
b.writeUInt32LE(Constants.ENDSIG, 0);
|
|
860
|
+
b.writeUInt32LE(0, 4);
|
|
861
|
+
b.writeUInt16LE(_volumeEntries, Constants.ENDSUB);
|
|
862
|
+
b.writeUInt16LE(_totalEntries, Constants.ENDTOT);
|
|
863
|
+
b.writeUInt32LE(_size, Constants.ENDSIZ);
|
|
864
|
+
b.writeUInt32LE(_offset, Constants.ENDOFF);
|
|
865
|
+
b.writeUInt16LE(_commentLength, Constants.ENDCOM);
|
|
866
|
+
b.fill(" ", Constants.ENDHDR);
|
|
867
|
+
return b;
|
|
868
|
+
},
|
|
869
|
+
toJSON: function() {
|
|
870
|
+
const offset = function(nr, len) {
|
|
871
|
+
let offs = nr.toString(16).toUpperCase();
|
|
872
|
+
while (offs.length < len)
|
|
873
|
+
offs = "0" + offs;
|
|
874
|
+
return "0x" + offs;
|
|
875
|
+
};
|
|
876
|
+
return {
|
|
877
|
+
diskEntries: _volumeEntries,
|
|
878
|
+
totalEntries: _totalEntries,
|
|
879
|
+
size: _size + " bytes",
|
|
880
|
+
offset: offset(_offset, 4),
|
|
881
|
+
commentLength: _commentLength
|
|
882
|
+
};
|
|
883
|
+
},
|
|
884
|
+
toString: function() {
|
|
885
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
};
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
// node_modules/adm-zip/headers/index.js
|
|
892
|
+
var require_headers = __commonJS((exports) => {
|
|
893
|
+
exports.EntryHeader = require_entryHeader();
|
|
894
|
+
exports.MainHeader = require_mainHeader();
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
// node_modules/adm-zip/methods/deflater.js
|
|
898
|
+
var require_deflater = __commonJS((exports, module) => {
|
|
899
|
+
module.exports = function(inbuf) {
|
|
900
|
+
var zlib = __require("zlib");
|
|
901
|
+
var opts = { chunkSize: (parseInt(inbuf.length / 1024) + 1) * 1024 };
|
|
902
|
+
return {
|
|
903
|
+
deflate: function() {
|
|
904
|
+
return zlib.deflateRawSync(inbuf, opts);
|
|
905
|
+
},
|
|
906
|
+
deflateAsync: function(callback) {
|
|
907
|
+
var tmp = zlib.createDeflateRaw(opts), parts = [], total = 0;
|
|
908
|
+
tmp.on("data", function(data) {
|
|
909
|
+
parts.push(data);
|
|
910
|
+
total += data.length;
|
|
911
|
+
});
|
|
912
|
+
tmp.on("end", function() {
|
|
913
|
+
var buf = Buffer.alloc(total), written = 0;
|
|
914
|
+
buf.fill(0);
|
|
915
|
+
for (var i = 0;i < parts.length; i++) {
|
|
916
|
+
var part = parts[i];
|
|
917
|
+
part.copy(buf, written);
|
|
918
|
+
written += part.length;
|
|
919
|
+
}
|
|
920
|
+
callback && callback(buf);
|
|
921
|
+
});
|
|
922
|
+
tmp.end(inbuf);
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
};
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
// node_modules/adm-zip/methods/inflater.js
|
|
929
|
+
var require_inflater = __commonJS((exports, module) => {
|
|
930
|
+
var version = +(process.versions ? process.versions.node : "").split(".")[0] || 0;
|
|
931
|
+
module.exports = function(inbuf, expectedLength) {
|
|
932
|
+
var zlib = __require("zlib");
|
|
933
|
+
const option = version >= 15 && expectedLength > 0 ? { maxOutputLength: expectedLength } : {};
|
|
934
|
+
return {
|
|
935
|
+
inflate: function() {
|
|
936
|
+
return zlib.inflateRawSync(inbuf, option);
|
|
937
|
+
},
|
|
938
|
+
inflateAsync: function(callback) {
|
|
939
|
+
var tmp = zlib.createInflateRaw(option), parts = [], total = 0;
|
|
940
|
+
tmp.on("data", function(data) {
|
|
941
|
+
parts.push(data);
|
|
942
|
+
total += data.length;
|
|
943
|
+
});
|
|
944
|
+
tmp.on("end", function() {
|
|
945
|
+
var buf = Buffer.alloc(total), written = 0;
|
|
946
|
+
buf.fill(0);
|
|
947
|
+
for (var i = 0;i < parts.length; i++) {
|
|
948
|
+
var part = parts[i];
|
|
949
|
+
part.copy(buf, written);
|
|
950
|
+
written += part.length;
|
|
951
|
+
}
|
|
952
|
+
callback && callback(buf);
|
|
953
|
+
});
|
|
954
|
+
tmp.end(inbuf);
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
// node_modules/adm-zip/methods/zipcrypto.js
|
|
961
|
+
var require_zipcrypto = __commonJS((exports, module) => {
|
|
962
|
+
var { randomFillSync } = __require("crypto");
|
|
963
|
+
var Errors = require_errors();
|
|
964
|
+
var crctable = new Uint32Array(256).map((t, crc) => {
|
|
965
|
+
for (let j = 0;j < 8; j++) {
|
|
966
|
+
if ((crc & 1) !== 0) {
|
|
967
|
+
crc = crc >>> 1 ^ 3988292384;
|
|
968
|
+
} else {
|
|
969
|
+
crc >>>= 1;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return crc >>> 0;
|
|
973
|
+
});
|
|
974
|
+
var uMul = (a, b) => Math.imul(a, b) >>> 0;
|
|
975
|
+
var crc32update = (pCrc32, bval) => {
|
|
976
|
+
return crctable[(pCrc32 ^ bval) & 255] ^ pCrc32 >>> 8;
|
|
977
|
+
};
|
|
978
|
+
var genSalt = () => {
|
|
979
|
+
if (typeof randomFillSync === "function") {
|
|
980
|
+
return randomFillSync(Buffer.alloc(12));
|
|
981
|
+
} else {
|
|
982
|
+
return genSalt.node();
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
genSalt.node = () => {
|
|
986
|
+
const salt = Buffer.alloc(12);
|
|
987
|
+
const len = salt.length;
|
|
988
|
+
for (let i = 0;i < len; i++)
|
|
989
|
+
salt[i] = Math.random() * 256 & 255;
|
|
990
|
+
return salt;
|
|
991
|
+
};
|
|
992
|
+
var config = {
|
|
993
|
+
genSalt
|
|
994
|
+
};
|
|
995
|
+
function Initkeys(pw) {
|
|
996
|
+
const pass = Buffer.isBuffer(pw) ? pw : Buffer.from(pw);
|
|
997
|
+
this.keys = new Uint32Array([305419896, 591751049, 878082192]);
|
|
998
|
+
for (let i = 0;i < pass.length; i++) {
|
|
999
|
+
this.updateKeys(pass[i]);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
Initkeys.prototype.updateKeys = function(byteValue) {
|
|
1003
|
+
const keys = this.keys;
|
|
1004
|
+
keys[0] = crc32update(keys[0], byteValue);
|
|
1005
|
+
keys[1] += keys[0] & 255;
|
|
1006
|
+
keys[1] = uMul(keys[1], 134775813) + 1;
|
|
1007
|
+
keys[2] = crc32update(keys[2], keys[1] >>> 24);
|
|
1008
|
+
return byteValue;
|
|
1009
|
+
};
|
|
1010
|
+
Initkeys.prototype.next = function() {
|
|
1011
|
+
const k = (this.keys[2] | 2) >>> 0;
|
|
1012
|
+
return uMul(k, k ^ 1) >> 8 & 255;
|
|
1013
|
+
};
|
|
1014
|
+
function make_decrypter(pwd) {
|
|
1015
|
+
const keys = new Initkeys(pwd);
|
|
1016
|
+
return function(data) {
|
|
1017
|
+
const result = Buffer.alloc(data.length);
|
|
1018
|
+
let pos = 0;
|
|
1019
|
+
for (let c of data) {
|
|
1020
|
+
result[pos++] = keys.updateKeys(c ^ keys.next());
|
|
1021
|
+
}
|
|
1022
|
+
return result;
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function make_encrypter(pwd) {
|
|
1026
|
+
const keys = new Initkeys(pwd);
|
|
1027
|
+
return function(data, result, pos = 0) {
|
|
1028
|
+
if (!result)
|
|
1029
|
+
result = Buffer.alloc(data.length);
|
|
1030
|
+
for (let c of data) {
|
|
1031
|
+
const k = keys.next();
|
|
1032
|
+
result[pos++] = c ^ k;
|
|
1033
|
+
keys.updateKeys(c);
|
|
1034
|
+
}
|
|
1035
|
+
return result;
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
function decrypt(data, header, pwd) {
|
|
1039
|
+
if (!data || !Buffer.isBuffer(data) || data.length < 12) {
|
|
1040
|
+
return Buffer.alloc(0);
|
|
1041
|
+
}
|
|
1042
|
+
const decrypter = make_decrypter(pwd);
|
|
1043
|
+
const salt = decrypter(data.slice(0, 12));
|
|
1044
|
+
const verifyByte = (header.flags & 8) === 8 ? header.timeHighByte : header.crc >>> 24;
|
|
1045
|
+
if (salt[11] !== verifyByte) {
|
|
1046
|
+
throw Errors.WRONG_PASSWORD();
|
|
1047
|
+
}
|
|
1048
|
+
return decrypter(data.slice(12));
|
|
1049
|
+
}
|
|
1050
|
+
function _salter(data) {
|
|
1051
|
+
if (Buffer.isBuffer(data) && data.length >= 12) {
|
|
1052
|
+
config.genSalt = function() {
|
|
1053
|
+
return data.slice(0, 12);
|
|
1054
|
+
};
|
|
1055
|
+
} else if (data === "node") {
|
|
1056
|
+
config.genSalt = genSalt.node;
|
|
1057
|
+
} else {
|
|
1058
|
+
config.genSalt = genSalt;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function encrypt(data, header, pwd, oldlike = false) {
|
|
1062
|
+
if (data == null)
|
|
1063
|
+
data = Buffer.alloc(0);
|
|
1064
|
+
if (!Buffer.isBuffer(data))
|
|
1065
|
+
data = Buffer.from(data.toString());
|
|
1066
|
+
const encrypter = make_encrypter(pwd);
|
|
1067
|
+
const salt = config.genSalt();
|
|
1068
|
+
salt[11] = header.crc >>> 24 & 255;
|
|
1069
|
+
if (oldlike)
|
|
1070
|
+
salt[10] = header.crc >>> 16 & 255;
|
|
1071
|
+
const result = Buffer.alloc(data.length + 12);
|
|
1072
|
+
encrypter(salt, result);
|
|
1073
|
+
return encrypter(data, result, 12);
|
|
1074
|
+
}
|
|
1075
|
+
module.exports = { decrypt, encrypt, _salter };
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
// node_modules/adm-zip/methods/index.js
|
|
1079
|
+
var require_methods = __commonJS((exports) => {
|
|
1080
|
+
exports.Deflater = require_deflater();
|
|
1081
|
+
exports.Inflater = require_inflater();
|
|
1082
|
+
exports.ZipCrypto = require_zipcrypto();
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
// node_modules/adm-zip/zipEntry.js
|
|
1086
|
+
var require_zipEntry = __commonJS((exports, module) => {
|
|
1087
|
+
var Utils = require_util();
|
|
1088
|
+
var Headers = require_headers();
|
|
1089
|
+
var Constants = Utils.Constants;
|
|
1090
|
+
var Methods = require_methods();
|
|
1091
|
+
module.exports = function(options, input) {
|
|
1092
|
+
var _centralHeader = new Headers.EntryHeader, _entryName = Buffer.alloc(0), _comment = Buffer.alloc(0), _isDirectory = false, uncompressedData = null, _extra = Buffer.alloc(0), _extralocal = Buffer.alloc(0), _efs = true;
|
|
1093
|
+
const opts = options;
|
|
1094
|
+
const decoder = typeof opts.decoder === "object" ? opts.decoder : Utils.decoder;
|
|
1095
|
+
_efs = decoder.hasOwnProperty("efs") ? decoder.efs : false;
|
|
1096
|
+
function getCompressedDataFromZip() {
|
|
1097
|
+
if (!input || !(input instanceof Uint8Array)) {
|
|
1098
|
+
return Buffer.alloc(0);
|
|
1099
|
+
}
|
|
1100
|
+
_extralocal = _centralHeader.loadLocalHeaderFromBinary(input);
|
|
1101
|
+
return input.slice(_centralHeader.realDataOffset, _centralHeader.realDataOffset + _centralHeader.compressedSize);
|
|
1102
|
+
}
|
|
1103
|
+
function crc32OK(data) {
|
|
1104
|
+
if (!_centralHeader.flags_desc) {
|
|
1105
|
+
if (Utils.crc32(data) !== _centralHeader.localHeader.crc) {
|
|
1106
|
+
return false;
|
|
1107
|
+
}
|
|
1108
|
+
} else {
|
|
1109
|
+
const descriptor = {};
|
|
1110
|
+
const dataEndOffset = _centralHeader.realDataOffset + _centralHeader.compressedSize;
|
|
1111
|
+
if (input.readUInt32LE(dataEndOffset) == Constants.LOCSIG || input.readUInt32LE(dataEndOffset) == Constants.CENSIG) {
|
|
1112
|
+
throw Utils.Errors.DESCRIPTOR_NOT_EXIST();
|
|
1113
|
+
}
|
|
1114
|
+
if (input.readUInt32LE(dataEndOffset) == Constants.EXTSIG) {
|
|
1115
|
+
descriptor.crc = input.readUInt32LE(dataEndOffset + Constants.EXTCRC);
|
|
1116
|
+
descriptor.compressedSize = input.readUInt32LE(dataEndOffset + Constants.EXTSIZ);
|
|
1117
|
+
descriptor.size = input.readUInt32LE(dataEndOffset + Constants.EXTLEN);
|
|
1118
|
+
} else if (input.readUInt16LE(dataEndOffset + 12) === 19280) {
|
|
1119
|
+
descriptor.crc = input.readUInt32LE(dataEndOffset + Constants.EXTCRC - 4);
|
|
1120
|
+
descriptor.compressedSize = input.readUInt32LE(dataEndOffset + Constants.EXTSIZ - 4);
|
|
1121
|
+
descriptor.size = input.readUInt32LE(dataEndOffset + Constants.EXTLEN - 4);
|
|
1122
|
+
} else {
|
|
1123
|
+
throw Utils.Errors.DESCRIPTOR_UNKNOWN();
|
|
1124
|
+
}
|
|
1125
|
+
if (descriptor.compressedSize !== _centralHeader.compressedSize || descriptor.size !== _centralHeader.size || descriptor.crc !== _centralHeader.crc) {
|
|
1126
|
+
throw Utils.Errors.DESCRIPTOR_FAULTY();
|
|
1127
|
+
}
|
|
1128
|
+
if (Utils.crc32(data) !== descriptor.crc) {
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return true;
|
|
1133
|
+
}
|
|
1134
|
+
function decompress(async, callback, pass) {
|
|
1135
|
+
if (typeof callback === "undefined" && typeof async === "string") {
|
|
1136
|
+
pass = async;
|
|
1137
|
+
async = undefined;
|
|
1138
|
+
}
|
|
1139
|
+
if (_isDirectory) {
|
|
1140
|
+
if (async && callback) {
|
|
1141
|
+
callback(Buffer.alloc(0), Utils.Errors.DIRECTORY_CONTENT_ERROR());
|
|
1142
|
+
}
|
|
1143
|
+
return Buffer.alloc(0);
|
|
1144
|
+
}
|
|
1145
|
+
var compressedData = getCompressedDataFromZip();
|
|
1146
|
+
if (compressedData.length === 0) {
|
|
1147
|
+
if (async && callback)
|
|
1148
|
+
callback(compressedData);
|
|
1149
|
+
return compressedData;
|
|
1150
|
+
}
|
|
1151
|
+
if (_centralHeader.encrypted) {
|
|
1152
|
+
if (typeof pass !== "string" && !Buffer.isBuffer(pass)) {
|
|
1153
|
+
throw Utils.Errors.INVALID_PASS_PARAM();
|
|
1154
|
+
}
|
|
1155
|
+
compressedData = Methods.ZipCrypto.decrypt(compressedData, _centralHeader, pass);
|
|
1156
|
+
}
|
|
1157
|
+
var data = Buffer.alloc(_centralHeader.size);
|
|
1158
|
+
switch (_centralHeader.method) {
|
|
1159
|
+
case Utils.Constants.STORED:
|
|
1160
|
+
compressedData.copy(data);
|
|
1161
|
+
if (!crc32OK(data)) {
|
|
1162
|
+
if (async && callback)
|
|
1163
|
+
callback(data, Utils.Errors.BAD_CRC());
|
|
1164
|
+
throw Utils.Errors.BAD_CRC();
|
|
1165
|
+
} else {
|
|
1166
|
+
if (async && callback)
|
|
1167
|
+
callback(data);
|
|
1168
|
+
return data;
|
|
1169
|
+
}
|
|
1170
|
+
case Utils.Constants.DEFLATED:
|
|
1171
|
+
var inflater = new Methods.Inflater(compressedData, _centralHeader.size);
|
|
1172
|
+
if (!async) {
|
|
1173
|
+
const result = inflater.inflate(data);
|
|
1174
|
+
result.copy(data, 0);
|
|
1175
|
+
if (!crc32OK(data)) {
|
|
1176
|
+
throw Utils.Errors.BAD_CRC(`"${decoder.decode(_entryName)}"`);
|
|
1177
|
+
}
|
|
1178
|
+
return data;
|
|
1179
|
+
} else {
|
|
1180
|
+
inflater.inflateAsync(function(result) {
|
|
1181
|
+
result.copy(result, 0);
|
|
1182
|
+
if (callback) {
|
|
1183
|
+
if (!crc32OK(result)) {
|
|
1184
|
+
callback(result, Utils.Errors.BAD_CRC());
|
|
1185
|
+
} else {
|
|
1186
|
+
callback(result);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
break;
|
|
1192
|
+
default:
|
|
1193
|
+
if (async && callback)
|
|
1194
|
+
callback(Buffer.alloc(0), Utils.Errors.UNKNOWN_METHOD());
|
|
1195
|
+
throw Utils.Errors.UNKNOWN_METHOD();
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
function compress(async, callback) {
|
|
1199
|
+
if ((!uncompressedData || !uncompressedData.length) && Buffer.isBuffer(input)) {
|
|
1200
|
+
if (async && callback)
|
|
1201
|
+
callback(getCompressedDataFromZip());
|
|
1202
|
+
return getCompressedDataFromZip();
|
|
1203
|
+
}
|
|
1204
|
+
if (uncompressedData.length && !_isDirectory) {
|
|
1205
|
+
var compressedData;
|
|
1206
|
+
switch (_centralHeader.method) {
|
|
1207
|
+
case Utils.Constants.STORED:
|
|
1208
|
+
_centralHeader.compressedSize = _centralHeader.size;
|
|
1209
|
+
compressedData = Buffer.alloc(uncompressedData.length);
|
|
1210
|
+
uncompressedData.copy(compressedData);
|
|
1211
|
+
if (async && callback)
|
|
1212
|
+
callback(compressedData);
|
|
1213
|
+
return compressedData;
|
|
1214
|
+
default:
|
|
1215
|
+
case Utils.Constants.DEFLATED:
|
|
1216
|
+
var deflater = new Methods.Deflater(uncompressedData);
|
|
1217
|
+
if (!async) {
|
|
1218
|
+
var deflated = deflater.deflate();
|
|
1219
|
+
_centralHeader.compressedSize = deflated.length;
|
|
1220
|
+
return deflated;
|
|
1221
|
+
} else {
|
|
1222
|
+
deflater.deflateAsync(function(data) {
|
|
1223
|
+
compressedData = Buffer.alloc(data.length);
|
|
1224
|
+
_centralHeader.compressedSize = data.length;
|
|
1225
|
+
data.copy(compressedData);
|
|
1226
|
+
callback && callback(compressedData);
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
deflater = null;
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
} else if (async && callback) {
|
|
1233
|
+
callback(Buffer.alloc(0));
|
|
1234
|
+
} else {
|
|
1235
|
+
return Buffer.alloc(0);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
function readUInt64LE(buffer, offset) {
|
|
1239
|
+
return (buffer.readUInt32LE(offset + 4) << 4) + buffer.readUInt32LE(offset);
|
|
1240
|
+
}
|
|
1241
|
+
function parseExtra(data) {
|
|
1242
|
+
try {
|
|
1243
|
+
var offset = 0;
|
|
1244
|
+
var signature, size, part;
|
|
1245
|
+
while (offset + 4 < data.length) {
|
|
1246
|
+
signature = data.readUInt16LE(offset);
|
|
1247
|
+
offset += 2;
|
|
1248
|
+
size = data.readUInt16LE(offset);
|
|
1249
|
+
offset += 2;
|
|
1250
|
+
part = data.slice(offset, offset + size);
|
|
1251
|
+
offset += size;
|
|
1252
|
+
if (Constants.ID_ZIP64 === signature) {
|
|
1253
|
+
parseZip64ExtendedInformation(part);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
} catch (error) {
|
|
1257
|
+
throw Utils.Errors.EXTRA_FIELD_PARSE_ERROR();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
function parseZip64ExtendedInformation(data) {
|
|
1261
|
+
var size, compressedSize, offset, diskNumStart;
|
|
1262
|
+
if (data.length >= Constants.EF_ZIP64_SCOMP) {
|
|
1263
|
+
size = readUInt64LE(data, Constants.EF_ZIP64_SUNCOMP);
|
|
1264
|
+
if (_centralHeader.size === Constants.EF_ZIP64_OR_32) {
|
|
1265
|
+
_centralHeader.size = size;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
if (data.length >= Constants.EF_ZIP64_RHO) {
|
|
1269
|
+
compressedSize = readUInt64LE(data, Constants.EF_ZIP64_SCOMP);
|
|
1270
|
+
if (_centralHeader.compressedSize === Constants.EF_ZIP64_OR_32) {
|
|
1271
|
+
_centralHeader.compressedSize = compressedSize;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
if (data.length >= Constants.EF_ZIP64_DSN) {
|
|
1275
|
+
offset = readUInt64LE(data, Constants.EF_ZIP64_RHO);
|
|
1276
|
+
if (_centralHeader.offset === Constants.EF_ZIP64_OR_32) {
|
|
1277
|
+
_centralHeader.offset = offset;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
if (data.length >= Constants.EF_ZIP64_DSN + 4) {
|
|
1281
|
+
diskNumStart = data.readUInt32LE(Constants.EF_ZIP64_DSN);
|
|
1282
|
+
if (_centralHeader.diskNumStart === Constants.EF_ZIP64_OR_16) {
|
|
1283
|
+
_centralHeader.diskNumStart = diskNumStart;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
return {
|
|
1288
|
+
get entryName() {
|
|
1289
|
+
return decoder.decode(_entryName);
|
|
1290
|
+
},
|
|
1291
|
+
get rawEntryName() {
|
|
1292
|
+
return _entryName;
|
|
1293
|
+
},
|
|
1294
|
+
set entryName(val) {
|
|
1295
|
+
_entryName = Utils.toBuffer(val, decoder.encode);
|
|
1296
|
+
var lastChar = _entryName[_entryName.length - 1];
|
|
1297
|
+
_isDirectory = lastChar === 47 || lastChar === 92;
|
|
1298
|
+
_centralHeader.fileNameLength = _entryName.length;
|
|
1299
|
+
},
|
|
1300
|
+
get efs() {
|
|
1301
|
+
if (typeof _efs === "function") {
|
|
1302
|
+
return _efs(this.entryName);
|
|
1303
|
+
} else {
|
|
1304
|
+
return _efs;
|
|
1305
|
+
}
|
|
1306
|
+
},
|
|
1307
|
+
get extra() {
|
|
1308
|
+
return _extra;
|
|
1309
|
+
},
|
|
1310
|
+
set extra(val) {
|
|
1311
|
+
_extra = val;
|
|
1312
|
+
_centralHeader.extraLength = val.length;
|
|
1313
|
+
parseExtra(val);
|
|
1314
|
+
},
|
|
1315
|
+
get comment() {
|
|
1316
|
+
return decoder.decode(_comment);
|
|
1317
|
+
},
|
|
1318
|
+
set comment(val) {
|
|
1319
|
+
_comment = Utils.toBuffer(val, decoder.encode);
|
|
1320
|
+
_centralHeader.commentLength = _comment.length;
|
|
1321
|
+
if (_comment.length > 65535)
|
|
1322
|
+
throw Utils.Errors.COMMENT_TOO_LONG();
|
|
1323
|
+
},
|
|
1324
|
+
get name() {
|
|
1325
|
+
var n = decoder.decode(_entryName);
|
|
1326
|
+
return _isDirectory ? n.substr(n.length - 1).split("/").pop() : n.split("/").pop();
|
|
1327
|
+
},
|
|
1328
|
+
get isDirectory() {
|
|
1329
|
+
return _isDirectory;
|
|
1330
|
+
},
|
|
1331
|
+
getCompressedData: function() {
|
|
1332
|
+
return compress(false, null);
|
|
1333
|
+
},
|
|
1334
|
+
getCompressedDataAsync: function(callback) {
|
|
1335
|
+
compress(true, callback);
|
|
1336
|
+
},
|
|
1337
|
+
setData: function(value) {
|
|
1338
|
+
uncompressedData = Utils.toBuffer(value, Utils.decoder.encode);
|
|
1339
|
+
if (!_isDirectory && uncompressedData.length) {
|
|
1340
|
+
_centralHeader.size = uncompressedData.length;
|
|
1341
|
+
_centralHeader.method = Utils.Constants.DEFLATED;
|
|
1342
|
+
_centralHeader.crc = Utils.crc32(value);
|
|
1343
|
+
_centralHeader.changed = true;
|
|
1344
|
+
} else {
|
|
1345
|
+
_centralHeader.method = Utils.Constants.STORED;
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
getData: function(pass) {
|
|
1349
|
+
if (_centralHeader.changed) {
|
|
1350
|
+
return uncompressedData;
|
|
1351
|
+
} else {
|
|
1352
|
+
return decompress(false, null, pass);
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
getDataAsync: function(callback, pass) {
|
|
1356
|
+
if (_centralHeader.changed) {
|
|
1357
|
+
callback(uncompressedData);
|
|
1358
|
+
} else {
|
|
1359
|
+
decompress(true, callback, pass);
|
|
1360
|
+
}
|
|
1361
|
+
},
|
|
1362
|
+
set attr(attr) {
|
|
1363
|
+
_centralHeader.attr = attr;
|
|
1364
|
+
},
|
|
1365
|
+
get attr() {
|
|
1366
|
+
return _centralHeader.attr;
|
|
1367
|
+
},
|
|
1368
|
+
set header(data) {
|
|
1369
|
+
_centralHeader.loadFromBinary(data);
|
|
1370
|
+
},
|
|
1371
|
+
get header() {
|
|
1372
|
+
return _centralHeader;
|
|
1373
|
+
},
|
|
1374
|
+
packCentralHeader: function() {
|
|
1375
|
+
_centralHeader.flags_efs = this.efs;
|
|
1376
|
+
_centralHeader.extraLength = _extra.length;
|
|
1377
|
+
var header = _centralHeader.centralHeaderToBinary();
|
|
1378
|
+
var addpos = Utils.Constants.CENHDR;
|
|
1379
|
+
_entryName.copy(header, addpos);
|
|
1380
|
+
addpos += _entryName.length;
|
|
1381
|
+
_extra.copy(header, addpos);
|
|
1382
|
+
addpos += _centralHeader.extraLength;
|
|
1383
|
+
_comment.copy(header, addpos);
|
|
1384
|
+
return header;
|
|
1385
|
+
},
|
|
1386
|
+
packLocalHeader: function() {
|
|
1387
|
+
let addpos = 0;
|
|
1388
|
+
_centralHeader.flags_efs = this.efs;
|
|
1389
|
+
_centralHeader.extraLocalLength = _extralocal.length;
|
|
1390
|
+
const localHeaderBuf = _centralHeader.localHeaderToBinary();
|
|
1391
|
+
const localHeader = Buffer.alloc(localHeaderBuf.length + _entryName.length + _centralHeader.extraLocalLength);
|
|
1392
|
+
localHeaderBuf.copy(localHeader, addpos);
|
|
1393
|
+
addpos += localHeaderBuf.length;
|
|
1394
|
+
_entryName.copy(localHeader, addpos);
|
|
1395
|
+
addpos += _entryName.length;
|
|
1396
|
+
_extralocal.copy(localHeader, addpos);
|
|
1397
|
+
addpos += _extralocal.length;
|
|
1398
|
+
return localHeader;
|
|
1399
|
+
},
|
|
1400
|
+
toJSON: function() {
|
|
1401
|
+
const bytes = function(nr) {
|
|
1402
|
+
return "<" + (nr && nr.length + " bytes buffer" || "null") + ">";
|
|
1403
|
+
};
|
|
1404
|
+
return {
|
|
1405
|
+
entryName: this.entryName,
|
|
1406
|
+
name: this.name,
|
|
1407
|
+
comment: this.comment,
|
|
1408
|
+
isDirectory: this.isDirectory,
|
|
1409
|
+
header: _centralHeader.toJSON(),
|
|
1410
|
+
compressedData: bytes(input),
|
|
1411
|
+
data: bytes(uncompressedData)
|
|
1412
|
+
};
|
|
1413
|
+
},
|
|
1414
|
+
toString: function() {
|
|
1415
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
};
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// node_modules/adm-zip/zipFile.js
|
|
1422
|
+
var require_zipFile = __commonJS((exports, module) => {
|
|
1423
|
+
var ZipEntry = require_zipEntry();
|
|
1424
|
+
var Headers = require_headers();
|
|
1425
|
+
var Utils = require_util();
|
|
1426
|
+
module.exports = function(inBuffer, options) {
|
|
1427
|
+
var entryList = [], entryTable = {}, _comment = Buffer.alloc(0), mainHeader = new Headers.MainHeader, loadedEntries = false;
|
|
1428
|
+
var password = null;
|
|
1429
|
+
const temporary = new Set;
|
|
1430
|
+
const opts = options;
|
|
1431
|
+
const { noSort, decoder } = opts;
|
|
1432
|
+
if (inBuffer) {
|
|
1433
|
+
readMainHeader(opts.readEntries);
|
|
1434
|
+
} else {
|
|
1435
|
+
loadedEntries = true;
|
|
1436
|
+
}
|
|
1437
|
+
function makeTemporaryFolders() {
|
|
1438
|
+
const foldersList = new Set;
|
|
1439
|
+
for (const elem of Object.keys(entryTable)) {
|
|
1440
|
+
const elements = elem.split("/");
|
|
1441
|
+
elements.pop();
|
|
1442
|
+
if (!elements.length)
|
|
1443
|
+
continue;
|
|
1444
|
+
for (let i = 0;i < elements.length; i++) {
|
|
1445
|
+
const sub = elements.slice(0, i + 1).join("/") + "/";
|
|
1446
|
+
foldersList.add(sub);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
for (const elem of foldersList) {
|
|
1450
|
+
if (!(elem in entryTable)) {
|
|
1451
|
+
const tempfolder = new ZipEntry(opts);
|
|
1452
|
+
tempfolder.entryName = elem;
|
|
1453
|
+
tempfolder.attr = 16;
|
|
1454
|
+
tempfolder.temporary = true;
|
|
1455
|
+
entryList.push(tempfolder);
|
|
1456
|
+
entryTable[tempfolder.entryName] = tempfolder;
|
|
1457
|
+
temporary.add(tempfolder);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function readEntries() {
|
|
1462
|
+
loadedEntries = true;
|
|
1463
|
+
entryTable = {};
|
|
1464
|
+
if (mainHeader.diskEntries > (inBuffer.length - mainHeader.offset) / Utils.Constants.CENHDR) {
|
|
1465
|
+
throw Utils.Errors.DISK_ENTRY_TOO_LARGE();
|
|
1466
|
+
}
|
|
1467
|
+
entryList = new Array(mainHeader.diskEntries);
|
|
1468
|
+
var index = mainHeader.offset;
|
|
1469
|
+
for (var i = 0;i < entryList.length; i++) {
|
|
1470
|
+
var tmp = index, entry = new ZipEntry(opts, inBuffer);
|
|
1471
|
+
entry.header = inBuffer.slice(tmp, tmp += Utils.Constants.CENHDR);
|
|
1472
|
+
entry.entryName = inBuffer.slice(tmp, tmp += entry.header.fileNameLength);
|
|
1473
|
+
if (entry.header.extraLength) {
|
|
1474
|
+
entry.extra = inBuffer.slice(tmp, tmp += entry.header.extraLength);
|
|
1475
|
+
}
|
|
1476
|
+
if (entry.header.commentLength)
|
|
1477
|
+
entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);
|
|
1478
|
+
index += entry.header.centralHeaderSize;
|
|
1479
|
+
entryList[i] = entry;
|
|
1480
|
+
entryTable[entry.entryName] = entry;
|
|
1481
|
+
}
|
|
1482
|
+
temporary.clear();
|
|
1483
|
+
makeTemporaryFolders();
|
|
1484
|
+
}
|
|
1485
|
+
function readMainHeader(readNow) {
|
|
1486
|
+
var i = inBuffer.length - Utils.Constants.ENDHDR, max = Math.max(0, i - 65535), n = max, endStart = inBuffer.length, endOffset = -1, commentEnd = 0;
|
|
1487
|
+
const trailingSpace = typeof opts.trailingSpace === "boolean" ? opts.trailingSpace : false;
|
|
1488
|
+
if (trailingSpace)
|
|
1489
|
+
max = 0;
|
|
1490
|
+
for (i;i >= n; i--) {
|
|
1491
|
+
if (inBuffer[i] !== 80)
|
|
1492
|
+
continue;
|
|
1493
|
+
if (inBuffer.readUInt32LE(i) === Utils.Constants.ENDSIG) {
|
|
1494
|
+
endOffset = i;
|
|
1495
|
+
commentEnd = i;
|
|
1496
|
+
endStart = i + Utils.Constants.ENDHDR;
|
|
1497
|
+
n = i - Utils.Constants.END64HDR;
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
if (inBuffer.readUInt32LE(i) === Utils.Constants.END64SIG) {
|
|
1501
|
+
n = max;
|
|
1502
|
+
continue;
|
|
1503
|
+
}
|
|
1504
|
+
if (inBuffer.readUInt32LE(i) === Utils.Constants.ZIP64SIG) {
|
|
1505
|
+
endOffset = i;
|
|
1506
|
+
endStart = i + Utils.readBigUInt64LE(inBuffer, i + Utils.Constants.ZIP64SIZE) + Utils.Constants.ZIP64LEAD;
|
|
1507
|
+
break;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
if (endOffset == -1)
|
|
1511
|
+
throw Utils.Errors.INVALID_FORMAT();
|
|
1512
|
+
mainHeader.loadFromBinary(inBuffer.slice(endOffset, endStart));
|
|
1513
|
+
if (mainHeader.commentLength) {
|
|
1514
|
+
_comment = inBuffer.slice(commentEnd + Utils.Constants.ENDHDR);
|
|
1515
|
+
}
|
|
1516
|
+
if (readNow)
|
|
1517
|
+
readEntries();
|
|
1518
|
+
}
|
|
1519
|
+
function sortEntries() {
|
|
1520
|
+
if (entryList.length > 1 && !noSort) {
|
|
1521
|
+
entryList.sort((a, b) => a.entryName.toLowerCase().localeCompare(b.entryName.toLowerCase()));
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return {
|
|
1525
|
+
get entries() {
|
|
1526
|
+
if (!loadedEntries) {
|
|
1527
|
+
readEntries();
|
|
1528
|
+
}
|
|
1529
|
+
return entryList.filter((e) => !temporary.has(e));
|
|
1530
|
+
},
|
|
1531
|
+
get comment() {
|
|
1532
|
+
return decoder.decode(_comment);
|
|
1533
|
+
},
|
|
1534
|
+
set comment(val) {
|
|
1535
|
+
_comment = Utils.toBuffer(val, decoder.encode);
|
|
1536
|
+
mainHeader.commentLength = _comment.length;
|
|
1537
|
+
},
|
|
1538
|
+
getEntryCount: function() {
|
|
1539
|
+
if (!loadedEntries) {
|
|
1540
|
+
return mainHeader.diskEntries;
|
|
1541
|
+
}
|
|
1542
|
+
return entryList.length;
|
|
1543
|
+
},
|
|
1544
|
+
forEach: function(callback) {
|
|
1545
|
+
this.entries.forEach(callback);
|
|
1546
|
+
},
|
|
1547
|
+
getEntry: function(entryName) {
|
|
1548
|
+
if (!loadedEntries) {
|
|
1549
|
+
readEntries();
|
|
1550
|
+
}
|
|
1551
|
+
return entryTable[entryName] || null;
|
|
1552
|
+
},
|
|
1553
|
+
setEntry: function(entry) {
|
|
1554
|
+
if (!loadedEntries) {
|
|
1555
|
+
readEntries();
|
|
1556
|
+
}
|
|
1557
|
+
entryList.push(entry);
|
|
1558
|
+
entryTable[entry.entryName] = entry;
|
|
1559
|
+
mainHeader.totalEntries = entryList.length;
|
|
1560
|
+
},
|
|
1561
|
+
deleteFile: function(entryName, withsubfolders = true) {
|
|
1562
|
+
if (!loadedEntries) {
|
|
1563
|
+
readEntries();
|
|
1564
|
+
}
|
|
1565
|
+
const entry = entryTable[entryName];
|
|
1566
|
+
const list = this.getEntryChildren(entry, withsubfolders).map((child) => child.entryName);
|
|
1567
|
+
list.forEach(this.deleteEntry);
|
|
1568
|
+
},
|
|
1569
|
+
deleteEntry: function(entryName) {
|
|
1570
|
+
if (!loadedEntries) {
|
|
1571
|
+
readEntries();
|
|
1572
|
+
}
|
|
1573
|
+
const entry = entryTable[entryName];
|
|
1574
|
+
const index = entryList.indexOf(entry);
|
|
1575
|
+
if (index >= 0) {
|
|
1576
|
+
entryList.splice(index, 1);
|
|
1577
|
+
delete entryTable[entryName];
|
|
1578
|
+
mainHeader.totalEntries = entryList.length;
|
|
1579
|
+
}
|
|
1580
|
+
},
|
|
1581
|
+
getEntryChildren: function(entry, subfolders = true) {
|
|
1582
|
+
if (!loadedEntries) {
|
|
1583
|
+
readEntries();
|
|
1584
|
+
}
|
|
1585
|
+
if (typeof entry === "object") {
|
|
1586
|
+
if (entry.isDirectory && subfolders) {
|
|
1587
|
+
const list = [];
|
|
1588
|
+
const name = entry.entryName;
|
|
1589
|
+
for (const zipEntry of entryList) {
|
|
1590
|
+
if (zipEntry.entryName.startsWith(name)) {
|
|
1591
|
+
list.push(zipEntry);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
return list;
|
|
1595
|
+
} else {
|
|
1596
|
+
return [entry];
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return [];
|
|
1600
|
+
},
|
|
1601
|
+
getChildCount: function(entry) {
|
|
1602
|
+
if (entry && entry.isDirectory) {
|
|
1603
|
+
const list = this.getEntryChildren(entry);
|
|
1604
|
+
return list.includes(entry) ? list.length - 1 : list.length;
|
|
1605
|
+
}
|
|
1606
|
+
return 0;
|
|
1607
|
+
},
|
|
1608
|
+
compressToBuffer: function() {
|
|
1609
|
+
if (!loadedEntries) {
|
|
1610
|
+
readEntries();
|
|
1611
|
+
}
|
|
1612
|
+
sortEntries();
|
|
1613
|
+
const dataBlock = [];
|
|
1614
|
+
const headerBlocks = [];
|
|
1615
|
+
let totalSize = 0;
|
|
1616
|
+
let dindex = 0;
|
|
1617
|
+
mainHeader.size = 0;
|
|
1618
|
+
mainHeader.offset = 0;
|
|
1619
|
+
let totalEntries = 0;
|
|
1620
|
+
for (const entry of this.entries) {
|
|
1621
|
+
const compressedData = entry.getCompressedData();
|
|
1622
|
+
entry.header.offset = dindex;
|
|
1623
|
+
const localHeader = entry.packLocalHeader();
|
|
1624
|
+
const dataLength = localHeader.length + compressedData.length;
|
|
1625
|
+
dindex += dataLength;
|
|
1626
|
+
dataBlock.push(localHeader);
|
|
1627
|
+
dataBlock.push(compressedData);
|
|
1628
|
+
const centralHeader = entry.packCentralHeader();
|
|
1629
|
+
headerBlocks.push(centralHeader);
|
|
1630
|
+
mainHeader.size += centralHeader.length;
|
|
1631
|
+
totalSize += dataLength + centralHeader.length;
|
|
1632
|
+
totalEntries++;
|
|
1633
|
+
}
|
|
1634
|
+
totalSize += mainHeader.mainHeaderSize;
|
|
1635
|
+
mainHeader.offset = dindex;
|
|
1636
|
+
mainHeader.totalEntries = totalEntries;
|
|
1637
|
+
dindex = 0;
|
|
1638
|
+
const outBuffer = Buffer.alloc(totalSize);
|
|
1639
|
+
for (const content of dataBlock) {
|
|
1640
|
+
content.copy(outBuffer, dindex);
|
|
1641
|
+
dindex += content.length;
|
|
1642
|
+
}
|
|
1643
|
+
for (const content of headerBlocks) {
|
|
1644
|
+
content.copy(outBuffer, dindex);
|
|
1645
|
+
dindex += content.length;
|
|
1646
|
+
}
|
|
1647
|
+
const mh = mainHeader.toBinary();
|
|
1648
|
+
if (_comment) {
|
|
1649
|
+
_comment.copy(mh, Utils.Constants.ENDHDR);
|
|
1650
|
+
}
|
|
1651
|
+
mh.copy(outBuffer, dindex);
|
|
1652
|
+
inBuffer = outBuffer;
|
|
1653
|
+
loadedEntries = false;
|
|
1654
|
+
return outBuffer;
|
|
1655
|
+
},
|
|
1656
|
+
toAsyncBuffer: function(onSuccess, onFail, onItemStart, onItemEnd) {
|
|
1657
|
+
try {
|
|
1658
|
+
if (!loadedEntries) {
|
|
1659
|
+
readEntries();
|
|
1660
|
+
}
|
|
1661
|
+
sortEntries();
|
|
1662
|
+
const dataBlock = [];
|
|
1663
|
+
const centralHeaders = [];
|
|
1664
|
+
let totalSize = 0;
|
|
1665
|
+
let dindex = 0;
|
|
1666
|
+
let totalEntries = 0;
|
|
1667
|
+
mainHeader.size = 0;
|
|
1668
|
+
mainHeader.offset = 0;
|
|
1669
|
+
const compress2Buffer = function(entryLists) {
|
|
1670
|
+
if (entryLists.length > 0) {
|
|
1671
|
+
const entry = entryLists.shift();
|
|
1672
|
+
const name = entry.entryName + entry.extra.toString();
|
|
1673
|
+
if (onItemStart)
|
|
1674
|
+
onItemStart(name);
|
|
1675
|
+
entry.getCompressedDataAsync(function(compressedData) {
|
|
1676
|
+
if (onItemEnd)
|
|
1677
|
+
onItemEnd(name);
|
|
1678
|
+
entry.header.offset = dindex;
|
|
1679
|
+
const localHeader = entry.packLocalHeader();
|
|
1680
|
+
const dataLength = localHeader.length + compressedData.length;
|
|
1681
|
+
dindex += dataLength;
|
|
1682
|
+
dataBlock.push(localHeader);
|
|
1683
|
+
dataBlock.push(compressedData);
|
|
1684
|
+
const centalHeader = entry.packCentralHeader();
|
|
1685
|
+
centralHeaders.push(centalHeader);
|
|
1686
|
+
mainHeader.size += centalHeader.length;
|
|
1687
|
+
totalSize += dataLength + centalHeader.length;
|
|
1688
|
+
totalEntries++;
|
|
1689
|
+
compress2Buffer(entryLists);
|
|
1690
|
+
});
|
|
1691
|
+
} else {
|
|
1692
|
+
totalSize += mainHeader.mainHeaderSize;
|
|
1693
|
+
mainHeader.offset = dindex;
|
|
1694
|
+
mainHeader.totalEntries = totalEntries;
|
|
1695
|
+
dindex = 0;
|
|
1696
|
+
const outBuffer = Buffer.alloc(totalSize);
|
|
1697
|
+
dataBlock.forEach(function(content) {
|
|
1698
|
+
content.copy(outBuffer, dindex);
|
|
1699
|
+
dindex += content.length;
|
|
1700
|
+
});
|
|
1701
|
+
centralHeaders.forEach(function(content) {
|
|
1702
|
+
content.copy(outBuffer, dindex);
|
|
1703
|
+
dindex += content.length;
|
|
1704
|
+
});
|
|
1705
|
+
const mh = mainHeader.toBinary();
|
|
1706
|
+
if (_comment) {
|
|
1707
|
+
_comment.copy(mh, Utils.Constants.ENDHDR);
|
|
1708
|
+
}
|
|
1709
|
+
mh.copy(outBuffer, dindex);
|
|
1710
|
+
inBuffer = outBuffer;
|
|
1711
|
+
loadedEntries = false;
|
|
1712
|
+
onSuccess(outBuffer);
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
compress2Buffer(Array.from(this.entries));
|
|
1716
|
+
} catch (e) {
|
|
1717
|
+
onFail(e);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
};
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
// node_modules/adm-zip/adm-zip.js
|
|
1725
|
+
var require_adm_zip = __commonJS((exports, module) => {
|
|
1726
|
+
var Utils = require_util();
|
|
1727
|
+
var pth = __require("path");
|
|
1728
|
+
var ZipEntry = require_zipEntry();
|
|
1729
|
+
var ZipFile = require_zipFile();
|
|
1730
|
+
var get_Bool = (...val) => Utils.findLast(val, (c) => typeof c === "boolean");
|
|
1731
|
+
var get_Str = (...val) => Utils.findLast(val, (c) => typeof c === "string");
|
|
1732
|
+
var get_Fun = (...val) => Utils.findLast(val, (c) => typeof c === "function");
|
|
1733
|
+
var defaultOptions = {
|
|
1734
|
+
noSort: false,
|
|
1735
|
+
readEntries: false,
|
|
1736
|
+
method: Utils.Constants.NONE,
|
|
1737
|
+
fs: null
|
|
1738
|
+
};
|
|
1739
|
+
module.exports = function(input, options) {
|
|
1740
|
+
let inBuffer = null;
|
|
1741
|
+
const opts = Object.assign(Object.create(null), defaultOptions);
|
|
1742
|
+
if (input && typeof input === "object") {
|
|
1743
|
+
if (!(input instanceof Uint8Array)) {
|
|
1744
|
+
Object.assign(opts, input);
|
|
1745
|
+
input = opts.input ? opts.input : undefined;
|
|
1746
|
+
if (opts.input)
|
|
1747
|
+
delete opts.input;
|
|
1748
|
+
}
|
|
1749
|
+
if (Buffer.isBuffer(input)) {
|
|
1750
|
+
inBuffer = input;
|
|
1751
|
+
opts.method = Utils.Constants.BUFFER;
|
|
1752
|
+
input = undefined;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
Object.assign(opts, options);
|
|
1756
|
+
const filetools = new Utils(opts);
|
|
1757
|
+
if (typeof opts.decoder !== "object" || typeof opts.decoder.encode !== "function" || typeof opts.decoder.decode !== "function") {
|
|
1758
|
+
opts.decoder = Utils.decoder;
|
|
1759
|
+
}
|
|
1760
|
+
if (input && typeof input === "string") {
|
|
1761
|
+
if (filetools.fs.existsSync(input)) {
|
|
1762
|
+
opts.method = Utils.Constants.FILE;
|
|
1763
|
+
opts.filename = input;
|
|
1764
|
+
inBuffer = filetools.fs.readFileSync(input);
|
|
1765
|
+
} else {
|
|
1766
|
+
throw Utils.Errors.INVALID_FILENAME();
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
const _zip = new ZipFile(inBuffer, opts);
|
|
1770
|
+
const { canonical, sanitize, zipnamefix } = Utils;
|
|
1771
|
+
function getEntry(entry) {
|
|
1772
|
+
if (entry && _zip) {
|
|
1773
|
+
var item;
|
|
1774
|
+
if (typeof entry === "string")
|
|
1775
|
+
item = _zip.getEntry(pth.posix.normalize(entry));
|
|
1776
|
+
if (typeof entry === "object" && typeof entry.entryName !== "undefined" && typeof entry.header !== "undefined")
|
|
1777
|
+
item = _zip.getEntry(entry.entryName);
|
|
1778
|
+
if (item) {
|
|
1779
|
+
return item;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
return null;
|
|
1783
|
+
}
|
|
1784
|
+
function fixPath(zipPath) {
|
|
1785
|
+
const { join, normalize, sep } = pth.posix;
|
|
1786
|
+
return join(".", normalize(sep + zipPath.split("\\").join(sep) + sep));
|
|
1787
|
+
}
|
|
1788
|
+
function filenameFilter(filterfn) {
|
|
1789
|
+
if (filterfn instanceof RegExp) {
|
|
1790
|
+
return function(rx) {
|
|
1791
|
+
return function(filename) {
|
|
1792
|
+
return rx.test(filename);
|
|
1793
|
+
};
|
|
1794
|
+
}(filterfn);
|
|
1795
|
+
} else if (typeof filterfn !== "function") {
|
|
1796
|
+
return () => true;
|
|
1797
|
+
}
|
|
1798
|
+
return filterfn;
|
|
1799
|
+
}
|
|
1800
|
+
const relativePath = (local, entry) => {
|
|
1801
|
+
let lastChar = entry.slice(-1);
|
|
1802
|
+
lastChar = lastChar === filetools.sep ? filetools.sep : "";
|
|
1803
|
+
return pth.relative(local, entry) + lastChar;
|
|
1804
|
+
};
|
|
1805
|
+
return {
|
|
1806
|
+
readFile: function(entry, pass) {
|
|
1807
|
+
var item = getEntry(entry);
|
|
1808
|
+
return item && item.getData(pass) || null;
|
|
1809
|
+
},
|
|
1810
|
+
childCount: function(entry) {
|
|
1811
|
+
const item = getEntry(entry);
|
|
1812
|
+
if (item) {
|
|
1813
|
+
return _zip.getChildCount(item);
|
|
1814
|
+
}
|
|
1815
|
+
},
|
|
1816
|
+
readFileAsync: function(entry, callback) {
|
|
1817
|
+
var item = getEntry(entry);
|
|
1818
|
+
if (item) {
|
|
1819
|
+
item.getDataAsync(callback);
|
|
1820
|
+
} else {
|
|
1821
|
+
callback(null, "getEntry failed for:" + entry);
|
|
1822
|
+
}
|
|
1823
|
+
},
|
|
1824
|
+
readAsText: function(entry, encoding) {
|
|
1825
|
+
var item = getEntry(entry);
|
|
1826
|
+
if (item) {
|
|
1827
|
+
var data = item.getData();
|
|
1828
|
+
if (data && data.length) {
|
|
1829
|
+
return data.toString(encoding || "utf8");
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
return "";
|
|
1833
|
+
},
|
|
1834
|
+
readAsTextAsync: function(entry, callback, encoding) {
|
|
1835
|
+
var item = getEntry(entry);
|
|
1836
|
+
if (item) {
|
|
1837
|
+
item.getDataAsync(function(data, err) {
|
|
1838
|
+
if (err) {
|
|
1839
|
+
callback(data, err);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
if (data && data.length) {
|
|
1843
|
+
callback(data.toString(encoding || "utf8"));
|
|
1844
|
+
} else {
|
|
1845
|
+
callback("");
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
} else {
|
|
1849
|
+
callback("");
|
|
1850
|
+
}
|
|
1851
|
+
},
|
|
1852
|
+
deleteFile: function(entry, withsubfolders = true) {
|
|
1853
|
+
var item = getEntry(entry);
|
|
1854
|
+
if (item) {
|
|
1855
|
+
_zip.deleteFile(item.entryName, withsubfolders);
|
|
1856
|
+
}
|
|
1857
|
+
},
|
|
1858
|
+
deleteEntry: function(entry) {
|
|
1859
|
+
var item = getEntry(entry);
|
|
1860
|
+
if (item) {
|
|
1861
|
+
_zip.deleteEntry(item.entryName);
|
|
1862
|
+
}
|
|
1863
|
+
},
|
|
1864
|
+
addZipComment: function(comment) {
|
|
1865
|
+
_zip.comment = comment;
|
|
1866
|
+
},
|
|
1867
|
+
getZipComment: function() {
|
|
1868
|
+
return _zip.comment || "";
|
|
1869
|
+
},
|
|
1870
|
+
addZipEntryComment: function(entry, comment) {
|
|
1871
|
+
var item = getEntry(entry);
|
|
1872
|
+
if (item) {
|
|
1873
|
+
item.comment = comment;
|
|
1874
|
+
}
|
|
1875
|
+
},
|
|
1876
|
+
getZipEntryComment: function(entry) {
|
|
1877
|
+
var item = getEntry(entry);
|
|
1878
|
+
if (item) {
|
|
1879
|
+
return item.comment || "";
|
|
1880
|
+
}
|
|
1881
|
+
return "";
|
|
1882
|
+
},
|
|
1883
|
+
updateFile: function(entry, content) {
|
|
1884
|
+
var item = getEntry(entry);
|
|
1885
|
+
if (item) {
|
|
1886
|
+
item.setData(content);
|
|
1887
|
+
}
|
|
1888
|
+
},
|
|
1889
|
+
addLocalFile: function(localPath2, zipPath, zipName, comment) {
|
|
1890
|
+
if (filetools.fs.existsSync(localPath2)) {
|
|
1891
|
+
zipPath = zipPath ? fixPath(zipPath) : "";
|
|
1892
|
+
const p = pth.win32.basename(pth.win32.normalize(localPath2));
|
|
1893
|
+
zipPath += zipName ? zipName : p;
|
|
1894
|
+
const _attr = filetools.fs.statSync(localPath2);
|
|
1895
|
+
const data = _attr.isFile() ? filetools.fs.readFileSync(localPath2) : Buffer.alloc(0);
|
|
1896
|
+
if (_attr.isDirectory())
|
|
1897
|
+
zipPath += filetools.sep;
|
|
1898
|
+
this.addFile(zipPath, data, comment, _attr);
|
|
1899
|
+
} else {
|
|
1900
|
+
throw Utils.Errors.FILE_NOT_FOUND(localPath2);
|
|
1901
|
+
}
|
|
1902
|
+
},
|
|
1903
|
+
addLocalFileAsync: function(options2, callback) {
|
|
1904
|
+
options2 = typeof options2 === "object" ? options2 : { localPath: options2 };
|
|
1905
|
+
const localPath2 = pth.resolve(options2.localPath);
|
|
1906
|
+
const { comment } = options2;
|
|
1907
|
+
let { zipPath, zipName } = options2;
|
|
1908
|
+
const self = this;
|
|
1909
|
+
filetools.fs.stat(localPath2, function(err, stats) {
|
|
1910
|
+
if (err)
|
|
1911
|
+
return callback(err, false);
|
|
1912
|
+
zipPath = zipPath ? fixPath(zipPath) : "";
|
|
1913
|
+
const p = pth.win32.basename(pth.win32.normalize(localPath2));
|
|
1914
|
+
zipPath += zipName ? zipName : p;
|
|
1915
|
+
if (stats.isFile()) {
|
|
1916
|
+
filetools.fs.readFile(localPath2, function(err2, data) {
|
|
1917
|
+
if (err2)
|
|
1918
|
+
return callback(err2, false);
|
|
1919
|
+
self.addFile(zipPath, data, comment, stats);
|
|
1920
|
+
return setImmediate(callback, undefined, true);
|
|
1921
|
+
});
|
|
1922
|
+
} else if (stats.isDirectory()) {
|
|
1923
|
+
zipPath += filetools.sep;
|
|
1924
|
+
self.addFile(zipPath, Buffer.alloc(0), comment, stats);
|
|
1925
|
+
return setImmediate(callback, undefined, true);
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
},
|
|
1929
|
+
addLocalFolder: function(localPath2, zipPath, filter) {
|
|
1930
|
+
filter = filenameFilter(filter);
|
|
1931
|
+
zipPath = zipPath ? fixPath(zipPath) : "";
|
|
1932
|
+
localPath2 = pth.normalize(localPath2);
|
|
1933
|
+
if (filetools.fs.existsSync(localPath2)) {
|
|
1934
|
+
const items = filetools.findFiles(localPath2);
|
|
1935
|
+
const self = this;
|
|
1936
|
+
if (items.length) {
|
|
1937
|
+
for (const filepath of items) {
|
|
1938
|
+
const p = pth.join(zipPath, relativePath(localPath2, filepath));
|
|
1939
|
+
if (filter(p)) {
|
|
1940
|
+
self.addLocalFile(filepath, pth.dirname(p));
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
} else {
|
|
1945
|
+
throw Utils.Errors.FILE_NOT_FOUND(localPath2);
|
|
1946
|
+
}
|
|
1947
|
+
},
|
|
1948
|
+
addLocalFolderAsync: function(localPath2, callback, zipPath, filter) {
|
|
1949
|
+
filter = filenameFilter(filter);
|
|
1950
|
+
zipPath = zipPath ? fixPath(zipPath) : "";
|
|
1951
|
+
localPath2 = pth.normalize(localPath2);
|
|
1952
|
+
var self = this;
|
|
1953
|
+
filetools.fs.open(localPath2, "r", function(err) {
|
|
1954
|
+
if (err && err.code === "ENOENT") {
|
|
1955
|
+
callback(undefined, Utils.Errors.FILE_NOT_FOUND(localPath2));
|
|
1956
|
+
} else if (err) {
|
|
1957
|
+
callback(undefined, err);
|
|
1958
|
+
} else {
|
|
1959
|
+
var items = filetools.findFiles(localPath2);
|
|
1960
|
+
var i = -1;
|
|
1961
|
+
var next = function() {
|
|
1962
|
+
i += 1;
|
|
1963
|
+
if (i < items.length) {
|
|
1964
|
+
var filepath = items[i];
|
|
1965
|
+
var p = relativePath(localPath2, filepath).split("\\").join("/");
|
|
1966
|
+
p = p.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\x20-\x7E]/g, "");
|
|
1967
|
+
if (filter(p)) {
|
|
1968
|
+
filetools.fs.stat(filepath, function(er0, stats) {
|
|
1969
|
+
if (er0)
|
|
1970
|
+
callback(undefined, er0);
|
|
1971
|
+
if (stats.isFile()) {
|
|
1972
|
+
filetools.fs.readFile(filepath, function(er1, data) {
|
|
1973
|
+
if (er1) {
|
|
1974
|
+
callback(undefined, er1);
|
|
1975
|
+
} else {
|
|
1976
|
+
self.addFile(zipPath + p, data, "", stats);
|
|
1977
|
+
next();
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
} else {
|
|
1981
|
+
self.addFile(zipPath + p + "/", Buffer.alloc(0), "", stats);
|
|
1982
|
+
next();
|
|
1983
|
+
}
|
|
1984
|
+
});
|
|
1985
|
+
} else {
|
|
1986
|
+
process.nextTick(() => {
|
|
1987
|
+
next();
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
} else {
|
|
1991
|
+
callback(true, undefined);
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
next();
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1997
|
+
},
|
|
1998
|
+
addLocalFolderAsync2: function(options2, callback) {
|
|
1999
|
+
const self = this;
|
|
2000
|
+
options2 = typeof options2 === "object" ? options2 : { localPath: options2 };
|
|
2001
|
+
localPath = pth.resolve(fixPath(options2.localPath));
|
|
2002
|
+
let { zipPath, filter, namefix } = options2;
|
|
2003
|
+
if (filter instanceof RegExp) {
|
|
2004
|
+
filter = function(rx) {
|
|
2005
|
+
return function(filename) {
|
|
2006
|
+
return rx.test(filename);
|
|
2007
|
+
};
|
|
2008
|
+
}(filter);
|
|
2009
|
+
} else if (typeof filter !== "function") {
|
|
2010
|
+
filter = function() {
|
|
2011
|
+
return true;
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
zipPath = zipPath ? fixPath(zipPath) : "";
|
|
2015
|
+
if (namefix == "latin1") {
|
|
2016
|
+
namefix = (str) => str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\x20-\x7E]/g, "");
|
|
2017
|
+
}
|
|
2018
|
+
if (typeof namefix !== "function")
|
|
2019
|
+
namefix = (str) => str;
|
|
2020
|
+
const relPathFix = (entry) => pth.join(zipPath, namefix(relativePath(localPath, entry)));
|
|
2021
|
+
const fileNameFix = (entry) => pth.win32.basename(pth.win32.normalize(namefix(entry)));
|
|
2022
|
+
filetools.fs.open(localPath, "r", function(err) {
|
|
2023
|
+
if (err && err.code === "ENOENT") {
|
|
2024
|
+
callback(undefined, Utils.Errors.FILE_NOT_FOUND(localPath));
|
|
2025
|
+
} else if (err) {
|
|
2026
|
+
callback(undefined, err);
|
|
2027
|
+
} else {
|
|
2028
|
+
filetools.findFilesAsync(localPath, function(err2, fileEntries) {
|
|
2029
|
+
if (err2)
|
|
2030
|
+
return callback(err2);
|
|
2031
|
+
fileEntries = fileEntries.filter((dir) => filter(relPathFix(dir)));
|
|
2032
|
+
if (!fileEntries.length)
|
|
2033
|
+
callback(undefined, false);
|
|
2034
|
+
setImmediate(fileEntries.reverse().reduce(function(next, entry) {
|
|
2035
|
+
return function(err3, done) {
|
|
2036
|
+
if (err3 || done === false)
|
|
2037
|
+
return setImmediate(next, err3, false);
|
|
2038
|
+
self.addLocalFileAsync({
|
|
2039
|
+
localPath: entry,
|
|
2040
|
+
zipPath: pth.dirname(relPathFix(entry)),
|
|
2041
|
+
zipName: fileNameFix(entry)
|
|
2042
|
+
}, next);
|
|
2043
|
+
};
|
|
2044
|
+
}, callback));
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
},
|
|
2049
|
+
addLocalFolderPromise: function(localPath2, props) {
|
|
2050
|
+
return new Promise((resolve, reject) => {
|
|
2051
|
+
this.addLocalFolderAsync2(Object.assign({ localPath: localPath2 }, props), (err, done) => {
|
|
2052
|
+
if (err)
|
|
2053
|
+
reject(err);
|
|
2054
|
+
if (done)
|
|
2055
|
+
resolve(this);
|
|
2056
|
+
});
|
|
2057
|
+
});
|
|
2058
|
+
},
|
|
2059
|
+
addFile: function(entryName, content, comment, attr) {
|
|
2060
|
+
entryName = zipnamefix(entryName);
|
|
2061
|
+
let entry = getEntry(entryName);
|
|
2062
|
+
const update = entry != null;
|
|
2063
|
+
if (!update) {
|
|
2064
|
+
entry = new ZipEntry(opts);
|
|
2065
|
+
entry.entryName = entryName;
|
|
2066
|
+
}
|
|
2067
|
+
entry.comment = comment || "";
|
|
2068
|
+
const isStat = typeof attr === "object" && attr instanceof filetools.fs.Stats;
|
|
2069
|
+
if (isStat) {
|
|
2070
|
+
entry.header.time = attr.mtime;
|
|
2071
|
+
}
|
|
2072
|
+
var fileattr = entry.isDirectory ? 16 : 0;
|
|
2073
|
+
let unix = entry.isDirectory ? 16384 : 32768;
|
|
2074
|
+
if (isStat) {
|
|
2075
|
+
unix |= 4095 & attr.mode;
|
|
2076
|
+
} else if (typeof attr === "number") {
|
|
2077
|
+
unix |= 4095 & attr;
|
|
2078
|
+
} else {
|
|
2079
|
+
unix |= entry.isDirectory ? 493 : 420;
|
|
2080
|
+
}
|
|
2081
|
+
fileattr = (fileattr | unix << 16) >>> 0;
|
|
2082
|
+
entry.attr = fileattr;
|
|
2083
|
+
entry.setData(content);
|
|
2084
|
+
if (!update)
|
|
2085
|
+
_zip.setEntry(entry);
|
|
2086
|
+
return entry;
|
|
2087
|
+
},
|
|
2088
|
+
getEntries: function(password) {
|
|
2089
|
+
_zip.password = password;
|
|
2090
|
+
return _zip ? _zip.entries : [];
|
|
2091
|
+
},
|
|
2092
|
+
getEntry: function(name) {
|
|
2093
|
+
return getEntry(name);
|
|
2094
|
+
},
|
|
2095
|
+
getEntryCount: function() {
|
|
2096
|
+
return _zip.getEntryCount();
|
|
2097
|
+
},
|
|
2098
|
+
forEach: function(callback) {
|
|
2099
|
+
return _zip.forEach(callback);
|
|
2100
|
+
},
|
|
2101
|
+
extractEntryTo: function(entry, targetPath, maintainEntryPath, overwrite, keepOriginalPermission, outFileName) {
|
|
2102
|
+
overwrite = get_Bool(false, overwrite);
|
|
2103
|
+
keepOriginalPermission = get_Bool(false, keepOriginalPermission);
|
|
2104
|
+
maintainEntryPath = get_Bool(true, maintainEntryPath);
|
|
2105
|
+
outFileName = get_Str(keepOriginalPermission, outFileName);
|
|
2106
|
+
var item = getEntry(entry);
|
|
2107
|
+
if (!item) {
|
|
2108
|
+
throw Utils.Errors.NO_ENTRY();
|
|
2109
|
+
}
|
|
2110
|
+
var entryName = canonical(item.entryName);
|
|
2111
|
+
var target = sanitize(targetPath, outFileName && !item.isDirectory ? outFileName : maintainEntryPath ? entryName : pth.basename(entryName));
|
|
2112
|
+
if (item.isDirectory) {
|
|
2113
|
+
var children = _zip.getEntryChildren(item);
|
|
2114
|
+
children.forEach(function(child) {
|
|
2115
|
+
if (child.isDirectory)
|
|
2116
|
+
return;
|
|
2117
|
+
var content2 = child.getData();
|
|
2118
|
+
if (!content2) {
|
|
2119
|
+
throw Utils.Errors.CANT_EXTRACT_FILE();
|
|
2120
|
+
}
|
|
2121
|
+
var name = canonical(child.entryName);
|
|
2122
|
+
var childName = sanitize(targetPath, maintainEntryPath ? name : pth.basename(name));
|
|
2123
|
+
const fileAttr2 = keepOriginalPermission ? child.header.fileAttr : undefined;
|
|
2124
|
+
filetools.writeFileTo(childName, content2, overwrite, fileAttr2);
|
|
2125
|
+
});
|
|
2126
|
+
return true;
|
|
2127
|
+
}
|
|
2128
|
+
var content = item.getData(_zip.password);
|
|
2129
|
+
if (!content)
|
|
2130
|
+
throw Utils.Errors.CANT_EXTRACT_FILE();
|
|
2131
|
+
if (filetools.fs.existsSync(target) && !overwrite) {
|
|
2132
|
+
throw Utils.Errors.CANT_OVERRIDE();
|
|
2133
|
+
}
|
|
2134
|
+
const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
|
|
2135
|
+
filetools.writeFileTo(target, content, overwrite, fileAttr);
|
|
2136
|
+
return true;
|
|
2137
|
+
},
|
|
2138
|
+
test: function(pass) {
|
|
2139
|
+
if (!_zip) {
|
|
2140
|
+
return false;
|
|
2141
|
+
}
|
|
2142
|
+
for (var entry in _zip.entries) {
|
|
2143
|
+
try {
|
|
2144
|
+
if (entry.isDirectory) {
|
|
2145
|
+
continue;
|
|
2146
|
+
}
|
|
2147
|
+
var content = _zip.entries[entry].getData(pass);
|
|
2148
|
+
if (!content) {
|
|
2149
|
+
return false;
|
|
2150
|
+
}
|
|
2151
|
+
} catch (err) {
|
|
2152
|
+
return false;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
return true;
|
|
2156
|
+
},
|
|
2157
|
+
extractAllTo: function(targetPath, overwrite, keepOriginalPermission, pass) {
|
|
2158
|
+
keepOriginalPermission = get_Bool(false, keepOriginalPermission);
|
|
2159
|
+
pass = get_Str(keepOriginalPermission, pass);
|
|
2160
|
+
overwrite = get_Bool(false, overwrite);
|
|
2161
|
+
if (!_zip)
|
|
2162
|
+
throw Utils.Errors.NO_ZIP();
|
|
2163
|
+
_zip.entries.forEach(function(entry) {
|
|
2164
|
+
var entryName = sanitize(targetPath, canonical(entry.entryName));
|
|
2165
|
+
if (entry.isDirectory) {
|
|
2166
|
+
filetools.makeDir(entryName);
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
var content = entry.getData(pass);
|
|
2170
|
+
if (!content) {
|
|
2171
|
+
throw Utils.Errors.CANT_EXTRACT_FILE();
|
|
2172
|
+
}
|
|
2173
|
+
const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
|
|
2174
|
+
filetools.writeFileTo(entryName, content, overwrite, fileAttr);
|
|
2175
|
+
try {
|
|
2176
|
+
filetools.fs.utimesSync(entryName, entry.header.time, entry.header.time);
|
|
2177
|
+
} catch (err) {
|
|
2178
|
+
throw Utils.Errors.CANT_EXTRACT_FILE();
|
|
2179
|
+
}
|
|
2180
|
+
});
|
|
2181
|
+
},
|
|
2182
|
+
extractAllToAsync: function(targetPath, overwrite, keepOriginalPermission, callback) {
|
|
2183
|
+
callback = get_Fun(overwrite, keepOriginalPermission, callback);
|
|
2184
|
+
keepOriginalPermission = get_Bool(false, keepOriginalPermission);
|
|
2185
|
+
overwrite = get_Bool(false, overwrite);
|
|
2186
|
+
if (!callback) {
|
|
2187
|
+
return new Promise((resolve, reject) => {
|
|
2188
|
+
this.extractAllToAsync(targetPath, overwrite, keepOriginalPermission, function(err) {
|
|
2189
|
+
if (err) {
|
|
2190
|
+
reject(err);
|
|
2191
|
+
} else {
|
|
2192
|
+
resolve(this);
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
if (!_zip) {
|
|
2198
|
+
callback(Utils.Errors.NO_ZIP());
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
targetPath = pth.resolve(targetPath);
|
|
2202
|
+
const getPath = (entry) => sanitize(targetPath, pth.normalize(canonical(entry.entryName)));
|
|
2203
|
+
const getError = (msg, file) => new Error(msg + ': "' + file + '"');
|
|
2204
|
+
const dirEntries = [];
|
|
2205
|
+
const fileEntries = [];
|
|
2206
|
+
_zip.entries.forEach((e) => {
|
|
2207
|
+
if (e.isDirectory) {
|
|
2208
|
+
dirEntries.push(e);
|
|
2209
|
+
} else {
|
|
2210
|
+
fileEntries.push(e);
|
|
2211
|
+
}
|
|
2212
|
+
});
|
|
2213
|
+
for (const entry of dirEntries) {
|
|
2214
|
+
const dirPath = getPath(entry);
|
|
2215
|
+
const dirAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
|
|
2216
|
+
try {
|
|
2217
|
+
filetools.makeDir(dirPath);
|
|
2218
|
+
if (dirAttr)
|
|
2219
|
+
filetools.fs.chmodSync(dirPath, dirAttr);
|
|
2220
|
+
filetools.fs.utimesSync(dirPath, entry.header.time, entry.header.time);
|
|
2221
|
+
} catch (er) {
|
|
2222
|
+
callback(getError("Unable to create folder", dirPath));
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
fileEntries.reverse().reduce(function(next, entry) {
|
|
2226
|
+
return function(err) {
|
|
2227
|
+
if (err) {
|
|
2228
|
+
next(err);
|
|
2229
|
+
} else {
|
|
2230
|
+
const entryName = pth.normalize(canonical(entry.entryName));
|
|
2231
|
+
const filePath = sanitize(targetPath, entryName);
|
|
2232
|
+
entry.getDataAsync(function(content, err_1) {
|
|
2233
|
+
if (err_1) {
|
|
2234
|
+
next(err_1);
|
|
2235
|
+
} else if (!content) {
|
|
2236
|
+
next(Utils.Errors.CANT_EXTRACT_FILE());
|
|
2237
|
+
} else {
|
|
2238
|
+
const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
|
|
2239
|
+
filetools.writeFileToAsync(filePath, content, overwrite, fileAttr, function(succ) {
|
|
2240
|
+
if (!succ) {
|
|
2241
|
+
next(getError("Unable to write file", filePath));
|
|
2242
|
+
}
|
|
2243
|
+
filetools.fs.utimes(filePath, entry.header.time, entry.header.time, function(err_2) {
|
|
2244
|
+
if (err_2) {
|
|
2245
|
+
next(getError("Unable to set times", filePath));
|
|
2246
|
+
} else {
|
|
2247
|
+
next();
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
});
|
|
2251
|
+
}
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
}, callback)();
|
|
2256
|
+
},
|
|
2257
|
+
writeZip: function(targetFileName, callback) {
|
|
2258
|
+
if (arguments.length === 1) {
|
|
2259
|
+
if (typeof targetFileName === "function") {
|
|
2260
|
+
callback = targetFileName;
|
|
2261
|
+
targetFileName = "";
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
if (!targetFileName && opts.filename) {
|
|
2265
|
+
targetFileName = opts.filename;
|
|
2266
|
+
}
|
|
2267
|
+
if (!targetFileName)
|
|
2268
|
+
return;
|
|
2269
|
+
var zipData = _zip.compressToBuffer();
|
|
2270
|
+
if (zipData) {
|
|
2271
|
+
var ok = filetools.writeFileTo(targetFileName, zipData, true);
|
|
2272
|
+
if (typeof callback === "function")
|
|
2273
|
+
callback(!ok ? new Error("failed") : null, "");
|
|
2274
|
+
}
|
|
2275
|
+
},
|
|
2276
|
+
writeZipPromise: function(targetFileName, props) {
|
|
2277
|
+
const { overwrite, perm } = Object.assign({ overwrite: true }, props);
|
|
2278
|
+
return new Promise((resolve, reject) => {
|
|
2279
|
+
if (!targetFileName && opts.filename)
|
|
2280
|
+
targetFileName = opts.filename;
|
|
2281
|
+
if (!targetFileName)
|
|
2282
|
+
reject("ADM-ZIP: ZIP File Name Missing");
|
|
2283
|
+
this.toBufferPromise().then((zipData) => {
|
|
2284
|
+
const ret = (done) => done ? resolve(done) : reject("ADM-ZIP: Wasn't able to write zip file");
|
|
2285
|
+
filetools.writeFileToAsync(targetFileName, zipData, overwrite, perm, ret);
|
|
2286
|
+
}, reject);
|
|
2287
|
+
});
|
|
2288
|
+
},
|
|
2289
|
+
toBufferPromise: function() {
|
|
2290
|
+
return new Promise((resolve, reject) => {
|
|
2291
|
+
_zip.toAsyncBuffer(resolve, reject);
|
|
2292
|
+
});
|
|
2293
|
+
},
|
|
2294
|
+
toBuffer: function(onSuccess, onFail, onItemStart, onItemEnd) {
|
|
2295
|
+
if (typeof onSuccess === "function") {
|
|
2296
|
+
_zip.toAsyncBuffer(onSuccess, onFail, onItemStart, onItemEnd);
|
|
2297
|
+
return null;
|
|
2298
|
+
}
|
|
2299
|
+
return _zip.compressToBuffer();
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2302
|
+
};
|
|
2303
|
+
});
|
|
2304
|
+
|
|
2305
|
+
// src/platform/detector.ts
|
|
2306
|
+
import os from "node:os";
|
|
2307
|
+
function detectPlatform() {
|
|
2308
|
+
const platform = process.platform;
|
|
2309
|
+
const arch = process.arch;
|
|
2310
|
+
const detectedOS = platform === "win32" ? "windows" : platform === "darwin" ? "macos" : "linux";
|
|
2311
|
+
const detectedArch = arch === "arm64" ? "arm64" : "x86_64";
|
|
2312
|
+
return {
|
|
2313
|
+
os: detectedOS,
|
|
2314
|
+
arch: detectedArch,
|
|
2315
|
+
gcloudDownloadUrl: getGcloudDownloadUrl(detectedOS, detectedArch),
|
|
2316
|
+
gcloudBinaryName: platform === "win32" ? "gcloud.cmd" : "gcloud",
|
|
2317
|
+
isWindows: platform === "win32"
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
function getGcloudDownloadUrl(os2, arch) {
|
|
2321
|
+
const baseUrl = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads";
|
|
2322
|
+
if (os2 === "macos") {
|
|
2323
|
+
if (arch === "arm64") {
|
|
2324
|
+
return `${baseUrl}/google-cloud-cli-darwin-arm.tar.gz`;
|
|
2325
|
+
}
|
|
2326
|
+
return `${baseUrl}/google-cloud-cli-darwin-x86_64.tar.gz`;
|
|
2327
|
+
}
|
|
2328
|
+
if (os2 === "linux") {
|
|
2329
|
+
return `${baseUrl}/google-cloud-cli-linux-x86_64.tar.gz`;
|
|
2330
|
+
}
|
|
2331
|
+
if (os2 === "windows") {
|
|
2332
|
+
return `${baseUrl}/google-cloud-cli-windows-x86_64-bundled-python.zip`;
|
|
2333
|
+
}
|
|
2334
|
+
throw new Error(`Unsupported platform: ${os2} ${arch}`);
|
|
2335
|
+
}
|
|
2336
|
+
function getHomeDir() {
|
|
2337
|
+
return os.homedir();
|
|
2338
|
+
}
|
|
2339
|
+
function getStitchDir() {
|
|
2340
|
+
return `${getHomeDir()}/.stitch-mcp`;
|
|
2341
|
+
}
|
|
2342
|
+
function getGcloudSdkPath() {
|
|
2343
|
+
return `${getStitchDir()}/google-cloud-sdk`;
|
|
2344
|
+
}
|
|
2345
|
+
function getGcloudConfigPath() {
|
|
2346
|
+
return `${getStitchDir()}/config`;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
// src/platform/shell.ts
|
|
2350
|
+
import * as childProcess from "node:child_process";
|
|
2351
|
+
function getSpawnArgs(command, args) {
|
|
2352
|
+
if (process.platform === "win32") {
|
|
2353
|
+
return {
|
|
2354
|
+
cmd: "cmd.exe",
|
|
2355
|
+
args: ["/d", "/s", "/c", command, ...args]
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
return { cmd: command, args };
|
|
2359
|
+
}
|
|
2360
|
+
async function execCommand(command, options) {
|
|
2361
|
+
const cmd = command[0];
|
|
2362
|
+
if (!cmd)
|
|
2363
|
+
throw new Error("Command cannot be empty");
|
|
2364
|
+
const args = command.slice(1);
|
|
2365
|
+
return new Promise((resolve) => {
|
|
2366
|
+
const stdoutChunks = [];
|
|
2367
|
+
const stderrChunks = [];
|
|
2368
|
+
const spawnOptions = {
|
|
2369
|
+
cwd: options?.cwd || process.cwd(),
|
|
2370
|
+
env: { ...process.env, ...options?.env || {} },
|
|
2371
|
+
stdio: "pipe",
|
|
2372
|
+
timeout: options?.timeout,
|
|
2373
|
+
shell: false
|
|
2374
|
+
};
|
|
2375
|
+
const { cmd: spawnCmd, args: spawnArgs } = getSpawnArgs(cmd, args);
|
|
2376
|
+
const child = childProcess.spawn(spawnCmd, spawnArgs, spawnOptions);
|
|
2377
|
+
if (child.stdout) {
|
|
2378
|
+
child.stdout.on("data", (data) => {
|
|
2379
|
+
stdoutChunks.push(data);
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
if (child.stderr) {
|
|
2383
|
+
child.stderr.on("data", (data) => {
|
|
2384
|
+
stderrChunks.push(data);
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
child.on("error", (err) => {
|
|
2388
|
+
resolve({
|
|
2389
|
+
success: false,
|
|
2390
|
+
stdout: Buffer.concat(stdoutChunks).toString(),
|
|
2391
|
+
stderr: Buffer.concat(stderrChunks).toString(),
|
|
2392
|
+
exitCode: 1,
|
|
2393
|
+
error: err.message
|
|
2394
|
+
});
|
|
2395
|
+
});
|
|
2396
|
+
child.on("close", (code) => {
|
|
2397
|
+
resolve({
|
|
2398
|
+
success: code === 0,
|
|
2399
|
+
stdout: Buffer.concat(stdoutChunks).toString(),
|
|
2400
|
+
stderr: Buffer.concat(stderrChunks).toString(),
|
|
2401
|
+
exitCode: code ?? 1
|
|
2402
|
+
});
|
|
2403
|
+
});
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
async function commandExists(command) {
|
|
2407
|
+
const result = await execCommand(process.platform === "win32" ? ["where", command] : ["which", command]);
|
|
2408
|
+
return result.success;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// src/platform/paths.ts
|
|
2412
|
+
import path from "node:path";
|
|
2413
|
+
function joinPath(...parts) {
|
|
2414
|
+
return path.join(...parts);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
// src/services/gcloud/core.ts
|
|
2418
|
+
import fs from "node:fs";
|
|
2419
|
+
|
|
2420
|
+
class GcloudExecutor {
|
|
2421
|
+
platform = detectPlatform();
|
|
2422
|
+
gcloudPath = null;
|
|
2423
|
+
useSystemGcloud = false;
|
|
2424
|
+
constructor() {}
|
|
2425
|
+
setGcloudPath(path2, isSystem) {
|
|
2426
|
+
this.gcloudPath = path2;
|
|
2427
|
+
this.useSystemGcloud = isSystem;
|
|
2428
|
+
this.setupEnvironment();
|
|
2429
|
+
}
|
|
2430
|
+
getGcloudPath() {
|
|
2431
|
+
return this.gcloudPath;
|
|
2432
|
+
}
|
|
2433
|
+
isSystemGcloud() {
|
|
2434
|
+
return this.useSystemGcloud;
|
|
2435
|
+
}
|
|
2436
|
+
setupEnvironment() {
|
|
2437
|
+
if (this.gcloudPath && !this.useSystemGcloud && !process.env.STITCH_USE_SYSTEM_GCLOUD) {
|
|
2438
|
+
const sdkPath = getGcloudSdkPath();
|
|
2439
|
+
const binPath = joinPath(sdkPath, "bin");
|
|
2440
|
+
process.env.PATH = `${binPath}:${process.env.PATH}`;
|
|
2441
|
+
const configPath = getGcloudConfigPath();
|
|
2442
|
+
process.env.CLOUDSDK_CONFIG = configPath;
|
|
2443
|
+
process.env.CLOUDSDK_CORE_DISABLE_PROMPTS = "1";
|
|
2444
|
+
process.env.CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK = "1";
|
|
2445
|
+
process.env.CLOUDSDK_CORE_DISABLE_USAGE_REPORTING = "true";
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
getEnvironment(useSystem) {
|
|
2449
|
+
if (useSystem || this.useSystemGcloud || process.env.STITCH_USE_SYSTEM_GCLOUD) {
|
|
2450
|
+
return {};
|
|
2451
|
+
}
|
|
2452
|
+
const configPath = getGcloudConfigPath();
|
|
2453
|
+
return {
|
|
2454
|
+
CLOUDSDK_CONFIG: configPath,
|
|
2455
|
+
CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
|
|
2456
|
+
CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK: "1",
|
|
2457
|
+
CLOUDSDK_CORE_DISABLE_USAGE_REPORTING: "true"
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
async getGcloudCommand() {
|
|
2461
|
+
if (this.gcloudPath) {
|
|
2462
|
+
return this.gcloudPath;
|
|
2463
|
+
}
|
|
2464
|
+
if (this.useSystemGcloud || process.env.STITCH_USE_SYSTEM_GCLOUD) {
|
|
2465
|
+
return this.platform.gcloudBinaryName;
|
|
2466
|
+
}
|
|
2467
|
+
const sdkPath = getGcloudSdkPath();
|
|
2468
|
+
const localBinaryPath = joinPath(sdkPath, "bin", this.platform.gcloudBinaryName);
|
|
2469
|
+
try {
|
|
2470
|
+
await fs.promises.access(localBinaryPath, fs.constants.F_OK);
|
|
2471
|
+
this.gcloudPath = localBinaryPath;
|
|
2472
|
+
this.setupEnvironment();
|
|
2473
|
+
return localBinaryPath;
|
|
2474
|
+
} catch {
|
|
2475
|
+
return this.platform.gcloudBinaryName;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
async exec(args, options) {
|
|
2479
|
+
const cmd = await this.getGcloudCommand();
|
|
2480
|
+
const env = { ...this.getEnvironment(), ...options?.env || {} };
|
|
2481
|
+
return execCommand([cmd, ...args], { ...options, env });
|
|
2482
|
+
}
|
|
2483
|
+
async execRaw(command, options) {
|
|
2484
|
+
const env = { ...this.getEnvironment(), ...options?.env || {} };
|
|
2485
|
+
return execCommand(command, { ...options, env });
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
// src/services/gcloud/install.ts
|
|
2490
|
+
var import_adm_zip = __toESM(require_adm_zip(), 1);
|
|
2491
|
+
import fs2 from "node:fs";
|
|
2492
|
+
class GcloudInstallService {
|
|
2493
|
+
executor;
|
|
2494
|
+
constructor(executor) {
|
|
2495
|
+
this.executor = executor;
|
|
2496
|
+
}
|
|
2497
|
+
async ensureInstalled(input) {
|
|
2498
|
+
if (!input.forceLocal) {
|
|
2499
|
+
const globalPath = await this.findGlobalGcloud();
|
|
2500
|
+
if (globalPath) {
|
|
2501
|
+
const version2 = await this.getVersionFromPath(globalPath);
|
|
2502
|
+
if (version2 && this.isVersionValid(version2, input.minVersion)) {
|
|
2503
|
+
this.executor.setGcloudPath(globalPath, true);
|
|
2504
|
+
return {
|
|
2505
|
+
success: true,
|
|
2506
|
+
data: {
|
|
2507
|
+
version: version2,
|
|
2508
|
+
location: "system",
|
|
2509
|
+
path: globalPath
|
|
2510
|
+
}
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
const localSdkPath = getGcloudSdkPath();
|
|
2516
|
+
const localBinaryPath = joinPath(localSdkPath, "bin", this.executor.platform.gcloudBinaryName);
|
|
2517
|
+
let localExists = false;
|
|
2518
|
+
try {
|
|
2519
|
+
await fs2.promises.access(localBinaryPath, fs2.constants.F_OK);
|
|
2520
|
+
localExists = true;
|
|
2521
|
+
} catch {}
|
|
2522
|
+
if (localExists) {
|
|
2523
|
+
const version2 = await this.getVersionFromPath(localBinaryPath);
|
|
2524
|
+
if (version2) {
|
|
2525
|
+
this.executor.setGcloudPath(localBinaryPath, false);
|
|
2526
|
+
return {
|
|
2527
|
+
success: true,
|
|
2528
|
+
data: {
|
|
2529
|
+
version: version2,
|
|
2530
|
+
location: "bundled",
|
|
2531
|
+
path: localBinaryPath
|
|
2532
|
+
}
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
if (!input.forceLocal) {
|
|
2537
|
+
const globalPath = await this.findGlobalGcloud();
|
|
2538
|
+
if (globalPath) {
|
|
2539
|
+
const version2 = await this.getVersionFromPath(globalPath);
|
|
2540
|
+
if (version2 && this.isVersionValid(version2, input.minVersion)) {
|
|
2541
|
+
this.executor.setGcloudPath(globalPath, true);
|
|
2542
|
+
return {
|
|
2543
|
+
success: true,
|
|
2544
|
+
data: {
|
|
2545
|
+
version: version2,
|
|
2546
|
+
location: "system",
|
|
2547
|
+
path: globalPath
|
|
2548
|
+
}
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
const localPath2 = await this.installLocal();
|
|
2554
|
+
if (!localPath2) {
|
|
2555
|
+
return {
|
|
2556
|
+
success: false,
|
|
2557
|
+
error: {
|
|
2558
|
+
code: "DOWNLOAD_FAILED",
|
|
2559
|
+
message: "Failed to install gcloud locally",
|
|
2560
|
+
suggestion: "Check your internet connection and try again",
|
|
2561
|
+
recoverable: true
|
|
2562
|
+
}
|
|
2563
|
+
};
|
|
2564
|
+
}
|
|
2565
|
+
const version = await this.getVersionFromPath(localPath2);
|
|
2566
|
+
if (!version) {
|
|
2567
|
+
return {
|
|
2568
|
+
success: false,
|
|
2569
|
+
error: {
|
|
2570
|
+
code: "VERSION_CHECK_FAILED",
|
|
2571
|
+
message: "Could not determine gcloud version",
|
|
2572
|
+
recoverable: false
|
|
2573
|
+
}
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
this.executor.setGcloudPath(localPath2, false);
|
|
2577
|
+
return {
|
|
2578
|
+
success: true,
|
|
2579
|
+
data: {
|
|
2580
|
+
version,
|
|
2581
|
+
location: "bundled",
|
|
2582
|
+
path: localPath2
|
|
2583
|
+
}
|
|
2584
|
+
};
|
|
2585
|
+
}
|
|
2586
|
+
async installBetaComponents() {
|
|
2587
|
+
try {
|
|
2588
|
+
const result = await this.executor.exec(["components", "install", "beta", "--quiet"]);
|
|
2589
|
+
if (!result.success) {
|
|
2590
|
+
return {
|
|
2591
|
+
success: false,
|
|
2592
|
+
error: {
|
|
2593
|
+
message: `Failed to install beta components: ${result.stderr || result.error || "Unknown error"}`
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
return { success: true };
|
|
2598
|
+
} catch (error) {
|
|
2599
|
+
return {
|
|
2600
|
+
success: false,
|
|
2601
|
+
error: {
|
|
2602
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2603
|
+
}
|
|
2604
|
+
};
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
async findGlobalGcloud() {
|
|
2608
|
+
const exists = await commandExists(this.executor.platform.gcloudBinaryName);
|
|
2609
|
+
if (!exists) {
|
|
2610
|
+
return null;
|
|
2611
|
+
}
|
|
2612
|
+
const result = await execCommand(this.executor.platform.isWindows ? ["where", this.executor.platform.gcloudBinaryName] : ["which", this.executor.platform.gcloudBinaryName]);
|
|
2613
|
+
if (result.success) {
|
|
2614
|
+
return result.stdout.trim().split(`
|
|
2615
|
+
`)[0] || null;
|
|
2616
|
+
}
|
|
2617
|
+
return null;
|
|
2618
|
+
}
|
|
2619
|
+
async getVersionFromPath(gcloudPath) {
|
|
2620
|
+
const result = await execCommand([gcloudPath, "version", "--format=json"]);
|
|
2621
|
+
if (result.success) {
|
|
2622
|
+
try {
|
|
2623
|
+
const versionData = JSON.parse(result.stdout);
|
|
2624
|
+
return versionData["Google Cloud SDK"] || null;
|
|
2625
|
+
} catch {
|
|
2626
|
+
const match = result.stdout.match(/Google Cloud SDK ([\d.]+)/);
|
|
2627
|
+
return match?.[1] || null;
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
return null;
|
|
2631
|
+
}
|
|
2632
|
+
isVersionValid(current, minimum) {
|
|
2633
|
+
const currentParts = current.split(".").map(Number);
|
|
2634
|
+
const minimumParts = minimum.split(".").map(Number);
|
|
2635
|
+
for (let i = 0;i < Math.max(currentParts.length, minimumParts.length); i++) {
|
|
2636
|
+
const cur = currentParts[i] || 0;
|
|
2637
|
+
const min = minimumParts[i] || 0;
|
|
2638
|
+
if (cur > min)
|
|
2639
|
+
return true;
|
|
2640
|
+
if (cur < min)
|
|
2641
|
+
return false;
|
|
2642
|
+
}
|
|
2643
|
+
return true;
|
|
2644
|
+
}
|
|
2645
|
+
async installLocal() {
|
|
2646
|
+
const sdkPath = getGcloudSdkPath();
|
|
2647
|
+
const stitchDir = getStitchDir();
|
|
2648
|
+
await fs2.promises.mkdir(stitchDir, { recursive: true });
|
|
2649
|
+
const downloadUrl = this.executor.platform.gcloudDownloadUrl;
|
|
2650
|
+
const downloadPath = joinPath(stitchDir, this.executor.platform.isWindows ? "gcloud.zip" : "gcloud.tar.gz");
|
|
2651
|
+
try {
|
|
2652
|
+
const response = await fetch(downloadUrl);
|
|
2653
|
+
if (!response.ok) {
|
|
2654
|
+
return null;
|
|
2655
|
+
}
|
|
2656
|
+
const buffer = await response.arrayBuffer();
|
|
2657
|
+
await fs2.promises.writeFile(downloadPath, Buffer.from(buffer));
|
|
2658
|
+
if (this.executor.platform.isWindows) {
|
|
2659
|
+
const zip = new import_adm_zip.default(downloadPath);
|
|
2660
|
+
await new Promise((resolve, reject) => {
|
|
2661
|
+
zip.extractAllToAsync(stitchDir, true, false, (err) => {
|
|
2662
|
+
if (err) {
|
|
2663
|
+
reject(err);
|
|
2664
|
+
} else {
|
|
2665
|
+
resolve();
|
|
2666
|
+
}
|
|
2667
|
+
});
|
|
2668
|
+
});
|
|
2669
|
+
} else {
|
|
2670
|
+
await execCommand(["tar", "-xzf", downloadPath, "-C", stitchDir]);
|
|
2671
|
+
}
|
|
2672
|
+
await fs2.promises.unlink(downloadPath);
|
|
2673
|
+
return joinPath(sdkPath, "bin", this.executor.platform.gcloudBinaryName);
|
|
2674
|
+
} catch {
|
|
2675
|
+
return null;
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
// src/services/gcloud/auth.ts
|
|
2681
|
+
import fs3 from "node:fs";
|
|
2682
|
+
class GcloudAuthService {
|
|
2683
|
+
executor;
|
|
2684
|
+
constructor(executor) {
|
|
2685
|
+
this.executor = executor;
|
|
2686
|
+
}
|
|
2687
|
+
async authenticate(input) {
|
|
2688
|
+
try {
|
|
2689
|
+
if (input.skipIfActive) {
|
|
2690
|
+
const activeAccount = await this.getActiveAccount();
|
|
2691
|
+
if (activeAccount) {
|
|
2692
|
+
return {
|
|
2693
|
+
success: true,
|
|
2694
|
+
data: {
|
|
2695
|
+
account: activeAccount,
|
|
2696
|
+
type: "user"
|
|
2697
|
+
}
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
const result = await this.runAuthFlow(["auth", "login"]);
|
|
2702
|
+
if (!result.success) {
|
|
2703
|
+
return {
|
|
2704
|
+
success: false,
|
|
2705
|
+
error: {
|
|
2706
|
+
code: "AUTH_FAILED",
|
|
2707
|
+
message: "Failed to authenticate with gcloud",
|
|
2708
|
+
suggestion: "Complete the browser authentication flow",
|
|
2709
|
+
recoverable: true
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
}
|
|
2713
|
+
const account = await this.getActiveAccount();
|
|
2714
|
+
if (!account) {
|
|
2715
|
+
return {
|
|
2716
|
+
success: false,
|
|
2717
|
+
error: {
|
|
2718
|
+
code: "AUTH_FAILED",
|
|
2719
|
+
message: "Authentication appeared to succeed but no active account found",
|
|
2720
|
+
recoverable: false
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
}
|
|
2724
|
+
return {
|
|
2725
|
+
success: true,
|
|
2726
|
+
data: {
|
|
2727
|
+
account,
|
|
2728
|
+
type: "user"
|
|
2729
|
+
}
|
|
2730
|
+
};
|
|
2731
|
+
} catch (error) {
|
|
2732
|
+
return {
|
|
2733
|
+
success: false,
|
|
2734
|
+
error: {
|
|
2735
|
+
code: "AUTH_FAILED",
|
|
2736
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2737
|
+
recoverable: false
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
async authenticateADC(input) {
|
|
2743
|
+
try {
|
|
2744
|
+
if (input.skipIfActive) {
|
|
2745
|
+
const hasADC = await this.hasADC();
|
|
2746
|
+
if (hasADC) {
|
|
2747
|
+
const account2 = await this.getActiveAccount();
|
|
2748
|
+
return {
|
|
2749
|
+
success: true,
|
|
2750
|
+
data: {
|
|
2751
|
+
account: account2 || "unknown",
|
|
2752
|
+
type: "adc"
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
const result = await this.runAuthFlow(["auth", "application-default", "login"]);
|
|
2758
|
+
if (!result.success) {
|
|
2759
|
+
return {
|
|
2760
|
+
success: false,
|
|
2761
|
+
error: {
|
|
2762
|
+
code: "ADC_FAILED",
|
|
2763
|
+
message: "Failed to authenticate application default credentials",
|
|
2764
|
+
suggestion: "Complete the browser authentication flow",
|
|
2765
|
+
recoverable: true
|
|
2766
|
+
}
|
|
2767
|
+
};
|
|
2768
|
+
}
|
|
2769
|
+
const account = await this.getActiveAccount();
|
|
2770
|
+
return {
|
|
2771
|
+
success: true,
|
|
2772
|
+
data: {
|
|
2773
|
+
account: account || "unknown",
|
|
2774
|
+
type: "adc"
|
|
2775
|
+
}
|
|
2776
|
+
};
|
|
2777
|
+
} catch (error) {
|
|
2778
|
+
return {
|
|
2779
|
+
success: false,
|
|
2780
|
+
error: {
|
|
2781
|
+
code: "ADC_FAILED",
|
|
2782
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2783
|
+
recoverable: false
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
async getAccessToken() {
|
|
2789
|
+
try {
|
|
2790
|
+
const result = await this.executor.exec(["auth", "application-default", "print-access-token"]);
|
|
2791
|
+
if (result.success) {
|
|
2792
|
+
return result.stdout.trim();
|
|
2793
|
+
}
|
|
2794
|
+
const loginCmd = await this.getLoginCommand();
|
|
2795
|
+
console.error(`[Gcloud] Token fetch failed. Please run:
|
|
2796
|
+
|
|
2797
|
+
${loginCmd}
|
|
2798
|
+
|
|
2799
|
+
to obtain new credentials.`);
|
|
2800
|
+
return null;
|
|
2801
|
+
} catch (e) {
|
|
2802
|
+
console.error("[Gcloud] Token fetch exception:", e);
|
|
2803
|
+
return null;
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
async getActiveAccount() {
|
|
2807
|
+
const result = await this.executor.exec(["auth", "list", "--filter=status:ACTIVE", "--format=value(account)"]);
|
|
2808
|
+
if (result.success && result.stdout.trim()) {
|
|
2809
|
+
return result.stdout.trim().split(`
|
|
2810
|
+
`)[0] || null;
|
|
2811
|
+
}
|
|
2812
|
+
return null;
|
|
2813
|
+
}
|
|
2814
|
+
async hasADC() {
|
|
2815
|
+
let fileExists = false;
|
|
2816
|
+
if (!this.executor.isSystemGcloud() && !process.env.STITCH_USE_SYSTEM_GCLOUD) {
|
|
2817
|
+
const stitchConfigPath = getGcloudConfigPath();
|
|
2818
|
+
const stitchAdcPath = joinPath(stitchConfigPath, "application_default_credentials.json");
|
|
2819
|
+
try {
|
|
2820
|
+
await fs3.promises.access(stitchAdcPath, fs3.constants.F_OK);
|
|
2821
|
+
fileExists = true;
|
|
2822
|
+
} catch {
|
|
2823
|
+
fileExists = false;
|
|
2824
|
+
}
|
|
2825
|
+
} else {
|
|
2826
|
+
try {
|
|
2827
|
+
const result = await this.executor.exec(["info", "--format=value(config.paths.global_config_dir)"]);
|
|
2828
|
+
if (result.success && result.stdout.trim()) {
|
|
2829
|
+
const configDir = result.stdout.trim();
|
|
2830
|
+
const adcPath = joinPath(configDir, "application_default_credentials.json");
|
|
2831
|
+
try {
|
|
2832
|
+
await fs3.promises.access(adcPath, fs3.constants.F_OK);
|
|
2833
|
+
fileExists = true;
|
|
2834
|
+
} catch {
|
|
2835
|
+
fileExists = false;
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
} catch {}
|
|
2839
|
+
}
|
|
2840
|
+
if (!fileExists) {
|
|
2841
|
+
return false;
|
|
2842
|
+
}
|
|
2843
|
+
try {
|
|
2844
|
+
const result = await this.executor.exec(["auth", "application-default", "print-access-token"]);
|
|
2845
|
+
return result.success && !!result.stdout.trim();
|
|
2846
|
+
} catch {
|
|
2847
|
+
return false;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
async runAuthFlow(authArgs) {
|
|
2851
|
+
console.log(theme.gray(" Opening browser for authentication..."));
|
|
2852
|
+
const noBrowserResult = await this.executor.exec([...authArgs, "--no-launch-browser"], { timeout: 5000 });
|
|
2853
|
+
const outputText = noBrowserResult.stderr || noBrowserResult.stdout || "";
|
|
2854
|
+
const urlMatch = outputText.match(/https:\/\/accounts\.google\.com[^\s]+/);
|
|
2855
|
+
if (urlMatch) {
|
|
2856
|
+
console.log(theme.gray(` If it doesn't open automatically, visit this URL: ${theme.cyan(urlMatch[0])}
|
|
2857
|
+
`));
|
|
2858
|
+
} else {
|
|
2859
|
+
console.log(theme.gray(` Note: Could not extract authentication URL from gcloud output
|
|
2860
|
+
`));
|
|
2861
|
+
}
|
|
2862
|
+
return this.executor.exec([...authArgs, "--quiet"]);
|
|
2863
|
+
}
|
|
2864
|
+
async getLoginCommand() {
|
|
2865
|
+
const gcloudCmd = await this.executor.getGcloudCommand();
|
|
2866
|
+
if (this.executor.isSystemGcloud() || process.env.STITCH_USE_SYSTEM_GCLOUD) {
|
|
2867
|
+
return `${gcloudCmd} auth application-default login`;
|
|
2868
|
+
}
|
|
2869
|
+
const configPath = getGcloudConfigPath();
|
|
2870
|
+
return `CLOUDSDK_CONFIG="${configPath}" ${gcloudCmd} auth application-default login`;
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
// src/services/gcloud/spec.ts
|
|
2875
|
+
var PROJECT_ID_REGEX = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
|
|
2876
|
+
var EnsureGcloudInputSchema = exports_external.object({
|
|
2877
|
+
minVersion: exports_external.string().default("400.0.0"),
|
|
2878
|
+
forceLocal: exports_external.boolean().default(false),
|
|
2879
|
+
useSystemGcloud: exports_external.boolean().default(false).optional()
|
|
2880
|
+
});
|
|
2881
|
+
var AuthenticateInputSchema = exports_external.object({
|
|
2882
|
+
skipIfActive: exports_external.boolean().default(true)
|
|
2883
|
+
});
|
|
2884
|
+
var ListProjectsInputSchema = exports_external.object({
|
|
2885
|
+
limit: exports_external.number().optional(),
|
|
2886
|
+
filter: exports_external.string().optional(),
|
|
2887
|
+
sortBy: exports_external.string().optional()
|
|
2888
|
+
});
|
|
2889
|
+
var SetProjectInputSchema = exports_external.object({
|
|
2890
|
+
projectId: exports_external.string().regex(PROJECT_ID_REGEX, {
|
|
2891
|
+
message: "Invalid project ID format. Project IDs must be 6-30 characters, start with a letter, end with a letter or number, and contain only lowercase letters, numbers, and hyphens."
|
|
2892
|
+
})
|
|
2893
|
+
});
|
|
2894
|
+
var GcloudErrorCode = exports_external.enum([
|
|
2895
|
+
"DOWNLOAD_FAILED",
|
|
2896
|
+
"EXTRACTION_FAILED",
|
|
2897
|
+
"VERSION_CHECK_FAILED",
|
|
2898
|
+
"INVALID_VERSION",
|
|
2899
|
+
"AUTH_FAILED",
|
|
2900
|
+
"ADC_FAILED",
|
|
2901
|
+
"PROJECT_LIST_FAILED",
|
|
2902
|
+
"PROJECT_SET_FAILED",
|
|
2903
|
+
"COMMAND_NOT_FOUND",
|
|
2904
|
+
"UNKNOWN_ERROR"
|
|
2905
|
+
]);
|
|
2906
|
+
var GcloudInstallDataSchema = exports_external.object({
|
|
2907
|
+
version: exports_external.string(),
|
|
2908
|
+
location: exports_external.enum(["system", "bundled"]),
|
|
2909
|
+
path: exports_external.string()
|
|
2910
|
+
});
|
|
2911
|
+
var GcloudSuccess = exports_external.object({
|
|
2912
|
+
success: exports_external.literal(true),
|
|
2913
|
+
data: GcloudInstallDataSchema
|
|
2914
|
+
});
|
|
2915
|
+
var GcloudFailure = exports_external.object({
|
|
2916
|
+
success: exports_external.literal(false),
|
|
2917
|
+
error: exports_external.object({
|
|
2918
|
+
code: GcloudErrorCode,
|
|
2919
|
+
message: exports_external.string(),
|
|
2920
|
+
suggestion: exports_external.string().optional(),
|
|
2921
|
+
recoverable: exports_external.boolean()
|
|
2922
|
+
})
|
|
2923
|
+
});
|
|
2924
|
+
var AuthDataSchema = exports_external.object({
|
|
2925
|
+
account: exports_external.string(),
|
|
2926
|
+
type: exports_external.enum(["user", "adc"])
|
|
2927
|
+
});
|
|
2928
|
+
var AuthSuccess = exports_external.object({
|
|
2929
|
+
success: exports_external.literal(true),
|
|
2930
|
+
data: AuthDataSchema
|
|
2931
|
+
});
|
|
2932
|
+
var AuthFailure = exports_external.object({
|
|
2933
|
+
success: exports_external.literal(false),
|
|
2934
|
+
error: exports_external.object({
|
|
2935
|
+
code: GcloudErrorCode,
|
|
2936
|
+
message: exports_external.string(),
|
|
2937
|
+
suggestion: exports_external.string().optional(),
|
|
2938
|
+
recoverable: exports_external.boolean()
|
|
2939
|
+
})
|
|
2940
|
+
});
|
|
2941
|
+
var ProjectSchema = exports_external.object({
|
|
2942
|
+
projectId: exports_external.string(),
|
|
2943
|
+
name: exports_external.string(),
|
|
2944
|
+
projectNumber: exports_external.string().optional(),
|
|
2945
|
+
createTime: exports_external.string().optional()
|
|
2946
|
+
});
|
|
2947
|
+
var ProjectListSuccess = exports_external.object({
|
|
2948
|
+
success: exports_external.literal(true),
|
|
2949
|
+
data: exports_external.object({
|
|
2950
|
+
projects: exports_external.array(ProjectSchema)
|
|
2951
|
+
})
|
|
2952
|
+
});
|
|
2953
|
+
var ProjectListFailure = exports_external.object({
|
|
2954
|
+
success: exports_external.literal(false),
|
|
2955
|
+
error: exports_external.object({
|
|
2956
|
+
code: GcloudErrorCode,
|
|
2957
|
+
message: exports_external.string(),
|
|
2958
|
+
suggestion: exports_external.string().optional(),
|
|
2959
|
+
recoverable: exports_external.boolean()
|
|
2960
|
+
})
|
|
2961
|
+
});
|
|
2962
|
+
var ProjectSetSuccess = exports_external.object({
|
|
2963
|
+
success: exports_external.literal(true),
|
|
2964
|
+
data: exports_external.object({
|
|
2965
|
+
projectId: exports_external.string()
|
|
2966
|
+
})
|
|
2967
|
+
});
|
|
2968
|
+
var ProjectSetFailure = exports_external.object({
|
|
2969
|
+
success: exports_external.literal(false),
|
|
2970
|
+
error: exports_external.object({
|
|
2971
|
+
code: GcloudErrorCode,
|
|
2972
|
+
message: exports_external.string(),
|
|
2973
|
+
suggestion: exports_external.string().optional(),
|
|
2974
|
+
recoverable: exports_external.boolean()
|
|
2975
|
+
})
|
|
2976
|
+
});
|
|
2977
|
+
|
|
2978
|
+
// src/services/gcloud/projects.ts
|
|
2979
|
+
class GcloudProjectService {
|
|
2980
|
+
executor;
|
|
2981
|
+
constructor(executor) {
|
|
2982
|
+
this.executor = executor;
|
|
2983
|
+
}
|
|
2984
|
+
async listProjects(input) {
|
|
2985
|
+
try {
|
|
2986
|
+
const args = ["projects", "list", "--format=json"];
|
|
2987
|
+
if (input.limit) {
|
|
2988
|
+
args.push(`--limit=${input.limit}`);
|
|
2989
|
+
}
|
|
2990
|
+
if (input.filter) {
|
|
2991
|
+
args.push(`--filter=${input.filter}`);
|
|
2992
|
+
}
|
|
2993
|
+
if (input.sortBy) {
|
|
2994
|
+
args.push(`--sort-by=${input.sortBy}`);
|
|
2995
|
+
}
|
|
2996
|
+
const result = await this.executor.exec(args);
|
|
2997
|
+
if (!result.success) {
|
|
2998
|
+
return {
|
|
2999
|
+
success: false,
|
|
3000
|
+
error: {
|
|
3001
|
+
code: "PROJECT_LIST_FAILED",
|
|
3002
|
+
message: `Failed to list projects: ${result.stderr}`,
|
|
3003
|
+
suggestion: "Ensure you are authenticated and have access to projects",
|
|
3004
|
+
recoverable: true
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
3007
|
+
}
|
|
3008
|
+
const projects = JSON.parse(result.stdout);
|
|
3009
|
+
return {
|
|
3010
|
+
success: true,
|
|
3011
|
+
data: {
|
|
3012
|
+
projects: projects.map((p) => ({
|
|
3013
|
+
projectId: p.projectId,
|
|
3014
|
+
name: p.name,
|
|
3015
|
+
projectNumber: p.projectNumber,
|
|
3016
|
+
createTime: p.createTime
|
|
3017
|
+
}))
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
} catch (error) {
|
|
3021
|
+
return {
|
|
3022
|
+
success: false,
|
|
3023
|
+
error: {
|
|
3024
|
+
code: "PROJECT_LIST_FAILED",
|
|
3025
|
+
message: error instanceof Error ? error.message : String(error),
|
|
3026
|
+
recoverable: false
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
async setProject(input) {
|
|
3032
|
+
if (!PROJECT_ID_REGEX.test(input.projectId)) {
|
|
3033
|
+
return {
|
|
3034
|
+
success: false,
|
|
3035
|
+
error: {
|
|
3036
|
+
code: "PROJECT_SET_FAILED",
|
|
3037
|
+
message: `Invalid project ID: ${input.projectId}. Project IDs must be 6-30 characters, start with a letter, and contain only lowercase letters, numbers, and hyphens.`,
|
|
3038
|
+
suggestion: "Verify the project ID is correct",
|
|
3039
|
+
recoverable: false
|
|
3040
|
+
}
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
try {
|
|
3044
|
+
const result = await this.executor.exec(["config", "set", "project", input.projectId, "--quiet"]);
|
|
3045
|
+
if (!result.success) {
|
|
3046
|
+
return {
|
|
3047
|
+
success: false,
|
|
3048
|
+
error: {
|
|
3049
|
+
code: "PROJECT_SET_FAILED",
|
|
3050
|
+
message: `Failed to set project: ${input.projectId}`,
|
|
3051
|
+
suggestion: "Verify the project ID is correct",
|
|
3052
|
+
recoverable: true
|
|
3053
|
+
}
|
|
3054
|
+
};
|
|
3055
|
+
}
|
|
3056
|
+
return {
|
|
3057
|
+
success: true,
|
|
3058
|
+
data: {
|
|
3059
|
+
projectId: input.projectId
|
|
3060
|
+
}
|
|
3061
|
+
};
|
|
3062
|
+
} catch (error) {
|
|
3063
|
+
return {
|
|
3064
|
+
success: false,
|
|
3065
|
+
error: {
|
|
3066
|
+
code: "PROJECT_SET_FAILED",
|
|
3067
|
+
message: error instanceof Error ? error.message : String(error),
|
|
3068
|
+
recoverable: false
|
|
3069
|
+
}
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
async getProjectId() {
|
|
3074
|
+
if (process.env.STITCH_PROJECT_ID) {
|
|
3075
|
+
return process.env.STITCH_PROJECT_ID;
|
|
3076
|
+
}
|
|
3077
|
+
if (process.env.GOOGLE_CLOUD_PROJECT) {
|
|
3078
|
+
return process.env.GOOGLE_CLOUD_PROJECT;
|
|
3079
|
+
}
|
|
3080
|
+
try {
|
|
3081
|
+
const result = await this.executor.exec(["config", "get-value", "project"]);
|
|
3082
|
+
if (result.success && result.stdout.trim()) {
|
|
3083
|
+
return result.stdout.trim();
|
|
3084
|
+
}
|
|
3085
|
+
return null;
|
|
3086
|
+
} catch (e) {
|
|
3087
|
+
return null;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
// src/services/gcloud/handler.ts
|
|
3093
|
+
class GcloudHandler {
|
|
3094
|
+
executor;
|
|
3095
|
+
installService;
|
|
3096
|
+
authService;
|
|
3097
|
+
projectService;
|
|
3098
|
+
constructor() {
|
|
3099
|
+
this.executor = new GcloudExecutor;
|
|
3100
|
+
this.installService = new GcloudInstallService(this.executor);
|
|
3101
|
+
this.authService = new GcloudAuthService(this.executor);
|
|
3102
|
+
this.projectService = new GcloudProjectService(this.executor);
|
|
3103
|
+
}
|
|
3104
|
+
async ensureInstalled(input) {
|
|
3105
|
+
return this.installService.ensureInstalled(input);
|
|
3106
|
+
}
|
|
3107
|
+
async authenticate(input) {
|
|
3108
|
+
return this.authService.authenticate(input);
|
|
3109
|
+
}
|
|
3110
|
+
async authenticateADC(input) {
|
|
3111
|
+
return this.authService.authenticateADC(input);
|
|
3112
|
+
}
|
|
3113
|
+
async listProjects(input) {
|
|
3114
|
+
return this.projectService.listProjects(input);
|
|
3115
|
+
}
|
|
3116
|
+
async setProject(input) {
|
|
3117
|
+
return this.projectService.setProject(input);
|
|
3118
|
+
}
|
|
3119
|
+
async getAccessToken() {
|
|
3120
|
+
return this.authService.getAccessToken();
|
|
3121
|
+
}
|
|
3122
|
+
async getProjectId() {
|
|
3123
|
+
return this.projectService.getProjectId();
|
|
3124
|
+
}
|
|
3125
|
+
async installBetaComponents() {
|
|
3126
|
+
return this.installService.installBetaComponents();
|
|
3127
|
+
}
|
|
3128
|
+
async getActiveAccount() {
|
|
3129
|
+
return this.authService.getActiveAccount();
|
|
3130
|
+
}
|
|
3131
|
+
async hasADC() {
|
|
3132
|
+
return this.authService.hasADC();
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
export { getStitchDir, getGcloudConfigPath, execCommand, GcloudExecutor, GcloudHandler };
|
|
3137
|
+
|
|
3138
|
+
//# debugId=CD3A09070AD99D0C64756E2164756E21
|