@rebasepro/cli 0.0.1-canary.4f204c2 → 0.0.1-canary.626e45b

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.
@@ -0,0 +1 @@
1
+ export declare function buildCommand(): Promise<void>;
@@ -1,8 +1,16 @@
1
+ import type { PackageManager, PMCommands } from "../utils/package-manager";
1
2
  export interface InitOptions {
2
3
  projectName: string;
3
4
  git: boolean;
4
5
  installDeps: boolean;
5
6
  targetDirectory: string;
6
7
  templateDirectory: string;
8
+ databaseUrl?: string;
9
+ introspect?: boolean;
10
+ /** Detected package manager (pnpm or npm). */
11
+ pm: PackageManager;
12
+ /** Command helpers for the detected PM. */
13
+ pmCommands: PMCommands;
7
14
  }
8
15
  export declare function createRebaseApp(rawArgs: string[]): Promise<void>;
16
+ export declare function configureEnvFile(targetDirectory: string, databaseUrl?: string): void;
@@ -0,0 +1 @@
1
+ export declare function startCommand(): Promise<void>;
package/dist/index.cjs CHANGED
@@ -20,6 +20,45 @@
20
20
  return Object.freeze(n);
21
21
  }
22
22
  const os__namespace = /* @__PURE__ */ _interopNamespaceDefault(os);
23
+ function detectPackageManager(targetDir) {
24
+ const userAgent = process.env.npm_config_user_agent ?? "";
25
+ if (userAgent.startsWith("npm/")) return "npm";
26
+ if (userAgent.startsWith("pnpm/")) return "pnpm";
27
+ if (targetDir) {
28
+ if (fs.existsSync(path.join(targetDir, "package-lock.json"))) return "npm";
29
+ if (fs.existsSync(path.join(targetDir, "pnpm-lock.yaml"))) return "pnpm";
30
+ }
31
+ const cwd = process.cwd();
32
+ if (cwd !== targetDir) {
33
+ if (fs.existsSync(path.join(cwd, "package-lock.json"))) return "npm";
34
+ if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
35
+ }
36
+ return "pnpm";
37
+ }
38
+ function getPMCommands(pm) {
39
+ if (pm === "npm") {
40
+ return {
41
+ name: "npm",
42
+ install: ["npm", "install"],
43
+ run: (script) => ["npm", "run", script],
44
+ exec: (bin, args) => ["npx", bin, ...args],
45
+ view: (pkg, field) => ["npm", "view", pkg, field],
46
+ runAll: (script) => ["npm", "run", script, "--workspaces", "--if-present"],
47
+ runWorkspace: (workspace, script) => ["npm", "run", script, "-w", workspace],
48
+ workspaceProtocol: "*"
49
+ };
50
+ }
51
+ return {
52
+ name: "pnpm",
53
+ install: ["pnpm", "install"],
54
+ run: (script) => ["pnpm", "run", script],
55
+ exec: (bin, args) => ["pnpm", "exec", bin, ...args],
56
+ view: (pkg, field) => ["pnpm", "view", pkg, field],
57
+ runAll: (script) => ["pnpm", "-r", "run", script],
58
+ runWorkspace: (workspace, script) => ["pnpm", "--filter", workspace, script],
59
+ workspaceProtocol: "workspace:*"
60
+ };
61
+ }
23
62
  const access = util.promisify(fs.access);
24
63
  const copy = util.promisify(ncp);
25
64
  const __filename$2 = url.fileURLToPath(typeof document === "undefined" && typeof location === "undefined" ? require("url").pathToFileURL(__filename).href : typeof document === "undefined" ? location.href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href);
@@ -39,10 +78,11 @@
39
78
  console.log(`
40
79
  ${chalk.bold("Rebase")} — Create a new project šŸš€
41
80
  `);
42
- const options = await promptForOptions(rawArgs);
81
+ const pm = detectPackageManager();
82
+ const options = await promptForOptions(rawArgs, pm);
43
83
  await createProject(options);
44
84
  }
45
- async function promptForOptions(rawArgs) {
85
+ async function promptForOptions(rawArgs, pm) {
46
86
  const args = arg(
47
87
  {
48
88
  "--git": Boolean,
@@ -85,20 +125,38 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
85
125
  questions.push({
86
126
  type: "confirm",
87
127
  name: "installDeps",
88
- message: "Install dependencies with pnpm?",
128
+ message: `Install dependencies with ${pm}?`,
89
129
  default: true
90
130
  });
91
131
  }
132
+ questions.push({
133
+ type: "input",
134
+ name: "databaseUrl",
135
+ message: "Enter your PostgreSQL database connection string (leave blank to use a local default):",
136
+ default: ""
137
+ });
138
+ questions.push({
139
+ type: "confirm",
140
+ name: "introspect",
141
+ message: "Would you like to introspect this database to automatically generate collections?",
142
+ default: true,
143
+ when: (answers2) => !!answers2.databaseUrl?.trim()
144
+ });
92
145
  const answers = await inquirer.prompt(questions);
93
146
  const targetDirectory = path.resolve(process.cwd(), nameArg || answers.projectName);
94
147
  const projectName = path.basename(targetDirectory);
95
148
  const templateDirectory = path.resolve(cliRoot, "templates", "template");
149
+ const pmCommands = getPMCommands(pm);
96
150
  return {
97
151
  projectName,
98
152
  git: args["--git"] || answers.git || false,
99
153
  installDeps: args["--install"] || answers.installDeps || false,
100
154
  targetDirectory,
101
- templateDirectory
155
+ templateDirectory,
156
+ databaseUrl: answers.databaseUrl?.trim() || void 0,
157
+ introspect: answers.introspect || false,
158
+ pm,
159
+ pmCommands
102
160
  };
103
161
  }
104
162
  async function createProject(options) {
@@ -131,27 +189,7 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
131
189
  process.exit(1);
132
190
  }
133
191
  await replacePlaceholders(options);
134
- const envTemplatePath = path.join(options.targetDirectory, ".env.template");
135
- const envPath = path.join(options.targetDirectory, ".env");
136
- if (fs.existsSync(envTemplatePath) && !fs.existsSync(envPath)) {
137
- fs.renameSync(envTemplatePath, envPath);
138
- const jwtSecret = crypto.randomBytes(32).toString("hex");
139
- const dbPassword = crypto.randomBytes(16).toString("hex");
140
- let envContent = fs.readFileSync(envPath, "utf-8");
141
- envContent = envContent.replace(
142
- "postgresql://rebase:password@localhost:5432/rebase",
143
- `postgresql://rebase:${dbPassword}@localhost:5432/rebase`
144
- );
145
- envContent = envContent.replace(
146
- "change-this-to-a-secure-random-string",
147
- jwtSecret
148
- );
149
- envContent += `
150
- # Docker Compose Database Password
151
- POSTGRES_PASSWORD=${dbPassword}
152
- `;
153
- fs.writeFileSync(envPath, envContent, "utf-8");
154
- }
192
+ configureEnvFile(options.targetDirectory, options.databaseUrl);
155
193
  if (options.git) {
156
194
  console.log(chalk.gray(" Initializing git repository..."));
157
195
  try {
@@ -160,17 +198,40 @@ POSTGRES_PASSWORD=${dbPassword}
160
198
  console.warn(chalk.yellow(" Warning: Failed to initialize git repository"));
161
199
  }
162
200
  }
201
+ const { pm, pmCommands } = options;
202
+ const installCmd = pmCommands.install;
203
+ const execCmd = pmCommands.exec("rebase", ["schema", "introspect", "--force"]);
163
204
  if (options.installDeps) {
164
205
  console.log("");
165
- console.log(chalk.gray(" Installing dependencies with pnpm..."));
206
+ console.log(chalk.gray(` Installing dependencies with ${pm}...`));
166
207
  console.log("");
167
208
  try {
168
- await execa("pnpm", ["install"], {
209
+ await execa(installCmd[0], installCmd.slice(1), {
169
210
  cwd: options.targetDirectory,
170
211
  stdio: "inherit"
171
212
  });
172
213
  } catch {
173
- console.warn(chalk.yellow(" Warning: Failed to install dependencies. You may need to run `pnpm install` manually."));
214
+ console.warn(chalk.yellow(` Warning: Failed to install dependencies. You may need to run \`${installCmd.join(" ")}\` manually.`));
215
+ }
216
+ }
217
+ if (options.introspect) {
218
+ console.log("");
219
+ if (options.installDeps) {
220
+ console.log(chalk.gray(" Introspecting database and generating collections..."));
221
+ console.log("");
222
+ try {
223
+ await execa(execCmd[0], execCmd.slice(1), {
224
+ cwd: options.targetDirectory,
225
+ stdio: "inherit"
226
+ });
227
+ console.log(chalk.green(" Database successfully introspected!"));
228
+ } catch {
229
+ console.warn(chalk.yellow(" Warning: Failed to introspect database automatically."));
230
+ console.warn(chalk.yellow(` You can run \`${execCmd.join(" ")}\` manually after setup.`));
231
+ }
232
+ } else {
233
+ console.warn(chalk.yellow(" Skipping introspection because dependencies were not installed."));
234
+ console.warn(chalk.yellow(` Run \`${installCmd.join(" ")}\` then \`${execCmd.join(" ")}\` manually.`));
174
235
  }
175
236
  }
176
237
  console.log("");
@@ -178,15 +239,23 @@ POSTGRES_PASSWORD=${dbPassword}
178
239
  console.log("");
179
240
  console.log(chalk.bold("Next steps:"));
180
241
  console.log("");
242
+ const runDev = pmCommands.run("dev");
181
243
  console.log(` ${chalk.cyan("cd")} ${options.projectName}`);
182
244
  if (!options.installDeps) {
183
- console.log(` ${chalk.cyan("pnpm install")}`);
245
+ console.log(` ${chalk.cyan(installCmd.join(" "))}`);
184
246
  }
185
247
  console.log("");
186
- console.log(chalk.gray(" # Set up your database connection in .env"));
187
- console.log(chalk.gray(" # Then run:"));
248
+ if (options.databaseUrl) {
249
+ console.log(chalk.gray(" # Your database is configured! Start the dev server:"));
250
+ } else {
251
+ console.log(chalk.gray(" # A local database configuration has been generated in .env."));
252
+ console.log(chalk.gray(" # If using the included docker-compose.yml, start it with:"));
253
+ console.log(` ${chalk.cyan("docker compose up -d")}`);
254
+ console.log("");
255
+ console.log(chalk.gray(" # Then start the dev server:"));
256
+ }
188
257
  console.log("");
189
- console.log(` ${chalk.cyan("pnpm dev")}`);
258
+ console.log(` ${chalk.cyan(runDev.join(" "))}`);
190
259
  console.log("");
191
260
  console.log(chalk.gray("This starts both the backend (Hono + PostgreSQL)") + chalk.gray(" and the frontend (Vite + React) concurrently."));
192
261
  console.log("");
@@ -200,7 +269,8 @@ POSTGRES_PASSWORD=${dbPassword}
200
269
  "frontend/package.json",
201
270
  "backend/package.json",
202
271
  "config/package.json",
203
- "frontend/index.html"
272
+ "frontend/index.html",
273
+ "README.md"
204
274
  ];
205
275
  const packageJsonPath = path.resolve(cliRoot, "package.json");
206
276
  let cliVersion = "latest";
@@ -209,22 +279,23 @@ POSTGRES_PASSWORD=${dbPassword}
209
279
  cliVersion = pkg.version || "latest";
210
280
  }
211
281
  const versionCache = /* @__PURE__ */ new Map();
282
+ const viewBin = "npm";
212
283
  const getPackageVersion = async (pkgName) => {
213
284
  if (versionCache.has(pkgName)) return versionCache.get(pkgName);
214
285
  let versionToUse = cliVersion;
215
286
  try {
216
- const { stdout } = await execa("npm", ["--loglevel", "error", "info", `${pkgName}@${cliVersion}`, "version"]);
287
+ const { stdout } = await execa(viewBin, ["view", `${pkgName}@${cliVersion}`, "version"]);
217
288
  if (!stdout.trim()) throw new Error("Not found");
218
289
  versionToUse = stdout.trim();
219
290
  } catch {
220
291
  try {
221
292
  const tag = cliVersion.includes("canary") ? "canary" : "latest";
222
- const { stdout } = await execa("npm", ["--loglevel", "error", "info", `${pkgName}@${tag}`, "version"]);
293
+ const { stdout } = await execa(viewBin, ["view", `${pkgName}@${tag}`, "version"]);
223
294
  if (!stdout.trim()) throw new Error("Not found");
224
295
  versionToUse = stdout.trim();
225
296
  } catch {
226
297
  try {
227
- const { stdout } = await execa("npm", ["--loglevel", "error", "info", pkgName, "version"]);
298
+ const { stdout } = await execa(viewBin, ["view", pkgName, "version"]);
228
299
  versionToUse = stdout.trim() || "latest";
229
300
  } catch {
230
301
  versionToUse = "latest";
@@ -259,6 +330,32 @@ POSTGRES_PASSWORD=${dbPassword}
259
330
  fs.writeFileSync(fullPath, content, "utf-8");
260
331
  }
261
332
  }
333
+ function configureEnvFile(targetDirectory, databaseUrl) {
334
+ const envExamplePath = path.join(targetDirectory, ".env.example");
335
+ const envPath = path.join(targetDirectory, ".env");
336
+ if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
337
+ fs.copyFileSync(envExamplePath, envPath);
338
+ const jwtSecret = crypto.randomBytes(32).toString("hex");
339
+ const dbPassword = crypto.randomBytes(16).toString("hex");
340
+ let envContent = fs.readFileSync(envPath, "utf-8");
341
+ envContent = envContent.replace(
342
+ /^JWT_SECRET=.*$/m,
343
+ `JWT_SECRET=${jwtSecret}`
344
+ );
345
+ if (databaseUrl) {
346
+ envContent = envContent.replace(
347
+ /^DATABASE_URL=.*$/m,
348
+ `DATABASE_URL=${databaseUrl}`
349
+ );
350
+ } else {
351
+ envContent = envContent.replace(
352
+ /^DATABASE_URL=.*$/m,
353
+ `DATABASE_URL=postgresql://rebase:${dbPassword}@localhost:5432/rebase`
354
+ );
355
+ }
356
+ fs.writeFileSync(envPath, envContent, "utf-8");
357
+ }
358
+ }
262
359
  async function loadCollections(collectionsDir) {
263
360
  const absDir = path.resolve(collectionsDir);
264
361
  if (!fs.existsSync(absDir)) {
@@ -429,6 +526,7 @@ Expected a default export of EntityCollection[] or an object with named collecti
429
526
  path.join(backendDir, "node_modules", pluginName, "src", "cli.ts"),
430
527
  path.join(backendDir, "node_modules", pluginName, "dist", "cli.js"),
431
528
  // For monorepo dev mode:
529
+ path.resolve(backendDir, "..", "..", "..", "packages", pluginName.replace("@rebasepro/", ""), "src", "cli.ts"),
432
530
  path.resolve(backendDir, "..", "..", "packages", pluginName.replace("@rebasepro/", ""), "src", "cli.ts"),
433
531
  path.resolve(backendDir, "..", "packages", pluginName.replace("@rebasepro/", ""), "src", "cli.ts")
434
532
  ];
@@ -551,11 +649,15 @@ ${chalk.green.bold("Usage")}
551
649
  ${chalk.green.bold("Commands")}
552
650
  ${chalk.gray("(Commands are provided by your active database driver plugin)")}
553
651
  ${chalk.blue.bold("generate")} Generate Schema from collection definitions
652
+ ${chalk.blue.bold("introspect")} Introspect an existing database to generate collection definitions
554
653
 
555
654
  ${chalk.green.bold("generate Options")}
556
655
  ${chalk.blue("--collections, -c")} Path to collections directory
557
656
  ${chalk.blue("--output, -o")} Output path for generated schema
558
657
  ${chalk.blue("--watch, -w")} Watch for changes and regenerate automatically
658
+
659
+ ${chalk.green.bold("introspect Options")}
660
+ ${chalk.blue("--output, -o")} Output directory for generated collection files
559
661
  `);
560
662
  }
561
663
  async function dbCommand(subcommand, rawArgs) {
@@ -615,7 +717,6 @@ ${chalk.green.bold("Usage")}
615
717
  ${chalk.green.bold("Commands")}
616
718
  ${chalk.gray("(Commands are provided by your active database driver plugin)")}
617
719
  ${chalk.blue.bold("push")} Apply schema directly to database (development)
618
- ${chalk.blue.bold("pull")} Introspect database → Schema
619
720
  ${chalk.blue.bold("generate")} Generate migration files
620
721
  ${chalk.blue.bold("migrate")} Run pending migrations
621
722
  ${chalk.blue.bold("studio")} Open Studio viewer
@@ -746,9 +847,12 @@ ${chalk.green.bold("Examples")}
746
847
  frontendEnv.VITE_API_URL = `http://localhost:${backendPort}`;
747
848
  console.log(` ${chalk.gray("↳ VITE_API_URL")} = ${chalk.white(`http://localhost:${backendPort}`)}`);
748
849
  }
850
+ const pm = detectPackageManager(projectRoot);
851
+ const pmCmds = getPMCommands(pm);
852
+ const runDevCmd = pmCmds.run("dev");
749
853
  const frontendChild = execa(
750
- "pnpm",
751
- ["run", "dev"],
854
+ runDevCmd[0],
855
+ runDevCmd.slice(1),
752
856
  {
753
857
  cwd: frontendDir,
754
858
  stdio: ["inherit", "pipe", "pipe"],
@@ -782,8 +886,10 @@ ${chalk.green.bold("Examples")}
782
886
  if (!frontendOnly && backendDir) {
783
887
  const tsxBin = resolveTsx(projectRoot);
784
888
  if (!tsxBin) {
889
+ const pmName = detectPackageManager(projectRoot);
890
+ const addCmd = pmName === "npm" ? "npm install -D tsx" : "pnpm add -D tsx";
785
891
  console.error(chalk.red(" āœ— Could not find tsx binary for backend."));
786
- console.error(chalk.gray(" Install it with: pnpm add -D tsx"));
892
+ console.error(chalk.gray(` Install it with: ${addCmd}`));
787
893
  process.exit(1);
788
894
  }
789
895
  const envFile = findEnvFile(projectRoot);
@@ -884,6 +990,46 @@ ${chalk.green.bold("Description")}
884
990
  backend is ready, and VITE_API_URL is injected automatically.
885
991
  `);
886
992
  }
993
+ async function buildCommand() {
994
+ const projectRoot = requireProjectRoot();
995
+ const pm = detectPackageManager(projectRoot);
996
+ const cmds = getPMCommands(pm);
997
+ const buildCmd = cmds.runAll("build");
998
+ console.log(`${chalk.bold("Rebase")} — Building all workspaces with ${chalk.cyan(pm)}...
999
+ `);
1000
+ try {
1001
+ await execa(buildCmd[0], buildCmd.slice(1), {
1002
+ cwd: projectRoot,
1003
+ stdio: "inherit"
1004
+ });
1005
+ } catch {
1006
+ console.error(chalk.red("\nāœ— Build failed."));
1007
+ process.exit(1);
1008
+ }
1009
+ }
1010
+ async function startCommand() {
1011
+ const projectRoot = requireProjectRoot();
1012
+ const pm = detectPackageManager(projectRoot);
1013
+ const cmds = getPMCommands(pm);
1014
+ const startCmd = cmds.runWorkspace("backend", "start");
1015
+ const envFile = findEnvFile(projectRoot);
1016
+ const env = { ...process.env };
1017
+ if (envFile) {
1018
+ env.DOTENV_CONFIG_PATH = envFile;
1019
+ }
1020
+ console.log(`${chalk.bold("Rebase")} — Starting backend server...
1021
+ `);
1022
+ try {
1023
+ await execa(startCmd[0], startCmd.slice(1), {
1024
+ cwd: projectRoot,
1025
+ stdio: "inherit",
1026
+ env
1027
+ });
1028
+ } catch {
1029
+ console.error(chalk.red("\nāœ— Failed to start server."));
1030
+ process.exit(1);
1031
+ }
1032
+ }
887
1033
  async function authCommand(subcommand, rawArgs) {
888
1034
  if (!subcommand || subcommand === "--help") {
889
1035
  printAuthHelp();
@@ -1092,7 +1238,7 @@ ${chalk.green.bold("Examples")}
1092
1238
  }
1093
1239
  const command = parsedArgs._[0];
1094
1240
  const subcommand = parsedArgs._[1];
1095
- const namespacedCommands = ["schema", "db", "dev", "auth", "doctor"];
1241
+ const namespacedCommands = ["schema", "db", "dev", "build", "start", "auth", "doctor"];
1096
1242
  if (!command || parsedArgs["--help"] && !namespacedCommands.includes(command)) {
1097
1243
  printHelp();
1098
1244
  return;
@@ -1131,6 +1277,12 @@ ${chalk.green.bold("Examples")}
1131
1277
  case "dev":
1132
1278
  await devCommand(args);
1133
1279
  break;
1280
+ case "build":
1281
+ await buildCommand();
1282
+ break;
1283
+ case "start":
1284
+ await startCommand();
1285
+ break;
1134
1286
  case "auth":
1135
1287
  await authCommand(effectiveSubcommand, args);
1136
1288
  break;
@@ -1153,14 +1305,16 @@ ${chalk.green.bold("Usage")}
1153
1305
  ${chalk.green.bold("Commands")}
1154
1306
  ${chalk.blue.bold("init")} Create a new Rebase project
1155
1307
  ${chalk.blue.bold("dev")} Start the development server
1308
+ ${chalk.blue.bold("build")} Build all workspace packages
1309
+ ${chalk.blue.bold("start")} Start the backend server ${chalk.gray("(production)")}
1156
1310
 
1157
1311
  ${chalk.green.bold("Schema")}
1158
1312
  ${chalk.blue.bold("schema generate")} Generate Drizzle schema from collections
1313
+ ${chalk.blue.bold("schema introspect")} Introspect database → Rebase collections
1159
1314
  ${chalk.blue.bold("schema")} ${chalk.gray("--help")} Show schema command help
1160
1315
 
1161
1316
  ${chalk.green.bold("Database")}
1162
1317
  ${chalk.blue.bold("db push")} Apply schema directly to database ${chalk.gray("(dev)")}
1163
- ${chalk.blue.bold("db pull")} Introspect database → Drizzle schema
1164
1318
  ${chalk.blue.bold("db generate")} Generate SQL migration files
1165
1319
  ${chalk.blue.bold("db migrate")} Run pending migrations
1166
1320
  ${chalk.blue.bold("db studio")} Open Drizzle Studio
@@ -1227,6 +1381,8 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
1227
1381
  }
1228
1382
  }
1229
1383
  exports2.authCommand = authCommand;
1384
+ exports2.buildCommand = buildCommand;
1385
+ exports2.configureEnvFile = configureEnvFile;
1230
1386
  exports2.createRebaseApp = createRebaseApp;
1231
1387
  exports2.dbCommand = dbCommand;
1232
1388
  exports2.devCommand = devCommand;
@@ -1247,6 +1403,7 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
1247
1403
  exports2.resolvePluginCliScript = resolvePluginCliScript;
1248
1404
  exports2.resolveTsx = resolveTsx;
1249
1405
  exports2.schemaCommand = schemaCommand;
1406
+ exports2.startCommand = startCommand;
1250
1407
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
1251
1408
  }));
1252
1409
  //# sourceMappingURL=index.cjs.map