badmfck-api-server 4.1.44 → 4.1.46
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.
|
@@ -67,6 +67,7 @@ async function Deploy(opt) {
|
|
|
67
67
|
var execResult = run("npm run build");
|
|
68
68
|
console.log(execResult);
|
|
69
69
|
const items = [];
|
|
70
|
+
let spaMode = false;
|
|
70
71
|
const binExists = fs_1.default.existsSync("./bin");
|
|
71
72
|
if (binExists) {
|
|
72
73
|
items.push("./bin");
|
|
@@ -78,8 +79,8 @@ async function Deploy(opt) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
else if (fs_1.default.existsSync("./dist") && fs_1.default.existsSync(path_1.default.resolve("dist", "index.html"))) {
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
spaMode = true;
|
|
83
|
+
console.log("No ./bin found — using entire ./dist contents as distribution");
|
|
83
84
|
}
|
|
84
85
|
if (Array.isArray(opt.includes)) {
|
|
85
86
|
for (const inc of opt.includes) {
|
|
@@ -95,8 +96,8 @@ async function Deploy(opt) {
|
|
|
95
96
|
items.push(inc);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
if (items.length === 0) {
|
|
99
|
-
throw new Error("Nothing to archive (no ./bin
|
|
99
|
+
if (items.length === 0 && !spaMode) {
|
|
100
|
+
throw new Error("Nothing to archive (no ./bin, no ./dist/index.html, no valid includes)");
|
|
100
101
|
}
|
|
101
102
|
const excludes = new Set();
|
|
102
103
|
const addExclude = (raw, source) => {
|
|
@@ -122,11 +123,28 @@ async function Deploy(opt) {
|
|
|
122
123
|
addExclude(ex, "config.excludes");
|
|
123
124
|
}
|
|
124
125
|
const excludeArgs = Array.from(excludes).map(p => `--exclude=${p}`);
|
|
125
|
-
|
|
126
|
+
const tarArgs = ["-czvf", archiveName, ...excludeArgs];
|
|
127
|
+
if (spaMode) {
|
|
128
|
+
tarArgs.push("-C", "./dist", ".");
|
|
129
|
+
if (items.length > 0) {
|
|
130
|
+
tarArgs.push("-C", process.cwd(), ...items);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
tarArgs.push(...items);
|
|
135
|
+
}
|
|
136
|
+
if (spaMode) {
|
|
137
|
+
console.log("Archiving: contents of ./dist (recursively, at archive root)");
|
|
138
|
+
if (items.length > 0)
|
|
139
|
+
console.log("Also archiving from cwd:", items.join(", "));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.log("Archiving:", items.join(", "));
|
|
143
|
+
}
|
|
126
144
|
if (excludeArgs.length > 0)
|
|
127
145
|
console.log("Excluding:", Array.from(excludes).join(", "));
|
|
128
146
|
try {
|
|
129
|
-
(0, child_process_1.execFileSync)("tar",
|
|
147
|
+
(0, child_process_1.execFileSync)("tar", tarArgs, { encoding: "utf-8", stdio: "inherit" });
|
|
130
148
|
}
|
|
131
149
|
catch (err) {
|
|
132
150
|
console.error(`\ntar failed while creating ${archiveName}\n`);
|
|
@@ -155,12 +173,35 @@ async function Deploy(opt) {
|
|
|
155
173
|
headersTimeout: 5 * 60 * 1000,
|
|
156
174
|
bodyTimeout: 5 * 60 * 1000,
|
|
157
175
|
});
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
176
|
+
const abortController = new AbortController();
|
|
177
|
+
const abortTimer = setTimeout(() => abortController.abort(), 5 * 60 * 1000);
|
|
178
|
+
let uploadResponse;
|
|
179
|
+
try {
|
|
180
|
+
const res = await fetch(opt.host, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
headers: { authorization: `Bearer ${authToken}` },
|
|
183
|
+
body: formData,
|
|
184
|
+
signal: abortController.signal,
|
|
185
|
+
...{ dispatcher: uploadAgent },
|
|
186
|
+
});
|
|
187
|
+
const rawText = await res.text();
|
|
188
|
+
let parsed;
|
|
189
|
+
try {
|
|
190
|
+
parsed = rawText.length > 0 ? JSON.parse(rawText) : null;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
parsed = rawText;
|
|
194
|
+
}
|
|
195
|
+
uploadResponse = res.ok
|
|
196
|
+
? { ok: true, status: res.status, data: parsed }
|
|
197
|
+
: { ok: false, status: res.status, error: parsed };
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
uploadResponse = { ok: false, error: err };
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
clearTimeout(abortTimer);
|
|
204
|
+
}
|
|
164
205
|
const elapsedMs = Date.now() - startedAt;
|
|
165
206
|
const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
166
207
|
const c = (code, t) => useColor ? `\x1b[${code}m${t}\x1b[0m` : t;
|