@niscorp/cli 0.1.0 → 0.2.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @niscorp/cli
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3a9866e: `nisc dev` starts the app's own vite itself (`--port`), and for an app behind moss adds moss's dev plugin fed from `nisc.config.ts` — the same boot and drawing `build` and `start` use. An app's `vite.config.ts` no longer carries any server glue. `NiscMossProject.dev.signIn(server, who)` makes `/dev/as/<who>` a signed-in URL in development.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [3a9866e]
12
+ - @niscorp/moss@0.2.0
package/README.md CHANGED
@@ -6,6 +6,9 @@
6
6
  pnpm add -D @niscorp/cli
7
7
  ```
8
8
 
9
+ A new app starts with `npm create nisc`, which writes the `nisc.config.ts`
10
+ described below.
11
+
9
12
  ```bash
10
13
  nisc dev # the app's dev server
11
14
  nisc build # bundle the app, draw every path, and check what was drawn
@@ -203,10 +206,29 @@ manifest page at its path. A signed-in person gets their screen in the markup
203
206
  (`private, no-store`); nobody gets the page as nobody sees it. `--port <n>`, or
204
207
  `$PORT`, default 8787.
205
208
 
206
- ## `nisc dev`, `nisc check`
209
+ ## `nisc dev`
210
+
211
+ The app's own vite, started from here (`--port <n>`). For an app behind moss
212
+ the app server runs inside it — moss's dev plugin (`@niscorp/moss/vite`), fed
213
+ from `nisc.config.ts`, so the dev server boots and draws exactly what `build`
214
+ and `start` do:
215
+
216
+ - `/`, and every page's path, is answered with its first screen drawn — and is
217
+ still a vite page (its client, the framework's refresh preamble);
218
+ - moss's own paths (`/api`, `/catalog`, the socket, …) go to the app server,
219
+ everything else to vite;
220
+ - an edit under `src/app`, `src/server`, `src/db`, `src/ui` or to the config
221
+ re-boots the app (a fresh database, fresh shells) and reloads the page — the
222
+ old server answers until the new one is up;
223
+ - `dev.signIn(server, who)` in the config, if the app gives one, makes
224
+ `/dev/as/<who>` a signed-in URL — in the dev server and nowhere else.
225
+
226
+ The app's `vite.config.ts` holds its framework's plugin and nothing about the
227
+ server. An app with its own shell is a vite app and nothing more.
228
+
229
+ ## `nisc check`
207
230
 
208
- Hand over to tools the app already has: its vite config (which hosts the app
209
- server, so pages are drawn in dev too), and its check suite.
231
+ The app's check suite (`src/dev/all-checks.ts`, or `checks` in the config).
210
232
 
211
233
  ## Options
212
234
 
package/dist/adopt.js CHANGED
@@ -30,7 +30,7 @@ var main = async () => {
30
30
  const [root, asked, answered] = process.argv.slice(2);
31
31
  if (root === void 0 || asked === void 0 || answered === void 0) throw new Error("usage: adopt <root> <pages.json> <answer.json>");
32
32
  standDom(root);
33
- const { isShellProject, loadProject } = await import('./project-JL74OSJC.js');
33
+ const { isShellProject, loadProject } = await import('./project-PODTS3SZ.js');
34
34
  const project = await loadProject(root);
35
35
  if (!isShellProject(project)) throw new Error("nisc: this app has no shell of its own to adopt with.");
36
36
  const pages = JSON.parse(readFileSync(asked, "utf8"));
@@ -11,8 +11,10 @@ var isProject = (value) => {
11
11
  const [moss, own] = [has(value, "boot"), has(value, "shell")];
12
12
  return moss !== own && (moss || has(value, "adopt"));
13
13
  };
14
+ var configFileOf = (root) => CONFIG_NAMES.find((name) => existsSync(join(root, name)));
14
15
  var loadProject = async (root) => {
15
- const file = CONFIG_NAMES.map((name) => join(root, name)).find((candidate) => existsSync(candidate));
16
+ const name = configFileOf(root);
17
+ const file = name === void 0 ? void 0 : join(root, name);
16
18
  if (file === void 0) {
17
19
  throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \`project\`: how the app boots, and how one of its screens is drawn.`);
18
20
  }
@@ -28,6 +30,6 @@ var loadProject = async (root) => {
28
30
  return project;
29
31
  };
30
32
 
31
- export { isShellProject, loadProject };
32
- //# sourceMappingURL=chunk-E73LP64A.js.map
33
- //# sourceMappingURL=chunk-E73LP64A.js.map
33
+ export { configFileOf, isProject, isShellProject, loadProject };
34
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AA,EAA8B,IAAI,CAAA,iFAAA,CAAmF,CAAA;AAAA,EACvI;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAM,OAAO,aAAa,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,IAAA,EAAM,eAAe,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAkB,MAAM,QAAA,CAAS,aAAA,CAAc,IAAI,CAAA,CAAE,IAAA,EAAM,EAAE,SAAA,EAAW,MAAA,CAAA,IAAA,CAAY,KAAK,GAAI,UAAA,CAAW,QAAQ,CAAA,GAAI,EAAE,UAAS,GAAI,IAAK,CAAA;AAC9I,EAAA,MAAM,OAAA,GAAmB,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,SAAS,CAAA,GAAI,MAAA;AAC1G,EAAA,IAAI,CAAC,SAAA,CAAU,OAAO,CAAA,EAAG;AACvB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,SAAS,IAAI,CAAA,kLAAA;AAAA,KACf;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-MRNC4GI5.js","sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { DocumentConfig, MossServer } from '@niscorp/moss';\nimport type { Shell } from '@niscorp/nova';\n\n// ═══════════════════════════════════════════════════════════════\n// WHAT AN APP SAYS ABOUT ITSELF — `nisc.config.ts`, at the app's root, exporting\n// `project`. What only the app knows: how it stands up, and how one of its\n// screens is drawn. Everything the command does is derived from those.\n//\n// An app is one of two things, and its config says which by what it hands over.\n//\n// BEHIND MOSS — the shell lives on the server. The config hands over the\n// server; which paths exist and what each needs is read off its manifest.\n//\n// export const project: NiscProject = {\n// boot: async () => ({ server: (await boot()).server }),\n// draw: (snapshot) => renderSnapshot({ snapshot, registry, slotWrapper }),\n// };\n//\n// ITS OWN SHELL — the shell lives in the page (AGENTS.md, \"the client-degrade\n// path\"). The config hands over the app's own boot, the SAME one its browser\n// entry runs. A build runs it where there is no browser, draws the screen to\n// markup, and the page's boot picks that markup up.\n//\n// export const project: NiscShellProject = {\n// shell: async () => ({ shell: (await boot()).shell }),\n// draw: (shell) => renderToString(createElement(Screen, { shell })),\n// adopt: (root, shell) => { hydrateRoot(root, createElement(Screen, { shell })); },\n// };\n// ═══════════════════════════════════════════════════════════════\n\ntype Common = {\n // Where the bundler writes the terminal (default `dist`), relative to the root.\n dist?: string;\n // The app's check suite, for `nisc check` (default `src/dev/all-checks.ts`).\n checks?: string;\n};\n\nexport type NiscMossProject = Common & {\n // Stand the app up: the moss server, and how to let it go again. The same boot\n // the app's dev server and its checks run.\n boot: () => Promise<{ server: MossServer; close?: () => void | Promise<void> }>;\n // A terminal that draws one screen to a string — the app's kit bound to one of\n // moss's server targets (`@niscorp/moss/terminal/react/server`, …).\n draw: DocumentConfig['draw'];\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: DocumentConfig['htmlAttributes'];\n // The wire's token key, when it is not `nisc.token`.\n tokenKey?: string;\n // The paths to build. Default: `/`, and every page whose path has no\n // parameter. A page with parameters (\"/docs/:slug\") has as many paths as there\n // are rows, and only the app knows them — list them here (`server.executeAs`\n // runs a seeded read as a charter role).\n paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;\n // Routes of the app's own that a served site needs before the catch-all — a\n // sign-in handoff, a webhook. `nisc start` registers them first.\n routes?: (server: MossServer) => void | Promise<void>;\n // What only `nisc dev` uses.\n dev?: {\n // A signed-in URL in development: `/dev/as/<who>` stores the token this\n // mints and goes to `/`. `null` is nobody of that name. It exists in the\n // dev server and nowhere else.\n signIn?: (server: MossServer, who: string) => string | null | Promise<string | null>;\n };\n};\n\nexport type NiscShellProject = Common & {\n // One fresh copy of the app's shell, for one path — the boot the browser entry\n // runs. It is handed the path and NOTHING ELSE: there is no credential to pass\n // and no way to pass one, so what a build draws is the screen as nobody in\n // particular sees it. Called more than once per path (the build boots twice\n // to compare, and once more inside a DOM to adopt), so it must not memoize.\n shell: (request: { path: string }) => Promise<{ shell: Shell; close?: () => void | Promise<void> }>;\n // Draw a shell to markup where there is no browser: the app's kit through an\n // adapter's string target (`react-dom/server`, `vue/server-renderer`,\n // `@niscorp/nova/adapters/dom/server`).\n draw: (shell: Shell) => string | Promise<string>;\n // Pick the markup up: `root` already holds it, `shell` is the page's own. The\n // SAME call the browser entry makes (`hydrateRoot`, `createSSRApp().mount`,\n // nova's `mountShell`). A build runs it inside a DOM and fails on anything it\n // complains about.\n adopt: (root: HTMLElement, shell: Shell) => void | Promise<void>;\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: (shell: Shell) => Record<string, string>;\n // The paths to build (default: `/`). An app that maps paths to actions lists\n // its own — only it knows them.\n paths?: () => readonly string[] | Promise<readonly string[]>;\n // How long a build waits for a screen to be whole (default 5000ms). Past it\n // the build FAILS: a file that says \"loading\" is not the page.\n waitMs?: number;\n};\n\n// What a config exports. Written against one of the two names above, a config's\n// callbacks are typed for it (`draw`'s argument is a snapshot in one and a shell\n// in the other).\nexport type NiscProject = NiscMossProject | NiscShellProject;\n\nconst CONFIG_NAMES = ['nisc.config.ts', 'nisc.config.mts', 'nisc.config.js', 'nisc.config.mjs'];\n\nconst has = (value: object, key: string): boolean => typeof Reflect.get(value, key) === 'function';\n\nexport const isShellProject = (project: NiscProject): project is NiscShellProject => 'shell' in project;\n\nexport const isProject = (value: unknown): value is NiscProject => {\n if (value === null || typeof value !== 'object' || !has(value, 'draw')) return false;\n const [moss, own] = [has(value, 'boot'), has(value, 'shell')];\n // one or the other — a config that hands over both has not said which it is\n return moss !== own && (moss || has(value, 'adopt'));\n};\n\n// The config's file name, if the app has one.\nexport const configFileOf = (root: string): string | undefined => CONFIG_NAMES.find((name) => existsSync(join(root, name)));\n\n// Load the app's config through tsx, so it is TypeScript with the app's own\n// tsconfig (its path aliases included) — the way the app's checks already run.\nexport const loadProject = async (root: string): Promise<NiscProject> => {\n const name = configFileOf(root);\n const file = name === undefined ? undefined : join(root, name);\n if (file === undefined) {\n throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \\`project\\`: how the app boots, and how one of its screens is drawn.`);\n }\n const { tsImport } = await import('tsx/esm/api');\n const tsconfig = join(root, 'tsconfig.json');\n const loaded: unknown = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...(existsSync(tsconfig) ? { tsconfig } : {}) });\n const project: unknown = loaded !== null && typeof loaded === 'object' ? Reflect.get(loaded, 'project') : undefined;\n if (!isProject(project)) {\n throw new Error(\n `nisc: ${file} does not export a \\`project\\` the command can run. It hands over EITHER \\`boot\\` + \\`draw\\` (an app behind moss) OR \\`shell\\` + \\`draw\\` + \\`adopt\\` (an app with its own shell).`,\n );\n }\n return project;\n};\n"]}
package/dist/cli.js CHANGED
@@ -1,14 +1,62 @@
1
- import { loadProject, isShellProject } from './chunk-TCI624CB.js';
2
- import { resolve, join, dirname, sep, extname } from 'path';
1
+ import { loadProject, isShellProject, configFileOf, isProject } from './chunk-MRNC4GI5.js';
2
+ import { resolve, join, sep, extname, dirname } from 'path';
3
3
  import { spawn, spawnSync } from 'child_process';
4
- import { existsSync, readFileSync, rmSync, cpSync, mkdirSync, writeFileSync, statSync, mkdtempSync } from 'fs';
4
+ import { existsSync, statSync, readFileSync, rmSync, cpSync, mkdirSync, writeFileSync, mkdtempSync } from 'fs';
5
5
  import { createRequire } from 'module';
6
6
  import { serve } from '@hono/node-server';
7
+ import { pathToFileURL, fileURLToPath } from 'url';
7
8
  import { tmpdir } from 'os';
8
- import { fileURLToPath } from 'url';
9
9
  import { shellSettled } from '@niscorp/nova';
10
10
  import { livenessOf } from '@niscorp/nova/reflect';
11
11
 
12
+ var isViteApi = (value) => value !== null && typeof value === "object" && typeof Reflect.get(value, "createServer") === "function";
13
+ var viteOf = async (root) => {
14
+ let entry;
15
+ try {
16
+ entry = createRequire(join(root, "package.json")).resolve("vite");
17
+ } catch {
18
+ throw new Error(`nisc: this app has no vite installed (looked from ${root}).`);
19
+ }
20
+ const loaded = await import(pathToFileURL(entry).href);
21
+ if (!isViteApi(loaded)) throw new Error(`nisc: ${entry} is not vite.`);
22
+ return loaded;
23
+ };
24
+ var mossPlugin = async (configFile) => {
25
+ const { mossDev } = await import('@niscorp/moss/vite');
26
+ return mossDev({
27
+ label: "nisc",
28
+ app: async (load) => {
29
+ const loaded = await load(`/${configFile}`);
30
+ const project = Reflect.get(loaded, "project");
31
+ if (!isProject(project) || isShellProject(project)) throw new Error(`nisc: ${configFile} no longer describes an app behind moss.`);
32
+ const booted = await project.boot();
33
+ const signIn = project.dev?.signIn;
34
+ return {
35
+ server: booted.server,
36
+ ...booted.close !== void 0 ? { close: booted.close } : {},
37
+ draw: project.draw,
38
+ ...project.htmlAttributes !== void 0 ? { htmlAttributes: project.htmlAttributes } : {},
39
+ ...project.tokenKey !== void 0 ? { tokenKey: project.tokenKey } : {},
40
+ ...signIn !== void 0 ? { signIn: (who) => signIn(booted.server, who) } : {}
41
+ };
42
+ }
43
+ });
44
+ };
45
+ var devServer = async (options) => {
46
+ const project = await loadProject(options.root);
47
+ const configFile = configFileOf(options.root);
48
+ const vite = await viteOf(options.root);
49
+ const server = await vite.createServer({
50
+ root: options.root,
51
+ ...options.port !== void 0 ? { server: { port: options.port } } : {},
52
+ plugins: isShellProject(project) || configFile === void 0 ? [] : [await mossPlugin(configFile)]
53
+ });
54
+ await server.listen();
55
+ server.printUrls();
56
+ const url = server.resolvedUrls?.local[0] ?? `http://localhost:${options.port ?? 5173}/`;
57
+ return { url, close: () => server.close() };
58
+ };
59
+
12
60
  // src/routes.ts
13
61
  var defaultPaths = (pages) => [
14
62
  "/",
@@ -349,7 +397,7 @@ var handOver = (options, tool, args) => new Promise((done) => {
349
397
  const child = spawn(process.execPath, [tool, ...args], { cwd: options.root, stdio: "inherit" });
350
398
  child.once("exit", (code) => done(code ?? 1));
351
399
  });
352
- var dev = (options) => handOver(options, toolOf(options.root, "vite", "vite"), []);
400
+ var dev = (options) => devServer({ root: options.root, ...options.port !== void 0 ? { port: options.port } : {} });
353
401
  var check = async (options) => {
354
402
  const project = await loadProject(options.root);
355
403
  return handOver(options, toolOf(options.root, "tsx", "tsx"), [project.checks ?? "src/dev/all-checks.ts"]);
@@ -358,7 +406,7 @@ var check = async (options) => {
358
406
  // src/cli.ts
359
407
  var USAGE = `nisc \u2014 the command for a nisc application
360
408
 
361
- nisc dev the app's dev server
409
+ nisc dev the app's dev server \u2014 its vite, with the app server inside
362
410
  nisc build bundle the app, draw every path, and check what was drawn
363
411
  nisc export build, then write every path as a file (the site as a folder)
364
412
  nisc start serve the built app, each path's first screen drawn
@@ -367,7 +415,7 @@ var USAGE = `nisc \u2014 the command for a nisc application
367
415
  --root <dir> the app's root (default: here) \u2014 where nisc.config.ts is
368
416
  --out <dir> export: where the files go (default: out)
369
417
  --allow-live export: write even though some path wants a server behind it
370
- --port <n> start: the port (default: $PORT, then 8787)
418
+ --port <n> dev, start: the port (start: $PORT, then 8787)
371
419
  --skip-bundle build, export: the terminal is already built
372
420
 
373
421
  An app says in nisc.config.ts how it boots and how one of its screens is drawn.
@@ -389,14 +437,8 @@ var main = async () => {
389
437
  allowLive: args.includes("--allow-live"),
390
438
  skipBundle: args.includes("--skip-bundle")
391
439
  };
392
- if (command === "dev") return dev(options);
393
- if (command === "check") return check(options);
394
- if (command === "build") {
395
- return (await build(options)).ok ? 0 : 1;
396
- }
397
- if (command === "export") return (await exportSite(options)).written ? 0 : 1;
398
- if (command === "start") {
399
- const served = await start(options);
440
+ if (command === "dev" || command === "start") {
441
+ const served = command === "dev" ? await dev(options) : await start(options);
400
442
  const stop = () => {
401
443
  void served.close().finally(() => process.exit(0));
402
444
  };
@@ -404,6 +446,11 @@ var main = async () => {
404
446
  process.on("SIGTERM", stop);
405
447
  return new Promise(() => void 0);
406
448
  }
449
+ if (command === "check") return check(options);
450
+ if (command === "build") {
451
+ return (await build(options)).ok ? 0 : 1;
452
+ }
453
+ if (command === "export") return (await exportSite(options)).written ? 0 : 1;
407
454
  console.log(USAGE);
408
455
  return command === void 0 || command === "help" || command === "--help" ? 0 : 1;
409
456
  };
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/routes.ts","../src/shell-site.ts","../src/commands.ts","../src/cli.ts"],"names":["pad","require","join","readFileSync","dirname","resolve","spawnSync","existsSync","rmSync","writeFileSync","httpServer","url"],"mappings":";;;;;;;;;;;;AAsBO,IAAM,YAAA,GAAe,CAAC,KAAA,KAA+D;AAAA,EAC1F,GAAA;AAAA,EACA,GAAG,KAAA,CACA,GAAA,CAAI,CAAC,IAAA,KAAS,KAAK,IAAI,CAAA,CACvB,MAAA,CAAO,CAAC,IAAA,KAAS,CAAC,KAAK,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,CAAC,OAAA,KAAY,OAAA,CAAQ,UAAA,CAAW,GAAG,CAAC,CAAC,CAAA,CAC5E,IAAA;AACL,CAAA;AAKO,IAAM,MAAA,GAAS,CAAC,IAAA,KAAyB;AAC9C,EAAA,MAAM,WAAW,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAG,KAAA,CAAM,GAAG,CAAA,CAAE,OAAO,CAAC,OAAA,KAAY,OAAA,KAAY,EAAE,KAAK,EAAC;AACxF,EAAA,IAAI,QAAA,CAAS,IAAA,CAAK,CAAC,OAAA,KAAY,YAAY,IAAA,IAAQ,OAAA,KAAY,GAAG,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,CAAA,OAAA,EAAU,IAAI,CAAA,0CAAA,CAA4C,CAAA;AAC/I,EAAA,OAAO,CAAC,GAAG,QAAA,EAAU,YAAY,CAAA,CAAE,KAAK,GAAG,CAAA;AAC7C,CAAA;AAEA,IAAM,GAAA,GAAM,CAAC,IAAA,EAAc,KAAA,KAA0B,IAAA,GAAO,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,GAAA,CAAI,CAAA,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AAA,EAGL,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAAA,EAC3B,CAAC,KAAA,KAAmB;AAClB,IAAA,OAAA,CAAQ,KAAA,CAAM,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,UAAU,KAAK,CAAA;AAC5D,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAA","file":"cli.js","sourcesContent":["// ═══════════════════════════════════════════════════════════════\n// The paths an app has, where each one's file goes, and the table a build\n// prints. Pure: no server, no disk — the command hands these what it found.\n// ═══════════════════════════════════════════════════════════════\n\n// What a build learned about one path (moss's `ExportedDocument`, without the\n// markup).\nexport type RouteReport = {\n path: string;\n // the page the path led to; absent: the app's own shell\n page?: string;\n drawn: boolean;\n // something on it can still happen — it wants a server behind it\n live: boolean;\n why: readonly string[];\n // reads whose answers are in the markup as they were when it was drawn\n drawnWith: readonly string[];\n settled: boolean;\n};\n\n// `/`, and every page whose path names no parameter. A parameterised page has\n// as many paths as there are rows; those are the app's to list.\nexport const defaultPaths = (pages: readonly { name: string; path: string }[]): string[] => [\n '/',\n ...pages\n .map((page) => page.path)\n .filter((path) => !path.split('/').some((segment) => segment.startsWith(':')))\n .sort(),\n];\n\n// Where a path's file goes under the output directory: `/` is index.html, and\n// every other path is a folder with an index.html in it — what every static\n// host serves for that path without being told to.\nexport const fileOf = (path: string): string => {\n const segments = path.split('?')[0]?.split('/').filter((segment) => segment !== '') ?? [];\n if (segments.some((segment) => segment === '..' || segment === '.')) throw new Error(`nisc: \"${path}\" is not a path a file can be written for.`);\n return [...segments, 'index.html'].join('/');\n};\n\nconst pad = (text: string, width: number): string => text + ' '.repeat(Math.max(0, width - text.length));\n\n// The table. One row per path: whether a file is the whole of it, or a server\n// has to stand behind it — and, in the build's own words, why.\nexport const routeTable = (routes: readonly RouteReport[]): string => {\n const rows = routes.map((route) => {\n const mark = !route.drawn ? '✗' : route.live ? '●' : '○';\n const what = route.page === undefined ? 'the app' : `page ${route.page}`;\n const served = !route.drawn ? 'not drawn' : route.live ? 'server' : 'file';\n const notes = [\n ...(route.drawn ? route.why : ['it could not be drawn — it goes out as the undrawn template']),\n ...(route.drawn && !route.settled ? ['it was still loading when the wait ran out — drawn with what it had'] : []),\n ...(route.drawnWith.length > 0 ? [`drawn with ${route.drawnWith.join(', ')} — as it answered at build`] : []),\n ];\n return { mark, path: route.path, what, served, notes };\n });\n const widths = {\n path: Math.max(5, ...rows.map((row) => row.path.length)),\n what: Math.max(4, ...rows.map((row) => row.what.length)),\n served: Math.max(9, ...rows.map((row) => row.served.length)),\n };\n const lines = [` ${pad('Route', widths.path + 2)}${pad('What', widths.what + 2)}${pad('Served as', widths.served + 2)}Because`];\n for (const row of rows) {\n const head = `${row.mark} ${pad(row.path, widths.path + 2)}${pad(row.what, widths.what + 2)}${pad(row.served, widths.served + 2)}`;\n const [first, ...rest] = row.notes.length > 0 ? row.notes : ['nothing on it can still happen'];\n lines.push(`${head}${first ?? ''}`);\n for (const note of rest) lines.push(`${' '.repeat(head.length)}${note}`);\n }\n lines.push('');\n lines.push('○ file drawn once, for nobody in particular; nothing on it can still happen');\n lines.push('● server something on it can still happen; it wants moss behind it');\n return lines.join('\\n');\n};\n","import { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { dirname, extname, join, resolve, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { shellSettled } from '@niscorp/nova';\nimport type { Shell } from '@niscorp/nova';\nimport { livenessOf } from '@niscorp/nova/reflect';\nimport type { NiscShellProject } from './project';\n\n// ═══════════════════════════════════════════════════════════════\n// AN APP WITH ITS OWN SHELL, DRAWN AHEAD OF TIME.\n//\n// The shell lives in the page. A build runs the app's own boot where there is\n// no browser, waits for the screen to be whole, and has the app's adapter draw\n// it to markup; the page's boot then picks that markup up and from there the\n// app is what it always was. No server holds a shell at any point.\n//\n// A file is a claim — \"this is the page\" — so a build does not write one it has\n// not checked. Per path, and each one FAILS the build:\n//\n// drawn the app booted and its screen drew to markup that is not empty\n// whole nothing was still loading when it was drawn\n// same twice a second boot draws the same markup, byte for byte — or the\n// page's own boot would not match what the file says\n// adopted inside a DOM, a third boot picks the markup up and the\n// adapter complains about nothing\n//\n// And one that holds by construction: the boot is handed a path and nothing\n// else, so a file is only ever the screen as nobody in particular sees it.\n//\n// What a build cannot fail on, it reports: what the screen opened with (those\n// answers are in the markup as they were at build), what it can still call, and\n// what it waits on.\n// ═══════════════════════════════════════════════════════════════\n\nconst DEFAULT_BUILD_WAIT_MS = 5000;\nexport const DEFAULT_ROOT = '<div id=\"root\"></div>';\n\nexport type ShellRouteReport = {\n path: string;\n // the whole document; the template as it is when the screen could not be drawn\n html: string;\n // every check that did not hold — empty is a file that may be written\n problems: readonly string[];\n // the actions on the first screen\n actions: readonly string[];\n // endpoints answered while the screen opened: their answers are in the markup\n // as they were when it was drawn\n opensWith: readonly string[];\n // endpoints the first screen can still call once it is in the page\n callsLater: readonly string[];\n // channels the first screen waits on\n listens: readonly string[];\n};\n\nconst escapeAttribute = (value: string): string => value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;');\n\n// The screen, in the app's own index.html: inside the empty root, with whatever\n// the kit would have put on <html>.\nexport const placeScreen = (template: string, screen: string, attributes: Record<string, string> = {}, root = DEFAULT_ROOT): string => {\n const written = Object.entries(attributes)\n .map(([name, value]) => ` ${name}=\"${escapeAttribute(value)}\"`)\n .join('');\n return (\n template\n // functions, both, so nothing in the screen is read as a replacement pattern\n .replace(root, () => root.replace('></div>', () => `>${screen}</div>`))\n .replace(/<html([^>]*)>/, (whole, existing: string) => (written === '' ? whole : `<html${existing}${written}>`))\n );\n};\n\n// What the first screen is made of, read off the definitions of what is mounted.\nconst factsOf = (shell: Shell): Pick<ShellRouteReport, 'actions' | 'opensWith' | 'callsLater' | 'listens'> => {\n const [actions, opensWith, callsLater, listens] = [new Set<string>(), new Set<string>(), new Set<string>(), new Set<string>()];\n for (const canvas of Object.values(shell.getState().canvases)) {\n for (const instance of canvas.stack) {\n const definition = shell.getRuntime(instance.id)?.definition;\n if (definition === undefined) continue;\n actions.add(definition.id);\n const liveness = livenessOf(definition);\n for (const channel of liveness.listens) listens.add(channel);\n for (const endpoint of liveness.endpoints) {\n const label = `${definition.id}.${endpoint.name}${endpoint.kind === 'fn' ? ' (a function)' : endpoint.url !== undefined ? ` (${endpoint.url})` : ''}`;\n if (endpoint.onOpen) opensWith.add(label);\n if (endpoint.later) callsLater.add(label);\n }\n }\n }\n const sorted = (set: Set<string>): string[] => [...set].sort();\n return { actions: sorted(actions), opensWith: sorted(opensWith), callsLater: sorted(callsLater), listens: sorted(listens) };\n};\n\ntype Drawn = { screen: string; whole: boolean; attributes: Record<string, string>; facts: ReturnType<typeof factsOf> };\n\n// One boot, one draw, and the app let go again.\nconst drawOnce = async (project: NiscShellProject, path: string): Promise<Drawn> => {\n const booted = await project.shell({ path });\n try {\n const whole = await shellSettled(booted.shell, { waitMs: project.waitMs ?? DEFAULT_BUILD_WAIT_MS });\n const screen = await project.draw(booted.shell);\n return { screen, whole, attributes: project.htmlAttributes?.(booted.shell) ?? {}, facts: factsOf(booted.shell) };\n } finally {\n await booted.close?.();\n }\n};\n\nconst said = (error: unknown): string => (error instanceof Error ? error.message : String(error));\n\n// ── adopted ──\n//\n// The one check that needs a browser's world. A DOM has to exist BEFORE the\n// app's modules load (an adapter decides what it is running in when it is\n// imported), so it runs in a process of its own: ./adopt stands a DOM up, loads\n// the same config, and for each path puts the markup in a root and makes the\n// app's own `adopt` call over a fresh boot.\n\ntype Adoption = { path: string; complaints: string[] };\n\nconst isAdoption = (value: unknown): value is Adoption =>\n value !== null &&\n typeof value === 'object' &&\n typeof Reflect.get(value, 'path') === 'string' &&\n Array.isArray(Reflect.get(value, 'complaints'));\n\nconst adoptAll = (root: string, pages: readonly { path: string; screen: string }[]): Adoption[] => {\n if (pages.length === 0) return [];\n const here = dirname(fileURLToPath(import.meta.url));\n // built: beside this file. From source (the package's own tests): in dist.\n const entry = [join(here, 'adopt.js'), join(here, '..', 'dist', 'adopt.js')].find((candidate) => existsSync(candidate));\n if (entry === undefined) throw new Error('nisc: the adoption check is not built (packages/cli/dist/adopt.js).');\n const scratch = mkdtempSync(join(tmpdir(), 'nisc-adopt-'));\n try {\n const [asked, answered] = [join(scratch, 'pages.json'), join(scratch, 'adopted.json')];\n writeFileSync(asked, JSON.stringify(pages));\n const result = spawnSync(process.execPath, [entry, root, asked, answered], { cwd: root, stdio: ['ignore', 'ignore', 'pipe'], encoding: 'utf8' });\n if (!existsSync(answered)) {\n const why = result.stderr.trim().split('\\n').slice(-6).join('\\n');\n return pages.map((page) => ({ path: page.path, complaints: [`the adoption check could not run${why === '' ? '' : ` — ${why}`}`] }));\n }\n const parsed: unknown = JSON.parse(readFileSync(answered, 'utf8'));\n return Array.isArray(parsed) ? parsed.filter(isAdoption) : [];\n } finally {\n rmSync(scratch, { recursive: true, force: true });\n }\n};\n\n// Every path, checked.\nexport const surveyShell = async (root: string, project: NiscShellProject, template: string): Promise<ShellRouteReport[]> => {\n if (!template.includes(DEFAULT_ROOT)) {\n throw new Error(`nisc: the built index.html has no empty root (${DEFAULT_ROOT}) — that is where a screen goes.`);\n }\n const paths = project.paths === undefined ? ['/'] : await project.paths();\n const none = { actions: [], opensWith: [], callsLater: [], listens: [] };\n\n const first: { path: string; drawn?: Drawn; problems: string[] }[] = [];\n for (const path of paths) {\n const problems: string[] = [];\n let drawn: Drawn | undefined;\n try {\n drawn = await drawOnce(project, path);\n if (drawn.screen.trim() === '') problems.push('drawn: it drew to nothing');\n if (!drawn.whole) problems.push(`whole: it was still loading after ${project.waitMs ?? DEFAULT_BUILD_WAIT_MS}ms`);\n const again = await drawOnce(project, path);\n if (again.screen !== drawn.screen) problems.push(`same twice: a second boot drew different markup${differenceOf(drawn.screen, again.screen)}`);\n } catch (error) {\n problems.push(`drawn: ${said(error)}`);\n }\n first.push({ path, ...(drawn !== undefined ? { drawn } : {}), problems });\n }\n\n // only what is worth adopting: a screen that drew, whole\n const adoptable = first.flatMap((route) => (route.drawn !== undefined && route.drawn.whole && route.drawn.screen.trim() !== '' ? [{ path: route.path, screen: route.drawn.screen }] : []));\n const adoptions = new Map(adoptAll(root, adoptable).map((adoption) => [adoption.path, adoption.complaints]));\n\n return first.map((route) => {\n const asked = adoptable.some((page) => page.path === route.path);\n const complaints = asked ? (adoptions.get(route.path) ?? ['the adoption check said nothing about it']) : [];\n const problems = [...route.problems, ...complaints.map((complaint) => `adopted: ${complaint}`)];\n return {\n path: route.path,\n html: route.drawn === undefined ? template : placeScreen(template, route.drawn.screen, route.drawn.attributes),\n problems,\n ...(route.drawn?.facts ?? none),\n };\n });\n};\n\n// Where two draws part, in a few words — enough to find it.\nconst differenceOf = (a: string, b: string): string => {\n let at = 0;\n while (at < a.length && at < b.length && a[at] === b[at]) at += 1;\n const around = (text: string): string => JSON.stringify(text.slice(Math.max(0, at - 30), at + 50));\n return ` — at character ${at}: ${around(a)} then ${around(b)}`;\n};\n\nconst pad = (text: string, width: number): string => text + ' '.repeat(Math.max(0, width - text.length));\n\nexport const shellRouteTable = (routes: readonly ShellRouteReport[]): string => {\n const width = Math.max(5, ...routes.map((route) => route.path.length)) + 2;\n const lines = [` ${pad('Route', width)}First screen`];\n const indent = ' '.repeat(width + 2);\n for (const route of routes) {\n const ok = route.problems.length === 0;\n const notes = ok\n ? [\n `drawn · whole · same twice · adopted${route.actions.length > 0 ? ` (${route.actions.join(', ')})` : ''}`,\n ...(route.opensWith.length > 0 ? [`opened with ${route.opensWith.join(', ')} — in the file as answered at build`] : []),\n ...(route.callsLater.length > 0 ? [`can still call ${route.callsLater.join(', ')}`] : []),\n ...(route.listens.length > 0 ? [`waits on ${route.listens.join(', ')}`] : []),\n ]\n : route.problems;\n const [head, ...rest] = notes;\n lines.push(`${ok ? '○' : '✗'} ${pad(route.path, width)}${head ?? ''}`);\n for (const note of rest) lines.push(`${indent}${note}`);\n }\n lines.push('');\n lines.push('○ a file: the first screen, drawn for nobody in particular; the page’s own shell picks it up');\n lines.push('✗ not written: a check did not hold');\n return lines.join('\\n');\n};\n\n// ── served ──\n//\n// The same draw, per request: the first answer to a path is its screen, and\n// everything else in the built folder is a file. No checks here — a build made\n// them; a screen that will not draw goes out as the template, and the page's\n// own boot paints it as it did before any of this existed.\n\nconst TYPES: Record<string, string> = {\n '.html': 'text/html; charset=utf-8',\n '.js': 'text/javascript; charset=utf-8',\n '.mjs': 'text/javascript; charset=utf-8',\n '.css': 'text/css; charset=utf-8',\n '.json': 'application/json; charset=utf-8',\n '.svg': 'image/svg+xml',\n '.png': 'image/png',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.webp': 'image/webp',\n '.ico': 'image/x-icon',\n '.woff2': 'font/woff2',\n '.woff': 'font/woff',\n '.wasm': 'application/wasm',\n '.data': 'application/octet-stream',\n '.map': 'application/json; charset=utf-8',\n '.txt': 'text/plain; charset=utf-8',\n};\n\nexport const shellSite = (project: NiscShellProject, dist: string): ((request: Request) => Promise<Response>) => {\n const base = resolve(dist);\n return async (request) => {\n const path = decodeURIComponent(new URL(request.url).pathname);\n if (path !== '/' && path !== '/index.html') {\n const file = resolve(base, `.${path}`);\n if ((file === base || file.startsWith(base + sep)) && existsSync(file) && statSync(file).isFile()) {\n return new Response(readFileSync(file), { headers: { 'content-type': TYPES[extname(file)] ?? 'application/octet-stream' } });\n }\n // a name with an extension that is not there is a missing file, not a page\n if (extname(path) !== '') return new Response('not found', { status: 404 });\n }\n const template = readFileSync(join(base, 'index.html'), 'utf8');\n const headers = { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-cache' };\n try {\n const drawn = await drawOnce(project, path === '/index.html' ? '/' : path);\n return new Response(placeScreen(template, drawn.screen, drawn.attributes), { headers });\n } catch (error) {\n console.error(`[nisc] \"${path}\" could not be drawn — serving it undrawn:`, error);\n return new Response(template, { headers });\n }\n };\n};\n","import { spawn, spawnSync } from 'node:child_process';\nimport { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport type { AddressInfo } from 'node:net';\nimport { dirname, join, resolve } from 'node:path';\nimport { serve } from '@hono/node-server';\nimport type { ExportedDocument } from '@niscorp/moss';\nimport { isShellProject, loadProject } from './project';\nimport type { NiscMossProject, NiscProject, NiscShellProject } from './project';\nimport { defaultPaths, fileOf, routeTable } from './routes';\nimport { shellRouteTable, shellSite, surveyShell } from './shell-site';\nimport type { ShellRouteReport } from './shell-site';\n\n// ═══════════════════════════════════════════════════════════════\n// What `nisc` does. Each command is the app's own machinery, run in order:\n//\n// dev the app's dev server (its vite config, which hosts the app server)\n// build bundle the terminal, then draw every path once and say how each is\n// served — a file, or a server\n// export build, then write every path as a file: the whole site as a folder\n// start serve the built terminal from the app's own process, pages drawn\n// check the app's check suite\n//\n// Nothing here knows an app. How it boots and how a screen is drawn come from\n// its nisc.config.ts. An app behind moss hands over its server, and which paths\n// exist and what each needs come from that (`server.pages`, `exportDocuments`).\n// An app with its own shell hands over its boot, and every path is drawn from\n// that and checked (./shell-site). Moss is loaded only for the first kind — an\n// app without it does not have it installed.\n// ═══════════════════════════════════════════════════════════════\n\nexport type CommandOptions = {\n // the app's root (where nisc.config.ts is)\n root: string;\n // export: where the files go (default `out`), relative to the root\n out?: string;\n // export: write the site even though some path wants a server behind it\n allowLive?: boolean;\n // start: the port (default $PORT, then 8787)\n port?: number;\n // build/export: skip the bundler (the terminal is already built)\n skipBundle?: boolean;\n print?: (line: string) => void;\n};\n\nconst say = (options: CommandOptions): ((line: string) => void) => options.print ?? ((line) => console.log(line));\n\n// A tool the APP has installed, found from the app's own root — the command\n// carries no bundler and no test runner of its own.\nconst toolOf = (root: string, name: string, bin: string): string => {\n const require = createRequire(join(root, 'package.json'));\n let manifestPath: string;\n try {\n manifestPath = require.resolve(`${name}/package.json`);\n } catch {\n throw new Error(`nisc: this app has no ${name} installed (looked from ${root}).`);\n }\n const manifest: unknown = JSON.parse(readFileSync(manifestPath, 'utf8'));\n const bins: unknown = manifest !== null && typeof manifest === 'object' ? Reflect.get(manifest, 'bin') : undefined;\n const relative: unknown = typeof bins === 'string' ? bins : bins !== null && typeof bins === 'object' ? Reflect.get(bins, bin) : undefined;\n if (typeof relative !== 'string') throw new Error(`nisc: ${name} ships no \"${bin}\" command.`);\n return join(dirname(manifestPath), relative);\n};\n\nconst distOf = (root: string, project: NiscProject): string => resolve(root, project.dist ?? 'dist');\n\nconst bundle = (options: CommandOptions): void => {\n const result = spawnSync(process.execPath, [toolOf(options.root, 'vite', 'vite'), 'build'], { cwd: options.root, stdio: 'inherit' });\n if (result.status !== 0) throw new Error('nisc: the bundler failed — nothing was drawn.');\n};\n\n// Stand the app up, draw every path once for nobody, let the app go.\nconst templateOf = (options: CommandOptions, project: NiscProject): string => {\n const template = join(distOf(options.root, project), 'index.html');\n if (!existsSync(template)) throw new Error(`nisc: no built terminal at ${template} — run \\`nisc build\\`.`);\n return readFileSync(template, 'utf8');\n};\n\nconst survey = async (options: CommandOptions, project: NiscMossProject): Promise<ExportedDocument[]> => {\n const template = templateOf(options, project);\n const { exportDocuments } = await import('@niscorp/moss');\n const booted = await project.boot();\n try {\n const paths = project.paths === undefined ? defaultPaths(booted.server.pages) : await project.paths(booted.server);\n return await exportDocuments({\n server: booted.server,\n template,\n draw: project.draw,\n ...(project.htmlAttributes !== undefined ? { htmlAttributes: project.htmlAttributes } : {}),\n ...(project.tokenKey !== undefined ? { tokenKey: project.tokenKey } : {}),\n paths,\n });\n } finally {\n await booted.close?.();\n }\n};\n\n// What a build found, either way round: every path, and whether the build holds.\nexport type BuildResult =\n | { kind: 'moss'; ok: boolean; routes: ExportedDocument[] }\n | { kind: 'shell'; ok: boolean; routes: ShellRouteReport[] };\n\nconst buildShell = async (options: CommandOptions, project: NiscShellProject): Promise<BuildResult> => {\n const routes = await surveyShell(options.root, project, templateOf(options, project));\n say(options)('');\n say(options)(shellRouteTable(routes));\n return { kind: 'shell', ok: routes.every((route) => route.problems.length === 0), routes };\n};\n\nexport const build = async (options: CommandOptions): Promise<BuildResult> => {\n const project = await loadProject(options.root);\n if (options.skipBundle !== true) bundle(options);\n if (isShellProject(project)) return buildShell(options, project);\n const routes = await survey(options, project);\n say(options)('');\n say(options)(routeTable(routes));\n return { kind: 'moss', ok: routes.every((route) => route.drawn), routes };\n};\n\nconst write = (options: CommandOptions, project: NiscProject, out: string, routes: readonly { path: string; html: string }[]): void => {\n rmSync(out, { recursive: true, force: true });\n cpSync(distOf(options.root, project), out, { recursive: true });\n for (const route of routes) {\n const file = join(out, fileOf(route.path));\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, route.html);\n }\n say(options)('');\n say(options)(`nisc: ${routes.length} paths written to ${out}`);\n};\n\n// The whole site as a folder. A path that wants a server behind it is not\n// something a folder can be — so unless the caller says a server will stand\n// beside the files (`allowLive`), nothing is written and the table says why.\n//\n// An app with its own shell has no such path: the shell is in the page, so a\n// folder is all of it. What stops ITS files is a check that did not hold.\nexport const exportSite = async (options: CommandOptions): Promise<{ written: boolean; result: BuildResult; out: string }> => {\n const project = await loadProject(options.root);\n const result = await build(options);\n const out = resolve(options.root, options.out ?? 'out');\n if (result.kind === 'shell') {\n if (!result.ok) {\n const failed = result.routes.filter((route) => route.problems.length > 0);\n say(options)('');\n say(options)(`nisc: ${failed.length} of ${result.routes.length} paths did not hold (${failed.map((route) => route.path).join(', ')}). Nothing was written.`);\n return { written: false, result, out };\n }\n write(options, project, out, result.routes);\n return { written: true, result, out };\n }\n const routes = result.routes;\n const live = routes.filter((route) => route.live || !route.drawn);\n if (live.length > 0 && options.allowLive !== true) {\n say(options)('');\n say(options)(`nisc: ${live.length} of ${routes.length} paths cannot be a file alone (${live.map((route) => route.path).join(', ')}).`);\n say(options)(' Nothing was written. With a server beside the files they still work: `nisc export --allow-live`.');\n return { written: false, result, out };\n }\n write(options, project, out, routes);\n return { written: true, result, out };\n};\n\nconst listening = async (httpServer: ReturnType<typeof serve>, options: CommandOptions): Promise<string> => {\n await new Promise<void>((up) => httpServer.once('listening', () => up()));\n const address = httpServer.address();\n const port = address !== null && typeof address === 'object' ? (address satisfies AddressInfo).port : options.port;\n return `http://localhost:${port}`;\n};\n\nexport const start = async (options: CommandOptions): Promise<{ url: string; close: () => Promise<void> }> => {\n const project = await loadProject(options.root);\n const dist = distOf(options.root, project);\n if (!existsSync(join(dist, 'index.html'))) throw new Error(`nisc: no built terminal in ${dist} — run \\`nisc build\\`.`);\n const port = options.port ?? Number(process.env['PORT'] ?? 8787);\n if (isShellProject(project)) {\n // no server shell, no socket: each path's first answer is its screen, drawn\n // from a boot of the app's own, and the page's shell takes it from there\n const httpServer = serve({ fetch: shellSite(project, dist), port });\n const url = await listening(httpServer, options);\n say(options)(`nisc: serving ${url} — the built app, each path’s first screen drawn; the shell is the page’s own`);\n return { url, close: async () => void httpServer.close() };\n }\n const { attachSocket, mountSite } = await import('@niscorp/moss/node');\n const booted = await project.boot();\n await project.routes?.(booted.server);\n mountSite(booted.server, {\n dist,\n draw: project.draw,\n ...(project.htmlAttributes !== undefined ? { htmlAttributes: project.htmlAttributes } : {}),\n ...(project.tokenKey !== undefined ? { tokenKey: project.tokenKey } : {}),\n });\n const httpServer = serve({ fetch: booted.server.fetch, port });\n attachSocket(httpServer, booted.server.socket);\n const url = await listening(httpServer, options);\n say(options)(`nisc: serving ${url} — the built terminal, its pages drawn; the socket at /socket`);\n return {\n url,\n close: async () => {\n httpServer.close();\n await booted.close?.();\n },\n };\n};\n\n// The two that hand over to a tool of the app's own and stay out of the way.\nconst handOver = (options: CommandOptions, tool: string, args: readonly string[]): Promise<number> =>\n new Promise((done) => {\n const child = spawn(process.execPath, [tool, ...args], { cwd: options.root, stdio: 'inherit' });\n child.once('exit', (code) => done(code ?? 1));\n });\n\nexport const dev = (options: CommandOptions): Promise<number> => handOver(options, toolOf(options.root, 'vite', 'vite'), []);\n\nexport const check = async (options: CommandOptions): Promise<number> => {\n const project = await loadProject(options.root);\n return handOver(options, toolOf(options.root, 'tsx', 'tsx'), [project.checks ?? 'src/dev/all-checks.ts']);\n};\n","import { resolve } from 'node:path';\nimport { build, check, dev, exportSite, start } from './commands';\nimport type { CommandOptions } from './commands';\n\n// ═══════════════════════════════════════════════════════════════\n// nisc — the command line. It parses, and hands over to ./commands.\n// ═══════════════════════════════════════════════════════════════\n\nconst USAGE = `nisc — the command for a nisc application\n\n nisc dev the app's dev server\n nisc build bundle the app, draw every path, and check what was drawn\n nisc export build, then write every path as a file (the site as a folder)\n nisc start serve the built app, each path's first screen drawn\n nisc check the app's check suite\n\n --root <dir> the app's root (default: here) — where nisc.config.ts is\n --out <dir> export: where the files go (default: out)\n --allow-live export: write even though some path wants a server behind it\n --port <n> start: the port (default: $PORT, then 8787)\n --skip-bundle build, export: the terminal is already built\n\nAn app says in nisc.config.ts how it boots and how one of its screens is drawn.\nBehind moss (boot + draw): which paths exist and what each needs is read off the\nserver. With its own shell (shell + draw + adopt): every path is drawn from the\napp's own boot, and a file is written only if the page's boot picks it up clean.`;\n\nconst valueAfter = (args: readonly string[], flag: string): string | undefined => {\n const at = args.indexOf(flag);\n return at < 0 ? undefined : args[at + 1];\n};\n\nconst main = async (): Promise<number> => {\n const [command, ...args] = process.argv.slice(2);\n const port = valueAfter(args, '--port');\n const out = valueAfter(args, '--out');\n const options: CommandOptions = {\n root: resolve(valueAfter(args, '--root') ?? process.cwd()),\n ...(out !== undefined ? { out } : {}),\n ...(port !== undefined ? { port: Number(port) } : {}),\n allowLive: args.includes('--allow-live'),\n skipBundle: args.includes('--skip-bundle'),\n };\n\n if (command === 'dev') return dev(options);\n if (command === 'check') return check(options);\n if (command === 'build') {\n return (await build(options)).ok ? 0 : 1;\n }\n if (command === 'export') return (await exportSite(options)).written ? 0 : 1;\n if (command === 'start') {\n const served = await start(options);\n const stop = (): void => {\n void served.close().finally(() => process.exit(0));\n };\n process.on('SIGINT', stop);\n process.on('SIGTERM', stop);\n // stays up until it is told to stop\n return new Promise<number>(() => undefined);\n }\n console.log(USAGE);\n return command === undefined || command === 'help' || command === '--help' ? 0 : 1;\n};\n\nmain().then(\n // An app's own handles (a database, a timer) must not keep a finished command\n // open: a command that is done says so and leaves.\n (code) => process.exit(code),\n (error: unknown) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n },\n);\n"]}
1
+ {"version":3,"sources":["../src/dev.ts","../src/routes.ts","../src/shell-site.ts","../src/commands.ts","../src/cli.ts"],"names":["join","pad","require","createRequire","readFileSync","dirname","resolve","spawnSync","existsSync","rmSync","writeFileSync","httpServer","url"],"mappings":";;;;;;;;;;;AA0BA,IAAM,SAAA,GAAY,CAAC,KAAA,KACjB,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,EAAO,cAAc,CAAA,KAAM,UAAA;AAG/F,IAAM,MAAA,GAAS,OAAO,IAAA,KAAmC;AACvD,EAAA,IAAI,KAAA;AACJ,EAAA,IAAI;AACF,IAAA,KAAA,GAAQ,cAAc,IAAA,CAAK,IAAA,EAAM,cAAc,CAAC,CAAA,CAAE,QAAQ,MAAM,CAAA;AAAA,EAClE,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kDAAA,EAAqD,IAAI,CAAA,EAAA,CAAI,CAAA;AAAA,EAC/E;AACA,EAAA,MAAM,MAAA,GAAkB,MAAM,OAAO,aAAA,CAAc,KAAK,CAAA,CAAE,IAAA,CAAA;AAC1D,EAAA,IAAI,CAAC,UAAU,MAAM,CAAA,QAAS,IAAI,KAAA,CAAM,CAAA,MAAA,EAAS,KAAK,CAAA,aAAA,CAAe,CAAA;AACrE,EAAA,OAAO,MAAA;AACT,CAAA;AAGA,IAAM,UAAA,GAAa,OAAO,UAAA,KAAyC;AACjE,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MA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AA;AACzB,IAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,IAAI,CAAA;AAE1B,IAAA,OAAO,IAAI,OAAA,CAAgB,MAAM,MAAS,CAAA;AAAA,EAC5C;AACA,EAAA,IAAI,OAAA,KAAY,OAAA,EAAS,OAAO,KAAA,CAAM,OAAO,CAAA;AAC7C,EAAA,IAAI,YAAY,OAAA,EAAS;AACvB,IAAA,OAAA,CAAQ,MAAM,KAAA,CAAM,OAAO,CAAA,EAAG,KAAK,CAAA,GAAI,CAAA;AAAA,EACzC;AACA,EAAA,IAAI,OAAA,KAAY,UAAU,OAAA,CAAQ,MAAM,WAAW,OAAO,CAAA,EAAG,UAAU,CAAA,GAAI,CAAA;AAC3E,EAAA,OAAA,CAAQ,IAAI,KAAK,CAAA;AACjB,EAAA,OAAO,YAAY,MAAA,IAAa,OAAA,KAAY,MAAA,IAAU,OAAA,KAAY,WAAW,CAAA,GAAI,CAAA;AACnF,CAAA;AAEA,IAAA,EAAK,CAAE,IAAA;AAAA;AAAA;AAAA,EAGL,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAAA,EAC3B,CAAC,KAAA,KAAmB;AAClB,IAAA,OAAA,CAAQ,KAAA,CAAM,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,UAAU,KAAK,CAAA;AAC5D,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAA","file":"cli.js","sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { configFileOf, isProject, isShellProject, loadProject } from './project';\n\n// ═══════════════════════════════════════════════════════════════\n// `nisc dev` — the app's own vite, started from here.\n//\n// An app with its own shell is a vite app and nothing more. An app behind moss\n// also needs its server inside that dev process, and that is moss's plugin\n// (`@niscorp/moss/vite`): added here, fed from the app's nisc.config.ts — the\n// same boot and the same drawing `nisc build` and `nisc start` use, loaded\n// through vite so an edit is a fresh boot. The app's vite.config.ts stays what\n// it is: its framework's plugin, its aliases.\n// ═══════════════════════════════════════════════════════════════\n\n// What is used of the app's vite — described here rather than imported, since\n// the vite is the app's and its types are the app's too.\ntype DevServer = {\n listen: () => Promise<unknown>;\n printUrls: () => void;\n resolvedUrls: { local: string[] } | null;\n close: () => Promise<void>;\n};\ntype ViteApi = { createServer: (config: { root: string; server?: { port: number }; plugins: unknown[] }) => Promise<DevServer> };\n\nconst isViteApi = (value: unknown): value is ViteApi =>\n value !== null && typeof value === 'object' && typeof Reflect.get(value, 'createServer') === 'function';\n\n// The app's vite — the command carries none of its own.\nconst viteOf = async (root: string): Promise<ViteApi> => {\n let entry: string;\n try {\n entry = createRequire(join(root, 'package.json')).resolve('vite');\n } catch {\n throw new Error(`nisc: this app has no vite installed (looked from ${root}).`);\n }\n const loaded: unknown = await import(pathToFileURL(entry).href);\n if (!isViteApi(loaded)) throw new Error(`nisc: ${entry} is not vite.`);\n return loaded;\n};\n\n// moss's dev plugin, fed from the config as vite loads it.\nconst mossPlugin = async (configFile: string): Promise<unknown> => {\n const { mossDev } = await import('@niscorp/moss/vite');\n return mossDev({\n label: 'nisc',\n app: async (load) => {\n const loaded = await load(`/${configFile}`);\n const project: unknown = Reflect.get(loaded, 'project');\n if (!isProject(project) || isShellProject(project)) throw new Error(`nisc: ${configFile} no longer describes an app behind moss.`);\n const booted = await project.boot();\n const signIn = project.dev?.signIn;\n return {\n server: booted.server,\n ...(booted.close !== undefined ? { close: booted.close } : {}),\n draw: project.draw,\n ...(project.htmlAttributes !== undefined ? { htmlAttributes: project.htmlAttributes } : {}),\n ...(project.tokenKey !== undefined ? { tokenKey: project.tokenKey } : {}),\n ...(signIn !== undefined ? { signIn: (who: string) => signIn(booted.server, who) } : {}),\n };\n },\n });\n};\n\nexport const devServer = async (options: { root: string; port?: number }): Promise<{ url: string; close: () => Promise<void> }> => {\n const project = await loadProject(options.root);\n const configFile = configFileOf(options.root);\n const vite = await viteOf(options.root);\n const server = await vite.createServer({\n root: options.root,\n ...(options.port !== undefined ? { server: { port: options.port } } : {}),\n plugins: isShellProject(project) || configFile === undefined ? [] : [await mossPlugin(configFile)],\n });\n await server.listen();\n server.printUrls();\n const url = server.resolvedUrls?.local[0] ?? `http://localhost:${options.port ?? 5173}/`;\n return { url, close: () => server.close() };\n};\n","// ═══════════════════════════════════════════════════════════════\n// The paths an app has, where each one's file goes, and the table a build\n// prints. Pure: no server, no disk — the command hands these what it found.\n// ═══════════════════════════════════════════════════════════════\n\n// What a build learned about one path (moss's `ExportedDocument`, without the\n// markup).\nexport type RouteReport = {\n path: string;\n // the page the path led to; absent: the app's own shell\n page?: string;\n drawn: boolean;\n // something on it can still happen — it wants a server behind it\n live: boolean;\n why: readonly string[];\n // reads whose answers are in the markup as they were when it was drawn\n drawnWith: readonly string[];\n settled: boolean;\n};\n\n// `/`, and every page whose path names no parameter. A parameterised page has\n// as many paths as there are rows; those are the app's to list.\nexport const defaultPaths = (pages: readonly { name: string; path: string }[]): string[] => [\n '/',\n ...pages\n .map((page) => page.path)\n .filter((path) => !path.split('/').some((segment) => segment.startsWith(':')))\n .sort(),\n];\n\n// Where a path's file goes under the output directory: `/` is index.html, and\n// every other path is a folder with an index.html in it — what every static\n// host serves for that path without being told to.\nexport const fileOf = (path: string): string => {\n const segments = path.split('?')[0]?.split('/').filter((segment) => segment !== '') ?? [];\n if (segments.some((segment) => segment === '..' || segment === '.')) throw new Error(`nisc: \"${path}\" is not a path a file can be written for.`);\n return [...segments, 'index.html'].join('/');\n};\n\nconst pad = (text: string, width: number): string => text + ' '.repeat(Math.max(0, width - text.length));\n\n// The table. One row per path: whether a file is the whole of it, or a server\n// has to stand behind it — and, in the build's own words, why.\nexport const routeTable = (routes: readonly RouteReport[]): string => {\n const rows = routes.map((route) => {\n const mark = !route.drawn ? '✗' : route.live ? '●' : '○';\n const what = route.page === undefined ? 'the app' : `page ${route.page}`;\n const served = !route.drawn ? 'not drawn' : route.live ? 'server' : 'file';\n const notes = [\n ...(route.drawn ? route.why : ['it could not be drawn — it goes out as the undrawn template']),\n ...(route.drawn && !route.settled ? ['it was still loading when the wait ran out — drawn with what it had'] : []),\n ...(route.drawnWith.length > 0 ? [`drawn with ${route.drawnWith.join(', ')} — as it answered at build`] : []),\n ];\n return { mark, path: route.path, what, served, notes };\n });\n const widths = {\n path: Math.max(5, ...rows.map((row) => row.path.length)),\n what: Math.max(4, ...rows.map((row) => row.what.length)),\n served: Math.max(9, ...rows.map((row) => row.served.length)),\n };\n const lines = [` ${pad('Route', widths.path + 2)}${pad('What', widths.what + 2)}${pad('Served as', widths.served + 2)}Because`];\n for (const row of rows) {\n const head = `${row.mark} ${pad(row.path, widths.path + 2)}${pad(row.what, widths.what + 2)}${pad(row.served, widths.served + 2)}`;\n const [first, ...rest] = row.notes.length > 0 ? row.notes : ['nothing on it can still happen'];\n lines.push(`${head}${first ?? ''}`);\n for (const note of rest) lines.push(`${' '.repeat(head.length)}${note}`);\n }\n lines.push('');\n lines.push('○ file drawn once, for nobody in particular; nothing on it can still happen');\n lines.push('● server something on it can still happen; it wants moss behind it');\n return lines.join('\\n');\n};\n","import { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { dirname, extname, join, resolve, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { shellSettled } from '@niscorp/nova';\nimport type { Shell } from '@niscorp/nova';\nimport { livenessOf } from '@niscorp/nova/reflect';\nimport type { NiscShellProject } from './project';\n\n// ═══════════════════════════════════════════════════════════════\n// AN APP WITH ITS OWN SHELL, DRAWN AHEAD OF TIME.\n//\n// The shell lives in the page. A build runs the app's own boot where there is\n// no browser, waits for the screen to be whole, and has the app's adapter draw\n// it to markup; the page's boot then picks that markup up and from there the\n// app is what it always was. No server holds a shell at any point.\n//\n// A file is a claim — \"this is the page\" — so a build does not write one it has\n// not checked. Per path, and each one FAILS the build:\n//\n// drawn the app booted and its screen drew to markup that is not empty\n// whole nothing was still loading when it was drawn\n// same twice a second boot draws the same markup, byte for byte — or the\n// page's own boot would not match what the file says\n// adopted inside a DOM, a third boot picks the markup up and the\n// adapter complains about nothing\n//\n// And one that holds by construction: the boot is handed a path and nothing\n// else, so a file is only ever the screen as nobody in particular sees it.\n//\n// What a build cannot fail on, it reports: what the screen opened with (those\n// answers are in the markup as they were at build), what it can still call, and\n// what it waits on.\n// ═══════════════════════════════════════════════════════════════\n\nconst DEFAULT_BUILD_WAIT_MS = 5000;\nexport const DEFAULT_ROOT = '<div id=\"root\"></div>';\n\nexport type ShellRouteReport = {\n path: string;\n // the whole document; the template as it is when the screen could not be drawn\n html: string;\n // every check that did not hold — empty is a file that may be written\n problems: readonly string[];\n // the actions on the first screen\n actions: readonly string[];\n // endpoints answered while the screen opened: their answers are in the markup\n // as they were when it was drawn\n opensWith: readonly string[];\n // endpoints the first screen can still call once it is in the page\n callsLater: readonly string[];\n // channels the first screen waits on\n listens: readonly string[];\n};\n\nconst escapeAttribute = (value: string): string => value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;');\n\n// The screen, in the app's own index.html: inside the empty root, with whatever\n// the kit would have put on <html>.\nexport const placeScreen = (template: string, screen: string, attributes: Record<string, string> = {}, root = DEFAULT_ROOT): string => {\n const written = Object.entries(attributes)\n .map(([name, value]) => ` ${name}=\"${escapeAttribute(value)}\"`)\n .join('');\n return (\n template\n // functions, both, so nothing in the screen is read as a replacement pattern\n .replace(root, () => root.replace('></div>', () => `>${screen}</div>`))\n .replace(/<html([^>]*)>/, (whole, existing: string) => (written === '' ? whole : `<html${existing}${written}>`))\n );\n};\n\n// What the first screen is made of, read off the definitions of what is mounted.\nconst factsOf = (shell: Shell): Pick<ShellRouteReport, 'actions' | 'opensWith' | 'callsLater' | 'listens'> => {\n const [actions, opensWith, callsLater, listens] = [new Set<string>(), new Set<string>(), new Set<string>(), new Set<string>()];\n for (const canvas of Object.values(shell.getState().canvases)) {\n for (const instance of canvas.stack) {\n const definition = shell.getRuntime(instance.id)?.definition;\n if (definition === undefined) continue;\n actions.add(definition.id);\n const liveness = livenessOf(definition);\n for (const channel of liveness.listens) listens.add(channel);\n for (const endpoint of liveness.endpoints) {\n const label = `${definition.id}.${endpoint.name}${endpoint.kind === 'fn' ? ' (a function)' : endpoint.url !== undefined ? ` (${endpoint.url})` : ''}`;\n if (endpoint.onOpen) opensWith.add(label);\n if (endpoint.later) callsLater.add(label);\n }\n }\n }\n const sorted = (set: Set<string>): string[] => [...set].sort();\n return { actions: sorted(actions), opensWith: sorted(opensWith), callsLater: sorted(callsLater), listens: sorted(listens) };\n};\n\ntype Drawn = { screen: string; whole: boolean; attributes: Record<string, string>; facts: ReturnType<typeof factsOf> };\n\n// One boot, one draw, and the app let go again.\nconst drawOnce = async (project: NiscShellProject, path: string): Promise<Drawn> => {\n const booted = await project.shell({ path });\n try {\n const whole = await shellSettled(booted.shell, { waitMs: project.waitMs ?? DEFAULT_BUILD_WAIT_MS });\n const screen = await project.draw(booted.shell);\n return { screen, whole, attributes: project.htmlAttributes?.(booted.shell) ?? {}, facts: factsOf(booted.shell) };\n } finally {\n await booted.close?.();\n }\n};\n\nconst said = (error: unknown): string => (error instanceof Error ? error.message : String(error));\n\n// ── adopted ──\n//\n// The one check that needs a browser's world. A DOM has to exist BEFORE the\n// app's modules load (an adapter decides what it is running in when it is\n// imported), so it runs in a process of its own: ./adopt stands a DOM up, loads\n// the same config, and for each path puts the markup in a root and makes the\n// app's own `adopt` call over a fresh boot.\n\ntype Adoption = { path: string; complaints: string[] };\n\nconst isAdoption = (value: unknown): value is Adoption =>\n value !== null &&\n typeof value === 'object' &&\n typeof Reflect.get(value, 'path') === 'string' &&\n Array.isArray(Reflect.get(value, 'complaints'));\n\nconst adoptAll = (root: string, pages: readonly { path: string; screen: string }[]): Adoption[] => {\n if (pages.length === 0) return [];\n const here = dirname(fileURLToPath(import.meta.url));\n // built: beside this file. From source (the package's own tests): in dist.\n const entry = [join(here, 'adopt.js'), join(here, '..', 'dist', 'adopt.js')].find((candidate) => existsSync(candidate));\n if (entry === undefined) throw new Error('nisc: the adoption check is not built (packages/cli/dist/adopt.js).');\n const scratch = mkdtempSync(join(tmpdir(), 'nisc-adopt-'));\n try {\n const [asked, answered] = [join(scratch, 'pages.json'), join(scratch, 'adopted.json')];\n writeFileSync(asked, JSON.stringify(pages));\n const result = spawnSync(process.execPath, [entry, root, asked, answered], { cwd: root, stdio: ['ignore', 'ignore', 'pipe'], encoding: 'utf8' });\n if (!existsSync(answered)) {\n const why = result.stderr.trim().split('\\n').slice(-6).join('\\n');\n return pages.map((page) => ({ path: page.path, complaints: [`the adoption check could not run${why === '' ? '' : ` — ${why}`}`] }));\n }\n const parsed: unknown = JSON.parse(readFileSync(answered, 'utf8'));\n return Array.isArray(parsed) ? parsed.filter(isAdoption) : [];\n } finally {\n rmSync(scratch, { recursive: true, force: true });\n }\n};\n\n// Every path, checked.\nexport const surveyShell = async (root: string, project: NiscShellProject, template: string): Promise<ShellRouteReport[]> => {\n if (!template.includes(DEFAULT_ROOT)) {\n throw new Error(`nisc: the built index.html has no empty root (${DEFAULT_ROOT}) — that is where a screen goes.`);\n }\n const paths = project.paths === undefined ? ['/'] : await project.paths();\n const none = { actions: [], opensWith: [], callsLater: [], listens: [] };\n\n const first: { path: string; drawn?: Drawn; problems: string[] }[] = [];\n for (const path of paths) {\n const problems: string[] = [];\n let drawn: Drawn | undefined;\n try {\n drawn = await drawOnce(project, path);\n if (drawn.screen.trim() === '') problems.push('drawn: it drew to nothing');\n if (!drawn.whole) problems.push(`whole: it was still loading after ${project.waitMs ?? DEFAULT_BUILD_WAIT_MS}ms`);\n const again = await drawOnce(project, path);\n if (again.screen !== drawn.screen) problems.push(`same twice: a second boot drew different markup${differenceOf(drawn.screen, again.screen)}`);\n } catch (error) {\n problems.push(`drawn: ${said(error)}`);\n }\n first.push({ path, ...(drawn !== undefined ? { drawn } : {}), problems });\n }\n\n // only what is worth adopting: a screen that drew, whole\n const adoptable = first.flatMap((route) => (route.drawn !== undefined && route.drawn.whole && route.drawn.screen.trim() !== '' ? [{ path: route.path, screen: route.drawn.screen }] : []));\n const adoptions = new Map(adoptAll(root, adoptable).map((adoption) => [adoption.path, adoption.complaints]));\n\n return first.map((route) => {\n const asked = adoptable.some((page) => page.path === route.path);\n const complaints = asked ? (adoptions.get(route.path) ?? ['the adoption check said nothing about it']) : [];\n const problems = [...route.problems, ...complaints.map((complaint) => `adopted: ${complaint}`)];\n return {\n path: route.path,\n html: route.drawn === undefined ? template : placeScreen(template, route.drawn.screen, route.drawn.attributes),\n problems,\n ...(route.drawn?.facts ?? none),\n };\n });\n};\n\n// Where two draws part, in a few words — enough to find it.\nconst differenceOf = (a: string, b: string): string => {\n let at = 0;\n while (at < a.length && at < b.length && a[at] === b[at]) at += 1;\n const around = (text: string): string => JSON.stringify(text.slice(Math.max(0, at - 30), at + 50));\n return ` — at character ${at}: ${around(a)} then ${around(b)}`;\n};\n\nconst pad = (text: string, width: number): string => text + ' '.repeat(Math.max(0, width - text.length));\n\nexport const shellRouteTable = (routes: readonly ShellRouteReport[]): string => {\n const width = Math.max(5, ...routes.map((route) => route.path.length)) + 2;\n const lines = [` ${pad('Route', width)}First screen`];\n const indent = ' '.repeat(width + 2);\n for (const route of routes) {\n const ok = route.problems.length === 0;\n const notes = ok\n ? [\n `drawn · whole · same twice · adopted${route.actions.length > 0 ? ` (${route.actions.join(', ')})` : ''}`,\n ...(route.opensWith.length > 0 ? [`opened with ${route.opensWith.join(', ')} — in the file as answered at build`] : []),\n ...(route.callsLater.length > 0 ? [`can still call ${route.callsLater.join(', ')}`] : []),\n ...(route.listens.length > 0 ? [`waits on ${route.listens.join(', ')}`] : []),\n ]\n : route.problems;\n const [head, ...rest] = notes;\n lines.push(`${ok ? '○' : '✗'} ${pad(route.path, width)}${head ?? ''}`);\n for (const note of rest) lines.push(`${indent}${note}`);\n }\n lines.push('');\n lines.push('○ a file: the first screen, drawn for nobody in particular; the page’s own shell picks it up');\n lines.push('✗ not written: a check did not hold');\n return lines.join('\\n');\n};\n\n// ── served ──\n//\n// The same draw, per request: the first answer to a path is its screen, and\n// everything else in the built folder is a file. No checks here — a build made\n// them; a screen that will not draw goes out as the template, and the page's\n// own boot paints it as it did before any of this existed.\n\nconst TYPES: Record<string, string> = {\n '.html': 'text/html; charset=utf-8',\n '.js': 'text/javascript; charset=utf-8',\n '.mjs': 'text/javascript; charset=utf-8',\n '.css': 'text/css; charset=utf-8',\n '.json': 'application/json; charset=utf-8',\n '.svg': 'image/svg+xml',\n '.png': 'image/png',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.webp': 'image/webp',\n '.ico': 'image/x-icon',\n '.woff2': 'font/woff2',\n '.woff': 'font/woff',\n '.wasm': 'application/wasm',\n '.data': 'application/octet-stream',\n '.map': 'application/json; charset=utf-8',\n '.txt': 'text/plain; charset=utf-8',\n};\n\nexport const shellSite = (project: NiscShellProject, dist: string): ((request: Request) => Promise<Response>) => {\n const base = resolve(dist);\n return async (request) => {\n const path = decodeURIComponent(new URL(request.url).pathname);\n if (path !== '/' && path !== '/index.html') {\n const file = resolve(base, `.${path}`);\n if ((file === base || file.startsWith(base + sep)) && existsSync(file) && statSync(file).isFile()) {\n return new Response(readFileSync(file), { headers: { 'content-type': TYPES[extname(file)] ?? 'application/octet-stream' } });\n }\n // a name with an extension that is not there is a missing file, not a page\n if (extname(path) !== '') return new Response('not found', { status: 404 });\n }\n const template = readFileSync(join(base, 'index.html'), 'utf8');\n const headers = { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-cache' };\n try {\n const drawn = await drawOnce(project, path === '/index.html' ? '/' : path);\n return new Response(placeScreen(template, drawn.screen, drawn.attributes), { headers });\n } catch (error) {\n console.error(`[nisc] \"${path}\" could not be drawn — serving it undrawn:`, error);\n return new Response(template, { headers });\n }\n };\n};\n","import { spawn, spawnSync } from 'node:child_process';\nimport { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport type { AddressInfo } from 'node:net';\nimport { dirname, join, resolve } from 'node:path';\nimport { serve } from '@hono/node-server';\nimport type { ExportedDocument } from '@niscorp/moss';\nimport { devServer } from './dev';\nimport { isShellProject, loadProject } from './project';\nimport type { NiscMossProject, NiscProject, NiscShellProject } from './project';\nimport { defaultPaths, fileOf, routeTable } from './routes';\nimport { shellRouteTable, shellSite, surveyShell } from './shell-site';\nimport type { ShellRouteReport } from './shell-site';\n\n// ═══════════════════════════════════════════════════════════════\n// What `nisc` does. Each command is the app's own machinery, run in order:\n//\n// dev the app's own vite, with the app server inside it when it has one\n// build bundle the terminal, then draw every path once and say how each is\n// served — a file, or a server\n// export build, then write every path as a file: the whole site as a folder\n// start serve the built terminal from the app's own process, pages drawn\n// check the app's check suite\n//\n// Nothing here knows an app. How it boots and how a screen is drawn come from\n// its nisc.config.ts. An app behind moss hands over its server, and which paths\n// exist and what each needs come from that (`server.pages`, `exportDocuments`).\n// An app with its own shell hands over its boot, and every path is drawn from\n// that and checked (./shell-site). Moss is loaded only for the first kind — an\n// app without it does not have it installed.\n// ═══════════════════════════════════════════════════════════════\n\nexport type CommandOptions = {\n // the app's root (where nisc.config.ts is)\n root: string;\n // export: where the files go (default `out`), relative to the root\n out?: string;\n // export: write the site even though some path wants a server behind it\n allowLive?: boolean;\n // start: the port (default $PORT, then 8787)\n port?: number;\n // build/export: skip the bundler (the terminal is already built)\n skipBundle?: boolean;\n print?: (line: string) => void;\n};\n\nconst say = (options: CommandOptions): ((line: string) => void) => options.print ?? ((line) => console.log(line));\n\n// A tool the APP has installed, found from the app's own root — the command\n// carries no bundler and no test runner of its own.\nconst toolOf = (root: string, name: string, bin: string): string => {\n const require = createRequire(join(root, 'package.json'));\n let manifestPath: string;\n try {\n manifestPath = require.resolve(`${name}/package.json`);\n } catch {\n throw new Error(`nisc: this app has no ${name} installed (looked from ${root}).`);\n }\n const manifest: unknown = JSON.parse(readFileSync(manifestPath, 'utf8'));\n const bins: unknown = manifest !== null && typeof manifest === 'object' ? Reflect.get(manifest, 'bin') : undefined;\n const relative: unknown = typeof bins === 'string' ? bins : bins !== null && typeof bins === 'object' ? Reflect.get(bins, bin) : undefined;\n if (typeof relative !== 'string') throw new Error(`nisc: ${name} ships no \"${bin}\" command.`);\n return join(dirname(manifestPath), relative);\n};\n\nconst distOf = (root: string, project: NiscProject): string => resolve(root, project.dist ?? 'dist');\n\nconst bundle = (options: CommandOptions): void => {\n const result = spawnSync(process.execPath, [toolOf(options.root, 'vite', 'vite'), 'build'], { cwd: options.root, stdio: 'inherit' });\n if (result.status !== 0) throw new Error('nisc: the bundler failed — nothing was drawn.');\n};\n\n// Stand the app up, draw every path once for nobody, let the app go.\nconst templateOf = (options: CommandOptions, project: NiscProject): string => {\n const template = join(distOf(options.root, project), 'index.html');\n if (!existsSync(template)) throw new Error(`nisc: no built terminal at ${template} — run \\`nisc build\\`.`);\n return readFileSync(template, 'utf8');\n};\n\nconst survey = async (options: CommandOptions, project: NiscMossProject): Promise<ExportedDocument[]> => {\n const template = templateOf(options, project);\n const { exportDocuments } = await import('@niscorp/moss');\n const booted = await project.boot();\n try {\n const paths = project.paths === undefined ? defaultPaths(booted.server.pages) : await project.paths(booted.server);\n return await exportDocuments({\n server: booted.server,\n template,\n draw: project.draw,\n ...(project.htmlAttributes !== undefined ? { htmlAttributes: project.htmlAttributes } : {}),\n ...(project.tokenKey !== undefined ? { tokenKey: project.tokenKey } : {}),\n paths,\n });\n } finally {\n await booted.close?.();\n }\n};\n\n// What a build found, either way round: every path, and whether the build holds.\nexport type BuildResult =\n | { kind: 'moss'; ok: boolean; routes: ExportedDocument[] }\n | { kind: 'shell'; ok: boolean; routes: ShellRouteReport[] };\n\nconst buildShell = async (options: CommandOptions, project: NiscShellProject): Promise<BuildResult> => {\n const routes = await surveyShell(options.root, project, templateOf(options, project));\n say(options)('');\n say(options)(shellRouteTable(routes));\n return { kind: 'shell', ok: routes.every((route) => route.problems.length === 0), routes };\n};\n\nexport const build = async (options: CommandOptions): Promise<BuildResult> => {\n const project = await loadProject(options.root);\n if (options.skipBundle !== true) bundle(options);\n if (isShellProject(project)) return buildShell(options, project);\n const routes = await survey(options, project);\n say(options)('');\n say(options)(routeTable(routes));\n return { kind: 'moss', ok: routes.every((route) => route.drawn), routes };\n};\n\nconst write = (options: CommandOptions, project: NiscProject, out: string, routes: readonly { path: string; html: string }[]): void => {\n rmSync(out, { recursive: true, force: true });\n cpSync(distOf(options.root, project), out, { recursive: true });\n for (const route of routes) {\n const file = join(out, fileOf(route.path));\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, route.html);\n }\n say(options)('');\n say(options)(`nisc: ${routes.length} paths written to ${out}`);\n};\n\n// The whole site as a folder. A path that wants a server behind it is not\n// something a folder can be — so unless the caller says a server will stand\n// beside the files (`allowLive`), nothing is written and the table says why.\n//\n// An app with its own shell has no such path: the shell is in the page, so a\n// folder is all of it. What stops ITS files is a check that did not hold.\nexport const exportSite = async (options: CommandOptions): Promise<{ written: boolean; result: BuildResult; out: string }> => {\n const project = await loadProject(options.root);\n const result = await build(options);\n const out = resolve(options.root, options.out ?? 'out');\n if (result.kind === 'shell') {\n if (!result.ok) {\n const failed = result.routes.filter((route) => route.problems.length > 0);\n say(options)('');\n say(options)(`nisc: ${failed.length} of ${result.routes.length} paths did not hold (${failed.map((route) => route.path).join(', ')}). Nothing was written.`);\n return { written: false, result, out };\n }\n write(options, project, out, result.routes);\n return { written: true, result, out };\n }\n const routes = result.routes;\n const live = routes.filter((route) => route.live || !route.drawn);\n if (live.length > 0 && options.allowLive !== true) {\n say(options)('');\n say(options)(`nisc: ${live.length} of ${routes.length} paths cannot be a file alone (${live.map((route) => route.path).join(', ')}).`);\n say(options)(' Nothing was written. With a server beside the files they still work: `nisc export --allow-live`.');\n return { written: false, result, out };\n }\n write(options, project, out, routes);\n return { written: true, result, out };\n};\n\nconst listening = async (httpServer: ReturnType<typeof serve>, options: CommandOptions): Promise<string> => {\n await new Promise<void>((up) => httpServer.once('listening', () => up()));\n const address = httpServer.address();\n const port = address !== null && typeof address === 'object' ? (address satisfies AddressInfo).port : options.port;\n return `http://localhost:${port}`;\n};\n\nexport const start = async (options: CommandOptions): Promise<{ url: string; close: () => Promise<void> }> => {\n const project = await loadProject(options.root);\n const dist = distOf(options.root, project);\n if (!existsSync(join(dist, 'index.html'))) throw new Error(`nisc: no built terminal in ${dist} — run \\`nisc build\\`.`);\n const port = options.port ?? Number(process.env['PORT'] ?? 8787);\n if (isShellProject(project)) {\n // no server shell, no socket: each path's first answer is its screen, drawn\n // from a boot of the app's own, and the page's shell takes it from there\n const httpServer = serve({ fetch: shellSite(project, dist), port });\n const url = await listening(httpServer, options);\n say(options)(`nisc: serving ${url} — the built app, each path’s first screen drawn; the shell is the page’s own`);\n return { url, close: async () => void httpServer.close() };\n }\n const { attachSocket, mountSite } = await import('@niscorp/moss/node');\n const booted = await project.boot();\n await project.routes?.(booted.server);\n mountSite(booted.server, {\n dist,\n draw: project.draw,\n ...(project.htmlAttributes !== undefined ? { htmlAttributes: project.htmlAttributes } : {}),\n ...(project.tokenKey !== undefined ? { tokenKey: project.tokenKey } : {}),\n });\n const httpServer = serve({ fetch: booted.server.fetch, port });\n attachSocket(httpServer, booted.server.socket);\n const url = await listening(httpServer, options);\n say(options)(`nisc: serving ${url} — the built terminal, its pages drawn; the socket at /socket`);\n return {\n url,\n close: async () => {\n httpServer.close();\n await booted.close?.();\n },\n };\n};\n\n// The two that hand over to a tool of the app's own and stay out of the way.\nconst handOver = (options: CommandOptions, tool: string, args: readonly string[]): Promise<number> =>\n new Promise((done) => {\n const child = spawn(process.execPath, [tool, ...args], { cwd: options.root, stdio: 'inherit' });\n child.once('exit', (code) => done(code ?? 1));\n });\n\nexport const dev = (options: CommandOptions): Promise<{ url: string; close: () => Promise<void> }> =>\n devServer({ root: options.root, ...(options.port !== undefined ? { port: options.port } : {}) });\n\nexport const check = async (options: CommandOptions): Promise<number> => {\n const project = await loadProject(options.root);\n return handOver(options, toolOf(options.root, 'tsx', 'tsx'), [project.checks ?? 'src/dev/all-checks.ts']);\n};\n","import { resolve } from 'node:path';\nimport { build, check, dev, exportSite, start } from './commands';\nimport type { CommandOptions } from './commands';\n\n// ═══════════════════════════════════════════════════════════════\n// nisc — the command line. It parses, and hands over to ./commands.\n// ═══════════════════════════════════════════════════════════════\n\nconst USAGE = `nisc — the command for a nisc application\n\n nisc dev the app's dev server — its vite, with the app server inside\n nisc build bundle the app, draw every path, and check what was drawn\n nisc export build, then write every path as a file (the site as a folder)\n nisc start serve the built app, each path's first screen drawn\n nisc check the app's check suite\n\n --root <dir> the app's root (default: here) — where nisc.config.ts is\n --out <dir> export: where the files go (default: out)\n --allow-live export: write even though some path wants a server behind it\n --port <n> dev, start: the port (start: $PORT, then 8787)\n --skip-bundle build, export: the terminal is already built\n\nAn app says in nisc.config.ts how it boots and how one of its screens is drawn.\nBehind moss (boot + draw): which paths exist and what each needs is read off the\nserver. With its own shell (shell + draw + adopt): every path is drawn from the\napp's own boot, and a file is written only if the page's boot picks it up clean.`;\n\nconst valueAfter = (args: readonly string[], flag: string): string | undefined => {\n const at = args.indexOf(flag);\n return at < 0 ? undefined : args[at + 1];\n};\n\nconst main = async (): Promise<number> => {\n const [command, ...args] = process.argv.slice(2);\n const port = valueAfter(args, '--port');\n const out = valueAfter(args, '--out');\n const options: CommandOptions = {\n root: resolve(valueAfter(args, '--root') ?? process.cwd()),\n ...(out !== undefined ? { out } : {}),\n ...(port !== undefined ? { port: Number(port) } : {}),\n allowLive: args.includes('--allow-live'),\n skipBundle: args.includes('--skip-bundle'),\n };\n\n if (command === 'dev' || command === 'start') {\n const served = command === 'dev' ? await dev(options) : await start(options);\n const stop = (): void => {\n void served.close().finally(() => process.exit(0));\n };\n process.on('SIGINT', stop);\n process.on('SIGTERM', stop);\n // stays up until it is told to stop\n return new Promise<number>(() => undefined);\n }\n if (command === 'check') return check(options);\n if (command === 'build') {\n return (await build(options)).ok ? 0 : 1;\n }\n if (command === 'export') return (await exportSite(options)).written ? 0 : 1;\n console.log(USAGE);\n return command === undefined || command === 'help' || command === '--help' ? 0 : 1;\n};\n\nmain().then(\n // An app's own handles (a database, a timer) must not keep a finished command\n // open: a command that is done says so and leaves.\n (code) => process.exit(code),\n (error: unknown) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n },\n);\n"]}
package/dist/index.d.cts CHANGED
@@ -15,6 +15,9 @@ type NiscMossProject = Common & {
15
15
  tokenKey?: string;
16
16
  paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;
17
17
  routes?: (server: MossServer) => void | Promise<void>;
18
+ dev?: {
19
+ signIn?: (server: MossServer, who: string) => string | null | Promise<string | null>;
20
+ };
18
21
  };
19
22
  type NiscShellProject = Common & {
20
23
  shell: (request: {
package/dist/index.d.ts CHANGED
@@ -15,6 +15,9 @@ type NiscMossProject = Common & {
15
15
  tokenKey?: string;
16
16
  paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;
17
17
  routes?: (server: MossServer) => void | Promise<void>;
18
+ dev?: {
19
+ signIn?: (server: MossServer, who: string) => string | null | Promise<string | null>;
20
+ };
18
21
  };
19
22
  type NiscShellProject = Common & {
20
23
  shell: (request: {
@@ -0,0 +1,3 @@
1
+ export { configFileOf, isProject, isShellProject, loadProject } from './chunk-MRNC4GI5.js';
2
+ //# sourceMappingURL=project-PODTS3SZ.js.map
3
+ //# sourceMappingURL=project-PODTS3SZ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"project-JL74OSJC.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"project-PODTS3SZ.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niscorp/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "nisc — the command for a nisc application: dev, build, export, start. One config file says how the app boots and how its pages are drawn; the command does the rest.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -38,8 +38,8 @@
38
38
  "node": ">=22.12"
39
39
  },
40
40
  "peerDependencies": {
41
- "@niscorp/moss": "^0.1.0",
42
- "@niscorp/nova": "^0.1.0"
41
+ "@niscorp/nova": "^0.1.1",
42
+ "@niscorp/moss": "^0.2.0"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@niscorp/moss": {
@@ -57,8 +57,8 @@
57
57
  "tsup": "^8.5.1",
58
58
  "typescript": "^6.0.2",
59
59
  "vitest": "^4.1.2",
60
- "@niscorp/moss": "^0.1.0",
61
- "@niscorp/nova": "^0.1.0"
60
+ "@niscorp/moss": "^0.2.0",
61
+ "@niscorp/nova": "^0.1.1"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "tsup",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/project.ts"],"names":[],"mappings":";;;;;AAyFA,IAAM,YAAA,GAAe,CAAC,gBAAA,EAAkB,iBAAA,EAAmB,kBAAkB,iBAAiB,CAAA;AAE9F,IAAM,GAAA,GAAM,CAAC,KAAA,EAAe,GAAA,KAAyB,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA,KAAM,UAAA;AAEjF,IAAM,cAAA,GAAiB,CAAC,OAAA,KAAsD,OAAA,IAAW;AAEhG,IAAM,SAAA,GAAY,CAAC,KAAA,KAAyC;AAC1D,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,GAAA,CAAI,KAAA,EAAO,MAAM,CAAA,EAAG,OAAO,KAAA;AAC/E,EAAA,MAAM,CAAC,IAAA,EAAM,GAAG,CAAA,GAAI,CAAC,GAAA,CAAI,KAAA,EAAO,MAAM,CAAA,EAAG,GAAA,CAAI,KAAA,EAAO,OAAO,CAAC,CAAA;AAE5D,EAAA,OAAO,IAAA,KAAS,GAAA,KAAQ,IAAA,IAAQ,GAAA,CAAI,OAAO,OAAO,CAAA,CAAA;AACpD,CAAA;AAIO,IAAM,WAAA,GAAc,OAAO,IAAA,KAAuC;AACvE,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,GAAA,CAAI,CAAC,SAAS,IAAA,CAAK,IAAA,EAAM,IAAI,CAAC,EAAE,IAAA,CAAK,CAAC,SAAA,KAAc,UAAA,CAAW,SAAS,CAAC,CAAA;AACnG,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2BAAA,EAA8B,IAAI,CAAA,iFAAA,CAAmF,CAAA;AAAA,EACvI;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAM,OAAO,aAAa,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,IAAA,EAAM,eAAe,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAkB,MAAM,QAAA,CAAS,aAAA,CAAc,IAAI,CAAA,CAAE,IAAA,EAAM,EAAE,SAAA,EAAW,MAAA,CAAA,IAAA,CAAY,KAAK,GAAI,UAAA,CAAW,QAAQ,CAAA,GAAI,EAAE,UAAS,GAAI,IAAK,CAAA;AAC9I,EAAA,MAAM,OAAA,GAAmB,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,SAAS,CAAA,GAAI,MAAA;AAC1G,EAAA,IAAI,CAAC,SAAA,CAAU,OAAO,CAAA,EAAG;AACvB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,SAAS,IAAI,CAAA,kLAAA;AAAA,KACf;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-E73LP64A.js","sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { DocumentConfig, MossServer } from '@niscorp/moss';\nimport type { Shell } from '@niscorp/nova';\n\n// ═══════════════════════════════════════════════════════════════\n// WHAT AN APP SAYS ABOUT ITSELF — `nisc.config.ts`, at the app's root, exporting\n// `project`. What only the app knows: how it stands up, and how one of its\n// screens is drawn. Everything the command does is derived from those.\n//\n// An app is one of two things, and its config says which by what it hands over.\n//\n// BEHIND MOSS — the shell lives on the server. The config hands over the\n// server; which paths exist and what each needs is read off its manifest.\n//\n// export const project: NiscProject = {\n// boot: async () => ({ server: (await boot()).server }),\n// draw: (snapshot) => renderSnapshot({ snapshot, registry, slotWrapper }),\n// };\n//\n// ITS OWN SHELL — the shell lives in the page (AGENTS.md, \"the client-degrade\n// path\"). The config hands over the app's own boot, the SAME one its browser\n// entry runs. A build runs it where there is no browser, draws the screen to\n// markup, and the page's boot picks that markup up.\n//\n// export const project: NiscProject = {\n// shell: async () => ({ shell: (await boot()).shell }),\n// draw: (shell) => renderToString(createElement(Screen, { shell })),\n// adopt: (root, shell) => { hydrateRoot(root, createElement(Screen, { shell })); },\n// };\n// ═══════════════════════════════════════════════════════════════\n\ntype Common = {\n // Where the bundler writes the terminal (default `dist`), relative to the root.\n dist?: string;\n // The app's check suite, for `nisc check` (default `src/dev/all-checks.ts`).\n checks?: string;\n};\n\nexport type NiscMossProject = Common & {\n // Stand the app up: the moss server, and how to let it go again. The same boot\n // the app's dev server and its checks run.\n boot: () => Promise<{ server: MossServer; close?: () => void | Promise<void> }>;\n // A terminal that draws one screen to a string — the app's kit bound to one of\n // moss's server targets (`@niscorp/moss/terminal/react/server`, …).\n draw: DocumentConfig['draw'];\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: DocumentConfig['htmlAttributes'];\n // The wire's token key, when it is not `nisc.token`.\n tokenKey?: string;\n // The paths to build. Default: `/`, and every page whose path has no\n // parameter. A page with parameters (\"/docs/:slug\") has as many paths as there\n // are rows, and only the app knows them — list them here (`server.executeAs`\n // runs a seeded read as a charter role).\n paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;\n // Routes of the app's own that a served site needs before the catch-all — a\n // sign-in handoff, a webhook. `nisc start` registers them first.\n routes?: (server: MossServer) => void | Promise<void>;\n};\n\nexport type NiscShellProject = Common & {\n // One fresh copy of the app's shell, for one path — the boot the browser entry\n // runs. It is handed the path and NOTHING ELSE: there is no credential to pass\n // and no way to pass one, so what a build draws is the screen as nobody in\n // particular sees it. Called more than once per path (the build boots twice\n // to compare, and once more inside a DOM to adopt), so it must not memoize.\n shell: (request: { path: string }) => Promise<{ shell: Shell; close?: () => void | Promise<void> }>;\n // Draw a shell to markup where there is no browser: the app's kit through an\n // adapter's string target (`react-dom/server`, `vue/server-renderer`,\n // `@niscorp/nova/adapters/dom/server`).\n draw: (shell: Shell) => string | Promise<string>;\n // Pick the markup up: `root` already holds it, `shell` is the page's own. The\n // SAME call the browser entry makes (`hydrateRoot`, `createSSRApp().mount`,\n // nova's `mountShell`). A build runs it inside a DOM and fails on anything it\n // complains about.\n adopt: (root: HTMLElement, shell: Shell) => void | Promise<void>;\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: (shell: Shell) => Record<string, string>;\n // The paths to build (default: `/`). An app that maps paths to actions lists\n // its own — only it knows them.\n paths?: () => readonly string[] | Promise<readonly string[]>;\n // How long a build waits for a screen to be whole (default 5000ms). Past it\n // the build FAILS: a file that says \"loading\" is not the page.\n waitMs?: number;\n};\n\nexport type NiscProject = NiscMossProject | NiscShellProject;\n\nconst CONFIG_NAMES = ['nisc.config.ts', 'nisc.config.mts', 'nisc.config.js', 'nisc.config.mjs'];\n\nconst has = (value: object, key: string): boolean => typeof Reflect.get(value, key) === 'function';\n\nexport const isShellProject = (project: NiscProject): project is NiscShellProject => 'shell' in project;\n\nconst isProject = (value: unknown): value is NiscProject => {\n if (value === null || typeof value !== 'object' || !has(value, 'draw')) return false;\n const [moss, own] = [has(value, 'boot'), has(value, 'shell')];\n // one or the other — a config that hands over both has not said which it is\n return moss !== own && (moss || has(value, 'adopt'));\n};\n\n// Load the app's config through tsx, so it is TypeScript with the app's own\n// tsconfig (its path aliases included) — the way the app's checks already run.\nexport const loadProject = async (root: string): Promise<NiscProject> => {\n const file = CONFIG_NAMES.map((name) => join(root, name)).find((candidate) => existsSync(candidate));\n if (file === undefined) {\n throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \\`project\\`: how the app boots, and how one of its screens is drawn.`);\n }\n const { tsImport } = await import('tsx/esm/api');\n const tsconfig = join(root, 'tsconfig.json');\n const loaded: unknown = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...(existsSync(tsconfig) ? { tsconfig } : {}) });\n const project: unknown = loaded !== null && typeof loaded === 'object' ? Reflect.get(loaded, 'project') : undefined;\n if (!isProject(project)) {\n throw new Error(\n `nisc: ${file} does not export a \\`project\\` the command can run. It hands over EITHER \\`boot\\` + \\`draw\\` (an app behind moss) OR \\`shell\\` + \\`draw\\` + \\`adopt\\` (an app with its own shell).`,\n );\n }\n return project;\n};\n"]}
@@ -1,33 +0,0 @@
1
- import { existsSync } from 'fs';
2
- import { join } from 'path';
3
- import { pathToFileURL } from 'url';
4
-
5
- // src/project.ts
6
- var CONFIG_NAMES = ["nisc.config.ts", "nisc.config.mts", "nisc.config.js", "nisc.config.mjs"];
7
- var has = (value, key) => typeof Reflect.get(value, key) === "function";
8
- var isShellProject = (project) => "shell" in project;
9
- var isProject = (value) => {
10
- if (value === null || typeof value !== "object" || !has(value, "draw")) return false;
11
- const [moss, own] = [has(value, "boot"), has(value, "shell")];
12
- return moss !== own && (moss || has(value, "adopt"));
13
- };
14
- var loadProject = async (root) => {
15
- const file = CONFIG_NAMES.map((name) => join(root, name)).find((candidate) => existsSync(candidate));
16
- if (file === void 0) {
17
- throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \`project\`: how the app boots, and how one of its screens is drawn.`);
18
- }
19
- const { tsImport } = await import('tsx/esm/api');
20
- const tsconfig = join(root, "tsconfig.json");
21
- const loaded = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...existsSync(tsconfig) ? { tsconfig } : {} });
22
- const project = loaded !== null && typeof loaded === "object" ? Reflect.get(loaded, "project") : void 0;
23
- if (!isProject(project)) {
24
- throw new Error(
25
- `nisc: ${file} does not export a \`project\` the command can run. It hands over EITHER \`boot\` + \`draw\` (an app behind moss) OR \`shell\` + \`draw\` + \`adopt\` (an app with its own shell).`
26
- );
27
- }
28
- return project;
29
- };
30
-
31
- export { isShellProject, loadProject };
32
- //# sourceMappingURL=chunk-TCI624CB.js.map
33
- //# sourceMappingURL=chunk-TCI624CB.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/project.ts"],"names":[],"mappings":";;;;;AA4FA,IAAM,YAAA,GAAe,CAAC,gBAAA,EAAkB,iBAAA,EAAmB,kBAAkB,iBAAiB,CAAA;AAE9F,IAAM,GAAA,GAAM,CAAC,KAAA,EAAe,GAAA,KAAyB,OAAO,OAAA,CAAQ,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA,KAAM,UAAA;AAEjF,IAAM,cAAA,GAAiB,CAAC,OAAA,KAAsD,OAAA,IAAW;AAEhG,IAAM,SAAA,GAAY,CAAC,KAAA,KAAyC;AAC1D,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,GAAA,CAAI,KAAA,EAAO,MAAM,CAAA,EAAG,OAAO,KAAA;AAC/E,EAAA,MAAM,CAAC,IAAA,EAAM,GAAG,CAAA,GAAI,CAAC,GAAA,CAAI,KAAA,EAAO,MAAM,CAAA,EAAG,GAAA,CAAI,KAAA,EAAO,OAAO,CAAC,CAAA;AAE5D,EAAA,OAAO,IAAA,KAAS,GAAA,KAAQ,IAAA,IAAQ,GAAA,CAAI,OAAO,OAAO,CAAA,CAAA;AACpD,CAAA;AAIO,IAAM,WAAA,GAAc,OAAO,IAAA,KAAuC;AACvE,EAAA,MAAM,IAAA,GAAO,YAAA,CAAa,GAAA,CAAI,CAAC,SAAS,IAAA,CAAK,IAAA,EAAM,IAAI,CAAC,EAAE,IAAA,CAAK,CAAC,SAAA,KAAc,UAAA,CAAW,SAAS,CAAC,CAAA;AACnG,EAAA,IAAI,SAAS,MAAA,EAAW;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2BAAA,EAA8B,IAAI,CAAA,iFAAA,CAAmF,CAAA;AAAA,EACvI;AACA,EAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAM,OAAO,aAAa,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,IAAA,EAAM,eAAe,CAAA;AAC3C,EAAA,MAAM,MAAA,GAAkB,MAAM,QAAA,CAAS,aAAA,CAAc,IAAI,CAAA,CAAE,IAAA,EAAM,EAAE,SAAA,EAAW,MAAA,CAAA,IAAA,CAAY,KAAK,GAAI,UAAA,CAAW,QAAQ,CAAA,GAAI,EAAE,UAAS,GAAI,IAAK,CAAA;AAC9I,EAAA,MAAM,OAAA,GAAmB,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,SAAS,CAAA,GAAI,MAAA;AAC1G,EAAA,IAAI,CAAC,SAAA,CAAU,OAAO,CAAA,EAAG;AACvB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,SAAS,IAAI,CAAA,kLAAA;AAAA,KACf;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-TCI624CB.js","sourcesContent":["import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { DocumentConfig, MossServer } from '@niscorp/moss';\nimport type { Shell } from '@niscorp/nova';\n\n// ═══════════════════════════════════════════════════════════════\n// WHAT AN APP SAYS ABOUT ITSELF — `nisc.config.ts`, at the app's root, exporting\n// `project`. What only the app knows: how it stands up, and how one of its\n// screens is drawn. Everything the command does is derived from those.\n//\n// An app is one of two things, and its config says which by what it hands over.\n//\n// BEHIND MOSS — the shell lives on the server. The config hands over the\n// server; which paths exist and what each needs is read off its manifest.\n//\n// export const project: NiscProject = {\n// boot: async () => ({ server: (await boot()).server }),\n// draw: (snapshot) => renderSnapshot({ snapshot, registry, slotWrapper }),\n// };\n//\n// ITS OWN SHELL — the shell lives in the page (AGENTS.md, \"the client-degrade\n// path\"). The config hands over the app's own boot, the SAME one its browser\n// entry runs. A build runs it where there is no browser, draws the screen to\n// markup, and the page's boot picks that markup up.\n//\n// export const project: NiscShellProject = {\n// shell: async () => ({ shell: (await boot()).shell }),\n// draw: (shell) => renderToString(createElement(Screen, { shell })),\n// adopt: (root, shell) => { hydrateRoot(root, createElement(Screen, { shell })); },\n// };\n// ═══════════════════════════════════════════════════════════════\n\ntype Common = {\n // Where the bundler writes the terminal (default `dist`), relative to the root.\n dist?: string;\n // The app's check suite, for `nisc check` (default `src/dev/all-checks.ts`).\n checks?: string;\n};\n\nexport type NiscMossProject = Common & {\n // Stand the app up: the moss server, and how to let it go again. The same boot\n // the app's dev server and its checks run.\n boot: () => Promise<{ server: MossServer; close?: () => void | Promise<void> }>;\n // A terminal that draws one screen to a string — the app's kit bound to one of\n // moss's server targets (`@niscorp/moss/terminal/react/server`, …).\n draw: DocumentConfig['draw'];\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: DocumentConfig['htmlAttributes'];\n // The wire's token key, when it is not `nisc.token`.\n tokenKey?: string;\n // The paths to build. Default: `/`, and every page whose path has no\n // parameter. A page with parameters (\"/docs/:slug\") has as many paths as there\n // are rows, and only the app knows them — list them here (`server.executeAs`\n // runs a seeded read as a charter role).\n paths?: (server: MossServer) => readonly string[] | Promise<readonly string[]>;\n // Routes of the app's own that a served site needs before the catch-all — a\n // sign-in handoff, a webhook. `nisc start` registers them first.\n routes?: (server: MossServer) => void | Promise<void>;\n};\n\nexport type NiscShellProject = Common & {\n // One fresh copy of the app's shell, for one path — the boot the browser entry\n // runs. It is handed the path and NOTHING ELSE: there is no credential to pass\n // and no way to pass one, so what a build draws is the screen as nobody in\n // particular sees it. Called more than once per path (the build boots twice\n // to compare, and once more inside a DOM to adopt), so it must not memoize.\n shell: (request: { path: string }) => Promise<{ shell: Shell; close?: () => void | Promise<void> }>;\n // Draw a shell to markup where there is no browser: the app's kit through an\n // adapter's string target (`react-dom/server`, `vue/server-renderer`,\n // `@niscorp/nova/adapters/dom/server`).\n draw: (shell: Shell) => string | Promise<string>;\n // Pick the markup up: `root` already holds it, `shell` is the page's own. The\n // SAME call the browser entry makes (`hydrateRoot`, `createSSRApp().mount`,\n // nova's `mountShell`). A build runs it inside a DOM and fails on anything it\n // complains about.\n adopt: (root: HTMLElement, shell: Shell) => void | Promise<void>;\n // What the kit would put on <html> from an effect (a palette, a scheme).\n htmlAttributes?: (shell: Shell) => Record<string, string>;\n // The paths to build (default: `/`). An app that maps paths to actions lists\n // its own — only it knows them.\n paths?: () => readonly string[] | Promise<readonly string[]>;\n // How long a build waits for a screen to be whole (default 5000ms). Past it\n // the build FAILS: a file that says \"loading\" is not the page.\n waitMs?: number;\n};\n\n// What a config exports. Written against one of the two names above, a config's\n// callbacks are typed for it (`draw`'s argument is a snapshot in one and a shell\n// in the other).\nexport type NiscProject = NiscMossProject | NiscShellProject;\n\nconst CONFIG_NAMES = ['nisc.config.ts', 'nisc.config.mts', 'nisc.config.js', 'nisc.config.mjs'];\n\nconst has = (value: object, key: string): boolean => typeof Reflect.get(value, key) === 'function';\n\nexport const isShellProject = (project: NiscProject): project is NiscShellProject => 'shell' in project;\n\nconst isProject = (value: unknown): value is NiscProject => {\n if (value === null || typeof value !== 'object' || !has(value, 'draw')) return false;\n const [moss, own] = [has(value, 'boot'), has(value, 'shell')];\n // one or the other — a config that hands over both has not said which it is\n return moss !== own && (moss || has(value, 'adopt'));\n};\n\n// Load the app's config through tsx, so it is TypeScript with the app's own\n// tsconfig (its path aliases included) — the way the app's checks already run.\nexport const loadProject = async (root: string): Promise<NiscProject> => {\n const file = CONFIG_NAMES.map((name) => join(root, name)).find((candidate) => existsSync(candidate));\n if (file === undefined) {\n throw new Error(`nisc: no nisc.config.ts in ${root}. It exports \\`project\\`: how the app boots, and how one of its screens is drawn.`);\n }\n const { tsImport } = await import('tsx/esm/api');\n const tsconfig = join(root, 'tsconfig.json');\n const loaded: unknown = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...(existsSync(tsconfig) ? { tsconfig } : {}) });\n const project: unknown = loaded !== null && typeof loaded === 'object' ? Reflect.get(loaded, 'project') : undefined;\n if (!isProject(project)) {\n throw new Error(\n `nisc: ${file} does not export a \\`project\\` the command can run. It hands over EITHER \\`boot\\` + \\`draw\\` (an app behind moss) OR \\`shell\\` + \\`draw\\` + \\`adopt\\` (an app with its own shell).`,\n );\n }\n return project;\n};\n"]}
@@ -1,3 +0,0 @@
1
- export { isShellProject, loadProject } from './chunk-TCI624CB.js';
2
- //# sourceMappingURL=project-JL74OSJC.js.map
3
- //# sourceMappingURL=project-JL74OSJC.js.map
@@ -1,3 +0,0 @@
1
- export { isShellProject, loadProject } from './chunk-E73LP64A.js';
2
- //# sourceMappingURL=project-VRM6S2BY.js.map
3
- //# sourceMappingURL=project-VRM6S2BY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"project-VRM6S2BY.js"}