create-protobase 0.51.0 → 0.51.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/dist/ask-dir.js CHANGED
@@ -1,9 +1,9 @@
1
1
  //#region src/ask-dir.ts
2
2
  /** The folder a new project goes in when nobody names one. */
3
3
  const defaultDir = "my-app";
4
- /** The folder for an answer: the answer trimmed, the default when it is empty. */
5
- const dirForAnswer = (answer) => answer.trim() || "my-app";
6
- /** Asks with `question`, a terminal prompt's, which folder to write the new project in. */
7
- const askDir = async (question) => dirForAnswer(await question(`Project folder [${defaultDir}]: `));
4
+ /** The folder for an answer: the answer trimmed, `fallback` when it is empty. */
5
+ const dirForAnswer = (answer, fallback = defaultDir) => answer.trim() || fallback;
6
+ /** Asks with `question`, a terminal prompt's, which folder to write the new project in, `fallback` by default. */
7
+ const askDir = async (question, fallback = defaultDir) => dirForAnswer(await question(`Project folder [${fallback}]: `), fallback);
8
8
  //#endregion
9
9
  export { askDir, defaultDir, dirForAnswer };
@@ -0,0 +1,63 @@
1
+ //#region src/ask-tables.ts
2
+ const keyOf = (table) => `${table.schema}.${table.name}`;
3
+ const tablesForPart = (keys, part) => {
4
+ const range = /^(\d+)(?:-(\d+))?$/.exec(part);
5
+ if (range) {
6
+ const from = Number(range[1]);
7
+ const to = Number(range[2] ?? range[1]);
8
+ if (from < 1 || to > keys.length || from > to) return void 0;
9
+ return keys.slice(from - 1, to);
10
+ }
11
+ if (keys.includes(part)) return [part];
12
+ const named = keys.filter((key) => key.endsWith(`.${part}`));
13
+ return named.length === 1 ? named : void 0;
14
+ };
15
+ /**
16
+ * The keys of the tables an answer picks from `keys`, in their order: every one for an empty answer or `all`, otherwise
17
+ * those its comma-separated numbers, ranges such as 2-4, schema.table names and table names name; nothing for an answer
18
+ * with a part that names none.
19
+ */
20
+ const tablesForAnswer = (keys, answer) => {
21
+ const text = answer.trim();
22
+ if (text === "" || text === "all") return keys;
23
+ const picked = /* @__PURE__ */ new Set();
24
+ for (const part of text.split(",").map((each) => each.trim()).filter(Boolean)) {
25
+ const tables = tablesForPart(keys, part);
26
+ if (!tables) return void 0;
27
+ for (const key of tables) picked.add(key);
28
+ }
29
+ return keys.filter((key) => picked.has(key));
30
+ };
31
+ /**
32
+ * The keys of `picked` and of every table they point to, directly or through others, in the order of `tables`: a
33
+ * relation names the resource of the table it points to, and the app refuses one whose resource is missing.
34
+ */
35
+ const withReferenced = (tables, picked) => {
36
+ const byKey = new Map(tables.map((table) => [keyOf(table), table]));
37
+ const found = /* @__PURE__ */ new Set();
38
+ const visit = (key) => {
39
+ if (found.has(key)) return;
40
+ found.add(key);
41
+ for (const referenced of byKey.get(key)?.references ?? []) visit(referenced);
42
+ };
43
+ for (const key of picked) visit(key);
44
+ return tables.map(keyOf).filter((key) => found.has(key));
45
+ };
46
+ /** The numbered list of `tables` the question picks from, and what scaffold leaves out with why. */
47
+ const tableMenu = (database, tables, skipped) => {
48
+ const width = Math.max(...tables.map((table) => keyOf(table).length));
49
+ const lines = tables.map((table, i) => ` ${String(i + 1).padStart(String(tables.length).length)}. ${keyOf(table).padEnd(width)} ${table.columns} column${table.columns === 1 ? "" : "s"}\n`);
50
+ const left = skipped.length === 0 ? "" : `Left out:\n${skipped.map((line) => ` ${line}\n`).join("")}`;
51
+ return `\nTables in ${database}:\n${lines.join("")}${left}`;
52
+ };
53
+ /** Asks with `question`, a terminal prompt's, which of `tables` become resources, again until the answer names them. */
54
+ const askTables = async (tables, question, print) => {
55
+ const keys = tables.map(keyOf);
56
+ for (;;) {
57
+ const picked = tablesForAnswer(keys, await question("Which tables become resources? Numbers, ranges or names, such as 1,3-5 [all]: "));
58
+ if (picked) return picked;
59
+ print(` pick numbers from 1 to ${keys.length}, ranges of them or table names, separated by commas\n`);
60
+ }
61
+ };
62
+ //#endregion
63
+ export { askTables, tableMenu, tablesForAnswer, withReferenced };
@@ -0,0 +1,11 @@
1
+ //#region src/ask-yes-no.ts
2
+ /** The answer to a yes or no question: `fallback` when it is empty, yes for y or yes, no otherwise. */
3
+ const yesForAnswer = (answer, fallback) => {
4
+ const text = answer.trim().toLowerCase();
5
+ if (text === "") return fallback;
6
+ return text === "y" || text === "yes";
7
+ };
8
+ /** Asks `text` with `question`, a terminal prompt's, showing which answer an empty one takes. */
9
+ const askYesNo = async (question, text, fallback) => yesForAnswer(await question(`${text} ${fallback ? "[Y/n]" : "[y/N]"}: `), fallback);
10
+ //#endregion
11
+ export { askYesNo, yesForAnswer };
@@ -1,29 +1,38 @@
1
- import { databaseUrl, envFile, withDatabasePort } from "./env-file.js";
1
+ import { databaseUrl, envFile, withDatabasePort, withDatabaseUrl, withoutPassword } from "./env-file.js";
2
2
  import { composeFile, databaseScripts } from "./local-database.js";
3
3
  import path from "node:path";
4
4
  import { cpSync, existsSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
5
5
  //#region src/create-project.ts
6
6
  /**
7
7
  * Writes a new project to `targetDir` from `templateDir`, which the build writes from a preset, and returns its
8
- * package.json: named after the folder, with db:up and db:down for the docker-compose.yml it adds, whose Postgres takes
9
- * `port` in it, .env.example and a .env with `secret`. The folder may exist only when it is empty.
8
+ * package.json, named after the folder. On a Postgres of its own it gets db:up and db:down for the docker-compose.yml it
9
+ * adds, whose Postgres takes `port` in .env.example and in a .env with `secret`; on an existing database its .env has
10
+ * that database's URL and `secret`, and .env.example the URL without its password. The folder may exist only when it is
11
+ * empty.
10
12
  */
11
- const createProject = (templateDir, targetDir, { port, secret }) => {
13
+ const createProject = (templateDir, targetDir, { secret, database }) => {
12
14
  if (existsSync(targetDir) && readdirSync(targetDir).length > 0) throw new Error(`${targetDir} is not empty`);
13
15
  cpSync(templateDir, targetDir, { recursive: true });
14
16
  for (const file of readdirSync(targetDir).filter((file) => file.startsWith("_"))) renameSync(path.join(targetDir, file), path.join(targetDir, file.slice(1)));
15
17
  const packageFile = path.join(targetDir, "package.json");
16
18
  const source = JSON.parse(readFileSync(packageFile, "utf8"));
19
+ const scripts = "url" in database ? source.scripts : {
20
+ ...databaseScripts,
21
+ ...source.scripts
22
+ };
17
23
  const manifest = {
18
24
  ...source,
19
25
  name: path.basename(targetDir),
20
- scripts: {
21
- ...databaseScripts,
22
- ...source.scripts
23
- }
26
+ scripts
24
27
  };
25
28
  writeFileSync(packageFile, `${JSON.stringify(manifest, null, 2)}\n`);
26
- const example = withDatabasePort(readFileSync(path.join(targetDir, ".env.example"), "utf8"), port);
29
+ const presetExample = readFileSync(path.join(targetDir, ".env.example"), "utf8");
30
+ if ("url" in database) {
31
+ writeFileSync(path.join(targetDir, ".env.example"), withDatabaseUrl(presetExample, withoutPassword(database.url)));
32
+ writeFileSync(path.join(targetDir, ".env"), envFile(withDatabaseUrl(presetExample, database.url), secret));
33
+ return manifest;
34
+ }
35
+ const example = withDatabasePort(presetExample, database.port);
27
36
  writeFileSync(path.join(targetDir, ".env.example"), example);
28
37
  writeFileSync(path.join(targetDir, ".env"), envFile(example, secret));
29
38
  writeFileSync(path.join(targetDir, "docker-compose.yml"), composeFile(databaseUrl(example)));
@@ -0,0 +1,70 @@
1
+ import { createProject } from "./create-project.js";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { spawn } from "node:child_process";
5
+ import { pathToFileURL } from "node:url";
6
+ import postgres from "postgres";
7
+ //#region src/database-steps.ts
8
+ const projectScaffold = async (dir) => {
9
+ const entry = createRequire(path.resolve(dir, "package.json")).resolve("@protobase/cli/scaffold");
10
+ return import(pathToFileURL(entry).href);
11
+ };
12
+ const checkConnection = async (url) => {
13
+ const sql = postgres(url, {
14
+ max: 1,
15
+ connect_timeout: 10,
16
+ onnotice: () => {},
17
+ connection: { default_transaction_read_only: true }
18
+ });
19
+ try {
20
+ const [row] = await sql`select current_database() as database, current_setting('server_version') as version`;
21
+ return row;
22
+ } finally {
23
+ await sql.end();
24
+ }
25
+ };
26
+ const install = (dir, manager) => new Promise((resolve, reject) => {
27
+ const child = spawn(manager, ["install"], {
28
+ cwd: dir,
29
+ stdio: [
30
+ "ignore",
31
+ "inherit",
32
+ "inherit"
33
+ ],
34
+ shell: process.platform === "win32"
35
+ });
36
+ child.once("error", reject);
37
+ child.once("exit", (code) => code === 0 ? resolve() : reject(/* @__PURE__ */ new Error(`${manager} install failed in ${dir}`)));
38
+ });
39
+ /** The steps of `createFromDatabase` on this machine: its folders, its package manager and the database. */
40
+ const databaseSteps = ({ templateDir, secret, tools, terminal, loadScaffold = projectScaffold }) => ({
41
+ checkConnection,
42
+ writeProject: async (dir, url) => {
43
+ createProject(templateDir, path.resolve(dir), {
44
+ secret,
45
+ database: { url }
46
+ });
47
+ },
48
+ install: async (dir, manager) => {
49
+ terminal.closePrompt();
50
+ await install(dir, manager);
51
+ },
52
+ listTables: async (dir, url) => (await loadScaffold(dir)).listTables(url),
53
+ importTables: async (dir, url, { excluded, ui, review }) => {
54
+ if (review && !terminal.ask) throw new Error("reviewing each column needs a terminal");
55
+ const scaffold = await loadScaffold(dir);
56
+ const decide = review && terminal.ask ? scaffold.asking(terminal.ask, terminal.print) : void 0;
57
+ await scaffold.runScaffold({
58
+ url,
59
+ configDir: path.join(dir, "config"),
60
+ yes: !review,
61
+ dryRun: false,
62
+ ui: ui ? ["names", "list"] : [],
63
+ excludes: excluded,
64
+ ...decide && { decide }
65
+ }, terminal.print);
66
+ },
67
+ tools
68
+ });
69
+ //#endregion
70
+ export { databaseSteps };
@@ -0,0 +1,54 @@
1
+ import { askDir } from "./ask-dir.js";
2
+ import { askTables, tableMenu, withReferenced } from "./ask-tables.js";
3
+ import { askYesNo } from "./ask-yes-no.js";
4
+ import { databaseNextSteps } from "./next-steps.js";
5
+ //#region src/database-wizard.ts
6
+ const keyOf = (table) => `${table.schema}.${table.name}`;
7
+ const where = (url) => `${url.hostname}${url.port ? `:${url.port}` : ""}${url.pathname}`;
8
+ const askChoices = async (tables, terminal) => {
9
+ const keys = tables.map(keyOf);
10
+ const { ask, print } = terminal;
11
+ if (!ask) return {
12
+ tables: keys,
13
+ excluded: [],
14
+ ui: true,
15
+ review: false
16
+ };
17
+ const answered = await askTables(tables, ask, print);
18
+ const picked = withReferenced(tables, answered);
19
+ const added = picked.filter((key) => !answered.includes(key));
20
+ if (added.length > 0) print(` and ${added.join(", ")}, which they point to\n`);
21
+ const ui = await askYesNo(ask, "Write a ui.ts for each too, with its names and list?", true);
22
+ const review = await askYesNo(ask, "Review the field proposed for each column?", false);
23
+ return {
24
+ tables: picked,
25
+ excluded: keys.filter((key) => !picked.includes(key)),
26
+ ui,
27
+ review
28
+ };
29
+ };
30
+ /**
31
+ * Creates a project on the existing database at `url`, in `dir` or the folder it asks for: checks the connection, writes
32
+ * the scratch preset on that database and installs it, then asks which tables become resources, and how, and scaffolds
33
+ * them with the project's own CLI. It only reads the database; the next steps it prints say which one writes to it.
34
+ */
35
+ const createFromDatabase = async (url, dir, terminal, steps) => {
36
+ const { ask, print } = terminal;
37
+ print(`Connecting to ${where(new URL(url))}, read-only...\n`);
38
+ const { database, version } = await steps.checkConnection(url);
39
+ print(`Connected to ${database}, PostgreSQL ${version}.\n\n`);
40
+ const folder = dir ?? (ask ? await askDir(ask, database) : database);
41
+ await steps.writeProject(folder, url);
42
+ const manager = steps.tools.bun ? "bun" : "npm";
43
+ print(`\nWrote the project to ${folder}. Installing its packages with ${manager}...\n`);
44
+ await steps.install(folder, manager);
45
+ const { tables, skipped } = await steps.listTables(folder, url);
46
+ if (tables.length === 0) print(`\n${database} has no tables to import${skipped.length > 0 ? `: it leaves out ${skipped.join(", ")}` : ""}. The project starts without resources.\n`);
47
+ else {
48
+ print(tableMenu(database, tables, skipped));
49
+ await steps.importTables(folder, url, await askChoices(tables, terminal));
50
+ }
51
+ print(`\nCreated a Protobase project in ${folder} on the database ${database}, which it has only read. Next:\n\n${databaseNextSteps(folder, steps.tools)}`);
52
+ };
53
+ //#endregion
54
+ export { createFromDatabase };
package/dist/env-file.js CHANGED
@@ -7,11 +7,19 @@ const setting = (text, name) => {
7
7
  const replaceSetting = (text, name, value) => text.split("\n").map((line) => line.startsWith(`${name}=`) ? `${name}=${value}` : line).join("\n");
8
8
  /** The DATABASE_URL of a preset's .env.example. */
9
9
  const databaseUrl = (example) => new URL(setting(example, "DATABASE_URL"));
10
+ /** `example`, a preset's .env.example, with `url` as its DATABASE_URL. */
11
+ const withDatabaseUrl = (example, url) => replaceSetting(example, "DATABASE_URL", url);
10
12
  /** `example`, a preset's .env.example, with its DATABASE_URL on `port`. */
11
13
  const withDatabasePort = (example, port) => {
12
14
  const url = databaseUrl(example);
13
15
  url.port = String(port);
14
- return replaceSetting(example, "DATABASE_URL", url.toString());
16
+ return withDatabaseUrl(example, url.toString());
17
+ };
18
+ /** `url` without its password, for a file that is committed. */
19
+ const withoutPassword = (url) => {
20
+ const parsed = new URL(url);
21
+ parsed.password = "";
22
+ return parsed.toString();
15
23
  };
16
24
  /** A new project's .env: its .env.example with `secret` as PROTOBASE_SECRET in place of the placeholder. */
17
25
  const envFile = (example, secret) => {
@@ -19,4 +27,4 @@ const envFile = (example, secret) => {
19
27
  return replaceSetting(example, "PROTOBASE_SECRET", secret);
20
28
  };
21
29
  //#endregion
22
- export { databaseUrl, envFile, withDatabasePort };
30
+ export { databaseUrl, envFile, withDatabasePort, withDatabaseUrl, withoutPassword };
package/dist/index.js CHANGED
@@ -2,17 +2,21 @@ import { askDir } from "./ask-dir.js";
2
2
  import { askPreset } from "./ask-preset.js";
3
3
  import { defaultPort } from "./local-database.js";
4
4
  import { createProject } from "./create-project.js";
5
- import { freePort } from "./free-port.js";
5
+ import { databaseSteps } from "./database-steps.js";
6
6
  import { nextSteps } from "./next-steps.js";
7
+ import { createFromDatabase } from "./database-wizard.js";
8
+ import { freePort } from "./free-port.js";
7
9
  import { checkPreset, defaultPreset, presetNames } from "./presets.js";
10
+ import { openTerminal } from "./terminal.js";
8
11
  import { findTools } from "./tools.js";
9
12
  import { randomBytes } from "node:crypto";
10
13
  import path from "node:path";
11
- import { createInterface } from "node:readline/promises";
12
14
  import { parseArgs } from "node:util";
13
15
  //#region src/index.ts
14
16
  const templatesDir = path.join(import.meta.dirname, "templates");
15
- const usage = "usage: npm create protobase <dir> [-- --preset <name>]";
17
+ const usage = "usage: npm create protobase [<dir>] [<postgres-url>] [-- --preset <name>]";
18
+ const isDatabaseUrl = (value) => /^postgres(ql)?:\/\//.test(value);
19
+ const newSecret = () => randomBytes(32).toString("base64");
16
20
  const checkNpmPreset = (flag) => {
17
21
  if (flag !== void 0 || process.env.npm_config_preset === void 0) return;
18
22
  throw new Error("npm took --preset for itself: put -- before it, as in npm create protobase my-app -- --preset erp");
@@ -30,20 +34,29 @@ const pickPreset = async (flag, question) => {
30
34
  if (question) return askPreset(names, question);
31
35
  return defaultPreset;
32
36
  };
33
- const pick = async (positionals, flag) => {
34
- const prompt = process.stdin.isTTY && process.stdout.isTTY ? createInterface({
35
- input: process.stdin,
36
- output: process.stdout
37
- }) : void 0;
38
- const question = prompt && ((text) => prompt.question(text));
39
- try {
40
- return {
41
- dir: await pickDir(positionals, question),
42
- preset: await pickPreset(flag, question)
43
- };
44
- } finally {
45
- prompt?.close();
46
- }
37
+ const fromPreset = async (positionals, flag, terminal) => {
38
+ const dir = await pickDir(positionals, terminal.ask);
39
+ const preset = await pickPreset(flag, terminal.ask);
40
+ terminal.closePrompt();
41
+ const port = await freePort(defaultPort);
42
+ const { scripts } = createProject(path.join(templatesDir, preset), path.resolve(dir), {
43
+ secret: newSecret(),
44
+ database: { port }
45
+ });
46
+ const steps = nextSteps(dir, scripts, port, findTools());
47
+ terminal.print(`Created a Protobase project in ${dir} from the ${preset} preset. Next:\n\n${steps}`);
48
+ };
49
+ const fromDatabase = async (url, positionals, flag, terminal) => {
50
+ if (flag !== void 0 && flag !== "scratch") throw new Error(`a project on an existing database starts from ${defaultPreset}: leave out --preset`);
51
+ const [dir, ...extra] = positionals;
52
+ if (extra.length > 0) throw new Error(usage);
53
+ const steps = databaseSteps({
54
+ templateDir: path.join(templatesDir, defaultPreset),
55
+ secret: newSecret(),
56
+ tools: findTools(),
57
+ terminal
58
+ });
59
+ await createFromDatabase(url, dir, terminal, steps);
47
60
  };
48
61
  const create = async (argv) => {
49
62
  const { values, positionals } = parseArgs({
@@ -52,15 +65,14 @@ const create = async (argv) => {
52
65
  options: { preset: { type: "string" } }
53
66
  });
54
67
  checkNpmPreset(values.preset);
55
- const { dir, preset } = await pick(positionals, values.preset);
56
- const port = await freePort(defaultPort);
57
- const secret = randomBytes(32).toString("base64");
58
- const { scripts } = createProject(path.join(templatesDir, preset), path.resolve(dir), {
59
- port,
60
- secret
61
- });
62
- const steps = nextSteps(dir, scripts, port, findTools());
63
- process.stdout.write(`Created a Protobase project in ${dir} from the ${preset} preset. Next:\n\n${steps}`);
68
+ const url = positionals.find(isDatabaseUrl);
69
+ const terminal = openTerminal();
70
+ try {
71
+ if (url) await fromDatabase(url, positionals.filter((each) => each !== url), values.preset, terminal);
72
+ else await fromPreset(positionals, values.preset, terminal);
73
+ } finally {
74
+ terminal.closePrompt();
75
+ }
64
76
  };
65
77
  const run = async (argv) => {
66
78
  try {
@@ -1,4 +1,9 @@
1
1
  //#region src/next-steps.ts
2
+ const withBun = (steps, tools) => {
3
+ const lines = steps.map((line) => ` ${line}\n`).join("");
4
+ if (tools.bun) return lines;
5
+ return `Bun 1.4 runs the project's scripts: install it first (https://bun.sh).\n\n${lines}`;
6
+ };
2
7
  /**
3
8
  * What to run in a new project, from `cwd`'s point of view, until its admin app serves. `scripts` are those of the
4
9
  * project's package.json: a preset with a base seed loads it, and one with sample data offers it, before the first user,
@@ -6,7 +11,7 @@
6
11
  * which runs every script, installing it comes first.
7
12
  */
8
13
  const nextSteps = (dir, scripts, port, tools) => {
9
- const lines = [
14
+ const steps = [
10
15
  `cd ${dir}`,
11
16
  "bun install",
12
17
  tools.docker ? `bun run db:up # Postgres 18 in Docker on port ${port}` : "# no Docker found: set DATABASE_URL in .env to a Postgres database of yours",
@@ -15,9 +20,18 @@ const nextSteps = (dir, scripts, port, tools) => {
15
20
  ..."db:seed" in scripts ? ["bun run db:seed --scale small # optional: sample data, replacing the app tables"] : [],
16
21
  "bun run protobase users create you@example.com --generate-password",
17
22
  "bun run dev # http://localhost:5173"
18
- ].map((line) => ` ${line}\n`).join("");
19
- if (tools.bun) return lines;
20
- return `Bun 1.4 runs the project's scripts: install it first (https://bun.sh).\n\n${lines}`;
23
+ ];
24
+ return withBun(steps, tools);
21
25
  };
26
+ /**
27
+ * What to run in a new project on an existing database, its packages installed, until its admin app serves: the first
28
+ * of them is the first that writes to the database, adding the auth schema sign-in keeps its users in.
29
+ */
30
+ const databaseNextSteps = (dir, tools) => withBun([
31
+ `cd ${dir}`,
32
+ "bun run db:migrate # the first write to the database: the auth schema, and public.schema_migrations",
33
+ "bun run protobase users create you@example.com --generate-password",
34
+ "bun run dev # http://localhost:5173"
35
+ ], tools);
22
36
  //#endregion
23
- export { nextSteps };
37
+ export { databaseNextSteps, nextSteps };
@@ -24,12 +24,12 @@
24
24
  "react": "^19.3.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@protobase/cli": "^0.51.0",
28
- "@protobase/config": "^0.51.0",
29
- "@protobase/layout": "^0.51.0",
30
- "@protobase/schema": "^0.51.0",
31
- "@protobase/server": "^0.51.0",
32
- "@protobase/ui": "^0.51.0",
27
+ "@protobase/cli": "^0.51.1",
28
+ "@protobase/config": "^0.51.1",
29
+ "@protobase/layout": "^0.51.1",
30
+ "@protobase/schema": "^0.51.1",
31
+ "@protobase/server": "^0.51.1",
32
+ "@protobase/ui": "^0.51.1",
33
33
  "@types/node": "^22.20.5",
34
34
  "@types/pg": "^8.23.1",
35
35
  "@types/react": "^19.3.0",
@@ -24,12 +24,12 @@
24
24
  "react": "^19.3.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@protobase/cli": "^0.51.0",
28
- "@protobase/config": "^0.51.0",
29
- "@protobase/layout": "^0.51.0",
30
- "@protobase/schema": "^0.51.0",
31
- "@protobase/server": "^0.51.0",
32
- "@protobase/ui": "^0.51.0",
27
+ "@protobase/cli": "^0.51.1",
28
+ "@protobase/config": "^0.51.1",
29
+ "@protobase/layout": "^0.51.1",
30
+ "@protobase/schema": "^0.51.1",
31
+ "@protobase/server": "^0.51.1",
32
+ "@protobase/ui": "^0.51.1",
33
33
  "@types/node": "^22.20.5",
34
34
  "@types/pg": "^8.23.1",
35
35
  "@types/react": "^19.3.0",
@@ -21,12 +21,12 @@
21
21
  "react": "^19.3.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@protobase/cli": "^0.51.0",
25
- "@protobase/config": "^0.51.0",
26
- "@protobase/layout": "^0.51.0",
27
- "@protobase/schema": "^0.51.0",
28
- "@protobase/server": "^0.51.0",
29
- "@protobase/ui": "^0.51.0",
24
+ "@protobase/cli": "^0.51.1",
25
+ "@protobase/config": "^0.51.1",
26
+ "@protobase/layout": "^0.51.1",
27
+ "@protobase/schema": "^0.51.1",
28
+ "@protobase/server": "^0.51.1",
29
+ "@protobase/ui": "^0.51.1",
30
30
  "@types/node": "^22.20.5",
31
31
  "@types/pg": "^8.23.1",
32
32
  "@types/react": "^19.3.0",
@@ -0,0 +1,34 @@
1
+ import { createInterface } from "node:readline/promises";
2
+ //#region src/terminal.ts
3
+ /**
4
+ * This process's terminal, with `ask` only when stdin and stdout are one. Its questions share one prompt, so none reads
5
+ * the answers typed ahead for the next, opened at the first and again after `closePrompt`, which a child process that
6
+ * runs on the terminal, such as an install, needs first: the prompt keeps the terminal in raw mode, where Ctrl+C reaches
7
+ * it instead of the child.
8
+ */
9
+ const openTerminal = () => {
10
+ let prompt;
11
+ const print = (text) => void process.stdout.write(text);
12
+ const closePrompt = () => {
13
+ prompt?.close();
14
+ prompt = void 0;
15
+ };
16
+ if (!process.stdin.isTTY || !process.stdout.isTTY) return {
17
+ print,
18
+ closePrompt
19
+ };
20
+ const ask = (text) => {
21
+ prompt ??= createInterface({
22
+ input: process.stdin,
23
+ output: process.stdout
24
+ });
25
+ return prompt.question(text);
26
+ };
27
+ return {
28
+ ask,
29
+ print,
30
+ closePrompt
31
+ };
32
+ };
33
+ //#endregion
34
+ export { openTerminal };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-protobase",
3
- "version": "0.51.0",
4
- "description": "npm create protobase: starts a new Protobase project from one of its presets.",
3
+ "version": "0.51.1",
4
+ "description": "npm create protobase: starts a new Protobase project from one of its presets, or on an existing Postgres database.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,6 +24,12 @@
24
24
  "build": "tsdown && bun ../presets/src/write-template.ts",
25
25
  "prepack": "tsdown && bun ../presets/src/write-template.ts"
26
26
  },
27
+ "dependencies": {
28
+ "postgres": "^3.4.9"
29
+ },
30
+ "devDependencies": {
31
+ "@protobase/cli": "0.51.1"
32
+ },
27
33
  "publishConfig": {
28
34
  "access": "public"
29
35
  }