glashjs 0.10.0 → 0.11.1

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
@@ -75,10 +75,19 @@ export const POST = (ctx) => json({ created: ctx.body }, { status: 201 });
75
75
  ```
76
76
 
77
77
  ```bash
78
- glash dev # dev server: routing + SSR + API, live route reload
79
- glash serve # production server over routes/ + built assets (Brotli-negotiated)
78
+ glashjs dev # dev server (live reload) prints a Local + Network (LAN IP) URL
79
+ # ➜ Local: http://localhost:3000
80
+ # ➜ Network: http://192.168.1.57:3000 (open from your phone/other devices)
81
+ glashjs serve # production server over routes/ + built assets (Brotli-negotiated)
82
+ glashjs update # update glashjs to the latest published version
83
+ glashjs build # optimize assets + precompile routes
84
+ glashjs deploy # build, then deploy to glashdb
80
85
  ```
81
86
 
87
+ > glashjs installs **two** bins — `glashjs` and `glash` — both run the same CLI.
88
+ > Use **`glashjs <cmd>`** in projects that also have the `@glash/cli`/`glashdb`
89
+ > deploy CLI installed, since that package owns the `glash` name there.
90
+
82
91
  **`<Image>`** (better than `next/image` — no runtime image server, uses the build's AVIF/WebP):
83
92
  ```jsx
84
93
  import { Image } from 'glashjs/image';
package/bin/glash.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  // glashjs CLI
3
3
  import { readFileSync } from 'node:fs';
4
+ import os from 'node:os';
4
5
  import { build } from '../src/build.mjs';
5
6
  import { optimizeAssets } from '../src/assets/optimize.mjs';
6
7
  import { createGlashServer } from '../src/server/server.mjs';
7
8
  import { deploy } from '../src/deploy.mjs';
9
+ import { update } from '../src/update.mjs';
8
10
 
9
11
  const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
10
12
  const [, , cmd, ...rest] = process.argv;
@@ -14,17 +16,34 @@ function arg(name, fallback) {
14
16
  return i >= 0 && rest[i + 1] ? rest[i + 1] : fallback;
15
17
  }
16
18
 
19
+ // LAN IPv4 addresses, so the dev server prints a Network URL you can open from
20
+ // your phone or another device on the same network.
21
+ function lanAddresses() {
22
+ const out = [];
23
+ const ifaces = os.networkInterfaces();
24
+ for (const name of Object.keys(ifaces)) {
25
+ for (const i of ifaces[name] || []) {
26
+ if (i.family === 'IPv4' && !i.internal) out.push(i.address);
27
+ }
28
+ }
29
+ return out;
30
+ }
31
+
17
32
  async function serve(dev) {
18
33
  const root = arg('--root', process.cwd());
19
34
  const { listen, cfg, routes } = await createGlashServer({ root, dev });
20
35
  const port = Number(arg('--port', cfg.port || 3000));
21
- const { host } = await listen(port);
36
+ await listen(port);
22
37
  const pages = routes.filter((r) => !r.isApi).length;
23
38
  const apis = routes.filter((r) => r.isApi).length;
24
39
  console.log(`\nglashjs ${dev ? 'dev' : 'serve'} — "${cfg.name}"`);
25
40
  console.log(` ${pages} page route(s), ${apis} api route(s)`);
26
41
  routes.forEach((r) => console.log(` ${r.isApi ? 'api ' : 'page'} ${r.pattern}`));
27
- console.log(`\n ▶ http://localhost:${port}${dev ? ' (live route reload)' : ''}\n`);
42
+ console.log('');
43
+ console.log(` ➜ Local: http://localhost:${port}`);
44
+ for (const ip of lanAddresses()) console.log(` ➜ Network: http://${ip}:${port} (preview on other devices)`);
45
+ if (dev) console.log('\n live reload on save · ctrl-c to stop');
46
+ console.log('');
28
47
  }
29
48
 
30
49
  async function main() {
@@ -38,6 +57,10 @@ async function main() {
38
57
  await deploy({ root: arg('--root', process.cwd()), dryRun: rest.includes('--dry-run'), args: passthrough });
39
58
  break;
40
59
  }
60
+ case 'update':
61
+ case 'upgrade':
62
+ await update({ root: arg('--root', process.cwd()) });
63
+ break;
41
64
  case 'dev':
42
65
  await serve(true);
43
66
  break;
@@ -61,13 +84,14 @@ async function main() {
61
84
  default:
62
85
  console.log(`glashjs — fast, offline-capable, hard-to-hack sites
63
86
 
64
- Usage:
65
- glash dev [--port 3000] Run the dev server (file-based routing, SSR, API, live reload)
66
- glash serve [--port 3000] Run the production server over routes/ + built assets
67
- glash build [--root <dir>] Optimize assets, generate offline SW + PWA + security manifests
68
- glash deploy [--dry-run] Build, then deploy to glashdb (hands off to the glashdb CLI)
69
- glash optimize [<dir>] Just run the asset optimizer over a directory
70
- glash version Print version
87
+ Usage: (run as "glashjs <cmd>"; "glash <cmd>" also works unless the glashdb deploy CLI owns that name)
88
+ glashjs dev [--port 3000] Run the dev server (routing, SSR, API, live reload) + Network preview URL
89
+ glashjs serve [--port 3000] Run the production server over routes/ + built assets
90
+ glashjs build [--root <dir>] Optimize assets, precompile routes, generate offline SW + PWA + security
91
+ glashjs update Update glashjs to the latest published version
92
+ glashjs deploy [--dry-run] Build, then deploy to glashdb (hands off to the glashdb CLI)
93
+ glashjs optimize [<dir>] Just run the asset optimizer over a directory
94
+ glashjs version Print version
71
95
 
72
96
  Docs: ./README.md`);
73
97
  }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "glashjs",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "glashjs — a web framework built on top of Next.js: file-based routing, SSR, API routes, JSX components with client hydration, nested layouts, streaming SSR, a best-in-class build-time asset optimizer, offline PWA layer, animated favicon, and secure-by-default headers. Zero mandatory dependencies.",
5
5
  "type": "module",
6
6
  "bin": {
7
+ "glashjs": "bin/glash.mjs",
7
8
  "glash": "bin/glash.mjs"
8
9
  },
9
10
  "exports": {
package/src/index.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  // glashjs public API
2
2
  export { defineConfig, loadConfig, DEFAULT_CONFIG } from './config.mjs';
3
3
  export { build } from './build.mjs';
4
+ export { deploy } from './deploy.mjs';
5
+ export { update } from './update.mjs';
4
6
  export { optimizeAssets } from './assets/optimize.mjs';
5
7
  export { generateAnimatedFavicon } from './assets/animated-favicon.mjs';
6
8
  export { generateServiceWorker } from './offline/generate-sw.mjs';
package/src/update.mjs ADDED
@@ -0,0 +1,39 @@
1
+ // glashjs update — bump the installed glashjs to the latest published version,
2
+ // using whichever package manager the project uses (npm/pnpm/yarn/bun).
3
+ import { spawn } from 'node:child_process';
4
+ import { readFileSync, existsSync } from 'node:fs';
5
+ import path from 'node:path';
6
+
7
+ function installedVersion(root) {
8
+ try {
9
+ return JSON.parse(readFileSync(path.join(root, 'node_modules/glashjs/package.json'), 'utf8')).version;
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
14
+
15
+ function packageManager(root) {
16
+ if (existsSync(path.join(root, 'pnpm-lock.yaml'))) return { cmd: 'pnpm', args: ['add', 'glashjs@latest'] };
17
+ if (existsSync(path.join(root, 'yarn.lock'))) return { cmd: 'yarn', args: ['add', 'glashjs@latest'] };
18
+ if (existsSync(path.join(root, 'bun.lockb'))) return { cmd: 'bun', args: ['add', 'glashjs@latest'] };
19
+ return { cmd: 'npm', args: ['install', 'glashjs@latest'] };
20
+ }
21
+
22
+ function run(cmd, args, root) {
23
+ return new Promise((resolve, reject) => {
24
+ const child = spawn(cmd, args, { cwd: root, stdio: 'inherit', shell: process.platform === 'win32' });
25
+ child.on('error', reject);
26
+ child.on('exit', (code) => (code === 0 ? resolve() : reject(new Error(`${cmd} exited with code ${code}`))));
27
+ });
28
+ }
29
+
30
+ export async function update({ root = process.cwd(), log = console.log } = {}) {
31
+ const current = installedVersion(root);
32
+ const { cmd, args } = packageManager(root);
33
+ log(`glashjs update — current: ${current ?? 'not installed'}\n $ ${cmd} ${args.join(' ')}\n`);
34
+ await run(cmd, args, root);
35
+ const next = installedVersion(root);
36
+ if (next && next === current) log(`\n✓ already on the latest version (${next})`);
37
+ else log(`\n✓ glashjs is now ${next ?? 'installed'}${current ? ` (was ${current})` : ''}`);
38
+ return { from: current, to: next };
39
+ }