@niscorp/cli 0.0.0-stage → 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 +12 -0
- package/LICENSE +202 -0
- package/README.md +244 -2
- package/bin/nisc.js +9 -0
- package/dist/adopt.js +82 -0
- package/dist/adopt.js.map +1 -0
- package/dist/chunk-MRNC4GI5.js +35 -0
- package/dist/chunk-MRNC4GI5.js.map +1 -0
- package/dist/cli.js +467 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +88 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/project-PODTS3SZ.js +3 -0
- package/dist/project-PODTS3SZ.js.map +1 -0
- package/package.json +67 -3
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/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,245 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @niscorp/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`nisc` — the command for a nisc application.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add -D @niscorp/cli
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A new app starts with `npm create nisc`, which writes the `nisc.config.ts`
|
|
10
|
+
described below.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
nisc dev # the app's dev server
|
|
14
|
+
nisc build # bundle the app, draw every path, and check what was drawn
|
|
15
|
+
nisc export # build, then write every path as a file — the site as a folder
|
|
16
|
+
nisc start # serve the built app, each path's first screen drawn
|
|
17
|
+
nisc check # the app's check suite
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
An app is one of two things, and the command runs both. **Behind moss**, the
|
|
21
|
+
shell lives on the server and the page is a terminal. **With its own shell**,
|
|
22
|
+
the shell lives in the page and there is no server at all. Either way the first
|
|
23
|
+
thing a browser — or a crawler — receives for a path is that path's screen, as
|
|
24
|
+
markup.
|
|
25
|
+
|
|
26
|
+
## What an app writes
|
|
27
|
+
|
|
28
|
+
One file at its root, `nisc.config.ts`, exporting `project` — what only the app
|
|
29
|
+
knows. Which of the two it is follows from what it hands over.
|
|
30
|
+
|
|
31
|
+
### An app behind moss
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import type { NiscMossProject } from '@niscorp/cli';
|
|
35
|
+
import { renderSnapshot } from '@niscorp/moss/terminal/react/server';
|
|
36
|
+
import { boot } from './src/server/boot';
|
|
37
|
+
import { buildRegistry } from './src/ui/registry';
|
|
38
|
+
|
|
39
|
+
const registry = buildRegistry();
|
|
40
|
+
|
|
41
|
+
export const project: NiscMossProject = {
|
|
42
|
+
// how it stands up — the same boot its dev server and its checks run
|
|
43
|
+
boot: async () => {
|
|
44
|
+
const { server } = await boot();
|
|
45
|
+
return { server, close: () => server.close() };
|
|
46
|
+
},
|
|
47
|
+
// how one of its screens is drawn to a string
|
|
48
|
+
draw: (snapshot) => renderSnapshot({ snapshot, registry }),
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Everything else is read off the booted app: which paths exist (`/`, and every
|
|
53
|
+
page in the manifest), and what each one needs once it has been drawn.
|
|
54
|
+
|
|
55
|
+
| Field | |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `boot` | stand the app up: `{ server, close? }` |
|
|
58
|
+
| `draw` | a terminal that draws a screen to a string (moss's `terminal/react/server`, `/vue/server`, `/dom/server`) |
|
|
59
|
+
| `htmlAttributes?` | what the kit would put on `<html>` from an effect (a palette, a scheme) |
|
|
60
|
+
| `paths?` | the paths to build. Default: `/` and every page whose path has no parameter. A page like `/docs/:slug` has as many paths as there are rows — list them here (`server.executeAs` runs a seeded read as a charter role) |
|
|
61
|
+
| `routes?` | routes of the app's own that `nisc start` registers before the site (a sign-in handoff, a webhook) |
|
|
62
|
+
| `dist?` | where the bundler writes the terminal (default `dist`) |
|
|
63
|
+
| `checks?` | the check suite `nisc check` runs (default `src/dev/all-checks.ts`) |
|
|
64
|
+
| `tokenKey?` | the wire's token key, when it is not `nisc.token` |
|
|
65
|
+
|
|
66
|
+
### An app with its own shell
|
|
67
|
+
|
|
68
|
+
No moss, and none installed. The config hands over the app's own boot — **the
|
|
69
|
+
same one its browser entry runs** — and the two ends of a drawn screen:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { createElement } from 'react';
|
|
73
|
+
import { renderToString } from 'react-dom/server';
|
|
74
|
+
import type { NiscShellProject } from '@niscorp/cli';
|
|
75
|
+
import { boot } from './src/boot';
|
|
76
|
+
import { Screen, adopt } from './src/ui/screen';
|
|
77
|
+
|
|
78
|
+
export const project: NiscShellProject = {
|
|
79
|
+
// one fresh shell per call, for one path — and nothing else is handed in
|
|
80
|
+
shell: async ({ path }) => {
|
|
81
|
+
const app = await boot();
|
|
82
|
+
return { shell: app.shell, close: () => app.db.close() };
|
|
83
|
+
},
|
|
84
|
+
// draw it to markup, where there is no browser
|
|
85
|
+
draw: (shell) => renderToString(createElement(Screen, { shell })),
|
|
86
|
+
// pick the markup up — the call the browser entry makes (hydrateRoot)
|
|
87
|
+
adopt,
|
|
88
|
+
};
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The browser entry does the same two things in the page — boot, then adopt:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
const app = await getApp();
|
|
95
|
+
if (root.hasChildNodes()) {
|
|
96
|
+
await shellSettled(app.shell); // reach the screen the file holds
|
|
97
|
+
adopt(root, app.shell); // hydrateRoot(root, <Screen shell={shell} />)
|
|
98
|
+
} else {
|
|
99
|
+
createRoot(root).render(<Screen shell={app.shell} />); // dev: nothing was drawn
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`draw` and `adopt` are the adapter's: `react-dom/server` + `hydrateRoot`,
|
|
104
|
+
`vue/server-renderer` + `createSSRApp().mount`, or — no framework in the page
|
|
105
|
+
at all — nova's DOM adapter, `renderToString` from
|
|
106
|
+
`@niscorp/nova/adapters/dom/server` + `mountShell`.
|
|
107
|
+
|
|
108
|
+
| Field | |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `shell` | one fresh copy of the app's shell for `{ path }`: `{ shell, close? }`. Called several times per path — it must not memoize |
|
|
111
|
+
| `draw` | the shell, drawn to a string |
|
|
112
|
+
| `adopt` | `(root, shell)` — the page picking the markup up |
|
|
113
|
+
| `htmlAttributes?` | what the kit would put on `<html>` from an effect |
|
|
114
|
+
| `paths?` | the paths to build (default `/`) — an app that maps paths to actions lists its own |
|
|
115
|
+
| `waitMs?` | how long a build waits for a screen to be whole (default 5000) |
|
|
116
|
+
| `dist?`, `checks?` | as above |
|
|
117
|
+
|
|
118
|
+
The built `index.html` must hold the empty root, `<div id="root"></div>` — that
|
|
119
|
+
is where a screen goes. The adoption check needs a DOM: `jsdom`, installed in
|
|
120
|
+
the app.
|
|
121
|
+
|
|
122
|
+
The config is TypeScript, loaded with the app's own `tsconfig.json` — path
|
|
123
|
+
aliases included.
|
|
124
|
+
|
|
125
|
+
## `nisc build`
|
|
126
|
+
|
|
127
|
+
**An app with its own shell.** Bundles the app, then for every path boots it,
|
|
128
|
+
draws it, and checks what it drew:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
Route First screen
|
|
132
|
+
○ / drawn · whole · same twice · adopted (todo-list, topbar)
|
|
133
|
+
opened with todo-list.loadTodos (/api/query), topbar.loadStats (/api/query) — in the file as answered at build
|
|
134
|
+
can still call todo-list.completeTodo (/api/todos/{{$.toggleId}}/done), todo-list.loadTodos (/api/query)
|
|
135
|
+
waits on todos-changed
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Check | Fails the build when |
|
|
139
|
+
|---|---|
|
|
140
|
+
| **drawn** | the boot threw, or the screen drew to nothing |
|
|
141
|
+
| **whole** | something was still loading when `waitMs` ran out — a file that says "loading" is not the page |
|
|
142
|
+
| **same twice** | a second boot drew different markup (it says where they part) — the page's boot would not match the file |
|
|
143
|
+
| **adopted** | inside a DOM, a third boot ran the app's own `adopt` over the markup and the adapter complained: a hydration error, or a rebuilt root that is not what it was handed |
|
|
144
|
+
|
|
145
|
+
And one that holds by construction: `shell` is handed a path and nothing else,
|
|
146
|
+
so a file is only ever the screen **as nobody in particular sees it**.
|
|
147
|
+
|
|
148
|
+
What cannot be failed is reported, read off the actions on the first screen:
|
|
149
|
+
which endpoints it **opened with** (their answers are in the file as they were
|
|
150
|
+
at build — if one answers differently in the page, the page's shell draws that
|
|
151
|
+
part again), which it **can still call**, and which channels it **waits on**.
|
|
152
|
+
All of those keep working: the shell is in the page.
|
|
153
|
+
|
|
154
|
+
Exit code 1 if any check did not hold.
|
|
155
|
+
|
|
156
|
+
**An app behind moss.** Bundles the terminal (the app's own vite), stands the app up, draws every path
|
|
157
|
+
once **for nobody**, and prints how each one is served:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
Route What Served as Because
|
|
161
|
+
● / the app server auth.login: a person can act on it
|
|
162
|
+
auth.login: it calls the function endpoint "enter", which is code
|
|
163
|
+
○ /about page about file nothing on it can still happen
|
|
164
|
+
|
|
165
|
+
○ file drawn once, for nobody in particular; nothing on it can still happen
|
|
166
|
+
● server something on it can still happen; it wants moss behind it
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The verdict is not configured anywhere. It is read off the actions mounted on
|
|
170
|
+
each path: a trigger a person can fire, a field they can type in, a channel the
|
|
171
|
+
screen waits on, a read that keeps answering, a function it calls. A path with
|
|
172
|
+
none of those is finished the moment it is drawn. A read made while the page
|
|
173
|
+
opened is named too ("drawn with …") — its answer is in the file as it was at
|
|
174
|
+
build.
|
|
175
|
+
|
|
176
|
+
Exit code 1 if a path could not be drawn at all.
|
|
177
|
+
|
|
178
|
+
## `nisc export`
|
|
179
|
+
|
|
180
|
+
`nisc build`, then the site as a folder (`out/` by default, `--out <dir>`): the
|
|
181
|
+
bundle, and one `index.html` per path — `/` at the top, `/about` at
|
|
182
|
+
`about/index.html` — which is what any static host serves for that path.
|
|
183
|
+
|
|
184
|
+
A file is **only ever the page as nobody sees it**. No credential reaches a
|
|
185
|
+
build, so there is nothing to leak into one.
|
|
186
|
+
|
|
187
|
+
For an app with its own shell that is the whole deployment: the folder goes on
|
|
188
|
+
any static host, each path answers with its screen, and the bundle's shell
|
|
189
|
+
picks it up. If a check did not hold, **nothing is written**.
|
|
190
|
+
|
|
191
|
+
For an app behind moss: if any path wants a server behind it, **nothing is written** and the command
|
|
192
|
+
says which paths and why (exit code 1). A folder cannot be a server. When one
|
|
193
|
+
will stand beside the files — the socket at `/socket` on the same origin —
|
|
194
|
+
`--allow-live` writes the site anyway: each such file is a true first screen,
|
|
195
|
+
and its terminal connects.
|
|
196
|
+
|
|
197
|
+
## `nisc start`
|
|
198
|
+
|
|
199
|
+
**An app with its own shell:** serves the built folder, and answers each path
|
|
200
|
+
with its first screen drawn from a fresh boot — per request, so the screen is
|
|
201
|
+
as the app answers now, not as it answered at build. No shell is kept.
|
|
202
|
+
|
|
203
|
+
**An app behind moss:** serves the built terminal from the app's own process: files from `dist/`, and
|
|
204
|
+
every page **drawn for whoever is asking** — the app's own screen at `/`, a
|
|
205
|
+
manifest page at its path. A signed-in person gets their screen in the markup
|
|
206
|
+
(`private, no-store`); nobody gets the page as nobody sees it. `--port <n>`, or
|
|
207
|
+
`$PORT`, default 8787.
|
|
208
|
+
|
|
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`
|
|
230
|
+
|
|
231
|
+
The app's check suite (`src/dev/all-checks.ts`, or `checks` in the config).
|
|
232
|
+
|
|
233
|
+
## Options
|
|
234
|
+
|
|
235
|
+
| | |
|
|
236
|
+
|---|---|
|
|
237
|
+
| `--root <dir>` | the app's root (default: the current directory) |
|
|
238
|
+
| `--out <dir>` | `export`: where the files go (default `out`) |
|
|
239
|
+
| `--allow-live` | `export`: write even though some path wants a server |
|
|
240
|
+
| `--skip-bundle` | `build`, `export`: the terminal is already built |
|
|
241
|
+
| `--port <n>` | `start`: the port |
|
|
242
|
+
|
|
243
|
+
## License
|
|
244
|
+
|
|
245
|
+
Apache-2.0
|
package/bin/nisc.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `nisc` command's launcher — a file that exists BEFORE the package is
|
|
3
|
+
// built. A package manager links a bin when it installs, and in this workspace
|
|
4
|
+
// that happens before anything is compiled: with the bin pointing at dist/
|
|
5
|
+
// directly, a fresh checkout installed, found no file to link, and every
|
|
6
|
+
// script that says `nisc` then failed with "command not found". This file is
|
|
7
|
+
// in the repository, so the link is always made; the command itself is what it
|
|
8
|
+
// imports.
|
|
9
|
+
import '../dist/cli.js';
|
package/dist/adopt.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { format } from 'util';
|
|
5
|
+
import { shellSettled } from '@niscorp/nova';
|
|
6
|
+
|
|
7
|
+
// src/adopt.ts
|
|
8
|
+
var QUIET_MS = 60;
|
|
9
|
+
var ADOPT_WAIT_MS = 1e4;
|
|
10
|
+
var pause = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
11
|
+
var standDom = (root) => {
|
|
12
|
+
const require2 = createRequire(join(root, "package.json"));
|
|
13
|
+
let library;
|
|
14
|
+
try {
|
|
15
|
+
library = require2("jsdom");
|
|
16
|
+
} catch {
|
|
17
|
+
throw new Error(`nisc: the adoption check needs a DOM, and this app has no jsdom installed (looked from ${root}). pnpm add -D jsdom`);
|
|
18
|
+
}
|
|
19
|
+
const constructor = library !== null && typeof library === "object" ? Reflect.get(library, "JSDOM") : void 0;
|
|
20
|
+
if (typeof constructor !== "function") throw new Error("nisc: jsdom exports no JSDOM.");
|
|
21
|
+
const dom = Reflect.construct(constructor, ["<!doctype html><html><body></body></html>", { url: "http://localhost/", pretendToBeVisual: true }]);
|
|
22
|
+
const window2 = dom !== null && typeof dom === "object" ? Reflect.get(dom, "window") : void 0;
|
|
23
|
+
if (window2 === null || typeof window2 !== "object") throw new Error("nisc: jsdom made no window.");
|
|
24
|
+
for (const name of ["window", "document", ...Object.getOwnPropertyNames(window2)]) {
|
|
25
|
+
if (name in globalThis) continue;
|
|
26
|
+
Object.defineProperty(globalThis, name, { configurable: true, get: () => Reflect.get(window2, name) });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var main = async () => {
|
|
30
|
+
const [root, asked, answered] = process.argv.slice(2);
|
|
31
|
+
if (root === void 0 || asked === void 0 || answered === void 0) throw new Error("usage: adopt <root> <pages.json> <answer.json>");
|
|
32
|
+
standDom(root);
|
|
33
|
+
const { isShellProject, loadProject } = await import('./project-PODTS3SZ.js');
|
|
34
|
+
const project = await loadProject(root);
|
|
35
|
+
if (!isShellProject(project)) throw new Error("nisc: this app has no shell of its own to adopt with.");
|
|
36
|
+
const pages = JSON.parse(readFileSync(asked, "utf8"));
|
|
37
|
+
if (!Array.isArray(pages)) throw new Error("nisc: no pages to adopt.");
|
|
38
|
+
let complaints = [];
|
|
39
|
+
const short = (text) => text.length > 600 ? `${text.slice(0, 600)}\u2026` : text;
|
|
40
|
+
console.error = (...args) => {
|
|
41
|
+
complaints.push(short(format(...args)));
|
|
42
|
+
};
|
|
43
|
+
window.addEventListener("error", (event) => {
|
|
44
|
+
complaints.push(short(event.message));
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
});
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const page of pages) {
|
|
49
|
+
const path = page !== null && typeof page === "object" ? Reflect.get(page, "path") : void 0;
|
|
50
|
+
const screen = page !== null && typeof page === "object" ? Reflect.get(page, "screen") : void 0;
|
|
51
|
+
if (typeof path !== "string" || typeof screen !== "string") continue;
|
|
52
|
+
complaints = [];
|
|
53
|
+
const mine = complaints;
|
|
54
|
+
try {
|
|
55
|
+
document.body.innerHTML = '<div id="root"></div>';
|
|
56
|
+
const element = document.getElementById("root");
|
|
57
|
+
if (element === null) throw new Error("no root");
|
|
58
|
+
element.innerHTML = screen;
|
|
59
|
+
const parsed = element.innerHTML;
|
|
60
|
+
const booted = await project.shell({ path });
|
|
61
|
+
if (!await shellSettled(booted.shell, { waitMs: ADOPT_WAIT_MS })) mine.push("the page\u2019s own boot was still loading when it came to adopt");
|
|
62
|
+
await project.adopt(element, booted.shell);
|
|
63
|
+
if (element.innerHTML !== parsed) mine.push("what the page\u2019s boot drew is not the markup it was handed");
|
|
64
|
+
await pause(QUIET_MS);
|
|
65
|
+
await booted.close?.();
|
|
66
|
+
} catch (error) {
|
|
67
|
+
mine.push(error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
69
|
+
out.push({ path, complaints: mine });
|
|
70
|
+
}
|
|
71
|
+
writeFileSync(answered, JSON.stringify(out));
|
|
72
|
+
};
|
|
73
|
+
main().then(
|
|
74
|
+
() => process.exit(0),
|
|
75
|
+
(error) => {
|
|
76
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
77
|
+
`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
//# sourceMappingURL=adopt.js.map
|
|
82
|
+
//# sourceMappingURL=adopt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adopt.ts"],"names":["require","window"],"mappings":";;;;;;;AAsBA,IAAM,QAAA,GAAW,EAAA;AACjB,IAAM,aAAA,GAAgB,GAAA;AAEtB,IAAM,KAAA,GAAQ,CAAC,EAAA,KAA8B,IAAI,OAAA,CAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,IAAA,EAAM,EAAE,CAA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AIzC,MAAA,IAAI,OAAA,CAAQ,SAAA,KAAc,MAAA,EAAQ,IAAA,CAAK,KAAK,gEAA2D,CAAA;AACvG,MAAA,MAAM,MAAM,QAAQ,CAAA;AACpB,MAAA,MAAM,OAAO,KAAA,IAAQ;AAAA,IACvB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,KAAK,KAAA,YAAiB,KAAA,GAAQ,MAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,IAClE;AACA,IAAA,GAAA,CAAI,IAAA,CAAK,EAAE,IAAA,EAAM,UAAA,EAAY,MAAM,CAAA;AAAA,EACrC;AACA,EAAA,aAAA,CAAc,QAAA,EAAU,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA;AAC7C,CAAA;AAEA,IAAA,EAAK,CAAE,IAAA;AAAA,EACL,MAAM,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA;AAAA,EACpB,CAAC,KAAA,KAAmB;AAClB,IAAA,OAAA,CAAQ,MAAA,CAAO,MAAM,CAAA,EAAG,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAC;AAAA,CAAI,CAAA;AAClF,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAA","file":"adopt.js","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { format } from 'node:util';\nimport { shellSettled } from '@niscorp/nova';\n\n// ═══════════════════════════════════════════════════════════════\n// THE ADOPTION CHECK — a process of its own (see ./shell-site).\n//\n// node adopt.js <app root> <pages.json> <answer.json>\n//\n// It is a page: a DOM stands before anything of the app's is loaded, exactly as\n// in a browser. Then, per path: the markup a build drew goes into a root, the\n// app's own boot runs again, and the app's own `adopt` is called over the two —\n// the call its browser entry makes. Whatever the adapter complains about (an\n// error logged, an error raised on the window, a root that was rebuilt into\n// something else) is written down, in its own words.\n//\n// The DOM is the app's: jsdom, found from the app's root. The command carries\n// none.\n// ═══════════════════════════════════════════════════════════════\n\nconst QUIET_MS = 60;\nconst ADOPT_WAIT_MS = 10_000;\n\nconst pause = (ms: number): Promise<void> => new Promise((done) => setTimeout(done, ms));\n\nconst standDom = (root: string): void => {\n const require = createRequire(join(root, 'package.json'));\n let library: unknown;\n try {\n library = require('jsdom');\n } catch {\n throw new Error(`nisc: the adoption check needs a DOM, and this app has no jsdom installed (looked from ${root}). pnpm add -D jsdom`);\n }\n const constructor: unknown = library !== null && typeof library === 'object' ? Reflect.get(library, 'JSDOM') : undefined;\n if (typeof constructor !== 'function') throw new Error('nisc: jsdom exports no JSDOM.');\n const dom: unknown = Reflect.construct(constructor, ['<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true }]);\n const window: unknown = dom !== null && typeof dom === 'object' ? Reflect.get(dom, 'window') : undefined;\n if (window === null || typeof window !== 'object') throw new Error('nisc: jsdom made no window.');\n // Everything a page has and this process does not. What the process already\n // has (timers, fetch, URL) stays its own.\n for (const name of ['window', 'document', ...Object.getOwnPropertyNames(window)]) {\n if (name in globalThis) continue;\n Object.defineProperty(globalThis, name, { configurable: true, get: () => Reflect.get(window, name) });\n }\n};\n\nconst main = async (): Promise<void> => {\n const [root, asked, answered] = process.argv.slice(2);\n if (root === undefined || asked === undefined || answered === undefined) throw new Error('usage: adopt <root> <pages.json> <answer.json>');\n standDom(root);\n // only now: the app's modules load into a world that has a DOM\n const { isShellProject, loadProject } = await import('./project');\n const project = await loadProject(root);\n if (!isShellProject(project)) throw new Error('nisc: this app has no shell of its own to adopt with.');\n\n const pages: unknown = JSON.parse(readFileSync(asked, 'utf8'));\n if (!Array.isArray(pages)) throw new Error('nisc: no pages to adopt.');\n\n // one ear for the whole run, pointed at the path being adopted\n let complaints: string[] = [];\n const short = (text: string): string => (text.length > 600 ? `${text.slice(0, 600)}…` : text);\n console.error = (...args: unknown[]): void => {\n complaints.push(short(format(...args)));\n };\n window.addEventListener('error', (event) => {\n complaints.push(short(event.message));\n event.preventDefault();\n });\n\n const out: { path: string; complaints: string[] }[] = [];\n for (const page of pages) {\n const path: unknown = page !== null && typeof page === 'object' ? Reflect.get(page, 'path') : undefined;\n const screen: unknown = page !== null && typeof page === 'object' ? Reflect.get(page, 'screen') : undefined;\n if (typeof path !== 'string' || typeof screen !== 'string') continue;\n complaints = [];\n const mine = complaints;\n try {\n document.body.innerHTML = '<div id=\"root\"></div>';\n const element = document.getElementById('root');\n if (element === null) throw new Error('no root');\n element.innerHTML = screen;\n const parsed = element.innerHTML;\n const booted = await project.shell({ path });\n // the page's entry waits for its own screen before it adopts; so does this\n if (!(await shellSettled(booted.shell, { waitMs: ADOPT_WAIT_MS }))) mine.push('the page’s own boot was still loading when it came to adopt');\n await project.adopt(element, booted.shell);\n // An adapter that REBUILDS its root (the DOM adapter) has done so by now:\n // what it built must be what was there. One that adopts in place (React,\n // Vue) says what it found wrong a moment later, through the ear above.\n if (element.innerHTML !== parsed) mine.push('what the page’s boot drew is not the markup it was handed');\n await pause(QUIET_MS);\n await booted.close?.();\n } catch (error) {\n mine.push(error instanceof Error ? error.message : String(error));\n }\n out.push({ path, complaints: mine });\n }\n writeFileSync(answered, JSON.stringify(out));\n};\n\nmain().then(\n () => process.exit(0),\n (error: unknown) => {\n process.stderr.write(`${error instanceof Error ? error.message : String(error)}\\n`);\n process.exit(1);\n },\n);\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 configFileOf = (root) => CONFIG_NAMES.find((name) => existsSync(join(root, name)));
|
|
15
|
+
var loadProject = async (root) => {
|
|
16
|
+
const name = configFileOf(root);
|
|
17
|
+
const file = name === void 0 ? void 0 : join(root, name);
|
|
18
|
+
if (file === void 0) {
|
|
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.`);
|
|
20
|
+
}
|
|
21
|
+
const { tsImport } = await import('tsx/esm/api');
|
|
22
|
+
const tsconfig = join(root, "tsconfig.json");
|
|
23
|
+
const loaded = await tsImport(pathToFileURL(file).href, { parentURL: import.meta.url, ...existsSync(tsconfig) ? { tsconfig } : {} });
|
|
24
|
+
const project = loaded !== null && typeof loaded === "object" ? Reflect.get(loaded, "project") : void 0;
|
|
25
|
+
if (!isProject(project)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`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).`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return project;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { configFileOf, isProject, isShellProject, loadProject };
|
|
34
|
+
//# sourceMappingURL=chunk-MRNC4GI5.js.map
|
|
35
|
+
//# sourceMappingURL=chunk-MRNC4GI5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/project.ts"],"names":[],"mappings":";;;;;AAmGA,IAAM,YAAA,GAAe,CAAC,gBAAA,EAAkB,iBAAA,EAAmB,kBAAkB,iBAAiB,CAAA;AAE9F,IAAM,GAAA,GAAM,CAAC,KAAA,EAAe,GAAA,KAAyB,OAAO,OAAA,CAAQ,GAAA,CAA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AA,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"]}
|