@rebasepro/cli 0.0.1-canary.892f711 ā 0.0.1-canary.a6becfb
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/commands/build.d.ts +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/start.d.ts +1 -0
- package/dist/index.cjs +137 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +138 -29
- package/dist/index.es.js.map +1 -1
- package/dist/utils/package-manager.d.ts +31 -0
- package/dist/utils/package-manager.test.d.ts +1 -0
- package/package.json +4 -4
- package/templates/template/README.md +3 -3
- package/templates/template/backend/package.json +1 -1
- package/templates/template/docker-compose.yml +1 -1
- package/templates/template/frontend/package.json +1 -1
- package/templates/template/package.json +9 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildCommand(): Promise<void>;
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -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
|
|
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:
|
|
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(
|
|
206
|
+
console.log(chalk.gray(` Installing dependencies with ${pm}...`));
|
|
161
207
|
console.log("");
|
|
162
208
|
try {
|
|
163
|
-
await execa(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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("
|
|
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("
|
|
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(
|
|
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(
|
|
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(
|
|
298
|
+
const { stdout } = await execa(viewBin, ["view", pkgName, "version"]);
|
|
250
299
|
versionToUse = stdout.trim() || "latest";
|
|
251
300
|
} catch {
|
|
252
301
|
versionToUse = "latest";
|
|
@@ -459,15 +508,20 @@ Expected a default export of EntityCollection[] or an object with named collecti
|
|
|
459
508
|
if (!fs.existsSync(pkgPath)) return null;
|
|
460
509
|
try {
|
|
461
510
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
462
|
-
const deps = {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
511
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
512
|
+
const candidates = Object.keys(deps).filter(
|
|
513
|
+
(dep) => dep.startsWith("@rebasepro/server-") && dep !== "@rebasepro/server-core"
|
|
514
|
+
);
|
|
515
|
+
if (candidates.length === 0) return null;
|
|
516
|
+
if (candidates.includes("@rebasepro/server-postgresql")) {
|
|
517
|
+
return "@rebasepro/server-postgresql";
|
|
518
|
+
}
|
|
519
|
+
for (const candidate of candidates) {
|
|
520
|
+
if (resolvePluginCliScript(backendDir, candidate)) {
|
|
521
|
+
return candidate;
|
|
469
522
|
}
|
|
470
523
|
}
|
|
524
|
+
return candidates[0];
|
|
471
525
|
} catch {
|
|
472
526
|
}
|
|
473
527
|
return null;
|
|
@@ -798,9 +852,12 @@ ${chalk.green.bold("Examples")}
|
|
|
798
852
|
frontendEnv.VITE_API_URL = `http://localhost:${backendPort}`;
|
|
799
853
|
console.log(` ${chalk.gray("ā³ VITE_API_URL")} = ${chalk.white(`http://localhost:${backendPort}`)}`);
|
|
800
854
|
}
|
|
855
|
+
const pm = detectPackageManager(projectRoot);
|
|
856
|
+
const pmCmds = getPMCommands(pm);
|
|
857
|
+
const runDevCmd = pmCmds.run("dev");
|
|
801
858
|
const frontendChild = execa(
|
|
802
|
-
|
|
803
|
-
|
|
859
|
+
runDevCmd[0],
|
|
860
|
+
runDevCmd.slice(1),
|
|
804
861
|
{
|
|
805
862
|
cwd: frontendDir,
|
|
806
863
|
stdio: ["inherit", "pipe", "pipe"],
|
|
@@ -834,8 +891,10 @@ ${chalk.green.bold("Examples")}
|
|
|
834
891
|
if (!frontendOnly && backendDir) {
|
|
835
892
|
const tsxBin = resolveTsx(projectRoot);
|
|
836
893
|
if (!tsxBin) {
|
|
894
|
+
const pmName = detectPackageManager(projectRoot);
|
|
895
|
+
const addCmd = pmName === "npm" ? "npm install -D tsx" : "pnpm add -D tsx";
|
|
837
896
|
console.error(chalk.red(" ā Could not find tsx binary for backend."));
|
|
838
|
-
console.error(chalk.gray(
|
|
897
|
+
console.error(chalk.gray(` Install it with: ${addCmd}`));
|
|
839
898
|
process.exit(1);
|
|
840
899
|
}
|
|
841
900
|
const envFile = findEnvFile(projectRoot);
|
|
@@ -936,6 +995,46 @@ ${chalk.green.bold("Description")}
|
|
|
936
995
|
backend is ready, and VITE_API_URL is injected automatically.
|
|
937
996
|
`);
|
|
938
997
|
}
|
|
998
|
+
async function buildCommand() {
|
|
999
|
+
const projectRoot = requireProjectRoot();
|
|
1000
|
+
const pm = detectPackageManager(projectRoot);
|
|
1001
|
+
const cmds = getPMCommands(pm);
|
|
1002
|
+
const buildCmd = cmds.runAll("build");
|
|
1003
|
+
console.log(`${chalk.bold("Rebase")} ā Building all workspaces with ${chalk.cyan(pm)}...
|
|
1004
|
+
`);
|
|
1005
|
+
try {
|
|
1006
|
+
await execa(buildCmd[0], buildCmd.slice(1), {
|
|
1007
|
+
cwd: projectRoot,
|
|
1008
|
+
stdio: "inherit"
|
|
1009
|
+
});
|
|
1010
|
+
} catch {
|
|
1011
|
+
console.error(chalk.red("\nā Build failed."));
|
|
1012
|
+
process.exit(1);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
async function startCommand() {
|
|
1016
|
+
const projectRoot = requireProjectRoot();
|
|
1017
|
+
const pm = detectPackageManager(projectRoot);
|
|
1018
|
+
const cmds = getPMCommands(pm);
|
|
1019
|
+
const startCmd = cmds.runWorkspace("backend", "start");
|
|
1020
|
+
const envFile = findEnvFile(projectRoot);
|
|
1021
|
+
const env = { ...process.env };
|
|
1022
|
+
if (envFile) {
|
|
1023
|
+
env.DOTENV_CONFIG_PATH = envFile;
|
|
1024
|
+
}
|
|
1025
|
+
console.log(`${chalk.bold("Rebase")} ā Starting backend server...
|
|
1026
|
+
`);
|
|
1027
|
+
try {
|
|
1028
|
+
await execa(startCmd[0], startCmd.slice(1), {
|
|
1029
|
+
cwd: projectRoot,
|
|
1030
|
+
stdio: "inherit",
|
|
1031
|
+
env
|
|
1032
|
+
});
|
|
1033
|
+
} catch {
|
|
1034
|
+
console.error(chalk.red("\nā Failed to start server."));
|
|
1035
|
+
process.exit(1);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
939
1038
|
async function authCommand(subcommand, rawArgs) {
|
|
940
1039
|
if (!subcommand || subcommand === "--help") {
|
|
941
1040
|
printAuthHelp();
|
|
@@ -1144,7 +1243,7 @@ ${chalk.green.bold("Examples")}
|
|
|
1144
1243
|
}
|
|
1145
1244
|
const command = parsedArgs._[0];
|
|
1146
1245
|
const subcommand = parsedArgs._[1];
|
|
1147
|
-
const namespacedCommands = ["schema", "db", "dev", "auth", "doctor"];
|
|
1246
|
+
const namespacedCommands = ["schema", "db", "dev", "build", "start", "auth", "doctor"];
|
|
1148
1247
|
if (!command || parsedArgs["--help"] && !namespacedCommands.includes(command)) {
|
|
1149
1248
|
printHelp();
|
|
1150
1249
|
return;
|
|
@@ -1183,6 +1282,12 @@ ${chalk.green.bold("Examples")}
|
|
|
1183
1282
|
case "dev":
|
|
1184
1283
|
await devCommand(args);
|
|
1185
1284
|
break;
|
|
1285
|
+
case "build":
|
|
1286
|
+
await buildCommand();
|
|
1287
|
+
break;
|
|
1288
|
+
case "start":
|
|
1289
|
+
await startCommand();
|
|
1290
|
+
break;
|
|
1186
1291
|
case "auth":
|
|
1187
1292
|
await authCommand(effectiveSubcommand, args);
|
|
1188
1293
|
break;
|
|
@@ -1205,14 +1310,16 @@ ${chalk.green.bold("Usage")}
|
|
|
1205
1310
|
${chalk.green.bold("Commands")}
|
|
1206
1311
|
${chalk.blue.bold("init")} Create a new Rebase project
|
|
1207
1312
|
${chalk.blue.bold("dev")} Start the development server
|
|
1313
|
+
${chalk.blue.bold("build")} Build all workspace packages
|
|
1314
|
+
${chalk.blue.bold("start")} Start the backend server ${chalk.gray("(production)")}
|
|
1208
1315
|
|
|
1209
1316
|
${chalk.green.bold("Schema")}
|
|
1210
1317
|
${chalk.blue.bold("schema generate")} Generate Drizzle schema from collections
|
|
1318
|
+
${chalk.blue.bold("schema introspect")} Introspect database ā Rebase collections
|
|
1211
1319
|
${chalk.blue.bold("schema")} ${chalk.gray("--help")} Show schema command help
|
|
1212
1320
|
|
|
1213
1321
|
${chalk.green.bold("Database")}
|
|
1214
1322
|
${chalk.blue.bold("db push")} Apply schema directly to database ${chalk.gray("(dev)")}
|
|
1215
|
-
${chalk.blue.bold("db pull")} Introspect database ā Drizzle schema
|
|
1216
1323
|
${chalk.blue.bold("db generate")} Generate SQL migration files
|
|
1217
1324
|
${chalk.blue.bold("db migrate")} Run pending migrations
|
|
1218
1325
|
${chalk.blue.bold("db studio")} Open Drizzle Studio
|
|
@@ -1279,6 +1386,7 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
|
|
|
1279
1386
|
}
|
|
1280
1387
|
}
|
|
1281
1388
|
exports2.authCommand = authCommand;
|
|
1389
|
+
exports2.buildCommand = buildCommand;
|
|
1282
1390
|
exports2.configureEnvFile = configureEnvFile;
|
|
1283
1391
|
exports2.createRebaseApp = createRebaseApp;
|
|
1284
1392
|
exports2.dbCommand = dbCommand;
|
|
@@ -1300,6 +1408,7 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
|
|
|
1300
1408
|
exports2.resolvePluginCliScript = resolvePluginCliScript;
|
|
1301
1409
|
exports2.resolveTsx = resolveTsx;
|
|
1302
1410
|
exports2.schemaCommand = schemaCommand;
|
|
1411
|
+
exports2.startCommand = startCommand;
|
|
1303
1412
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
1304
1413
|
}));
|
|
1305
1414
|
//# sourceMappingURL=index.cjs.map
|