ref0-git 0.26.0 → 0.29.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/app/apps/github/README.md +1 -5
- package/app/apps/github/package.json +0 -1
- package/app/apps/github/src/signin/auth.ts +17 -89
- package/app/apps/github/src/signin/credentials.ts +10 -14
- package/app/apps/github/src/signin/guarded-write.ts +19 -0
- package/app/apps/github/src/signin/owner-names.ts +11 -41
- package/app/apps/github/src/signin/unborn.ts +20 -30
- package/app/apps/github/tsconfig.json +0 -2
- package/app/pnpm-workspace.yaml +14 -34
- package/dist/cli/documents.mjs +39 -25
- package/dist/cli/keys.mjs +9 -3
- package/dist/cli/node.mjs +1 -2
- package/dist/cli/runtime.mjs +3 -4
- package/dist/cli/setup.mjs +216 -468
- package/dist/cli/tools-node.mjs +8 -7
- package/dist/cli/tools.mjs +3 -3
- package/dist/cli/vercel-stores.mjs +287 -0
- package/dist/init/app.mjs +4 -37
- package/dist/init/choices.mjs +62 -209
- package/dist/init/cloudflare.mjs +1 -2
- package/dist/init/detect.mjs +77 -167
- package/dist/init/files.mjs +2 -12
- package/dist/init/frameworks.mjs +50 -174
- package/dist/init/git-module.mjs +5 -1
- package/dist/init/metadata.mjs +4 -22
- package/dist/init/next.mjs +13 -66
- package/dist/init/output.mjs +3 -6
- package/dist/init/plan.mjs +1 -29
- package/dist/init/routes.mjs +1 -78
- package/dist/init/stores.mjs +6 -35
- package/dist/init/template.mjs +14 -49
- package/dist/init/templates.mjs +30 -115
- package/dist/init/vercel-regions.mjs +87 -0
- package/dist/init/vercel.mjs +313 -212
- package/dist/init/versions.mjs +3 -3
- package/package.json +5 -11
- package/app/apps/github/migrations/postgres/0001_auth.sql +0 -53
- package/app/apps/github/src/camo/lookup.ts +0 -23
- package/app/apps/github/src/camo/node.ts +0 -50
- package/app/apps/github/src/signin/person-lock.ts +0 -104
- package/dist/cli/sqlite.mjs +0 -28
- package/dist/init/astro.mjs +0 -49
- package/dist/init/create.mjs +0 -152
- package/dist/init/mounts.mjs +0 -104
- package/dist/init/node-app.mjs +0 -196
- package/dist/init/node.mjs +0 -446
- package/dist/init/nuxt.mjs +0 -240
- package/dist/init/react-router.mjs +0 -59
- package/dist/init/sveltekit.mjs +0 -141
package/dist/init/node-app.mjs
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { appGitModule, appManifest, copied } from "./app.mjs";
|
|
2
|
-
import { ignoring, lines, listed, withCli, withLines } from "./files.mjs";
|
|
3
|
-
import { withEntries } from "./jsonc.mjs";
|
|
4
|
-
import { keepsData, nodeNeeds, partsOf, secretFiles } from "./node.mjs";
|
|
5
|
-
import { needHelper } from "./stores.mjs";
|
|
6
|
-
import { platforms, templates } from "./template.mjs";
|
|
7
|
-
import { appPackages, nodeAppPackages, nodePackages } from "./metadata.mjs";
|
|
8
|
-
import * as Redacted from "effect/Redacted";
|
|
9
|
-
// src/init/node-app.ts
|
|
10
|
-
/**
|
|
11
|
-
* The starter app on Node, as `init --app --platform node` writes it: `apps/github`'s pages, built
|
|
12
|
-
* by Vite with Nitro's Node preset in place of Cloudflare's plugin, Git's jobs started by a Nitro
|
|
13
|
-
* plugin, and Better Auth's tables in the database `--records` chose, which `npm run migrate` makes.
|
|
14
|
-
*/
|
|
15
|
-
/** Where `npm start` serves the app, the one origin Better Auth takes a POST from until it's set. */
|
|
16
|
-
const startOrigin = "http://localhost:3000";
|
|
17
|
-
/** The app's own files on Cloudflare that Node writes instead, or leaves out. */
|
|
18
|
-
const cloudflareOnly = /^(README\.md|vite\.config\.ts|src\/server\.ts|tsconfig\.worker\.json|\.dev\.vars\.example|migrations\/.*|scripts\/serve\.ts)$/;
|
|
19
|
-
/** Where each `--records` keeps the app's people, for the README. */
|
|
20
|
-
const peopleIn = {
|
|
21
|
-
sqlite: "`.data/auth.db`, a SQLite file",
|
|
22
|
-
postgres: "`DATABASE_URL`'s Postgres, on a pool of their own, each sign-up one transaction",
|
|
23
|
-
turso: "a `git-auth` database in Turso's group",
|
|
24
|
-
"durable-objects": ""
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* The README's table of what's the host's to change: the app's own rows, from its README, each
|
|
28
|
-
* column as wide as its widest cell, as the formatter pads one.
|
|
29
|
-
*/
|
|
30
|
-
const yours = (rows) => {
|
|
31
|
-
const head = ["File", "What it decides"];
|
|
32
|
-
const all = [head, ...rows];
|
|
33
|
-
const fileWidth = Math.max(...all.map(([file]) => file.length));
|
|
34
|
-
const saysWidth = Math.max(...all.map(([, says]) => says.length));
|
|
35
|
-
const row = ([file, says]) => `| ${file.padEnd(fileWidth)} | ${says.padEnd(saysWidth)} |`;
|
|
36
|
-
return lines(row(head), row(["-".repeat(fileWidth), "-".repeat(saysWidth)]), ...rows.map(row));
|
|
37
|
-
};
|
|
38
|
-
/** `README.md` on Node: how to run the app, and what's the host's to change. */
|
|
39
|
-
const readme = (choices) => lines("# The starter", "", "Git, a GitHub-compatible API and a web app over them, in one Node server built by Nitro. Set it up, run it, and change it: its pages and its policy are yours, and the logic is in `@ref0/git` and `@ref0/github`.", "", "## Run it", "", "```sh", "npm run migrate # the people's tables", "npm run build", "npm start # on http://localhost:3000", "```", "", "`init` installed it, and wrote its secrets, `ADMIN_TOKEN`, `SESSION_SECRET` and `DEMO_PASSWORD`, which the dev seed signs its people up with, in `.env`, which git ignores. `npm start` reads it when there is one, and serves on `PORT`, 3000 when unset. A host that sets the variables itself needs no `.env`. `APP_ORIGIN` is the one origin sign-in takes a form from: set it to where the app is served before anyone signs up there.", "", "`npm run dev` serves it with Vite on the same http://localhost:3000, with a demo seeded at the first request: Pip and Mo, signed up with `DEMO_PASSWORD`, the org `acme` and its repos. A build holds none of the seed.", "", `To sign in, sign up at \`/signup\` with a login such as \`pip\` and a password of at least 15 characters. People, their passwords and their sessions are Better Auth's, in ${peopleIn[choices.records]}: \`src/signin/auth.ts\` sets it up, \`migrations/\` holds its tables, and \`npm run migrate\` applies each once.`, "", "`server/plugins/jobs.ts` runs Git's jobs in the server's process, such as the merge queue's, and stops them when it closes. `npx ref0-git doctor` checks the setup.", "", "## What's yours to change", "", yours([...templates.appYours.filter(([file]) => file !== "`wrangler.jsonc`"), ["`.env`", "The secrets, `APP_ORIGIN`, the stores' variables, and `SIGN_UP`: anyone may sign up until it's `closed`"]]), "", "## Other platforms", "", "[`docs/deploy/node.md`](https://github.com/ref-0/git/blob/main/docs/deploy/node.md) says how Git runs on Node, and what each store needs.", "");
|
|
40
|
-
/** The migrations `--records` reads: Postgres's own, else SQLite's, which libSQL speaks too. */
|
|
41
|
-
const migrationsOf = (records) => records === "postgres" ? "migrations/postgres/" : "migrations/sql/";
|
|
42
|
-
/** `src/env.ts` on Node: what the app reads from `.env`, each through `need()`. */
|
|
43
|
-
const envModule = lines("// What the app reads from `.env`: `npm start` passes it to Node, and `vite dev` reads it.", needHelper(".env").replace("const need =", "export const need ="), "", "/** The secrets `ref0-git init` made, where the app is served, and whether anyone may sign up. */", "export const env = {", " ADMIN_TOKEN: need('ADMIN_TOKEN'),", " SESSION_SECRET: need('SESSION_SECRET'),", " APP_ORIGIN: need('APP_ORIGIN'),", " SIGN_UP: process.env['SIGN_UP'],", " // `off` loads a text's remote images from their own origin, not through the image proxy.", " IMAGE_PROXY: process.env['IMAGE_PROXY'],", " // The header the proxy in front sets with the caller's address, such as `x-real-ip`: set it", " // only when that proxy overwrites the header. Unset, the caller's address is the socket's.", " CLIENT_IP_HEADER: process.env['CLIENT_IP_HEADER'],", " /** In dev only, at least 15 characters: the password the seed signs Pip and Mo up with. */", " DEMO_PASSWORD: process.env['DEMO_PASSWORD'],", "};", "");
|
|
44
|
-
/**
|
|
45
|
-
* `server/plugins/jobs.ts`: Git's jobs, started once a process. When Nitro closes, the runner stops,
|
|
46
|
-
* then the runtime is disposed, closing what its Layers opened.
|
|
47
|
-
*/
|
|
48
|
-
const jobsPlugin = lines("// Starts Git's jobs once this process, as Nitro loads its plugins. On close, it stops them, then", "// disposes the runtime, so what its Layers opened closes.", "import { definePlugin } from 'nitro';", "", "import * as Node from '@ref0/infra/node';", "", "import { runtime } from '../../src/git.ts';", "", "export default definePlugin((nitro) => {", " const stop = Node.toJobRunner(runtime);", " nitro.hooks.hook('close', async () => {", " await stop();", " await runtime.dispose();", " });", "});", "");
|
|
49
|
-
/** What `npm run migrate` opens, for each records store, and how it runs one file's SQL. */
|
|
50
|
-
const migrateParts = {
|
|
51
|
-
sqlite: lines("import { mkdirSync, readdirSync, readFileSync } from 'node:fs';", "import { DatabaseSync } from 'node:sqlite';", "", "mkdirSync('.data', { recursive: true });", "", "const database = new DatabaseSync('.data/auth.db');", "", "const run = async (sql: string) => {", " database.exec(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " database.exec('begin');", "", " try {", " database.exec(sql);", " database.prepare('insert into \"_migrations\" (\"name\") values (?)').run(name);", " database.exec('commit');", " } catch (cause) {", " if (database.isTransaction) database.exec('rollback');", "", " throw cause;", " }", "};", "", "const done = async () => {", " const rows = database.prepare('select \"name\" from \"_migrations\"').all();", "", " return new Set(rows.map((row) => String(row.name)));", "};"),
|
|
52
|
-
postgres: lines("import { readdirSync, readFileSync } from 'node:fs';", "import pg from 'pg';", "", "const client = new pg.Client({ connectionString: process.env['DATABASE_URL'] });", "", "await client.connect();", "", "const run = async (sql: string) => {", " await client.query(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " await client.query('begin');", "", " try {", " await client.query(sql);", " await client.query('insert into \"_migrations\" (\"name\") values ($1)', [name]);", " await client.query('commit');", " } catch (cause) {", " await client.query('rollback');", "", " throw cause;", " }", "};", "", "const done = async () => {", " const { rows } = await client.query<{ name: string }>('select \"name\" from \"_migrations\"');", "", " return new Set(rows.map((row) => row.name));", "};"),
|
|
53
|
-
turso: lines("import { createClient } from '@libsql/client';", "import * as Turso from '@ref0/infra/turso';", "import { readdirSync, readFileSync } from 'node:fs';", "", "const need = (name: string) => process.env[name] ?? '';", "", "const databases = Turso.platform({", " organization: need('TURSO_ORGANIZATION'),", " group: need('TURSO_GROUP'),", " region: need('TURSO_REGION'),", " apiToken: need('TURSO_API_TOKEN'),", "});", "", "// `git-auth`, made in the group the first time: 409 says it's there already.", "await databases.create('git-auth').catch((error: { status?: number }) => {", " if (error.status !== 409) throw error;", "});", "", "const client = createClient({", " url: databases.url('git-auth'),", " authToken: need('TURSO_GROUP_TOKEN'),", "});", "", "const run = async (sql: string) => {", " await client.executeMultiple(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " const transaction = await client.transaction('write');", "", " try {", " await transaction.executeMultiple(sql);", " await transaction.execute({", " sql: 'insert into \"_migrations\" (\"name\") values (?)',", " args: [name],", " });", " await transaction.commit();", " } catch (cause) {", " await transaction.rollback();", "", " throw cause;", " } finally {", " transaction.close();", " }", "};", "", "const done = async () => {", " const { rows } = await client.execute('select \"name\" from \"_migrations\"');", "", " return new Set(rows.map((row) => String(row['name'])));", "};"),
|
|
54
|
-
"durable-objects": ""
|
|
55
|
-
};
|
|
56
|
-
/** How `npm run migrate` closes what it opened, for each records store. */
|
|
57
|
-
const closeOf = {
|
|
58
|
-
sqlite: "database.close();",
|
|
59
|
-
postgres: "await client.end();",
|
|
60
|
-
turso: "client.close();",
|
|
61
|
-
"durable-objects": ""
|
|
62
|
-
};
|
|
63
|
-
/** `scripts/migrate.ts`: each of `migrations/` that hasn't run, in order, each recorded once it has. */
|
|
64
|
-
const migrateScript = (records) => lines("// Makes Better Auth's tables: each file in `migrations/` that hasn't run yet, in name order, each", "// recorded in `_migrations` once it has. Written by `ref0-git init`, and run by `npm run migrate`.", "// Each file runs in one transaction with its record, so a file must not manage its own: one", "// holding `BEGIN`, `COMMIT`, `ROLLBACK` or `END` can commit part of itself, and fail unrecorded.", migrateParts[records], "", "/** The connection, closed so the process ends once the migrations have run, or one fails. */", `const close = async () => {`, ` ${closeOf[records]}`, "};", "", "try {", " await run('create table if not exists \"_migrations\" (\"name\" text primary key)');", "", " const applied = await done();", " const files = readdirSync('migrations').filter((each) => each.endsWith('.sql'));", "", " for (const name of files.sort()) {", " if (applied.has(name)) continue;", "", " const sql = readFileSync(`migrations/${name}`, 'utf8');", "", " // The file and its record in one transaction: one that fails or stops partway leaves neither,", " // so the next run applies the file afresh.", " try {", " await apply(name, sql);", " } catch (cause) {", " throw new Error(`migrations/${name} failed, and is not recorded`, { cause });", " }", "", " console.log(`Applied ${name}`);", " }", "} finally {", " await close();", "}", "");
|
|
65
|
-
/** The Kysely dialect Better Auth's people take beside the store's client: Turso's alone isn't in it. */
|
|
66
|
-
const dialectPackages = {
|
|
67
|
-
turso: [["@libsql/kysely-libsql", nodeAppPackages["@libsql/kysely-libsql"]]],
|
|
68
|
-
sqlite: [],
|
|
69
|
-
postgres: [],
|
|
70
|
-
"durable-objects": []
|
|
71
|
-
};
|
|
72
|
-
/** The scripts and packages the app on Node has in place of the Worker's. */
|
|
73
|
-
const manifestOn = (choices) => {
|
|
74
|
-
const parts = partsOf(choices);
|
|
75
|
-
return {
|
|
76
|
-
scripts: {
|
|
77
|
-
dev: "vp dev --port 3000 --strictPort",
|
|
78
|
-
build: "vp build",
|
|
79
|
-
start: "node --env-file-if-exists=.env .output/server/index.mjs",
|
|
80
|
-
migrate: "node --env-file-if-exists=.env scripts/migrate.ts"
|
|
81
|
-
},
|
|
82
|
-
dropped: [
|
|
83
|
-
"@cloudflare/vite-plugin",
|
|
84
|
-
"wrangler",
|
|
85
|
-
"workerd"
|
|
86
|
-
],
|
|
87
|
-
dependencies: {
|
|
88
|
-
nitro: nodeAppPackages.nitro,
|
|
89
|
-
...Object.fromEntries(parts.flatMap((part) => part.dependencies)),
|
|
90
|
-
...Object.fromEntries(dialectPackages[choices.records])
|
|
91
|
-
},
|
|
92
|
-
devDependencies: {
|
|
93
|
-
...nodePackages,
|
|
94
|
-
...Object.fromEntries(parts.flatMap((part) => part.devDependencies))
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
/** Everything `init --app --platform node` writes for `choices`, named `name`, from `source`. */
|
|
99
|
-
const nodeAppOutput = (choices, name, source, secret, vendor) => {
|
|
100
|
-
const needs = nodeNeeds(choices);
|
|
101
|
-
const made = [...platforms.node.secrets, ...platforms.node.dev];
|
|
102
|
-
const migrations = migrationsOf(choices.records);
|
|
103
|
-
return {
|
|
104
|
-
files: [
|
|
105
|
-
...source.files.filter((file) => copied(file.path) && !cloudflareOnly.test(file.path)).map((file) => ({
|
|
106
|
-
path: file.path,
|
|
107
|
-
kind: "whole",
|
|
108
|
-
text: templates.nodeConfigs[file.path] ?? file.text
|
|
109
|
-
})),
|
|
110
|
-
...source.files.filter((file) => file.path.startsWith(migrations)).map((file) => ({
|
|
111
|
-
path: `migrations/${file.path.slice(migrations.length)}`,
|
|
112
|
-
kind: "whole",
|
|
113
|
-
text: file.text
|
|
114
|
-
})),
|
|
115
|
-
{
|
|
116
|
-
path: "tsconfig.base.json",
|
|
117
|
-
kind: "whole",
|
|
118
|
-
text: source.base
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
path: "README.md",
|
|
122
|
-
kind: "whole",
|
|
123
|
-
text: readme(choices)
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
path: "src/git.ts",
|
|
127
|
-
kind: "whole",
|
|
128
|
-
text: appGitModule(choices)
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
path: "src/env.ts",
|
|
132
|
-
kind: "whole",
|
|
133
|
-
text: envModule
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
path: "src/server.ts",
|
|
137
|
-
kind: "whole",
|
|
138
|
-
text: templates.nodeServer
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
path: "tsconfig.server.json",
|
|
142
|
-
kind: "whole",
|
|
143
|
-
text: templates.nodeServerConfig
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
path: "vite.config.ts",
|
|
147
|
-
kind: "whole",
|
|
148
|
-
text: templates.nodeVite
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
path: "server/plugins/jobs.ts",
|
|
152
|
-
kind: "whole",
|
|
153
|
-
text: jobsPlugin
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
path: "scripts/migrate.ts",
|
|
157
|
-
kind: "whole",
|
|
158
|
-
text: migrateScript(choices.records)
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
path: "package.json",
|
|
162
|
-
kind: "merge",
|
|
163
|
-
merge: (current) => {
|
|
164
|
-
const made = manifestOn(choices);
|
|
165
|
-
return current === void 0 ? appManifest(source, name, vendor, made) : withCli(withEntries(withEntries(current, ["dependencies"], made.dependencies), ["devDependencies"], made.devDependencies), vendor);
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
path: ".env",
|
|
170
|
-
kind: "merge",
|
|
171
|
-
secrets: made,
|
|
172
|
-
merge: (current) => withLines(current, [
|
|
173
|
-
...made.map((each) => `${each}=${Redacted.value(secret())}`),
|
|
174
|
-
`APP_ORIGIN=${startOrigin}`,
|
|
175
|
-
...needs.map((each) => `${each}=`)
|
|
176
|
-
], (line) => line.split("=")[0]?.trim() ?? "")
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
path: ".gitignore",
|
|
180
|
-
kind: "merge",
|
|
181
|
-
merge: (current) => ignoring(current, [
|
|
182
|
-
"node_modules",
|
|
183
|
-
".output",
|
|
184
|
-
"dist",
|
|
185
|
-
...keepsData(choices) ? [".data"] : []
|
|
186
|
-
], secretFiles)
|
|
187
|
-
}
|
|
188
|
-
],
|
|
189
|
-
manual: [],
|
|
190
|
-
needs,
|
|
191
|
-
packages: appPackages.map((each) => `@ref0/${each}`),
|
|
192
|
-
secret: `${listed(made)}, made for npm start, in .env`,
|
|
193
|
-
next: needs.length === 0 ? "Make the app's tables with `npm run migrate`, then check it" : `Set ${needs.join(", ")} in .env, make the app's tables with \`npm run migrate\`, then check it`
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
export { nodeAppOutput, startOrigin };
|
package/dist/init/node.mjs
DELETED
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
import { ignoring, lines, withCli, withCreatedTypes, withDependencies, withLines } from "./files.mjs";
|
|
2
|
-
import { adminLines, effectImports, featuresLines, gitDependencies, gitImports, gitPackages, header, mergeLines, policyLines, runtimeLines } from "./git-module.mjs";
|
|
3
|
-
import { manifestText, parseJsonc, stringAt, withEntries } from "./jsonc.mjs";
|
|
4
|
-
import { astroRouteFiles, astroSteps } from "./astro.mjs";
|
|
5
|
-
import { mountManual } from "./mounts.mjs";
|
|
6
|
-
import { nextConfigOutput, nextRouteFiles } from "./next.mjs";
|
|
7
|
-
import { nuxtOutput } from "./nuxt.mjs";
|
|
8
|
-
import { reactRouterRouteFiles, reactRouterSteps } from "./react-router.mjs";
|
|
9
|
-
import { bodySizeLimit, onAdapterNode, svelteAdapterAnchor, svelteHooks, svelteInitLines, svelteNodeAdapter, svelteRerouteLines, svelteRouteFiles, svelteServerHooks, svelteStartStep, withSvelteStart } from "./sveltekit.mjs";
|
|
10
|
-
import { envExample, needHelper, needsOf, recordsPart, s3Part } from "./stores.mjs";
|
|
11
|
-
import { frameworkPackages, nodePackages } from "./metadata.mjs";
|
|
12
|
-
import * as Redacted from "effect/Redacted";
|
|
13
|
-
import * as Predicate from "effect/Predicate";
|
|
14
|
-
// src/init/node.ts
|
|
15
|
-
/**
|
|
16
|
-
* What `init` writes for Git on Node, without the app: `src/git.ts`, which builds the store, the
|
|
17
|
-
* bucket, the queue and Git from `.env`, and `src/main.ts`, which serves it and runs its jobs in
|
|
18
|
-
* the process. An existing Node project gets `src/git.ts` and the lines that mount it.
|
|
19
|
-
*/
|
|
20
|
-
/** The shared records store the choices use, woken by a poller: none for SQLite. */
|
|
21
|
-
const recordsOf = (choices) => choices.records === "postgres" || choices.records === "turso" ? recordsPart(choices.records) : void 0;
|
|
22
|
-
/** The parts more than one platform offers that the choices use: Postgres or Turso, and S3. */
|
|
23
|
-
const partsOf = (choices) => [...[recordsOf(choices)].filter((part) => part !== void 0), ...choices.bucket === "s3" ? [s3Part] : []];
|
|
24
|
-
/** What `src/git.ts` reads from `.env` that `init` can't make, for the choices. */
|
|
25
|
-
const nodeNeeds = (choices) => needsOf(partsOf(choices));
|
|
26
|
-
/** The files that hold secrets on Node: `.gitignore` ends with them, and `init` refuses one Git tracks. */
|
|
27
|
-
const secretFiles = [".env"];
|
|
28
|
-
/** Whether the setup keeps files in `.data`: SQLite's records or the folder's packs. */
|
|
29
|
-
const keepsData = (choices) => choices.records === "sqlite" || choices.bucket === "disk";
|
|
30
|
-
/** The imports before Git's: Node's own, then the store's client. */
|
|
31
|
-
const firstImports = (choices, loadsEnv) => {
|
|
32
|
-
const fs = [...loadsEnv ? ["existsSync"] : [], ...choices.records === "sqlite" ? ["mkdirSync"] : []];
|
|
33
|
-
const builtins = lines(fs.length > 0 && `import { ${fs.join(", ")} } from 'node:fs';`, choices.records === "sqlite" && "import { DatabaseSync } from 'node:sqlite';");
|
|
34
|
-
const client = lines(...partsOf(choices).flatMap((part) => part.external));
|
|
35
|
-
const first = lines(builtins !== "" && `${builtins}\n`, client !== "" && `${client}\n`);
|
|
36
|
-
return first !== "" && first;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* infra's imports: each platform entry the choices take, as a namespace, in the entries' order.
|
|
40
|
-
* Node's, for its poller, or for its job runner where the module starts its own jobs, `runs`.
|
|
41
|
-
*/
|
|
42
|
-
const infraImports = (choices, runs = false) => lines(...[
|
|
43
|
-
choices.bucket === "disk" && "import * as Disk from '@ref0/infra/disk';",
|
|
44
|
-
(runs || recordsOf(choices) !== void 0) && "import * as Node from '@ref0/infra/node';",
|
|
45
|
-
choices.records === "sqlite" && "import * as Sqlite from '@ref0/infra/sqlite';",
|
|
46
|
-
...partsOf(choices).map((part) => part.infra)
|
|
47
|
-
].filter(Predicate.isString).toSorted());
|
|
48
|
-
/** The store, as chosen: a shared one woken by a poller, or SQLite's file. */
|
|
49
|
-
const storeLines = (choices) => {
|
|
50
|
-
const records = recordsOf(choices);
|
|
51
|
-
if (records !== void 0) return lines("// Every replica may run the queue: the poller looks for each one's due work once a second.", "const wake = Node.layerPoller();", "", records.code);
|
|
52
|
-
return lines("mkdirSync('.data', { recursive: true });", "", "// One file, whose jobs this process alone runs.", "const database = new DatabaseSync('.data/records.db', { timeout: 5_000 });", "", "// WAL makes a commit about 4 times faster.", "database.exec('PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL');", "", "const store = Sqlite.layer({ database });");
|
|
53
|
-
};
|
|
54
|
-
/** The bucket, as chosen, after a blank line: none for loose objects. */
|
|
55
|
-
const bucketLines = (choices) => choices.bucket === "s3" ? `\n${s3Part.code}` : choices.bucket === "disk" && "\nconst bucket = Disk.layer('.data/packs');";
|
|
56
|
-
/** The runtime's comment in the server module, on what runs its jobs. */
|
|
57
|
-
const jobsSays = {
|
|
58
|
-
main: "`src/main.ts` runs its jobs in this process.",
|
|
59
|
-
server: "Your server runs its jobs in its process.",
|
|
60
|
-
hook: "The framework's startup hook runs its jobs in each server process.",
|
|
61
|
-
"on-import": "This module starts its jobs on its first import."
|
|
62
|
-
};
|
|
63
|
-
/** A push's pack upload, to a bucket that signs parts: S3's. */
|
|
64
|
-
const uploads = lines(" // A push past 64 MiB may upload its pack, once the bucket signs parts.", " Git.layerUploads({ above: 64 * 1024 * 1024 }),");
|
|
65
|
-
/**
|
|
66
|
-
* A framework's `.env`, loaded before any `need()`: a Vite dev server gives `process.env` none of
|
|
67
|
-
* it, and adapter-node's server loads none. A variable the environment sets stays as it is.
|
|
68
|
-
*/
|
|
69
|
-
const loadEnvLines = lines("// `.env` from the folder the server runs in, `process.cwd()`, as `node --env-file` reads it: a", "// host that runs it from another folder sets the environment itself. A variable already set", "// stays as it is.", "if (existsSync('.env')) process.loadEnvFile('.env');", "");
|
|
70
|
-
/** The jobs' start on the module's first import, once a process: a dev reload imports it again. */
|
|
71
|
-
const startedOnImport = lines("// Started once a process, on this module's first import. A dev reload imports the module again.", "// SAFETY: only this module sets `gitJobs` on the global, to the stop `toJobRunner` returns.", "const started = globalThis as { gitJobs?: () => Promise<void> };", "", "started.gitJobs ??= Node.toJobRunner(runtime);", "");
|
|
72
|
-
/**
|
|
73
|
-
* The server module, `src/git.ts` or a framework's: the store, the bucket and the queue, then Git's
|
|
74
|
-
* features and the drop-in's, and the runtime that its entry, routes or mount take.
|
|
75
|
-
*/
|
|
76
|
-
const nodeModule = (choices, jobs) => {
|
|
77
|
-
const packs = choices.objects === "packs";
|
|
78
|
-
const framework = jobs === "hook" || jobs === "on-import";
|
|
79
|
-
return lines(header(choices, "Node"), firstImports(choices, framework), gitImports(choices), infraImports(choices, jobs === "on-import"), "import { xdiff } from '@ref0/xdiff-wasm/node';", effectImports(choices), "", framework && loadEnvLines, needHelper(".env"), "", adminLines, storeLines(choices), bucketLines(choices), "", mergeLines(choices), policyLines, featuresLines(choices, {
|
|
80
|
-
merges: "{ xdiff: await xdiff() }",
|
|
81
|
-
uploads: choices.bucket === "s3" && uploads
|
|
82
|
-
}), runtimeLines(choices, {
|
|
83
|
-
token: "need('ADMIN_TOKEN')",
|
|
84
|
-
adapter: packs ? "Layer.merge(store, bucket)" : "store",
|
|
85
|
-
jobs: jobsSays[jobs]
|
|
86
|
-
}), jobs === "on-import" && startedOnImport);
|
|
87
|
-
};
|
|
88
|
-
/** A stop waits this long for the responses still open, such as one a reader stopped reading. */
|
|
89
|
-
const stopGrace = 1e4;
|
|
90
|
-
/** The lines in `src/main.ts` that start the jobs and serve Git. */
|
|
91
|
-
const serveLines = lines("const stop = Node.toJobRunner(runtime);", "", "// Behind a proxy that ends TLS, set ORIGIN to the origin it serves, such as", "// https://git.example.com, which Git's links are built from. Unset, each request's connection's.", "const handler = toNodeHandler(runtime, { origin: process.env.ORIGIN });");
|
|
92
|
-
/** Where `src/main.ts` serves Git when `PORT` is unset. */
|
|
93
|
-
const mainOrigin = "http://localhost:8080";
|
|
94
|
-
const mainPort = new URL(mainOrigin).port;
|
|
95
|
-
/** `src/main.ts`: Git on `PORT`, its jobs in this process, stopped on `SIGTERM`. */
|
|
96
|
-
const mainModule = () => lines(`// Serves Git on PORT, ${mainPort} when unset, and runs its jobs in this process. Written by`, "// `ref0-git init`, and yours to change.", "import { createServer } from 'node:http';", "", "import { toNodeHandler } from '@ref0/git/node';", "import * as Node from '@ref0/infra/node';", "", "import { runtime } from './git.ts';", "", serveLines, "", "const server = createServer(handler);", "", "// Node cuts a request off at 300 s, which a large push over a slow link outlasts: an hour.", "server.requestTimeout = 60 * 60 * 1000;", "", `server.listen(Number(process.env.PORT ?? '${mainPort}'));`, "", "process.on('SIGTERM', () => {", " server.close();", " void stop();", "", ` // A response still open after ${stopGrace / 1e3} s, such as to a reader that stopped reading, is cut off.`, ` setTimeout(() => server.closeAllConnections(), ${stopGrace / 1e3} * 1000).unref();`, "});", "");
|
|
97
|
-
/** The packages a Node setup runs with, beside Git's, and the tools it type-checks with. */
|
|
98
|
-
const dependenciesOf = (choices, vendor) => {
|
|
99
|
-
const parts = partsOf(choices);
|
|
100
|
-
return {
|
|
101
|
-
run: Object.fromEntries([...gitDependencies(choices, vendor), ...parts.flatMap((part) => part.dependencies)]),
|
|
102
|
-
tools: Object.fromEntries([...Object.entries(nodePackages), ...parts.flatMap((part) => part.devDependencies)])
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
/** `package.json` with Git's packages added where it doesn't name them, or names them as the other source does, and its tools with `tools`. */
|
|
106
|
-
const mergePackage = (choices, name, tools, vendor) => (current) => {
|
|
107
|
-
const { run, tools: types } = dependenciesOf(choices, vendor);
|
|
108
|
-
if (current === void 0) return withCli(`${manifestText({
|
|
109
|
-
name,
|
|
110
|
-
private: true,
|
|
111
|
-
type: "module",
|
|
112
|
-
scripts: {
|
|
113
|
-
start: "node --env-file=.env src/main.ts",
|
|
114
|
-
dev: "node --env-file=.env --watch src/main.ts"
|
|
115
|
-
},
|
|
116
|
-
dependencies: run,
|
|
117
|
-
devDependencies: types
|
|
118
|
-
})}\n`, vendor);
|
|
119
|
-
const added = withCli(withDependencies(current, run), vendor);
|
|
120
|
-
return tools ? withEntries(added, ["devDependencies"], types) : added;
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* `.env`, with `ADMIN_TOKEN` made, each variable to set and `known`, the settings whose values
|
|
124
|
-
* `init` knows, and `.gitignore`, ending with it.
|
|
125
|
-
*/
|
|
126
|
-
const localFiles = (choices, secret, known = []) => [{
|
|
127
|
-
path: ".env",
|
|
128
|
-
kind: "merge",
|
|
129
|
-
secrets: ["ADMIN_TOKEN"],
|
|
130
|
-
merge: (current) => withLines(current, [
|
|
131
|
-
`ADMIN_TOKEN=${Redacted.value(secret())}`,
|
|
132
|
-
...nodeNeeds(choices).map((name) => `${name}=`),
|
|
133
|
-
...known
|
|
134
|
-
], (line) => line.split("=")[0]?.trim() ?? "")
|
|
135
|
-
}, {
|
|
136
|
-
path: ".gitignore",
|
|
137
|
-
kind: "merge",
|
|
138
|
-
merge: (current) => ignoring(current, ["node_modules", ...keepsData(choices) ? [".data"] : []], secretFiles)
|
|
139
|
-
}];
|
|
140
|
-
/** A `package.json`'s `@types/node` older than `typesMajor`, as a printed step. */
|
|
141
|
-
const typesStep = (packageJson, created) => {
|
|
142
|
-
if (created === true) return [];
|
|
143
|
-
const tree = packageJson === void 0 ? void 0 : parseJsonc(packageJson);
|
|
144
|
-
const spec = stringAt(tree, ["devDependencies", "@types/node"]) ?? "";
|
|
145
|
-
if (Number(/^[\^~=v]*(\d+)/.exec(spec)?.[1] ?? 22) >= 22) return [];
|
|
146
|
-
return [{
|
|
147
|
-
path: "package.json",
|
|
148
|
-
why: "yours",
|
|
149
|
-
says: `Move @types/node to 22 or later, which types the node:sqlite src/git.ts imports`,
|
|
150
|
-
lines: [`"@types/node": "^${nodePackages["@types/node"]}"`]
|
|
151
|
-
}];
|
|
152
|
-
};
|
|
153
|
-
/** Next.js's instrumentation files, at the root or in `src/`, beside its App Router's folder. */
|
|
154
|
-
const instrumentationOf = (framework) => `${framework.appDir === "src/app" ? "src/" : ""}instrumentation.ts`;
|
|
155
|
-
/** The lines that start Git's jobs in each Next.js server process, on Node only. */
|
|
156
|
-
const registerLines = [
|
|
157
|
-
"export async function register() {",
|
|
158
|
-
" if (process.env.NEXT_RUNTIME === 'nodejs') {",
|
|
159
|
-
" const { runtime } = await import('./lib/git');",
|
|
160
|
-
" const Node = await import('@ref0/infra/node');",
|
|
161
|
-
"",
|
|
162
|
-
" Node.toJobRunner(runtime);",
|
|
163
|
-
" }",
|
|
164
|
-
"}"
|
|
165
|
-
];
|
|
166
|
-
/**
|
|
167
|
-
* Next.js on Node: the server module at Next's path, its route files with no `maxDuration`,
|
|
168
|
-
* `instrumentation.ts` to start the jobs in each server process, and `next.config`'s rewrite of
|
|
169
|
-
* `gh`'s root URLs. Next.js loads `.env` itself, so `package.json` gets no `start` script.
|
|
170
|
-
*/
|
|
171
|
-
const nextNodeOutput = (choices, project, framework, secret, vendor) => {
|
|
172
|
-
const instrumentation = instrumentationOf(framework);
|
|
173
|
-
const theirs = framework.instrumentation;
|
|
174
|
-
const config = nextConfigOutput(choices, framework, project.created === true);
|
|
175
|
-
const needs = nodeNeeds(choices);
|
|
176
|
-
return {
|
|
177
|
-
files: [
|
|
178
|
-
{
|
|
179
|
-
path: "package.json",
|
|
180
|
-
kind: "merge",
|
|
181
|
-
merge: (current) => withCreatedTypes(project.created)(mergePackage(choices, project.name, true, vendor)(current))
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
path: framework.serverModule,
|
|
185
|
-
kind: "whole",
|
|
186
|
-
text: nodeModule(choices, "hook")
|
|
187
|
-
},
|
|
188
|
-
...nextRouteFiles(choices, framework, void 0),
|
|
189
|
-
...theirs === void 0 ? [{
|
|
190
|
-
path: instrumentation,
|
|
191
|
-
kind: "whole",
|
|
192
|
-
text: lines("// Starts Git's jobs once in each Next.js server process, on Node only. Written by", "// `ref0-git init`, and yours to change.", ...registerLines, "")
|
|
193
|
-
}] : [],
|
|
194
|
-
...config.files,
|
|
195
|
-
...localFiles(choices, secret)
|
|
196
|
-
],
|
|
197
|
-
manual: [
|
|
198
|
-
...theirs === void 0 || theirs.text.includes("await import('./lib/git')") ? [] : [{
|
|
199
|
-
path: theirs.path,
|
|
200
|
-
why: "yours",
|
|
201
|
-
says: "Start Git's jobs in register(), once in each server process",
|
|
202
|
-
lines: registerLines
|
|
203
|
-
}],
|
|
204
|
-
...typesStep(project.packageJson, project.created),
|
|
205
|
-
...config.manual
|
|
206
|
-
],
|
|
207
|
-
packages: gitPackages(choices),
|
|
208
|
-
needs,
|
|
209
|
-
secret: `ADMIN_TOKEN, made for ${framework.serverModule}, in .env`,
|
|
210
|
-
next: needs.length === 0 ? "Check it, then start it" : `Set ${needs.join(", ")} in .env, then check it`
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* SvelteKit on Node, under adapter-node: the server module, its `+server.ts` routes,
|
|
215
|
-
* `hooks.server.ts`'s `init` to start the jobs, and with `--serve github` `hooks.ts`'s `reroute`
|
|
216
|
-
* for `gh`'s root URLs. adapter-node takes 512 KB a request unless `BODY_SIZE_LIMIT` says, and
|
|
217
|
-
* reads it before the server module loads `.env`, so `.env` lifts it and `start` loads `.env`.
|
|
218
|
-
*/
|
|
219
|
-
const svelteNodeOutput = (choices, project, framework, secret, vendor) => {
|
|
220
|
-
const theirs = framework.hooks?.server;
|
|
221
|
-
const universal = framework.hooks?.universal;
|
|
222
|
-
const github = choices.serve === "github";
|
|
223
|
-
const needs = nodeNeeds(choices);
|
|
224
|
-
const { adapter } = framework;
|
|
225
|
-
const switched = project.created === true && adapter?.name === "auto" ? onAdapterNode(adapter.text) : void 0;
|
|
226
|
-
const template = switched === void 0 || adapter === void 0 ? void 0 : {
|
|
227
|
-
...adapter,
|
|
228
|
-
switched
|
|
229
|
-
};
|
|
230
|
-
return {
|
|
231
|
-
files: [
|
|
232
|
-
{
|
|
233
|
-
path: "package.json",
|
|
234
|
-
kind: "merge",
|
|
235
|
-
merge: (current) => {
|
|
236
|
-
const merged = withCreatedTypes(project.created)(withSvelteStart(mergePackage(choices, project.name, true, vendor)(current)));
|
|
237
|
-
return template === void 0 ? merged : withEntries(merged, ["devDependencies"], { "@sveltejs/adapter-node": frameworkPackages["@sveltejs/adapter-node"] });
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
...template === void 0 ? [] : [{
|
|
241
|
-
path: template.file,
|
|
242
|
-
kind: "edit",
|
|
243
|
-
from: template.text,
|
|
244
|
-
text: template.switched,
|
|
245
|
-
edit: {
|
|
246
|
-
anchor: svelteAdapterAnchor,
|
|
247
|
-
adds: [],
|
|
248
|
-
swaps: [{
|
|
249
|
-
from: svelteAdapterAnchor,
|
|
250
|
-
to: svelteNodeAdapter
|
|
251
|
-
}]
|
|
252
|
-
}
|
|
253
|
-
}],
|
|
254
|
-
{
|
|
255
|
-
path: framework.serverModule,
|
|
256
|
-
kind: "whole",
|
|
257
|
-
text: nodeModule(choices, "hook")
|
|
258
|
-
},
|
|
259
|
-
...svelteRouteFiles(choices, framework),
|
|
260
|
-
...theirs === void 0 ? [{
|
|
261
|
-
path: "src/hooks.server.ts",
|
|
262
|
-
kind: "whole",
|
|
263
|
-
text: svelteServerHooks(framework)
|
|
264
|
-
}] : [],
|
|
265
|
-
...github && universal === void 0 ? [{
|
|
266
|
-
path: "src/hooks.ts",
|
|
267
|
-
kind: "whole",
|
|
268
|
-
text: svelteHooks(choices)
|
|
269
|
-
}] : [],
|
|
270
|
-
{
|
|
271
|
-
path: ".env.example",
|
|
272
|
-
kind: "whole",
|
|
273
|
-
text: lines(envExample([`What ${framework.serverModule} and adapter-node read. Set each where the server runs.`], ["ADMIN_TOKEN", ...needs]), bodySizeLimit, "")
|
|
274
|
-
},
|
|
275
|
-
...localFiles(choices, secret, [bodySizeLimit])
|
|
276
|
-
],
|
|
277
|
-
manual: [
|
|
278
|
-
...theirs === void 0 || /\btoJobRunner\(/.test(theirs.text) ? [] : [{
|
|
279
|
-
path: theirs.path,
|
|
280
|
-
why: "yours",
|
|
281
|
-
says: "Start Git's jobs in the init hook, once in each server process: merge these imports with yours",
|
|
282
|
-
lines: svelteInitLines(framework)
|
|
283
|
-
}],
|
|
284
|
-
...!github || universal === void 0 || universal.text.includes("gitRoot") ? [] : [{
|
|
285
|
-
path: universal.path,
|
|
286
|
-
why: "yours",
|
|
287
|
-
says: "Reroute gh's root Git URLs to Git's route: merge this import with yours",
|
|
288
|
-
lines: svelteRerouteLines(choices)
|
|
289
|
-
}],
|
|
290
|
-
...adapter?.name === "node" || template !== void 0 ? [] : [{
|
|
291
|
-
path: adapter?.file ?? "vite.config.ts",
|
|
292
|
-
why: project.created === true ? "template_changed" : "yours",
|
|
293
|
-
says: "Build with adapter-node, which runs Git's jobs between requests: add @sveltejs/adapter-node and pass it to sveltekit()",
|
|
294
|
-
lines: ["import adapter from '@sveltejs/adapter-node';", "sveltekit({ adapter: adapter() })"]
|
|
295
|
-
}],
|
|
296
|
-
...svelteStartStep(project.packageJson),
|
|
297
|
-
...typesStep(project.packageJson, project.created)
|
|
298
|
-
],
|
|
299
|
-
packages: gitPackages(choices),
|
|
300
|
-
needs: [...needs, "BODY_SIZE_LIMIT"],
|
|
301
|
-
secret: `ADMIN_TOKEN, made for ${framework.serverModule}, in .env`,
|
|
302
|
-
next: needs.length === 0 ? "Check it, then build and start it" : `Set ${needs.join(", ")} in .env, then check it`
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
/**
|
|
306
|
-
* Nuxt on Node, under Nitro's Node preset: the server module at `server/git.ts`, a Nitro plugin
|
|
307
|
-
* to start the jobs, and a middleware that answers Git's URLs, and with `--serve github` the
|
|
308
|
-
* drop-in's. Nitro's server loads no `.env`, so the module loads it, and Nitro sets no body limit.
|
|
309
|
-
*/
|
|
310
|
-
const nuxtNodeOutput = (choices, project, framework, secret, vendor) => {
|
|
311
|
-
const nuxt = nuxtOutput(choices, framework, project.created === true);
|
|
312
|
-
const needs = nodeNeeds(choices);
|
|
313
|
-
return {
|
|
314
|
-
files: [
|
|
315
|
-
{
|
|
316
|
-
path: "package.json",
|
|
317
|
-
kind: "merge",
|
|
318
|
-
merge: (current) => withCreatedTypes(project.created)(mergePackage(choices, project.name, true, vendor)(current))
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
path: framework.serverModule,
|
|
322
|
-
kind: "whole",
|
|
323
|
-
text: nodeModule(choices, "hook")
|
|
324
|
-
},
|
|
325
|
-
...nuxt.files,
|
|
326
|
-
...localFiles(choices, secret)
|
|
327
|
-
],
|
|
328
|
-
manual: [...nuxt.manual, ...typesStep(project.packageJson, project.created)],
|
|
329
|
-
packages: gitPackages(choices),
|
|
330
|
-
needs,
|
|
331
|
-
secret: `ADMIN_TOKEN, made for ${framework.serverModule}, in .env`,
|
|
332
|
-
next: needs.length === 0 ? "Check it, then build and start it" : `Set ${needs.join(", ")} in .env, then check it`
|
|
333
|
-
};
|
|
334
|
-
};
|
|
335
|
-
/** The frameworks `init` routes on Node through route files of their own. */
|
|
336
|
-
const routedNames = /* @__PURE__ */ new Set(["astro", "react-router"]);
|
|
337
|
-
/**
|
|
338
|
-
* Astro or React Router on Node: the server module at the framework's path, which starts the
|
|
339
|
-
* jobs on its first import, since neither has a startup hook; a route file for each route; the
|
|
340
|
-
* framework's own steps. The module loads `.env`, which neither server does.
|
|
341
|
-
*/
|
|
342
|
-
const routedNodeOutput = (choices, project, framework, secret, vendor) => {
|
|
343
|
-
const astro = framework.name === "astro";
|
|
344
|
-
const needs = nodeNeeds(choices);
|
|
345
|
-
return {
|
|
346
|
-
files: [
|
|
347
|
-
{
|
|
348
|
-
path: "package.json",
|
|
349
|
-
kind: "merge",
|
|
350
|
-
merge: mergePackage(choices, project.name, true, vendor)
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
path: framework.serverModule,
|
|
354
|
-
kind: "whole",
|
|
355
|
-
text: nodeModule(choices, "on-import")
|
|
356
|
-
},
|
|
357
|
-
...astro ? astroRouteFiles(choices, framework) : reactRouterRouteFiles(choices, framework),
|
|
358
|
-
...localFiles(choices, secret)
|
|
359
|
-
],
|
|
360
|
-
manual: [...astro ? astroSteps(framework) : reactRouterSteps(choices, framework), ...typesStep(project.packageJson)],
|
|
361
|
-
packages: gitPackages(choices),
|
|
362
|
-
needs,
|
|
363
|
-
secret: `ADMIN_TOKEN, made for ${framework.serverModule}, in .env`,
|
|
364
|
-
next: needs.length === 0 ? "Check it, then build and start it" : `Set ${needs.join(", ")} in .env, then check it`
|
|
365
|
-
};
|
|
366
|
-
};
|
|
367
|
-
/** Whether `framework` is one `init` routes on Node through its own route files. */
|
|
368
|
-
const routed = (framework) => framework !== void 0 && framework.known && routedNames.has(framework.name);
|
|
369
|
-
/**
|
|
370
|
-
* `doctor`'s checks for Astro or React Router on Node: the jobs' late start, said once; each
|
|
371
|
-
* printed step not done yet; and Node's 300 s request timeout, which neither server lifts.
|
|
372
|
-
*/
|
|
373
|
-
const routedFindings = (choices, project, framework) => {
|
|
374
|
-
const steps = nodeOutput(choices, project, () => Redacted.make("")).manual;
|
|
375
|
-
const server = framework.name === "astro" ? "@astrojs/node" : "react-router-serve";
|
|
376
|
-
return [
|
|
377
|
-
{
|
|
378
|
-
check: "Jobs",
|
|
379
|
-
ok: true,
|
|
380
|
-
says: `${framework.serverModule} starts Git's jobs on its first load, from any route, so after a restart a push's packing and events wait for the next request to Git`
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
check: "Steps",
|
|
384
|
-
ok: steps.length === 0,
|
|
385
|
-
says: steps.length === 0 ? "Each step init printed is done" : `${steps.map((step) => `${step.path}: ${step.says}`).join("; ")}: add the lines init printed`,
|
|
386
|
-
blocks: "serving Git as init set it up"
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
check: "Push timeout",
|
|
390
|
-
ok: true,
|
|
391
|
-
says: `${server} keeps Node's 300 s requestTimeout, so a push that takes longer to upload is cut off: serve Git from your own node:http server to lift it`
|
|
392
|
-
}
|
|
393
|
-
];
|
|
394
|
-
};
|
|
395
|
-
/**
|
|
396
|
-
* Git on Node with no framework's own output: `src/main.ts` where the project is `init`'s own,
|
|
397
|
-
* or the printed mount in a server of the person's.
|
|
398
|
-
*/
|
|
399
|
-
const serverNodeOutput = (choices, project, secret, vendor) => {
|
|
400
|
-
const own = project.layout.kind === "own";
|
|
401
|
-
const needs = nodeNeeds(choices);
|
|
402
|
-
return {
|
|
403
|
-
files: [
|
|
404
|
-
{
|
|
405
|
-
path: "package.json",
|
|
406
|
-
kind: "merge",
|
|
407
|
-
merge: mergePackage(choices, project.name, own, vendor)
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
path: "src/git.ts",
|
|
411
|
-
kind: "whole",
|
|
412
|
-
text: nodeModule(choices, own ? "main" : "server")
|
|
413
|
-
},
|
|
414
|
-
...own ? [{
|
|
415
|
-
path: "src/main.ts",
|
|
416
|
-
kind: "whole",
|
|
417
|
-
text: mainModule()
|
|
418
|
-
}] : [],
|
|
419
|
-
...localFiles(choices, secret)
|
|
420
|
-
],
|
|
421
|
-
manual: own ? [] : [mountManual(choices, project.framework?.name), {
|
|
422
|
-
path: "package.json",
|
|
423
|
-
why: "yours",
|
|
424
|
-
says: "Load .env before src/git.ts, which reads its settings from it: start your server with --env-file-if-exists=.env",
|
|
425
|
-
lines: ["\"start\": \"node --env-file-if-exists=.env <your server's entry>\""]
|
|
426
|
-
}],
|
|
427
|
-
packages: gitPackages(choices),
|
|
428
|
-
needs,
|
|
429
|
-
secret: `ADMIN_TOKEN, made for ${own ? "npm start" : "src/git.ts"}, in .env`,
|
|
430
|
-
next: needs.length === 0 ? "Check it, then start it" : `Set ${needs.join(", ")} in .env, then check it`
|
|
431
|
-
};
|
|
432
|
-
};
|
|
433
|
-
/** Each framework's output on Node: a framework IN-5b adds can't compile without its own. */
|
|
434
|
-
const frameworkNodeOutputs = {
|
|
435
|
-
next: nextNodeOutput,
|
|
436
|
-
sveltekit: svelteNodeOutput,
|
|
437
|
-
nuxt: nuxtNodeOutput,
|
|
438
|
-
astro: (choices, project, framework, secret, vendor) => routed(framework) ? routedNodeOutput(choices, project, framework, secret, vendor) : serverNodeOutput(choices, project, secret, vendor),
|
|
439
|
-
"react-router": (choices, project, framework, secret, vendor) => routed(framework) ? routedNodeOutput(choices, project, framework, secret, vendor) : serverNodeOutput(choices, project, secret, vendor),
|
|
440
|
-
hono: (choices, project, _, secret, vendor) => serverNodeOutput(choices, project, secret, vendor),
|
|
441
|
-
express: (choices, project, _, secret, vendor) => serverNodeOutput(choices, project, secret, vendor),
|
|
442
|
-
fastify: (choices, project, _, secret, vendor) => serverNodeOutput(choices, project, secret, vendor)
|
|
443
|
-
};
|
|
444
|
-
/** Everything `init` writes for `choices` in `project`, with `secret` making each new secret. */
|
|
445
|
-
const nodeOutput = (choices, project, secret, vendor) => project.framework === void 0 ? serverNodeOutput(choices, project, secret, vendor) : frameworkNodeOutputs[project.framework.name](choices, project, project.framework, secret, vendor);
|
|
446
|
-
export { bucketLines, firstImports, infraImports, keepsData, mainOrigin, nodeModule, nodeNeeds, nodeOutput, partsOf, recordsOf, routed, routedFindings, secretFiles, stopGrace, storeLines };
|