@glash/cli 0.2.3 → 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/README.md CHANGED
@@ -33,6 +33,7 @@ glash deploy
33
33
  | `glash env:rm KEY` | Remove an env var |
34
34
  | `glash env:pull [--out .env.local]` | Pull env vars to a local file |
35
35
  | `glash env:push [<file>]` | Bulk upload from a `.env` file |
36
+ | `glash update` | Update `@glash/cli` to the latest version |
36
37
 
37
38
  Pass `--project <slug>` to any command to operate on a project other than
38
39
  the one linked in the current directory.
package/bin/glash.mjs CHANGED
@@ -3,7 +3,7 @@ import { argv, exit } from 'node:process';
3
3
  import { parseArgs } from '../lib/args.mjs';
4
4
  import { info, fail, color } from '../lib/ui.mjs';
5
5
 
6
- const VERSION = '0.2.3';
6
+ const VERSION = '0.2.5';
7
7
 
8
8
  const sub = argv[2];
9
9
  const rest = argv.slice(3);
@@ -42,6 +42,7 @@ const commands = {
42
42
 
43
43
  pull: () => import('../commands/pull.mjs').then((m) => m.pull(parsed)),
44
44
  open: () => import('../commands/open.mjs').then((m) => m.open(parsed)),
45
+ update: () => import('../commands/update.mjs').then((m) => m.update(parsed)),
45
46
  };
46
47
 
47
48
  function usage() {
@@ -82,6 +83,9 @@ ${color.bold('ENV VARS')}
82
83
  ${color.bold('PULL')}
83
84
  pull [<slug>] [--out dir] [--no-env] Pull source + .env from a glashDB project
84
85
 
86
+ ${color.bold('SYSTEM')}
87
+ update Update @glash/cli to the latest version
88
+
85
89
  ${color.bold('FLAGS')}
86
90
  --project <slug|id> Override the linked project for this command
87
91
  --environment <name> Env-var environment (default: production)
@@ -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 { access, readFile, rm } from 'node:fs/promises';
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 zipBuffer = await readFile(zipPath);
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
- // We wrap the buffer in a Blob so fetch treats it as a file
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(`Packaging failed: ${e.message}`);
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})`));
@@ -0,0 +1,11 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { ok, fail, info, color } from '../lib/ui.mjs';
3
+
4
+ export async function update() {
5
+ info(color.dim('→ updating @glash/cli to latest...'));
6
+ const child = spawnSync('npm', ['install', '-g', '@glash/cli@latest'], { stdio: 'inherit' });
7
+ if (child.status !== 0) {
8
+ return fail(`Update failed with exit code ${child.status ?? 'unknown'}. Please run \`npm install -g @glash/cli@latest\` manually.`);
9
+ }
10
+ ok('Successfully updated @glash/cli to the latest version.');
11
+ }
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
- const res = await fetch(url, {
27
- method,
28
- headers,
29
- body: body instanceof FormData ? body : (body === undefined ? undefined : JSON.stringify(body)),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glash/cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "glashDB command-line interface — deploy projects, pull source + env, manage env vars.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://glashdb.com",