@glash/cli 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/glash.mjs +1 -1
- package/commands/deploy.mjs +6 -5
- package/lib/api.mjs +11 -5
- package/package.json +1 -1
package/bin/glash.mjs
CHANGED
package/commands/deploy.mjs
CHANGED
|
@@ -5,7 +5,8 @@ import { execSync } from 'node:child_process';
|
|
|
5
5
|
import { zipDirectory } from '../lib/zip.mjs';
|
|
6
6
|
import { join, basename } from 'node:path';
|
|
7
7
|
import { tmpdir } from 'node:os';
|
|
8
|
-
import {
|
|
8
|
+
import { openAsBlob } from 'node:fs';
|
|
9
|
+
import { access, readFile, rm, stat } from 'node:fs/promises';
|
|
9
10
|
|
|
10
11
|
function currentCommit() {
|
|
11
12
|
try {
|
|
@@ -140,11 +141,11 @@ export async function deploy({ flags }) {
|
|
|
140
141
|
const zipPath = join(tmpdir(), `glash-deploy-${Date.now()}.zip`);
|
|
141
142
|
try {
|
|
142
143
|
await zipDirectory(process.cwd(), zipPath);
|
|
143
|
-
const
|
|
144
|
+
const zipStat = await stat(zipPath);
|
|
145
|
+
info(color.dim(`→ source bundle ${(zipStat.size / 1024 / 1024).toFixed(1)} MB`));
|
|
144
146
|
const formData = new FormData();
|
|
145
147
|
formData.append('projectId', projectId);
|
|
146
|
-
|
|
147
|
-
formData.append('file', new Blob([zipBuffer]), 'project.zip');
|
|
148
|
+
formData.append('file', await openAsBlob(zipPath, { type: 'application/zip' }), 'project.zip');
|
|
148
149
|
|
|
149
150
|
formData.append('commitHash', commitHash || 'local-upload');
|
|
150
151
|
formData.append('gitBranch', gitBranch || '');
|
|
@@ -154,7 +155,7 @@ export async function deploy({ flags }) {
|
|
|
154
155
|
await rm(zipPath, { force: true }).catch(() => {});
|
|
155
156
|
} catch (e) {
|
|
156
157
|
await rm(zipPath, { force: true }).catch(() => {});
|
|
157
|
-
return fail(`
|
|
158
|
+
return fail(`Upload failed: ${e.message}`);
|
|
158
159
|
}
|
|
159
160
|
} else {
|
|
160
161
|
info(color.dim(`→ deploying connected repo for project ${projectId}${commitHash ? ` @ ${commitHash.slice(0, 7)}` : ''} (${target})`));
|
package/lib/api.mjs
CHANGED
|
@@ -23,11 +23,17 @@ export async function api(method, path, { body, token, query } = {}) {
|
|
|
23
23
|
if (qs) url += (url.includes('?') ? '&' : '?') + qs;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
let res;
|
|
27
|
+
try {
|
|
28
|
+
res = await fetch(url, {
|
|
29
|
+
method,
|
|
30
|
+
headers,
|
|
31
|
+
body: body instanceof FormData ? body : (body === undefined ? undefined : JSON.stringify(body)),
|
|
32
|
+
});
|
|
33
|
+
} catch (e) {
|
|
34
|
+
const detail = e?.cause?.message || e?.message || String(e);
|
|
35
|
+
throw new GlashApiError(0, `Network request failed while calling ${method} ${path}: ${detail}`);
|
|
36
|
+
}
|
|
31
37
|
|
|
32
38
|
if (!res.ok) {
|
|
33
39
|
let message = `HTTP ${res.status}`;
|
package/package.json
CHANGED