@gjsify/cli 0.3.5 → 0.3.6
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/lib/actions/build.js +8 -2
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +1 -0
- package/lib/commands/install.d.ts +10 -0
- package/lib/commands/install.js +99 -0
- package/lib/commands/showcase.js +46 -34
- package/lib/index.js +2 -1
- package/lib/utils/check-system-deps.js +17 -6
- package/lib/utils/discover-showcases.d.ts +6 -5
- package/lib/utils/discover-showcases.js +28 -50
- package/package.json +5 -10
- package/showcases.json +40 -0
- package/src/actions/build.ts +8 -2
- package/src/commands/index.ts +2 -1
- package/src/commands/install.ts +116 -0
- package/src/commands/showcase.ts +40 -21
- package/src/index.ts +2 -0
- package/src/utils/check-system-deps.ts +17 -6
- package/src/utils/discover-showcases.ts +42 -53
package/lib/actions/build.js
CHANGED
|
@@ -60,10 +60,16 @@ async function getPnpPlugin() {
|
|
|
60
60
|
}
|
|
61
61
|
let pnpApi = null;
|
|
62
62
|
try {
|
|
63
|
-
// pnpapi has no npm package — it is a virtual module injected by
|
|
63
|
+
// pnpapi has no npm package — it is a virtual CJS module injected by
|
|
64
|
+
// Yarn PnP. `await import()` of a CJS module yields the ESM namespace
|
|
65
|
+
// `{ default, "module.exports" }`, NOT the exports object — so
|
|
66
|
+
// `mod.resolveRequest` is `undefined`. Unwrap `.default` (the CJS
|
|
67
|
+
// exports) before use, falling back to the namespace itself for ESM
|
|
68
|
+
// builds of pnpapi (none today, but defensive).
|
|
64
69
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
65
70
|
// @ts-expect-error
|
|
66
|
-
|
|
71
|
+
const mod = await import("pnpapi");
|
|
72
|
+
pnpApi = (mod.default ?? mod);
|
|
67
73
|
}
|
|
68
74
|
catch {
|
|
69
75
|
// Not in a PnP runtime (shouldn't happen since findPnpRoot passed)
|
package/lib/commands/index.d.ts
CHANGED
package/lib/commands/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Command } from '../types/index.js';
|
|
2
|
+
interface InstallOptions {
|
|
3
|
+
packages?: string[];
|
|
4
|
+
'save-dev'?: boolean;
|
|
5
|
+
'save-peer'?: boolean;
|
|
6
|
+
'save-optional'?: boolean;
|
|
7
|
+
verbose: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const installCommand: Command<any, InstallOptions>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// `gjsify install [pkg...]` — thin npm wrapper with gjsify-aware post-checks.
|
|
2
|
+
//
|
|
3
|
+
// The actual install is delegated to `npm install` in the user's project root
|
|
4
|
+
// (no `--prefix` rewrite, unlike `gjsify dlx`). After install completes we run
|
|
5
|
+
// `runMinimalChecks()` so missing system deps (gjs, gtk4, libsoup, ...) surface
|
|
6
|
+
// immediately, and report any installed `@gjsify/*` packages that ship native
|
|
7
|
+
// prebuilds so users know they can use `gjsify run` to wire `LD_LIBRARY_PATH` /
|
|
8
|
+
// `GI_TYPELIB_PATH` automatically.
|
|
9
|
+
//
|
|
10
|
+
// Modes:
|
|
11
|
+
// gjsify install → project install (npm install)
|
|
12
|
+
// gjsify install <pkg> [<pkg>...] → add package(s) (npm install <pkg>...)
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
|
+
import { buildInstallCommand, detectPackageManager, runMinimalChecks, } from '../utils/check-system-deps.js';
|
|
15
|
+
import { detectNativePackages } from '../utils/detect-native-packages.js';
|
|
16
|
+
export const installCommand = {
|
|
17
|
+
command: 'install [packages..]',
|
|
18
|
+
description: 'Install npm dependencies in the current project, then run gjsify-aware post-checks.',
|
|
19
|
+
builder: (yargs) => yargs
|
|
20
|
+
.positional('packages', {
|
|
21
|
+
description: 'Optional package specs. With none, runs a full project install.',
|
|
22
|
+
type: 'string',
|
|
23
|
+
array: true,
|
|
24
|
+
})
|
|
25
|
+
.option('save-dev', { type: 'boolean', alias: 'D' })
|
|
26
|
+
.option('save-peer', { type: 'boolean' })
|
|
27
|
+
.option('save-optional', { type: 'boolean', alias: 'O' })
|
|
28
|
+
.option('verbose', {
|
|
29
|
+
description: 'Verbose npm logging.',
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
default: false,
|
|
32
|
+
}),
|
|
33
|
+
handler: async (args) => {
|
|
34
|
+
const npmArgs = ['install'];
|
|
35
|
+
if (args['save-dev'])
|
|
36
|
+
npmArgs.push('--save-dev');
|
|
37
|
+
if (args['save-peer'])
|
|
38
|
+
npmArgs.push('--save-peer');
|
|
39
|
+
if (args['save-optional'])
|
|
40
|
+
npmArgs.push('--save-optional');
|
|
41
|
+
if (args.verbose)
|
|
42
|
+
npmArgs.push('--loglevel', 'verbose');
|
|
43
|
+
if (args.packages && args.packages.length > 0) {
|
|
44
|
+
npmArgs.push(...args.packages);
|
|
45
|
+
}
|
|
46
|
+
await spawnNpm(npmArgs);
|
|
47
|
+
await runPostInstallChecks();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
async function spawnNpm(npmArgs) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const child = spawn('npm', npmArgs, { stdio: 'inherit' });
|
|
53
|
+
child.on('close', (code) => {
|
|
54
|
+
if (code === 0)
|
|
55
|
+
resolve();
|
|
56
|
+
else
|
|
57
|
+
reject(new Error(`npm install exited with code ${code}`));
|
|
58
|
+
});
|
|
59
|
+
child.on('error', (err) => {
|
|
60
|
+
const code = err.code;
|
|
61
|
+
const msg = code === 'ENOENT'
|
|
62
|
+
? 'npm not found on PATH — install Node.js first.'
|
|
63
|
+
: `npm install failed: ${err.message}`;
|
|
64
|
+
reject(new Error(msg));
|
|
65
|
+
});
|
|
66
|
+
}).catch((err) => {
|
|
67
|
+
console.error(err.message);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async function runPostInstallChecks() {
|
|
72
|
+
console.log('\n--- gjsify post-install checks ---');
|
|
73
|
+
// 1. System deps that GJS apps typically need.
|
|
74
|
+
const results = runMinimalChecks();
|
|
75
|
+
const missing = results.filter((r) => !r.found && r.severity === 'required');
|
|
76
|
+
if (missing.length > 0) {
|
|
77
|
+
console.warn('Missing required system dependencies:\n');
|
|
78
|
+
for (const dep of missing) {
|
|
79
|
+
console.warn(` ✗ ${dep.name}`);
|
|
80
|
+
}
|
|
81
|
+
const pm = detectPackageManager();
|
|
82
|
+
const cmd = buildInstallCommand(pm, missing);
|
|
83
|
+
if (cmd)
|
|
84
|
+
console.warn(`\nInstall with:\n ${cmd}`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log('System dependencies OK.');
|
|
88
|
+
}
|
|
89
|
+
// 2. Surface @gjsify/* packages with native prebuilds — `gjsify run`
|
|
90
|
+
// will set LD_LIBRARY_PATH / GI_TYPELIB_PATH for these automatically.
|
|
91
|
+
const native = detectNativePackages(process.cwd());
|
|
92
|
+
if (native.length > 0) {
|
|
93
|
+
console.log(`\nDetected ${native.length} @gjsify/* package(s) with native prebuilds:`);
|
|
94
|
+
for (const pkg of native) {
|
|
95
|
+
console.log(` • ${pkg.name}`);
|
|
96
|
+
}
|
|
97
|
+
console.log('\nUse `gjsify run <bundle>` to launch with LD_LIBRARY_PATH/GI_TYPELIB_PATH set.');
|
|
98
|
+
}
|
|
99
|
+
}
|
package/lib/commands/showcase.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { discoverShowcases, findShowcase } from '../utils/discover-showcases.js';
|
|
2
|
-
import { runMinimalChecks, checkGwebgl, detectPackageManager, buildInstallCommand } from '../utils/check-system-deps.js';
|
|
3
|
-
import {
|
|
2
|
+
import { runMinimalChecks, checkGwebgl, detectPackageManager, buildInstallCommand, } from '../utils/check-system-deps.js';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
export const showcaseCommand = {
|
|
5
6
|
command: 'showcase [name]',
|
|
6
|
-
description: 'List or run
|
|
7
|
-
builder: (yargs) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
},
|
|
7
|
+
description: 'List or run curated gjsify showcase applications.',
|
|
8
|
+
builder: (yargs) => yargs
|
|
9
|
+
.positional('name', {
|
|
10
|
+
description: 'Showcase name to run (omit to list all)',
|
|
11
|
+
type: 'string',
|
|
12
|
+
})
|
|
13
|
+
.option('json', {
|
|
14
|
+
description: 'Output as JSON',
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
default: false,
|
|
17
|
+
})
|
|
18
|
+
.option('list', {
|
|
19
|
+
description: 'List available showcases',
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
default: false,
|
|
22
|
+
}),
|
|
24
23
|
handler: async (args) => {
|
|
25
24
|
// List mode: no name given, or --list flag
|
|
26
25
|
if (!args.name || args.list) {
|
|
@@ -30,10 +29,9 @@ export const showcaseCommand = {
|
|
|
30
29
|
return;
|
|
31
30
|
}
|
|
32
31
|
if (showcases.length === 0) {
|
|
33
|
-
console.log('No showcases found.
|
|
32
|
+
console.log('No showcases found. The CLI ships a curated list in `showcases.json`; if it is missing the CLI install is incomplete.');
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
36
|
-
// Group by category
|
|
37
35
|
const grouped = new Map();
|
|
38
36
|
for (const sc of showcases) {
|
|
39
37
|
const list = grouped.get(sc.category) ?? [];
|
|
@@ -43,7 +41,7 @@ export const showcaseCommand = {
|
|
|
43
41
|
console.log('Available gjsify showcases:\n');
|
|
44
42
|
for (const [category, list] of grouped) {
|
|
45
43
|
console.log(` ${category.toUpperCase()}:`);
|
|
46
|
-
const maxNameLen = Math.max(...list.map(e => e.name.length));
|
|
44
|
+
const maxNameLen = Math.max(...list.map((e) => e.name.length));
|
|
47
45
|
for (const sc of list) {
|
|
48
46
|
const pad = ' '.repeat(maxNameLen - sc.name.length + 2);
|
|
49
47
|
const desc = sc.description ? `${pad}${sc.description}` : '';
|
|
@@ -54,23 +52,18 @@ export const showcaseCommand = {
|
|
|
54
52
|
console.log('Run a showcase: gjsify showcase <name>');
|
|
55
53
|
return;
|
|
56
54
|
}
|
|
57
|
-
// Run mode: find the showcase
|
|
58
55
|
const showcase = findShowcase(args.name);
|
|
59
56
|
if (!showcase) {
|
|
60
57
|
console.error(`Unknown showcase: "${args.name}"`);
|
|
61
58
|
console.error('Run "gjsify showcase" to list available showcases.');
|
|
62
59
|
process.exit(1);
|
|
63
60
|
}
|
|
64
|
-
// System dependency check before
|
|
65
|
-
// All showcases need GJS; WebGL showcases additionally need gwebgl prebuilds.
|
|
61
|
+
// System dependency check before delegating — only what this showcase needs.
|
|
66
62
|
const results = runMinimalChecks();
|
|
67
|
-
|
|
68
|
-
if (needsWebgl) {
|
|
63
|
+
if (showcase.needsWebgl) {
|
|
69
64
|
results.push(checkGwebgl(process.cwd()));
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
// For showcase, gwebgl is treated as required because the bundle won't run without it.
|
|
73
|
-
const missingHard = results.filter(r => !r.found && (r.severity === 'required' || r.id === 'gwebgl'));
|
|
66
|
+
const missingHard = results.filter((r) => !r.found && (r.severity === 'required' || r.id === 'gwebgl'));
|
|
74
67
|
if (missingHard.length > 0) {
|
|
75
68
|
console.error('Missing system dependencies:\n');
|
|
76
69
|
for (const dep of missingHard) {
|
|
@@ -83,8 +76,27 @@ export const showcaseCommand = {
|
|
|
83
76
|
}
|
|
84
77
|
process.exit(1);
|
|
85
78
|
}
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
// Delegate to `gjsify dlx <package>` — same npm-cache, same atomic
|
|
80
|
+
// symlink-swap, same `gjsify.main` resolution. Re-spawning the CLI
|
|
81
|
+
// keeps the dlx logic in one place.
|
|
82
|
+
console.log(`Running showcase: ${showcase.name} (via gjsify dlx)\n`);
|
|
83
|
+
const cliBin = fileURLToPath(new URL('../index.js', import.meta.url));
|
|
84
|
+
const child = spawn(process.execPath, [cliBin, 'dlx', showcase.packageName], {
|
|
85
|
+
stdio: 'inherit',
|
|
86
|
+
});
|
|
87
|
+
await new Promise((resolvePromise, reject) => {
|
|
88
|
+
child.on('close', (code) => {
|
|
89
|
+
if (code !== 0) {
|
|
90
|
+
reject(new Error(`gjsify dlx exited with code ${code}`));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
resolvePromise();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
child.on('error', reject);
|
|
97
|
+
}).catch((err) => {
|
|
98
|
+
console.error(err.message);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
});
|
|
89
101
|
},
|
|
90
102
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import yargs from 'yargs';
|
|
3
3
|
import { hideBin } from 'yargs/helpers';
|
|
4
|
-
import { buildCommand as build, runCommand as run, infoCommand as info, checkCommand as check, showcaseCommand as showcase, createCommand as create, gresourceCommand as gresource, gettextCommand as gettext, dlxCommand as dlx, } from './commands/index.js';
|
|
4
|
+
import { buildCommand as build, runCommand as run, infoCommand as info, checkCommand as check, showcaseCommand as showcase, createCommand as create, gresourceCommand as gresource, gettextCommand as gettext, dlxCommand as dlx, installCommand as install, } from './commands/index.js';
|
|
5
5
|
import { APP_NAME } from './constants.js';
|
|
6
6
|
void yargs(hideBin(process.argv))
|
|
7
7
|
.scriptName(APP_NAME)
|
|
8
8
|
.strict()
|
|
9
9
|
.command(create.command, create.description, create.builder, create.handler)
|
|
10
|
+
.command(install.command, install.description, install.builder, install.handler)
|
|
10
11
|
.command(build.command, build.description, build.builder, build.handler)
|
|
11
12
|
.command(run.command, run.description, run.builder, run.handler)
|
|
12
13
|
.command(dlx.command, dlx.description, dlx.builder, dlx.handler)
|
|
@@ -96,8 +96,13 @@ const PACKAGE_DEPS = {
|
|
|
96
96
|
'@gjsify/canvas2d': ['gdk-pixbuf', 'pango', 'pangocairo', 'cairo'],
|
|
97
97
|
'@gjsify/canvas2d-core': ['gdk-pixbuf', 'pango', 'pangocairo', 'cairo'],
|
|
98
98
|
'@gjsify/dom-elements': ['gdk-pixbuf'],
|
|
99
|
-
// @gjsify/webgl
|
|
100
|
-
//
|
|
99
|
+
// @gjsify/webgl needs the gwebgl npm package (Vala prebuild) — handled
|
|
100
|
+
// as a special-case checkNpmPackage rather than checkPkgConfig in
|
|
101
|
+
// runOptionalChecks. Mapping it here so its presence in the project's
|
|
102
|
+
// dep tree triggers the check.
|
|
103
|
+
'@gjsify/webgl': ['gwebgl'],
|
|
104
|
+
// @gjsify/event-bridge only needs gtk4/gdk which are already in the
|
|
105
|
+
// required set, so it doesn't need an optional entry.
|
|
101
106
|
};
|
|
102
107
|
/** Walk up from cwd looking for the nearest package.json. */
|
|
103
108
|
function findProjectRoot(cwd) {
|
|
@@ -241,10 +246,16 @@ function runOptionalChecks(needed, cwd) {
|
|
|
241
246
|
.map(([pkg]) => pkg);
|
|
242
247
|
results.push(checkPkgConfig(dep.id, dep.name, dep.pkgName, 'optional', requiredBy));
|
|
243
248
|
}
|
|
244
|
-
// gwebgl npm package — special case (not a pkg-config lib).
|
|
245
|
-
//
|
|
246
|
-
//
|
|
247
|
-
|
|
249
|
+
// gwebgl npm package — special case (not a pkg-config lib). Only checked
|
|
250
|
+
// when the project directly or transitively depends on @gjsify/webgl —
|
|
251
|
+
// since the CLI tarball no longer ships any showcase example packages,
|
|
252
|
+
// gwebgl is not part of the CLI's own dep tree, so reporting it for every
|
|
253
|
+
// project would always be `found: false`. `needed === null` means "check
|
|
254
|
+
// everything" (no project context).
|
|
255
|
+
const hasWebglDep = needed === null || needed.has('gwebgl');
|
|
256
|
+
if (hasWebglDep) {
|
|
257
|
+
results.push(checkGwebgl(cwd));
|
|
258
|
+
}
|
|
248
259
|
return results;
|
|
249
260
|
}
|
|
250
261
|
// Per-package-manager install package names, keyed by dep id.
|
|
@@ -5,14 +5,15 @@ export interface ShowcaseInfo {
|
|
|
5
5
|
packageName: string;
|
|
6
6
|
/** Category: "dom" or "node" */
|
|
7
7
|
category: string;
|
|
8
|
-
/** Description
|
|
8
|
+
/** Description for the list view */
|
|
9
9
|
description: string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Whether the showcase needs the gwebgl native prebuild. */
|
|
11
|
+
needsWebgl: boolean;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Read the curated showcase list from `showcases.json`. Returns showcases
|
|
15
|
+
* sorted by category then name. An empty list (or missing manifest) yields
|
|
16
|
+
* an empty array — `gjsify showcase` then prints the empty-state message.
|
|
16
17
|
*/
|
|
17
18
|
export declare function discoverShowcases(): ShowcaseInfo[];
|
|
18
19
|
/** Find a single showcase by short name. */
|
|
@@ -1,68 +1,46 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// Static discovery of showcase packages from `showcases.json`.
|
|
2
|
+
//
|
|
3
|
+
// Earlier versions read showcases from the CLI's own `package.json#dependencies`
|
|
4
|
+
// — every showcase had to be a direct CLI dependency. That made the CLI tarball
|
|
5
|
+
// blow up with each new showcase and required a CLI rebuild to publish a new
|
|
6
|
+
// one. Static manifest decouples both: the CLI reads the manifest at runtime,
|
|
7
|
+
// `gjsify showcase <name>` delegates to `gjsify dlx <package>`.
|
|
8
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
9
|
import { dirname, join } from 'node:path';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
10
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// @gjsify/example-dom-three-postprocessing-pixel → category=dom, name=three-postprocessing-pixel
|
|
11
|
-
const suffix = packageName.slice(EXAMPLE_PREFIX.length);
|
|
12
|
-
const dashIdx = suffix.indexOf('-');
|
|
13
|
-
if (dashIdx === -1)
|
|
14
|
-
return null;
|
|
15
|
-
return {
|
|
16
|
-
category: suffix.slice(0, dashIdx),
|
|
17
|
-
name: suffix.slice(dashIdx + 1),
|
|
18
|
-
};
|
|
11
|
+
function manifestPath() {
|
|
12
|
+
// `showcases.json` lives at the package root: ../../showcases.json from lib/utils/.
|
|
13
|
+
return join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'showcases.json');
|
|
19
14
|
}
|
|
20
15
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
16
|
+
* Read the curated showcase list from `showcases.json`. Returns showcases
|
|
17
|
+
* sorted by category then name. An empty list (or missing manifest) yields
|
|
18
|
+
* an empty array — `gjsify showcase` then prints the empty-state message.
|
|
23
19
|
*/
|
|
24
20
|
export function discoverShowcases() {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const path = manifestPath();
|
|
22
|
+
if (!existsSync(path))
|
|
23
|
+
return [];
|
|
24
|
+
let manifest;
|
|
28
25
|
try {
|
|
29
|
-
|
|
26
|
+
manifest = JSON.parse(readFileSync(path, 'utf-8'));
|
|
30
27
|
}
|
|
31
28
|
catch {
|
|
32
29
|
return [];
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
if (!deps)
|
|
31
|
+
if (!Array.isArray(manifest.showcases))
|
|
36
32
|
return [];
|
|
37
|
-
const showcases =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
const pkgJsonPath = require.resolve(`${packageName}/package.json`);
|
|
46
|
-
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
47
|
-
const main = pkg['main'];
|
|
48
|
-
if (!main)
|
|
49
|
-
continue;
|
|
50
|
-
showcases.push({
|
|
51
|
-
name: parsed.name,
|
|
52
|
-
packageName,
|
|
53
|
-
category: parsed.category,
|
|
54
|
-
description: pkg['description'] ?? '',
|
|
55
|
-
bundlePath: join(dirname(pkgJsonPath), main),
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// Package listed as dep but not resolvable — skip silently
|
|
60
|
-
}
|
|
61
|
-
}
|
|
33
|
+
const showcases = manifest.showcases.map((e) => ({
|
|
34
|
+
name: e.name,
|
|
35
|
+
packageName: e.package,
|
|
36
|
+
category: e.category,
|
|
37
|
+
description: e.description ?? '',
|
|
38
|
+
needsWebgl: Boolean(e.needsWebgl),
|
|
39
|
+
}));
|
|
62
40
|
showcases.sort((a, b) => a.category.localeCompare(b.category) || a.name.localeCompare(b.name));
|
|
63
41
|
return showcases;
|
|
64
42
|
}
|
|
65
43
|
/** Find a single showcase by short name. */
|
|
66
44
|
export function findShowcase(name) {
|
|
67
|
-
return discoverShowcases().find(e => e.name === name);
|
|
45
|
+
return discoverShowcases().find((e) => e.name === name);
|
|
68
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -23,15 +23,10 @@
|
|
|
23
23
|
"cli"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@gjsify/create-app": "^0.3.
|
|
27
|
-
"@gjsify/esbuild-plugin-gjsify": "^0.3.
|
|
28
|
-
"@gjsify/
|
|
29
|
-
"@gjsify/
|
|
30
|
-
"@gjsify/example-dom-three-geometry-teapot": "^0.3.5",
|
|
31
|
-
"@gjsify/example-dom-three-postprocessing-pixel": "^0.3.5",
|
|
32
|
-
"@gjsify/example-node-express-webserver": "^0.3.5",
|
|
33
|
-
"@gjsify/node-polyfills": "^0.3.5",
|
|
34
|
-
"@gjsify/web-polyfills": "^0.3.5",
|
|
26
|
+
"@gjsify/create-app": "^0.3.6",
|
|
27
|
+
"@gjsify/esbuild-plugin-gjsify": "^0.3.6",
|
|
28
|
+
"@gjsify/node-polyfills": "^0.3.6",
|
|
29
|
+
"@gjsify/web-polyfills": "^0.3.6",
|
|
35
30
|
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
|
|
36
31
|
"cosmiconfig": "^9.0.1",
|
|
37
32
|
"esbuild": "^0.28.0",
|
package/showcases.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"showcases": [
|
|
4
|
+
{
|
|
5
|
+
"name": "canvas2d-fireworks",
|
|
6
|
+
"category": "dom",
|
|
7
|
+
"package": "@gjsify/example-dom-canvas2d-fireworks",
|
|
8
|
+
"description": "Colorful fireworks Canvas 2D example with Adwaita controls",
|
|
9
|
+
"needsWebgl": false
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "excalibur-jelly-jumper",
|
|
13
|
+
"category": "dom",
|
|
14
|
+
"package": "@gjsify/example-dom-excalibur-jelly-jumper",
|
|
15
|
+
"description": "Excalibur.js jelly-jumper game",
|
|
16
|
+
"needsWebgl": false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "three-geometry-teapot",
|
|
20
|
+
"category": "dom",
|
|
21
|
+
"package": "@gjsify/example-dom-three-geometry-teapot",
|
|
22
|
+
"description": "Three.js Utah teapot",
|
|
23
|
+
"needsWebgl": true
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "three-postprocessing-pixel",
|
|
27
|
+
"category": "dom",
|
|
28
|
+
"package": "@gjsify/example-dom-three-postprocessing-pixel",
|
|
29
|
+
"description": "Three.js postprocessing pixel demo",
|
|
30
|
+
"needsWebgl": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "express-webserver",
|
|
34
|
+
"category": "node",
|
|
35
|
+
"package": "@gjsify/example-node-express-webserver",
|
|
36
|
+
"description": "Express web server on GJS via @gjsify/http",
|
|
37
|
+
"needsWebgl": false
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
package/src/actions/build.ts
CHANGED
|
@@ -72,10 +72,16 @@ async function getPnpPlugin(): Promise<Plugin | null> {
|
|
|
72
72
|
};
|
|
73
73
|
let pnpApi: PnpApi | null = null;
|
|
74
74
|
try {
|
|
75
|
-
// pnpapi has no npm package — it is a virtual module injected by
|
|
75
|
+
// pnpapi has no npm package — it is a virtual CJS module injected by
|
|
76
|
+
// Yarn PnP. `await import()` of a CJS module yields the ESM namespace
|
|
77
|
+
// `{ default, "module.exports" }`, NOT the exports object — so
|
|
78
|
+
// `mod.resolveRequest` is `undefined`. Unwrap `.default` (the CJS
|
|
79
|
+
// exports) before use, falling back to the namespace itself for ESM
|
|
80
|
+
// builds of pnpapi (none today, but defensive).
|
|
76
81
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
77
82
|
// @ts-expect-error
|
|
78
|
-
|
|
83
|
+
const mod = await import("pnpapi");
|
|
84
|
+
pnpApi = ((mod as { default?: PnpApi }).default ?? mod) as PnpApi;
|
|
79
85
|
} catch {
|
|
80
86
|
// Not in a PnP runtime (shouldn't happen since findPnpRoot passed)
|
|
81
87
|
}
|
package/src/commands/index.ts
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// `gjsify install [pkg...]` — thin npm wrapper with gjsify-aware post-checks.
|
|
2
|
+
//
|
|
3
|
+
// The actual install is delegated to `npm install` in the user's project root
|
|
4
|
+
// (no `--prefix` rewrite, unlike `gjsify dlx`). After install completes we run
|
|
5
|
+
// `runMinimalChecks()` so missing system deps (gjs, gtk4, libsoup, ...) surface
|
|
6
|
+
// immediately, and report any installed `@gjsify/*` packages that ship native
|
|
7
|
+
// prebuilds so users know they can use `gjsify run` to wire `LD_LIBRARY_PATH` /
|
|
8
|
+
// `GI_TYPELIB_PATH` automatically.
|
|
9
|
+
//
|
|
10
|
+
// Modes:
|
|
11
|
+
// gjsify install → project install (npm install)
|
|
12
|
+
// gjsify install <pkg> [<pkg>...] → add package(s) (npm install <pkg>...)
|
|
13
|
+
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import type { Command } from '../types/index.js';
|
|
16
|
+
import {
|
|
17
|
+
buildInstallCommand,
|
|
18
|
+
detectPackageManager,
|
|
19
|
+
runMinimalChecks,
|
|
20
|
+
} from '../utils/check-system-deps.js';
|
|
21
|
+
import { detectNativePackages } from '../utils/detect-native-packages.js';
|
|
22
|
+
|
|
23
|
+
interface InstallOptions {
|
|
24
|
+
packages?: string[];
|
|
25
|
+
'save-dev'?: boolean;
|
|
26
|
+
'save-peer'?: boolean;
|
|
27
|
+
'save-optional'?: boolean;
|
|
28
|
+
verbose: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const installCommand: Command<any, InstallOptions> = {
|
|
32
|
+
command: 'install [packages..]',
|
|
33
|
+
description:
|
|
34
|
+
'Install npm dependencies in the current project, then run gjsify-aware post-checks.',
|
|
35
|
+
builder: (yargs) =>
|
|
36
|
+
yargs
|
|
37
|
+
.positional('packages', {
|
|
38
|
+
description: 'Optional package specs. With none, runs a full project install.',
|
|
39
|
+
type: 'string',
|
|
40
|
+
array: true,
|
|
41
|
+
})
|
|
42
|
+
.option('save-dev', { type: 'boolean', alias: 'D' })
|
|
43
|
+
.option('save-peer', { type: 'boolean' })
|
|
44
|
+
.option('save-optional', { type: 'boolean', alias: 'O' })
|
|
45
|
+
.option('verbose', {
|
|
46
|
+
description: 'Verbose npm logging.',
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
default: false,
|
|
49
|
+
}),
|
|
50
|
+
handler: async (args) => {
|
|
51
|
+
const npmArgs = ['install'];
|
|
52
|
+
if (args['save-dev']) npmArgs.push('--save-dev');
|
|
53
|
+
if (args['save-peer']) npmArgs.push('--save-peer');
|
|
54
|
+
if (args['save-optional']) npmArgs.push('--save-optional');
|
|
55
|
+
if (args.verbose) npmArgs.push('--loglevel', 'verbose');
|
|
56
|
+
if (args.packages && args.packages.length > 0) {
|
|
57
|
+
npmArgs.push(...args.packages);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await spawnNpm(npmArgs);
|
|
61
|
+
|
|
62
|
+
await runPostInstallChecks();
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
async function spawnNpm(npmArgs: string[]): Promise<void> {
|
|
67
|
+
return new Promise<void>((resolve, reject) => {
|
|
68
|
+
const child = spawn('npm', npmArgs, { stdio: 'inherit' });
|
|
69
|
+
child.on('close', (code) => {
|
|
70
|
+
if (code === 0) resolve();
|
|
71
|
+
else reject(new Error(`npm install exited with code ${code}`));
|
|
72
|
+
});
|
|
73
|
+
child.on('error', (err) => {
|
|
74
|
+
const code = (err as NodeJS.ErrnoException).code;
|
|
75
|
+
const msg = code === 'ENOENT'
|
|
76
|
+
? 'npm not found on PATH — install Node.js first.'
|
|
77
|
+
: `npm install failed: ${err.message}`;
|
|
78
|
+
reject(new Error(msg));
|
|
79
|
+
});
|
|
80
|
+
}).catch((err: Error) => {
|
|
81
|
+
console.error(err.message);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function runPostInstallChecks(): Promise<void> {
|
|
87
|
+
console.log('\n--- gjsify post-install checks ---');
|
|
88
|
+
|
|
89
|
+
// 1. System deps that GJS apps typically need.
|
|
90
|
+
const results = runMinimalChecks();
|
|
91
|
+
const missing = results.filter((r) => !r.found && r.severity === 'required');
|
|
92
|
+
if (missing.length > 0) {
|
|
93
|
+
console.warn('Missing required system dependencies:\n');
|
|
94
|
+
for (const dep of missing) {
|
|
95
|
+
console.warn(` ✗ ${dep.name}`);
|
|
96
|
+
}
|
|
97
|
+
const pm = detectPackageManager();
|
|
98
|
+
const cmd = buildInstallCommand(pm, missing);
|
|
99
|
+
if (cmd) console.warn(`\nInstall with:\n ${cmd}`);
|
|
100
|
+
} else {
|
|
101
|
+
console.log('System dependencies OK.');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 2. Surface @gjsify/* packages with native prebuilds — `gjsify run`
|
|
105
|
+
// will set LD_LIBRARY_PATH / GI_TYPELIB_PATH for these automatically.
|
|
106
|
+
const native = detectNativePackages(process.cwd());
|
|
107
|
+
if (native.length > 0) {
|
|
108
|
+
console.log(
|
|
109
|
+
`\nDetected ${native.length} @gjsify/* package(s) with native prebuilds:`,
|
|
110
|
+
);
|
|
111
|
+
for (const pkg of native) {
|
|
112
|
+
console.log(` • ${pkg.name}`);
|
|
113
|
+
}
|
|
114
|
+
console.log('\nUse `gjsify run <bundle>` to launch with LD_LIBRARY_PATH/GI_TYPELIB_PATH set.');
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/commands/showcase.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Command } from '../types/index.js';
|
|
2
2
|
import { discoverShowcases, findShowcase } from '../utils/discover-showcases.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
runMinimalChecks,
|
|
5
|
+
checkGwebgl,
|
|
6
|
+
detectPackageManager,
|
|
7
|
+
buildInstallCommand,
|
|
8
|
+
} from '../utils/check-system-deps.js';
|
|
9
|
+
import { spawn } from 'node:child_process';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
5
11
|
|
|
6
12
|
interface ShowcaseOptions {
|
|
7
13
|
name?: string;
|
|
@@ -11,9 +17,9 @@ interface ShowcaseOptions {
|
|
|
11
17
|
|
|
12
18
|
export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
13
19
|
command: 'showcase [name]',
|
|
14
|
-
description: 'List or run
|
|
15
|
-
builder: (yargs) =>
|
|
16
|
-
|
|
20
|
+
description: 'List or run curated gjsify showcase applications.',
|
|
21
|
+
builder: (yargs) =>
|
|
22
|
+
yargs
|
|
17
23
|
.positional('name', {
|
|
18
24
|
description: 'Showcase name to run (omit to list all)',
|
|
19
25
|
type: 'string',
|
|
@@ -27,8 +33,7 @@ export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
|
27
33
|
description: 'List available showcases',
|
|
28
34
|
type: 'boolean',
|
|
29
35
|
default: false,
|
|
30
|
-
})
|
|
31
|
-
},
|
|
36
|
+
}),
|
|
32
37
|
handler: async (args) => {
|
|
33
38
|
// List mode: no name given, or --list flag
|
|
34
39
|
if (!args.name || args.list) {
|
|
@@ -40,11 +45,10 @@ export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
if (showcases.length === 0) {
|
|
43
|
-
console.log('No showcases found.
|
|
48
|
+
console.log('No showcases found. The CLI ships a curated list in `showcases.json`; if it is missing the CLI install is incomplete.');
|
|
44
49
|
return;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
// Group by category
|
|
48
52
|
const grouped = new Map<string, typeof showcases>();
|
|
49
53
|
for (const sc of showcases) {
|
|
50
54
|
const list = grouped.get(sc.category) ?? [];
|
|
@@ -55,7 +59,7 @@ export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
|
55
59
|
console.log('Available gjsify showcases:\n');
|
|
56
60
|
for (const [category, list] of grouped) {
|
|
57
61
|
console.log(` ${category.toUpperCase()}:`);
|
|
58
|
-
const maxNameLen = Math.max(...list.map(e => e.name.length));
|
|
62
|
+
const maxNameLen = Math.max(...list.map((e) => e.name.length));
|
|
59
63
|
for (const sc of list) {
|
|
60
64
|
const pad = ' '.repeat(maxNameLen - sc.name.length + 2);
|
|
61
65
|
const desc = sc.description ? `${pad}${sc.description}` : '';
|
|
@@ -68,7 +72,6 @@ export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
// Run mode: find the showcase
|
|
72
75
|
const showcase = findShowcase(args.name);
|
|
73
76
|
if (!showcase) {
|
|
74
77
|
console.error(`Unknown showcase: "${args.name}"`);
|
|
@@ -76,16 +79,14 @@ export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
|
76
79
|
process.exit(1);
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
// System dependency check before
|
|
80
|
-
// All showcases need GJS; WebGL showcases additionally need gwebgl prebuilds.
|
|
82
|
+
// System dependency check before delegating — only what this showcase needs.
|
|
81
83
|
const results = runMinimalChecks();
|
|
82
|
-
|
|
83
|
-
if (needsWebgl) {
|
|
84
|
+
if (showcase.needsWebgl) {
|
|
84
85
|
results.push(checkGwebgl(process.cwd()));
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const missingHard = results.filter(
|
|
88
|
+
(r) => !r.found && (r.severity === 'required' || r.id === 'gwebgl'),
|
|
89
|
+
);
|
|
89
90
|
if (missingHard.length > 0) {
|
|
90
91
|
console.error('Missing system dependencies:\n');
|
|
91
92
|
for (const dep of missingHard) {
|
|
@@ -99,8 +100,26 @@ export const showcaseCommand: Command<any, ShowcaseOptions> = {
|
|
|
99
100
|
process.exit(1);
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
// Delegate to `gjsify dlx <package>` — same npm-cache, same atomic
|
|
104
|
+
// symlink-swap, same `gjsify.main` resolution. Re-spawning the CLI
|
|
105
|
+
// keeps the dlx logic in one place.
|
|
106
|
+
console.log(`Running showcase: ${showcase.name} (via gjsify dlx)\n`);
|
|
107
|
+
const cliBin = fileURLToPath(new URL('../index.js', import.meta.url));
|
|
108
|
+
const child = spawn(process.execPath, [cliBin, 'dlx', showcase.packageName], {
|
|
109
|
+
stdio: 'inherit',
|
|
110
|
+
});
|
|
111
|
+
await new Promise<void>((resolvePromise, reject) => {
|
|
112
|
+
child.on('close', (code) => {
|
|
113
|
+
if (code !== 0) {
|
|
114
|
+
reject(new Error(`gjsify dlx exited with code ${code}`));
|
|
115
|
+
} else {
|
|
116
|
+
resolvePromise();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
child.on('error', reject);
|
|
120
|
+
}).catch((err) => {
|
|
121
|
+
console.error(err.message);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
});
|
|
105
124
|
},
|
|
106
125
|
};
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
gresourceCommand as gresource,
|
|
13
13
|
gettextCommand as gettext,
|
|
14
14
|
dlxCommand as dlx,
|
|
15
|
+
installCommand as install,
|
|
15
16
|
} from './commands/index.js'
|
|
16
17
|
import { APP_NAME } from './constants.js'
|
|
17
18
|
|
|
@@ -19,6 +20,7 @@ void yargs(hideBin(process.argv))
|
|
|
19
20
|
.scriptName(APP_NAME)
|
|
20
21
|
.strict()
|
|
21
22
|
.command(create.command, create.description, create.builder, create.handler)
|
|
23
|
+
.command(install.command, install.description, install.builder, install.handler)
|
|
22
24
|
.command(build.command, build.description, build.builder, build.handler)
|
|
23
25
|
.command(run.command, run.description, run.builder, run.handler)
|
|
24
26
|
.command(dlx.command, dlx.description, dlx.builder, dlx.handler)
|
|
@@ -159,8 +159,13 @@ const PACKAGE_DEPS: Record<string, string[]> = {
|
|
|
159
159
|
'@gjsify/canvas2d': ['gdk-pixbuf', 'pango', 'pangocairo', 'cairo'],
|
|
160
160
|
'@gjsify/canvas2d-core': ['gdk-pixbuf', 'pango', 'pangocairo', 'cairo'],
|
|
161
161
|
'@gjsify/dom-elements': ['gdk-pixbuf'],
|
|
162
|
-
// @gjsify/webgl
|
|
163
|
-
//
|
|
162
|
+
// @gjsify/webgl needs the gwebgl npm package (Vala prebuild) — handled
|
|
163
|
+
// as a special-case checkNpmPackage rather than checkPkgConfig in
|
|
164
|
+
// runOptionalChecks. Mapping it here so its presence in the project's
|
|
165
|
+
// dep tree triggers the check.
|
|
166
|
+
'@gjsify/webgl': ['gwebgl'],
|
|
167
|
+
// @gjsify/event-bridge only needs gtk4/gdk which are already in the
|
|
168
|
+
// required set, so it doesn't need an optional entry.
|
|
164
169
|
};
|
|
165
170
|
|
|
166
171
|
/** Walk up from cwd looking for the nearest package.json. */
|
|
@@ -322,10 +327,16 @@ function runOptionalChecks(needed: Set<string> | null, cwd: string): DepCheck[]
|
|
|
322
327
|
results.push(checkPkgConfig(dep.id, dep.name, dep.pkgName, 'optional', requiredBy));
|
|
323
328
|
}
|
|
324
329
|
|
|
325
|
-
// gwebgl npm package — special case (not a pkg-config lib).
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
|
|
330
|
+
// gwebgl npm package — special case (not a pkg-config lib). Only checked
|
|
331
|
+
// when the project directly or transitively depends on @gjsify/webgl —
|
|
332
|
+
// since the CLI tarball no longer ships any showcase example packages,
|
|
333
|
+
// gwebgl is not part of the CLI's own dep tree, so reporting it for every
|
|
334
|
+
// project would always be `found: false`. `needed === null` means "check
|
|
335
|
+
// everything" (no project context).
|
|
336
|
+
const hasWebglDep = needed === null || needed.has('gwebgl');
|
|
337
|
+
if (hasWebglDep) {
|
|
338
|
+
results.push(checkGwebgl(cwd));
|
|
339
|
+
}
|
|
329
340
|
|
|
330
341
|
return results;
|
|
331
342
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// Static discovery of showcase packages from `showcases.json`.
|
|
2
|
+
//
|
|
3
|
+
// Earlier versions read showcases from the CLI's own `package.json#dependencies`
|
|
4
|
+
// — every showcase had to be a direct CLI dependency. That made the CLI tarball
|
|
5
|
+
// blow up with each new showcase and required a CLI rebuild to publish a new
|
|
6
|
+
// one. Static manifest decouples both: the CLI reads the manifest at runtime,
|
|
7
|
+
// `gjsify showcase <name>` delegates to `gjsify dlx <package>`.
|
|
3
8
|
|
|
4
|
-
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
10
|
import { dirname, join } from 'node:path';
|
|
6
|
-
import { createRequire } from 'node:module';
|
|
7
11
|
import { fileURLToPath } from 'node:url';
|
|
8
12
|
|
|
9
13
|
export interface ShowcaseInfo {
|
|
@@ -13,68 +17,53 @@ export interface ShowcaseInfo {
|
|
|
13
17
|
packageName: string;
|
|
14
18
|
/** Category: "dom" or "node" */
|
|
15
19
|
category: string;
|
|
16
|
-
/** Description
|
|
20
|
+
/** Description for the list view */
|
|
17
21
|
description: string;
|
|
18
|
-
/**
|
|
19
|
-
|
|
22
|
+
/** Whether the showcase needs the gwebgl native prebuild. */
|
|
23
|
+
needsWebgl: boolean;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
interface ManifestEntry {
|
|
27
|
+
name: string;
|
|
28
|
+
package: string;
|
|
29
|
+
category: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
needsWebgl?: boolean;
|
|
32
|
+
}
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
category: suffix.slice(0, dashIdx),
|
|
32
|
-
name: suffix.slice(dashIdx + 1),
|
|
33
|
-
};
|
|
34
|
+
interface Manifest {
|
|
35
|
+
showcases: ManifestEntry[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function manifestPath(): string {
|
|
39
|
+
// `showcases.json` lives at the package root: ../../showcases.json from lib/utils/.
|
|
40
|
+
return join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'showcases.json');
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
44
|
+
* Read the curated showcase list from `showcases.json`. Returns showcases
|
|
45
|
+
* sorted by category then name. An empty list (or missing manifest) yields
|
|
46
|
+
* an empty array — `gjsify showcase` then prints the empty-state message.
|
|
39
47
|
*/
|
|
40
48
|
export function discoverShowcases(): ShowcaseInfo[] {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
const path = manifestPath();
|
|
50
|
+
if (!existsSync(path)) return [];
|
|
51
|
+
|
|
52
|
+
let manifest: Manifest;
|
|
44
53
|
try {
|
|
45
|
-
|
|
54
|
+
manifest = JSON.parse(readFileSync(path, 'utf-8')) as Manifest;
|
|
46
55
|
} catch {
|
|
47
56
|
return [];
|
|
48
57
|
}
|
|
58
|
+
if (!Array.isArray(manifest.showcases)) return [];
|
|
49
59
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const parsed = parseShowcaseName(packageName);
|
|
59
|
-
if (!parsed) continue;
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const pkgJsonPath = require.resolve(`${packageName}/package.json`);
|
|
63
|
-
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8')) as Record<string, unknown>;
|
|
64
|
-
const main = pkg['main'] as string | undefined;
|
|
65
|
-
if (!main) continue;
|
|
66
|
-
|
|
67
|
-
showcases.push({
|
|
68
|
-
name: parsed.name,
|
|
69
|
-
packageName,
|
|
70
|
-
category: parsed.category,
|
|
71
|
-
description: (pkg['description'] as string) ?? '',
|
|
72
|
-
bundlePath: join(dirname(pkgJsonPath), main),
|
|
73
|
-
});
|
|
74
|
-
} catch {
|
|
75
|
-
// Package listed as dep but not resolvable — skip silently
|
|
76
|
-
}
|
|
77
|
-
}
|
|
60
|
+
const showcases: ShowcaseInfo[] = manifest.showcases.map((e) => ({
|
|
61
|
+
name: e.name,
|
|
62
|
+
packageName: e.package,
|
|
63
|
+
category: e.category,
|
|
64
|
+
description: e.description ?? '',
|
|
65
|
+
needsWebgl: Boolean(e.needsWebgl),
|
|
66
|
+
}));
|
|
78
67
|
|
|
79
68
|
showcases.sort((a, b) => a.category.localeCompare(b.category) || a.name.localeCompare(b.name));
|
|
80
69
|
return showcases;
|
|
@@ -82,5 +71,5 @@ export function discoverShowcases(): ShowcaseInfo[] {
|
|
|
82
71
|
|
|
83
72
|
/** Find a single showcase by short name. */
|
|
84
73
|
export function findShowcase(name: string): ShowcaseInfo | undefined {
|
|
85
|
-
return discoverShowcases().find(e => e.name === name);
|
|
74
|
+
return discoverShowcases().find((e) => e.name === name);
|
|
86
75
|
}
|