@rebasepro/cli 0.0.1-canary.f81da60 → 0.1.2

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,3 +1,4 @@
1
+ import type { PackageManager, PMCommands } from "../utils/package-manager";
1
2
  export interface InitOptions {
2
3
  projectName: string;
3
4
  git: boolean;
@@ -6,6 +7,10 @@ export interface InitOptions {
6
7
  templateDirectory: string;
7
8
  databaseUrl?: string;
8
9
  introspect?: boolean;
10
+ /** Detected package manager (pnpm or npm). */
11
+ pm: PackageManager;
12
+ /** Command helpers for the detected PM. */
13
+ pmCommands: PMCommands;
9
14
  }
10
15
  export declare function createRebaseApp(rawArgs: string[]): Promise<void>;
11
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,7 +125,7 @@ ${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
  }
@@ -106,6 +146,7 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
106
146
  const targetDirectory = path.resolve(process.cwd(), nameArg || answers.projectName);
107
147
  const projectName = path.basename(targetDirectory);
108
148
  const templateDirectory = path.resolve(cliRoot, "templates", "template");
149
+ const pmCommands = getPMCommands(pm);
109
150
  return {
110
151
  projectName,
111
152
  git: args["--git"] || answers.git || false,
@@ -113,7 +154,9 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
113
154
  targetDirectory,
114
155
  templateDirectory,
115
156
  databaseUrl: answers.databaseUrl?.trim() || void 0,
116
- introspect: answers.introspect || false
157
+ introspect: answers.introspect || false,
158
+ pm,
159
+ pmCommands
117
160
  };
118
161
  }
119
162
  async function createProject(options) {
@@ -155,17 +198,20 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
155
198
  console.warn(chalk.yellow(" Warning: Failed to initialize git repository"));
156
199
  }
157
200
  }
201
+ const { pm, pmCommands } = options;
202
+ const installCmd = pmCommands.install;
203
+ const execCmd = pmCommands.exec("rebase", ["schema", "introspect", "--force"]);
158
204
  if (options.installDeps) {
159
205
  console.log("");
160
- console.log(chalk.gray(" Installing dependencies with pnpm..."));
206
+ console.log(chalk.gray(` Installing dependencies with ${pm}...`));
161
207
  console.log("");
162
208
  try {
163
- await execa("pnpm", ["install"], {
209
+ await execa(installCmd[0], installCmd.slice(1), {
164
210
  cwd: options.targetDirectory,
165
211
  stdio: "inherit"
166
212
  });
167
213
  } catch {
168
- 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.`));
169
215
  }
170
216
  }
171
217
  if (options.introspect) {
@@ -174,18 +220,18 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
174
220
  console.log(chalk.gray(" Introspecting database and generating collections..."));
175
221
  console.log("");
176
222
  try {
177
- await execa("pnpm", ["exec", "rebase", "schema", "introspect", "--force"], {
223
+ await execa(execCmd[0], execCmd.slice(1), {
178
224
  cwd: options.targetDirectory,
179
225
  stdio: "inherit"
180
226
  });
181
227
  console.log(chalk.green(" Database successfully introspected!"));
182
228
  } catch {
183
229
  console.warn(chalk.yellow(" Warning: Failed to introspect database automatically."));
184
- console.warn(chalk.yellow(" You can run `pnpm exec rebase schema introspect` manually after setup."));
230
+ console.warn(chalk.yellow(` You can run \`${execCmd.join(" ")}\` manually after setup.`));
185
231
  }
186
232
  } else {
187
233
  console.warn(chalk.yellow(" Skipping introspection because dependencies were not installed."));
188
- console.warn(chalk.yellow(" Run `pnpm install` then `pnpm exec rebase schema introspect` manually."));
234
+ console.warn(chalk.yellow(` Run \`${installCmd.join(" ")}\` then \`${execCmd.join(" ")}\` manually.`));
189
235
  }
190
236
  }
191
237
  console.log("");
@@ -193,9 +239,10 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
193
239
  console.log("");
194
240
  console.log(chalk.bold("Next steps:"));
195
241
  console.log("");
242
+ const runDev = pmCommands.run("dev");
196
243
  console.log(` ${chalk.cyan("cd")} ${options.projectName}`);
197
244
  if (!options.installDeps) {
198
- console.log(` ${chalk.cyan("pnpm install")}`);
245
+ console.log(` ${chalk.cyan(installCmd.join(" "))}`);
199
246
  }
200
247
  console.log("");
201
248
  if (options.databaseUrl) {
@@ -208,7 +255,7 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
208
255
  console.log(chalk.gray(" # Then start the dev server:"));
209
256
  }
210
257
  console.log("");
211
- console.log(` ${chalk.cyan("pnpm dev")}`);
258
+ console.log(` ${chalk.cyan(runDev.join(" "))}`);
212
259
  console.log("");
213
260
  console.log(chalk.gray("This starts both the backend (Hono + PostgreSQL)") + chalk.gray(" and the frontend (Vite + React) concurrently."));
214
261
  console.log("");
@@ -222,7 +269,8 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
222
269
  "frontend/package.json",
223
270
  "backend/package.json",
224
271
  "config/package.json",
225
- "frontend/index.html"
272
+ "frontend/index.html",
273
+ "README.md"
226
274
  ];
227
275
  const packageJsonPath = path.resolve(cliRoot, "package.json");
228
276
  let cliVersion = "latest";
@@ -231,22 +279,23 @@ ${chalk.bold("Rebase")} — Create a new project šŸš€
231
279
  cliVersion = pkg.version || "latest";
232
280
  }
233
281
  const versionCache = /* @__PURE__ */ new Map();
282
+ const viewBin = "npm";
234
283
  const getPackageVersion = async (pkgName) => {
235
284
  if (versionCache.has(pkgName)) return versionCache.get(pkgName);
236
285
  let versionToUse = cliVersion;
237
286
  try {
238
- const { stdout } = await execa("pnpm", ["view", `${pkgName}@${cliVersion}`, "version"]);
287
+ const { stdout } = await execa(viewBin, ["view", `${pkgName}@${cliVersion}`, "version"]);
239
288
  if (!stdout.trim()) throw new Error("Not found");
240
289
  versionToUse = stdout.trim();
241
290
  } catch {
242
291
  try {
243
292
  const tag = cliVersion.includes("canary") ? "canary" : "latest";
244
- const { stdout } = await execa("pnpm", ["view", `${pkgName}@${tag}`, "version"]);
293
+ const { stdout } = await execa(viewBin, ["view", `${pkgName}@${tag}`, "version"]);
245
294
  if (!stdout.trim()) throw new Error("Not found");
246
295
  versionToUse = stdout.trim();
247
296
  } catch {
248
297
  try {
249
- const { stdout } = await execa("pnpm", ["view", pkgName, "version"]);
298
+ const { stdout } = await execa(viewBin, ["view", pkgName, "version"]);
250
299
  versionToUse = stdout.trim() || "latest";
251
300
  } catch {
252
301
  versionToUse = "latest";
@@ -668,7 +717,6 @@ ${chalk.green.bold("Usage")}
668
717
  ${chalk.green.bold("Commands")}
669
718
  ${chalk.gray("(Commands are provided by your active database driver plugin)")}
670
719
  ${chalk.blue.bold("push")} Apply schema directly to database (development)
671
- ${chalk.blue.bold("pull")} Introspect database → Schema
672
720
  ${chalk.blue.bold("generate")} Generate migration files
673
721
  ${chalk.blue.bold("migrate")} Run pending migrations
674
722
  ${chalk.blue.bold("studio")} Open Studio viewer
@@ -799,9 +847,12 @@ ${chalk.green.bold("Examples")}
799
847
  frontendEnv.VITE_API_URL = `http://localhost:${backendPort}`;
800
848
  console.log(` ${chalk.gray("↳ VITE_API_URL")} = ${chalk.white(`http://localhost:${backendPort}`)}`);
801
849
  }
850
+ const pm = detectPackageManager(projectRoot);
851
+ const pmCmds = getPMCommands(pm);
852
+ const runDevCmd = pmCmds.run("dev");
802
853
  const frontendChild = execa(
803
- "pnpm",
804
- ["run", "dev"],
854
+ runDevCmd[0],
855
+ runDevCmd.slice(1),
805
856
  {
806
857
  cwd: frontendDir,
807
858
  stdio: ["inherit", "pipe", "pipe"],
@@ -835,8 +886,10 @@ ${chalk.green.bold("Examples")}
835
886
  if (!frontendOnly && backendDir) {
836
887
  const tsxBin = resolveTsx(projectRoot);
837
888
  if (!tsxBin) {
889
+ const pmName = detectPackageManager(projectRoot);
890
+ const addCmd = pmName === "npm" ? "npm install -D tsx" : "pnpm add -D tsx";
838
891
  console.error(chalk.red(" āœ— Could not find tsx binary for backend."));
839
- console.error(chalk.gray(" Install it with: pnpm add -D tsx"));
892
+ console.error(chalk.gray(` Install it with: ${addCmd}`));
840
893
  process.exit(1);
841
894
  }
842
895
  const envFile = findEnvFile(projectRoot);
@@ -937,6 +990,46 @@ ${chalk.green.bold("Description")}
937
990
  backend is ready, and VITE_API_URL is injected automatically.
938
991
  `);
939
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
+ }
940
1033
  async function authCommand(subcommand, rawArgs) {
941
1034
  if (!subcommand || subcommand === "--help") {
942
1035
  printAuthHelp();
@@ -1145,7 +1238,7 @@ ${chalk.green.bold("Examples")}
1145
1238
  }
1146
1239
  const command = parsedArgs._[0];
1147
1240
  const subcommand = parsedArgs._[1];
1148
- const namespacedCommands = ["schema", "db", "dev", "auth", "doctor"];
1241
+ const namespacedCommands = ["schema", "db", "dev", "build", "start", "auth", "doctor"];
1149
1242
  if (!command || parsedArgs["--help"] && !namespacedCommands.includes(command)) {
1150
1243
  printHelp();
1151
1244
  return;
@@ -1184,6 +1277,12 @@ ${chalk.green.bold("Examples")}
1184
1277
  case "dev":
1185
1278
  await devCommand(args);
1186
1279
  break;
1280
+ case "build":
1281
+ await buildCommand();
1282
+ break;
1283
+ case "start":
1284
+ await startCommand();
1285
+ break;
1187
1286
  case "auth":
1188
1287
  await authCommand(effectiveSubcommand, args);
1189
1288
  break;
@@ -1206,14 +1305,16 @@ ${chalk.green.bold("Usage")}
1206
1305
  ${chalk.green.bold("Commands")}
1207
1306
  ${chalk.blue.bold("init")} Create a new Rebase project
1208
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)")}
1209
1310
 
1210
1311
  ${chalk.green.bold("Schema")}
1211
1312
  ${chalk.blue.bold("schema generate")} Generate Drizzle schema from collections
1313
+ ${chalk.blue.bold("schema introspect")} Introspect database → Rebase collections
1212
1314
  ${chalk.blue.bold("schema")} ${chalk.gray("--help")} Show schema command help
1213
1315
 
1214
1316
  ${chalk.green.bold("Database")}
1215
1317
  ${chalk.blue.bold("db push")} Apply schema directly to database ${chalk.gray("(dev)")}
1216
- ${chalk.blue.bold("db pull")} Introspect database → Drizzle schema
1217
1318
  ${chalk.blue.bold("db generate")} Generate SQL migration files
1218
1319
  ${chalk.blue.bold("db migrate")} Run pending migrations
1219
1320
  ${chalk.blue.bold("db studio")} Open Drizzle Studio
@@ -1280,6 +1381,7 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
1280
1381
  }
1281
1382
  }
1282
1383
  exports2.authCommand = authCommand;
1384
+ exports2.buildCommand = buildCommand;
1283
1385
  exports2.configureEnvFile = configureEnvFile;
1284
1386
  exports2.createRebaseApp = createRebaseApp;
1285
1387
  exports2.dbCommand = dbCommand;
@@ -1301,6 +1403,7 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
1301
1403
  exports2.resolvePluginCliScript = resolvePluginCliScript;
1302
1404
  exports2.resolveTsx = resolveTsx;
1303
1405
  exports2.schemaCommand = schemaCommand;
1406
+ exports2.startCommand = startCommand;
1304
1407
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
1305
1408
  }));
1306
1409
  //# sourceMappingURL=index.cjs.map