@ultimat3/cli 31.37.0 → 31.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +29 -29
- package/src/cmd-planned.ts +5 -28
- package/src/generate-sign-in-runtime.ts +70 -0
- package/src/generate-sign-in.ts +19 -6
- package/src/generate-write.ts +12 -0
- package/src/island-plugin-path.ts +35 -0
- package/src/island-realtime.ts +11 -8
- package/src/island-runtime.ts +4 -1
- package/src/new-shapes.ts +10 -1
- package/src/templates/shapes/agent-actions.ts +224 -0
- package/src/templates/shapes/agent-job.ts +171 -0
- package/src/templates/shapes/agent-model.ts +271 -0
- package/src/templates/shapes/agent-prompt.ts +254 -0
- package/src/templates/shapes/agent-scripted.ts +56 -0
- package/src/templates/shapes/agent.ts +138 -0
- package/src/templates/shapes/content-admin-es.ts +95 -0
- package/src/templates/shapes/content-pages.ts +221 -0
- package/src/templates/shapes/content-site.ts +343 -0
- package/src/templates/shapes/content.ts +133 -0
- package/src/templates/shapes/index.ts +10 -0
- package/src/templates/shapes/offline-e2e.ts +123 -0
- package/src/templates/shapes/offline-form.ts +334 -0
- package/src/templates/shapes/offline.ts +118 -0
- package/src/templates/shapes/realtime-mutator.ts +136 -0
- package/src/templates/shapes/realtime-nodes.ts +203 -0
- package/src/templates/shapes/realtime-slice.ts +166 -0
- package/src/templates/shapes/realtime.ts +162 -0
- package/src/templates/shapes/saas-billing-tests.ts +135 -0
- package/src/templates/shapes/saas-billing.ts +137 -0
- package/src/templates/shapes/saas-receiver.ts +136 -0
- package/src/templates/shapes/saas.ts +112 -0
- package/src/templates/sign-in-oidc.ts +2 -4
- package/src/templates/sign-in-runtime.ts +172 -0
- package/src/templates/sign-in-shared.ts +5 -36
- package/wiki/Building-Your-Own-Base.md +339 -0
- package/wiki/CLI-Reference.md +1 -14
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +2 -2
- package/wiki/Known-Gaps.md +8 -2
- package/wiki/MCP-And-AI.md +3 -3
- package/wiki/Money.md +1 -1
- package/wiki/Shapes.md +18 -9
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Upgrading.md +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// `x new <name> --shape saas`: the default app — every table tenant-scoped by `orgId`, the
|
|
2
|
+
// `member` and `admin` roles, `/admin` — plus billing as app code (`apps/web/app/billing/`), a
|
|
3
|
+
// signed payment webhook that moves an org between plans, a plan-sized usage meter on `createPost`,
|
|
4
|
+
// and sign-in and the member invite, each written by its own generator once the files land.
|
|
5
|
+
|
|
6
|
+
import { loadVersion } from '../../version-loader';
|
|
7
|
+
import { catalogJson } from '../catalog-json';
|
|
8
|
+
import { catalogPath } from '../locales';
|
|
9
|
+
import type { GeneratedFile, NameSet } from '../naming';
|
|
10
|
+
import type { ShapeEdit, ShapeOverlay } from './overlay';
|
|
11
|
+
import { BILLING_DIR, billingFiles } from './saas-billing';
|
|
12
|
+
import { billingReceiverFiles, RECEIVER_NAME } from './saas-receiver';
|
|
13
|
+
import { shapeLines } from './shared-edits';
|
|
14
|
+
|
|
15
|
+
const API = 'apps/web/api/index.ts';
|
|
16
|
+
const CREATE_POST = 'apps/web/app/post/actions/create-post.ts';
|
|
17
|
+
const ROLES = 'apps/web/shared/roles.ts';
|
|
18
|
+
const RECEIVER_MODULE = `../app/billing/jobs/${RECEIVER_NAME}`;
|
|
19
|
+
|
|
20
|
+
const edits = (app: NameSet): readonly ShapeEdit[] => [
|
|
21
|
+
// The receiver is a job: listed, so the boot registers it under its name and mounts its route.
|
|
22
|
+
{
|
|
23
|
+
path: API,
|
|
24
|
+
find: "import { defineApi } from '@ultimat3/action';\n",
|
|
25
|
+
replace: `import { defineApi } from '@ultimat3/action';\nimport * as billingEvents from '${RECEIVER_MODULE}';\n`,
|
|
26
|
+
},
|
|
27
|
+
{ path: API, find: 'jobs: [reindexPost],', replace: 'jobs: [reindexPost, billingEvents],' },
|
|
28
|
+
// The subscription table joins the typed handle, as `x g entity` would add it.
|
|
29
|
+
{
|
|
30
|
+
path: 'packages/db/src/client.ts',
|
|
31
|
+
find: `import { post } from '@${app.kebab}/web/app/post/entity';\n`,
|
|
32
|
+
replace: `import { subscription } from '@${app.kebab}/web/app/billing/entity';\nimport { post } from '@${app.kebab}/web/app/post/entity';\n`,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: 'packages/db/src/client.ts',
|
|
36
|
+
find: ' posts: post,\n};',
|
|
37
|
+
replace: ' posts: post,\n subscriptions: subscription,\n};',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: 'packages/db/src/schema.ts',
|
|
41
|
+
find: `export { post } from '@${app.kebab}/web/app/post/entity';`,
|
|
42
|
+
replace: `export { subscription } from '@${app.kebab}/web/app/billing/entity';\nexport { post } from '@${app.kebab}/web/app/post/entity';`,
|
|
43
|
+
},
|
|
44
|
+
// The usage meter: an org creates as many posts a day as its plan allows.
|
|
45
|
+
{
|
|
46
|
+
path: CREATE_POST,
|
|
47
|
+
find: "import { PostView, post } from '../entity';\n",
|
|
48
|
+
replace:
|
|
49
|
+
"import { postMeter } from '../../billing/entitlements';\nimport { PostView, post } from '../entity';\n",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
path: CREATE_POST,
|
|
53
|
+
find: ' cache: { invalidates: [postTag] },\n',
|
|
54
|
+
replace:
|
|
55
|
+
" cache: { invalidates: [postTag] },\n // The org's plan sizes it (`billing/plans.ts`); past it, X_METER_EXCEEDED (429).\n meter: postMeter,\n",
|
|
56
|
+
},
|
|
57
|
+
// A plan is the payment provider's to change: an operator reads subscriptions at /admin, and no
|
|
58
|
+
// role is granted a write the webhook would only overwrite.
|
|
59
|
+
{
|
|
60
|
+
path: ROLES,
|
|
61
|
+
find: " 'posts:delete',\n]);",
|
|
62
|
+
replace: " 'posts:delete',\n 'subscriptions:read',\n]);",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
path: ROLES,
|
|
66
|
+
find: " 'posts:delete',\n ],",
|
|
67
|
+
replace: " 'posts:delete',\n 'subscriptions:read',\n ],",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
path: 'apps/admin/app/admin/admin.ts',
|
|
71
|
+
find: ' entities: adminEntitiesOf(db),\n db,\n',
|
|
72
|
+
replace:
|
|
73
|
+
" entities: adminEntitiesOf(db),\n db,\n // A plan is the payment webhook's to write (`apps/web/app/billing/`): operators only read it.\n resources: { subscriptions: { operations: ['list', 'detail', 'search'] } },\n",
|
|
74
|
+
},
|
|
75
|
+
// A plan's features are flags: the package joins the app's dependencies, at the release's range.
|
|
76
|
+
{
|
|
77
|
+
path: 'package.json',
|
|
78
|
+
find: ' "@ultimat3/http": "^',
|
|
79
|
+
replace: ` "@ultimat3/flags": "^${loadVersion()}",\n "@ultimat3/http": "^`,
|
|
80
|
+
},
|
|
81
|
+
...shapeLines(
|
|
82
|
+
'saas',
|
|
83
|
+
`a multi-tenant app — billing is app code in \`${BILLING_DIR}/plans.ts\`, a signed payment webhook (\`${BILLING_DIR}/jobs/${RECEIVER_NAME}.ts\`) moves an org between plans, and \`x g sign-in --password\` and \`x g invite\` wrote sign-in and the member invite`,
|
|
84
|
+
),
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
/** The labels `/admin` derives for the subscriptions table, merged into the catalog the base wrote. */
|
|
88
|
+
const catalog = (): GeneratedFile => ({
|
|
89
|
+
path: catalogPath('en'),
|
|
90
|
+
merge: 'json',
|
|
91
|
+
contents: catalogJson({
|
|
92
|
+
'admin.subscriptions.title': 'Subscriptions',
|
|
93
|
+
'admin.subscriptions.field.id': 'ID',
|
|
94
|
+
'admin.subscriptions.field.orgId': 'Org ID',
|
|
95
|
+
'admin.subscriptions.field.plan': 'Plan',
|
|
96
|
+
'admin.subscriptions.field.lastEventId': 'Last payment event',
|
|
97
|
+
'admin.subscriptions.field.updatedAt': 'Updated at',
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const saasShape: ShapeOverlay = {
|
|
102
|
+
example: true,
|
|
103
|
+
drop: [],
|
|
104
|
+
dropKeys: [],
|
|
105
|
+
edits,
|
|
106
|
+
files: (app: NameSet): readonly GeneratedFile[] => [
|
|
107
|
+
...billingFiles(app),
|
|
108
|
+
...billingReceiverFiles(),
|
|
109
|
+
catalog(),
|
|
110
|
+
],
|
|
111
|
+
generate: [['sign-in', '--password'], ['invite']],
|
|
112
|
+
};
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
signInPageSource,
|
|
16
16
|
signInPageTest,
|
|
17
17
|
} from './sign-in-pages';
|
|
18
|
+
import { OIDC_RUNTIME_ROUTES } from './sign-in-runtime';
|
|
18
19
|
import { AUTH_DIR, sharedSignInFiles } from './sign-in-shared';
|
|
19
20
|
|
|
20
21
|
/** `bigco-sso` → `BIGCO_SSO`: the prefix `discoverOAuthProvider` derives its two env keys from. */
|
|
@@ -180,10 +181,7 @@ export function oidcSignInFiles(
|
|
|
180
181
|
...sharedSignInFiles(
|
|
181
182
|
oidcSignInEnv(provider),
|
|
182
183
|
`The issuer and the client are ${provider}'s; SESSION_SECRET seals the handshake and APP_URL is where the provider sends the browser back.`,
|
|
183
|
-
|
|
184
|
-
importLine: "import { signInRoutes } from './app/auth/sign-in-routes';",
|
|
185
|
-
expression: 'signInRoutes',
|
|
186
|
-
},
|
|
184
|
+
OIDC_RUNTIME_ROUTES,
|
|
187
185
|
),
|
|
188
186
|
{ path: `${AUTH_DIR}/oidc.ts`, contents: oidcSource(provider) },
|
|
189
187
|
{ path: `${AUTH_DIR}/oidc.test.ts`, contents: oidcTest(provider) },
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// What `x g sign-in` owes `apps/web/runtime.ts` and its test, as a splice: the guard's import and
|
|
2
|
+
// call, and for OIDC the routes, added to the file the author already has. `runtime.ts` is THE
|
|
3
|
+
// port-installation file, so almost every app has edited it — replacing it only while it was
|
|
4
|
+
// `x new`'s bytes refused the generator for every app past day one.
|
|
5
|
+
|
|
6
|
+
import { maskLiterals, stripComments } from '@ultimat3/core';
|
|
7
|
+
import { holdsKey } from '../source-edit';
|
|
8
|
+
import { baseRuntimeTest, RUNTIME_HEADER, runtimePortLines } from './scaffold-runtime-ports';
|
|
9
|
+
|
|
10
|
+
/** The plain routes a shape mounts: an import line, and the expression `routes:` takes. */
|
|
11
|
+
export interface RuntimeRoutes {
|
|
12
|
+
readonly importLine: string;
|
|
13
|
+
readonly expression: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The OIDC shape's routes: the start and callback legs, mounted as plain routes. */
|
|
17
|
+
export const OIDC_RUNTIME_ROUTES: RuntimeRoutes = {
|
|
18
|
+
importLine: "import { signInRoutes } from './app/auth/sign-in-routes';",
|
|
19
|
+
expression: 'signInRoutes',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const GUARD = 'assertSignInConfigured';
|
|
23
|
+
const GUARD_IMPORT = `import { ${GUARD} } from './app/auth/sign-in-guard';`;
|
|
24
|
+
const GUARD_CALL = `${GUARD}(process.env);`;
|
|
25
|
+
const GUARD_WHY = `// The sign-in guard runs HERE: a throw in this module stops the role, where the same throw in a
|
|
26
|
+
// module the app scan imports is logged and the boot goes on.`;
|
|
27
|
+
|
|
28
|
+
/** The full `runtime.ts` over `x new`'s: what the splice of the untouched scaffold must equal. */
|
|
29
|
+
export const signInRuntimeSource = (routes: RuntimeRoutes | undefined): string => `${RUNTIME_HEADER}
|
|
30
|
+
${GUARD_WHY}
|
|
31
|
+
import type { RuntimeOverrides } from '@ultimat3/cli/serve';
|
|
32
|
+
${GUARD_IMPORT}${routes === undefined ? '' : `\n${routes.importLine}`}
|
|
33
|
+
|
|
34
|
+
${GUARD_CALL}
|
|
35
|
+
|
|
36
|
+
export const runtime = {
|
|
37
|
+
${routes === undefined ? '' : ` routes: ${routes.expression},\n`}${runtimePortLines()}
|
|
38
|
+
} satisfies RuntimeOverrides;
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
/** The full `runtime.test.ts` over `x new`'s. */
|
|
42
|
+
export const signInRuntimeTest = (
|
|
43
|
+
routes: RuntimeRoutes | undefined,
|
|
44
|
+
): string => `// The runtime loads under test (the guard judges no local environment)${routes === undefined ? '' : ', and mounts the sign-in routes'}.
|
|
45
|
+
import { expect, unitTest } from '@ultimat3/testing';
|
|
46
|
+
${routes === undefined ? '' : `${routes.importLine}\n`}import { runtime } from './runtime';
|
|
47
|
+
|
|
48
|
+
unitTest('the runtime loads${routes === undefined ? '' : ' and mounts the sign-in routes'}', () => {
|
|
49
|
+
${routes === undefined ? 'expect(runtime).toEqual({});' : `expect(runtime.routes).toBe(${routes.expression});`}
|
|
50
|
+
});
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
/** What a splice made of a file: new bytes, the delta already there, or the line to edit by hand. */
|
|
54
|
+
export type RuntimeSplice =
|
|
55
|
+
| { readonly kind: 'spliced'; readonly source: string }
|
|
56
|
+
| { readonly kind: 'present' }
|
|
57
|
+
| { readonly kind: 'unrecognised'; readonly line: number; readonly edit: string };
|
|
58
|
+
|
|
59
|
+
const lineAt = (source: string, index: number): number =>
|
|
60
|
+
source.slice(0, Math.max(0, index)).split('\n').length;
|
|
61
|
+
|
|
62
|
+
const IMPORT = /^import\b[^;]*?from\s+'([^']+)';\n/gm;
|
|
63
|
+
const specifierOf = (line: string): string => /from '([^']+)'/.exec(line)?.[1] ?? '';
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* `source` with `line` imported where a sorted block has it: among the relative imports by
|
|
67
|
+
* specifier, else after the last import, else at `fallback`. Already imported is unchanged.
|
|
68
|
+
*/
|
|
69
|
+
function withRelativeImport(source: string, line: string, fallback: number): string {
|
|
70
|
+
const specifier = specifierOf(line);
|
|
71
|
+
if (source.includes(`from '${specifier}'`)) return source;
|
|
72
|
+
const imports = [...source.matchAll(IMPORT)];
|
|
73
|
+
const later = imports.find((match) => {
|
|
74
|
+
const from = match[1] ?? '';
|
|
75
|
+
return from.startsWith('.') && from > specifier;
|
|
76
|
+
});
|
|
77
|
+
const last = imports.at(-1);
|
|
78
|
+
const at = later?.index ?? (last === undefined ? fallback : last.index + last[0].length);
|
|
79
|
+
return `${source.slice(0, at)}${line}\n${source.slice(at)}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Where the comment block directly above the line at `index` starts: a doc comment stays on. */
|
|
83
|
+
function commentStart(source: string, index: number): number {
|
|
84
|
+
let at = index;
|
|
85
|
+
for (;;) {
|
|
86
|
+
const previous = source.lastIndexOf('\n', at - 2) + 1;
|
|
87
|
+
const text = source.slice(previous, at - 1).trim();
|
|
88
|
+
if (at === 0 || !(text.startsWith('//') || text.startsWith('/*') || text.startsWith('*'))) {
|
|
89
|
+
return at;
|
|
90
|
+
}
|
|
91
|
+
at = previous;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const DECLARATION = /^export const runtime\b[^=\n]*=\s*\{/m;
|
|
96
|
+
|
|
97
|
+
/** The guard (and `routes`) added to an existing `runtime.ts`; never a second copy of either. */
|
|
98
|
+
export function spliceSignInRuntime(
|
|
99
|
+
source: string,
|
|
100
|
+
routes: RuntimeRoutes | undefined,
|
|
101
|
+
): RuntimeSplice {
|
|
102
|
+
const code = stripComments(source);
|
|
103
|
+
if (new RegExp(`\\b${GUARD}\\(`).test(code)) return { kind: 'present' };
|
|
104
|
+
const masked = maskLiterals(source);
|
|
105
|
+
const declaration = DECLARATION.exec(masked);
|
|
106
|
+
if (declaration === null) {
|
|
107
|
+
const named = /^export\b[^\n]*\bruntime\b/m.exec(masked);
|
|
108
|
+
return {
|
|
109
|
+
kind: 'unrecognised',
|
|
110
|
+
line: named === null ? 1 : lineAt(source, named.index),
|
|
111
|
+
edit: 'declare the overrides as one object literal, export const runtime = { … } satisfies RuntimeOverrides',
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const open = declaration.index + declaration[0].length;
|
|
115
|
+
let next = source;
|
|
116
|
+
if (routes !== undefined) {
|
|
117
|
+
const close = masked.indexOf('\n}', open);
|
|
118
|
+
const body = stripComments(source.slice(open, close === -1 ? source.length : close));
|
|
119
|
+
if (holdsKey(body, 'routes')) {
|
|
120
|
+
const key = /\broutes\b/.exec(body)?.index ?? 0;
|
|
121
|
+
return {
|
|
122
|
+
kind: 'unrecognised',
|
|
123
|
+
line: lineAt(source, open + key),
|
|
124
|
+
edit: `move this routes value into a const above the export (const appRoutes = …) and list routes: [...${routes.expression}, ...appRoutes], importing ${routes.expression} from './app/auth/sign-in-routes', ${GUARD} from './app/auth/sign-in-guard', and calling ${GUARD_CALL} above the export`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const closes = /^[ \t]*\}/.test(masked.slice(open));
|
|
128
|
+
const entry = `\n routes: ${routes.expression},${closes ? '\n' : ''}`;
|
|
129
|
+
next = `${next.slice(0, open)}${entry}${next.slice(open)}`;
|
|
130
|
+
}
|
|
131
|
+
const start = commentStart(next, declaration.index);
|
|
132
|
+
next = `${next.slice(0, start)}${GUARD_CALL}\n\n${next.slice(start)}`;
|
|
133
|
+
next = withRelativeImport(next, GUARD_IMPORT, start);
|
|
134
|
+
if (routes !== undefined) next = withRelativeImport(next, routes.importLine, start);
|
|
135
|
+
const first = [...next.matchAll(IMPORT)][0]?.index ?? start;
|
|
136
|
+
return { kind: 'spliced', source: `${next.slice(0, first)}${GUARD_WHY}\n${next.slice(first)}` };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const imports = (source: string, name: string): boolean =>
|
|
140
|
+
[...stripComments(source).matchAll(IMPORT)].some((match) =>
|
|
141
|
+
new RegExp(`\\{[^}]*\\b${name}\\b[^}]*\\}`).test(match[0]),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The routes assertion added to an existing `runtime.test.ts`; the password shape mounts none, so
|
|
146
|
+
* its test is the author's as it stands. `x new`'s own test is replaced whole: its one assertion,
|
|
147
|
+
* `toEqual({})`, is false once routes are mounted.
|
|
148
|
+
*/
|
|
149
|
+
export function spliceSignInRuntimeTest(
|
|
150
|
+
source: string,
|
|
151
|
+
routes: RuntimeRoutes | undefined,
|
|
152
|
+
): RuntimeSplice {
|
|
153
|
+
if (source === baseRuntimeTest()) {
|
|
154
|
+
return { kind: 'spliced', source: signInRuntimeTest(routes) };
|
|
155
|
+
}
|
|
156
|
+
if (routes === undefined || imports(source, routes.expression)) {
|
|
157
|
+
return { kind: 'spliced', source };
|
|
158
|
+
}
|
|
159
|
+
if (!['runtime', 'unitTest', 'expect'].every((name) => imports(source, name))) {
|
|
160
|
+
return {
|
|
161
|
+
kind: 'unrecognised',
|
|
162
|
+
line: 1,
|
|
163
|
+
edit: `add a unitTest that asserts expect(runtime.routes).toBe(${routes.expression}), importing runtime from './runtime' and ${routes.expression} from './app/auth/sign-in-routes'`,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const withImport = withRelativeImport(source, routes.importLine, 0);
|
|
167
|
+
const block = `\nunitTest('the runtime mounts the sign-in routes', () => {\n expect(runtime.routes).toBe(${routes.expression});\n});\n`;
|
|
168
|
+
return {
|
|
169
|
+
kind: 'spliced',
|
|
170
|
+
source: `${withImport}${withImport.endsWith('\n') ? '' : '\n'}${block}`,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -8,12 +8,11 @@ import { authModule } from './scaffold-auth';
|
|
|
8
8
|
import {
|
|
9
9
|
baseRuntimeSource,
|
|
10
10
|
baseRuntimeTest,
|
|
11
|
-
RUNTIME_HEADER,
|
|
12
11
|
RUNTIME_MODULE,
|
|
13
12
|
RUNTIME_TEST,
|
|
14
|
-
runtimePortLines,
|
|
15
13
|
} from './scaffold-runtime-ports';
|
|
16
14
|
import { destroySessionTest } from './sign-in-action-tests';
|
|
15
|
+
import { type RuntimeRoutes, signInRuntimeSource, signInRuntimeTest } from './sign-in-runtime';
|
|
17
16
|
|
|
18
17
|
/** Every generated file lives under the scaffold's own auth slice, beside `auth.ts`. */
|
|
19
18
|
export const AUTH_DIR = 'apps/web/app/auth';
|
|
@@ -223,53 +222,23 @@ const styleSource =
|
|
|
223
222
|
`;
|
|
224
223
|
|
|
225
224
|
/** The files both shapes write, with the guard over this shape's settings. */
|
|
226
|
-
|
|
227
|
-
/** The plain routes a shape mounts: an import line, and the expression `routes:` takes. */
|
|
228
|
-
export interface RuntimeRoutes {
|
|
229
|
-
readonly importLine: string;
|
|
230
|
-
readonly expression: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const runtimeSource = (routes: RuntimeRoutes | undefined): string => `${RUNTIME_HEADER}
|
|
234
|
-
// The sign-in guard runs HERE: a throw in this module stops the role, where the same throw in a
|
|
235
|
-
// module the app scan imports is logged and the boot goes on.
|
|
236
|
-
import type { RuntimeOverrides } from '@ultimat3/cli/serve';
|
|
237
|
-
import { assertSignInConfigured } from './app/auth/sign-in-guard';${routes === undefined ? '' : `\n${routes.importLine}`}
|
|
238
|
-
|
|
239
|
-
assertSignInConfigured(process.env);
|
|
240
|
-
|
|
241
|
-
export const runtime = {
|
|
242
|
-
${routes === undefined ? '' : ` routes: ${routes.expression},\n`}${runtimePortLines()}
|
|
243
|
-
} satisfies RuntimeOverrides;
|
|
244
|
-
`;
|
|
245
|
-
|
|
246
|
-
const runtimeTest = (
|
|
247
|
-
routes: RuntimeRoutes | undefined,
|
|
248
|
-
): string => `// The runtime loads under test (the guard judges no local environment)${routes === undefined ? '' : ', and mounts the sign-in routes'}.
|
|
249
|
-
import { expect, unitTest } from '@ultimat3/testing';
|
|
250
|
-
${routes === undefined ? '' : `${routes.importLine}\n`}import { runtime } from './runtime';
|
|
251
|
-
|
|
252
|
-
unitTest('the runtime loads${routes === undefined ? '' : ' and mounts the sign-in routes'}', () => {
|
|
253
|
-
${routes === undefined ? 'expect(runtime).toEqual({});' : `expect(runtime.routes).toBe(${routes.expression});`}
|
|
254
|
-
});
|
|
255
|
-
`;
|
|
256
|
-
|
|
257
225
|
export function sharedSignInFiles(
|
|
258
226
|
keys: readonly string[],
|
|
259
227
|
why: string,
|
|
260
228
|
routes?: RuntimeRoutes,
|
|
261
229
|
): readonly GeneratedFile[] {
|
|
262
230
|
return [
|
|
263
|
-
// Over `x new`'s own pair while it is untouched
|
|
231
|
+
// Over `x new`'s own pair while it is untouched. An author's edited copy is spliced instead,
|
|
232
|
+
// by `generate-sign-in-runtime.ts`, which reads the disk this list never does.
|
|
264
233
|
{
|
|
265
234
|
path: RUNTIME_MODULE,
|
|
266
|
-
contents:
|
|
235
|
+
contents: signInRuntimeSource(routes),
|
|
267
236
|
merge: 'replaces-pristine',
|
|
268
237
|
pristine: baseRuntimeSource(),
|
|
269
238
|
},
|
|
270
239
|
{
|
|
271
240
|
path: RUNTIME_TEST,
|
|
272
|
-
contents:
|
|
241
|
+
contents: signInRuntimeTest(routes),
|
|
273
242
|
merge: 'replaces-pristine',
|
|
274
243
|
pristine: baseRuntimeTest(),
|
|
275
244
|
},
|