@rebasepro/cli 0.2.1 → 0.2.3

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.
@@ -13,4 +13,4 @@ export interface InitOptions {
13
13
  pmCommands: PMCommands;
14
14
  }
15
15
  export declare function createRebaseApp(rawArgs: string[]): Promise<void>;
16
- export declare function configureEnvFile(targetDirectory: string, databaseUrl?: string): void;
16
+ export declare function configureEnvFile(targetDirectory: string, databaseUrl?: string): Promise<void>;
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("chalk"), require("arg"), require("inquirer"), require("path"), require("fs"), require("util"), require("execa"), require("fs/promises"), require("url"), require("crypto"), require("@rebasepro/sdk-generator"), require("child_process"), require("os")) : typeof define === "function" && define.amd ? define(["exports", "chalk", "arg", "inquirer", "path", "fs", "util", "execa", "fs/promises", "url", "crypto", "@rebasepro/sdk-generator", "child_process", "os"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase CLI"] = {}, global.chalk, global.arg, global.inquirer, global.path, global.fs, global.util, global.execa, global.promises, global.url, global.crypto, global.sdkGenerator, global.child_process, global.os));
3
- })(this, (function(exports2, chalk, arg, inquirer, path, fs, util, execa, promises, url, crypto, sdkGenerator, child_process, os) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("chalk"), require("arg"), require("inquirer"), require("path"), require("fs"), require("net"), require("util"), require("execa"), require("fs/promises"), require("url"), require("crypto"), require("@rebasepro/sdk-generator"), require("child_process"), require("os")) : typeof define === "function" && define.amd ? define(["exports", "chalk", "arg", "inquirer", "path", "fs", "net", "util", "execa", "fs/promises", "url", "crypto", "@rebasepro/sdk-generator", "child_process", "os"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase CLI"] = {}, global.chalk, global.arg, global.inquirer, global.path, global.fs, global.net, global.util, global.execa, global.promises, global.url, global.crypto, global.sdkGenerator, global.child_process, global.os));
3
+ })(this, (function(exports2, chalk, arg, inquirer, path, fs, net, util, execa, promises, url, crypto, sdkGenerator, child_process, os) {
4
4
  "use strict";
5
5
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
6
6
  function _interopNamespaceDefault(e) {
@@ -209,7 +209,7 @@ ${chalk.bold("Rebase")} — Create a new project 🚀
209
209
  process.exit(1);
210
210
  }
211
211
  await replacePlaceholders(options);
212
- configureEnvFile(options.targetDirectory, options.databaseUrl);
212
+ await configureEnvFile(options.targetDirectory, options.databaseUrl);
213
213
  if (options.git) {
214
214
  console.log(chalk.gray(" Initializing git repository..."));
215
215
  try {
@@ -269,8 +269,8 @@ ${chalk.bold("Rebase")} — Create a new project 🚀
269
269
  console.log(chalk.gray(" # Your database is configured! Start the dev server:"));
270
270
  } else {
271
271
  console.log(chalk.gray(" # A local database configuration has been generated in .env."));
272
- console.log(chalk.gray(" # If using the included docker-compose.yml, start it with:"));
273
- console.log(` ${chalk.cyan("docker compose up -d")}`);
272
+ console.log(chalk.gray(" # If using the included docker-compose.yml, start the database with:"));
273
+ console.log(` ${chalk.cyan("docker compose up -d db")}`);
274
274
  console.log("");
275
275
  console.log(chalk.gray(" # Then start the dev server:"));
276
276
  }
@@ -290,6 +290,7 @@ ${chalk.bold("Rebase")} — Create a new project 🚀
290
290
  "backend/package.json",
291
291
  "config/package.json",
292
292
  "frontend/index.html",
293
+ "pnpm-workspace.yaml",
293
294
  "README.md"
294
295
  ];
295
296
  const packageJsonPath = path.resolve(cliRoot, "package.json");
@@ -354,7 +355,26 @@ ${chalk.bold("Rebase")} — Create a new project 🚀
354
355
  fs.writeFileSync(fullPath, content, "utf-8");
355
356
  }
356
357
  }
357
- function configureEnvFile(targetDirectory, databaseUrl) {
358
+ async function isPortAvailable(port) {
359
+ return new Promise((resolve) => {
360
+ const server = net.createServer();
361
+ server.once("error", () => {
362
+ resolve(false);
363
+ });
364
+ server.once("listening", () => {
365
+ server.close(() => resolve(true));
366
+ });
367
+ server.listen(port);
368
+ });
369
+ }
370
+ async function findAvailablePort(startPort) {
371
+ let port = startPort;
372
+ while (!await isPortAvailable(port)) {
373
+ port++;
374
+ }
375
+ return port;
376
+ }
377
+ async function configureEnvFile(targetDirectory, databaseUrl) {
358
378
  const envExamplePath = path.join(targetDirectory, ".env.example");
359
379
  const envPath = path.join(targetDirectory, ".env");
360
380
  if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
@@ -372,10 +392,21 @@ ${chalk.bold("Rebase")} — Create a new project 🚀
372
392
  `DATABASE_URL=${databaseUrl}`
373
393
  );
374
394
  } else {
395
+ const dbPort = await findAvailablePort(5432);
375
396
  envContent = envContent.replace(
376
397
  /^DATABASE_URL=.*$/m,
377
- `DATABASE_URL=postgresql://rebase:${dbPassword}@localhost:5432/rebase`
398
+ `DATABASE_URL=postgresql://rebase:${dbPassword}@localhost:${dbPort}/rebase?options=-c%20search_path=public
399
+ DATABASE_PASSWORD=${dbPassword}`
378
400
  );
401
+ const dockerComposePath = path.join(targetDirectory, "docker-compose.yml");
402
+ if (fs.existsSync(dockerComposePath)) {
403
+ let dockerComposeContent = fs.readFileSync(dockerComposePath, "utf-8");
404
+ dockerComposeContent = dockerComposeContent.replace(
405
+ /-\s*"5432:5432"/g,
406
+ `- "${dbPort}:5432"`
407
+ );
408
+ fs.writeFileSync(dockerComposePath, dockerComposeContent, "utf-8");
409
+ }
379
410
  }
380
411
  fs.writeFileSync(envPath, envContent, "utf-8");
381
412
  }