@govela/app 0.1.1 → 0.1.2

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
@@ -3,7 +3,22 @@
3
3
  The client router of Vela App, the application layer above the Vela compiler
4
4
  with a Go server. The contract is [docs/APP.md](../../docs/APP.md).
5
5
 
6
- This package is not published yet. `@govela/app/match` has the built-in
6
+ It also installs the `vela-app` command, which generates the app sources,
7
+ runs the development loop and makes production builds:
8
+
9
+ ```sh
10
+ npm install @govela/app @govela/runtime
11
+ npx vela-app dev
12
+ npx vela-app build
13
+ ```
14
+
15
+ `bin/vela-app.js` runs the binary of the optional dependency
16
+ `@govela/app-<os>-<cpu>` for this platform (linux x64/arm64, macOS
17
+ x64/arm64, Windows x64), or `$VELA_APP_BINARY`. Do not install with
18
+ `--omit=optional`. The guide is
19
+ [docs/VELA_APP.md](../../docs/VELA_APP.md).
20
+
21
+ `@govela/app/match` has the built-in
7
22
  matchers (`int`, `uuid`, `slug`) and `matchPath`, which the route table that
8
23
  `vela-app gen` writes (`src/_app/routes.js`) uses; the Go package
9
24
  `github.com/elauven/vela/app` matches with the same rules.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ // The `vela-app` command of @govela/app: runs the vela-app binary of this
3
+ // platform (the optional dependency @govela/app-<os>-<cpu>), or
4
+ // $VELA_APP_BINARY, with the arguments, standard streams and exit code of
5
+ // the command.
6
+ import { spawnSync } from 'node:child_process';
7
+ import { readFileSync } from 'node:fs';
8
+ import { createRequire } from 'node:module';
9
+
10
+ const require = createRequire(import.meta.url);
11
+ const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
12
+ const platforms = ['linux-x64', 'linux-arm64', 'darwin-x64', 'darwin-arm64', 'win32-x64'];
13
+
14
+ function binaryPath() {
15
+ if (process.env.VELA_APP_BINARY) {
16
+ return process.env.VELA_APP_BINARY;
17
+ }
18
+ const platform = `${process.platform}-${process.arch}`;
19
+ const name = `${manifest.name}-${platform}`;
20
+ if (!platforms.includes(platform)) {
21
+ throw new Error(`vela-app: no prebuilt binary for ${platform}; supported: ${platforms.join(', ')}. Install it with \`go install github.com/elauven/vela/app/cmd/vela-app@v${manifest.version}\` and set VELA_APP_BINARY to it.`);
22
+ }
23
+ const file = `bin/vela-app${process.platform === 'win32' ? '.exe' : ''}`;
24
+ try {
25
+ return require.resolve(`${name}/${file}`);
26
+ } catch {
27
+ throw new Error(`vela-app: the package ${name} is not installed. It is an optional dependency of ${manifest.name}; reinstall without --no-optional / --omit=optional, or set VELA_APP_BINARY to a vela-app binary.`);
28
+ }
29
+ }
30
+
31
+ let binary;
32
+ try {
33
+ binary = binaryPath();
34
+ } catch (error) {
35
+ console.error(error.message);
36
+ process.exit(1);
37
+ }
38
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit', windowsHide: true });
39
+ if (result.error) {
40
+ console.error(`vela-app: cannot run ${binary}: ${result.error.message}`);
41
+ process.exit(1);
42
+ }
43
+ if (result.signal) {
44
+ process.kill(process.pid, result.signal);
45
+ }
46
+ process.exit(result.status ?? 1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@govela/app",
3
- "version": "0.1.1",
4
- "description": "Client router of Vela App (docs/APP.md): hydration, data navigation and route matching.",
3
+ "version": "0.1.2",
4
+ "description": "Vela App (docs/APP.md): the client router (hydration, data navigation, route matching) and the vela-app command.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,6 +9,9 @@
9
9
  "directory": "packages/app"
10
10
  },
11
11
  "type": "module",
12
+ "bin": {
13
+ "vela-app": "bin/vela-app.js"
14
+ },
12
15
  "sideEffects": false,
13
16
  "exports": {
14
17
  "./client": {
@@ -21,6 +24,7 @@
21
24
  }
22
25
  },
23
26
  "files": [
27
+ "bin/vela-app.js",
24
28
  "client.js",
25
29
  "client.d.ts",
26
30
  "match.js",
@@ -33,5 +37,15 @@
33
37
  },
34
38
  "peerDependencies": {
35
39
  "@govela/runtime": ">=0.4.8"
40
+ },
41
+ "engines": {
42
+ "node": ">=18"
43
+ },
44
+ "optionalDependencies": {
45
+ "@govela/app-darwin-arm64": "0.1.2",
46
+ "@govela/app-darwin-x64": "0.1.2",
47
+ "@govela/app-linux-arm64": "0.1.2",
48
+ "@govela/app-linux-x64": "0.1.2",
49
+ "@govela/app-win32-x64": "0.1.2"
36
50
  }
37
51
  }