@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.
- package/dist/commands/init.d.ts +1 -1
- package/dist/index.cjs +38 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +37 -5
- package/dist/index.es.js.map +1 -1
- package/package.json +9 -4
- package/templates/template/.env.example +1 -1
- package/templates/template/README.md +1 -1
- package/templates/template/config/collections/posts.ts +6 -12
- package/templates/template/docker-compose.yml +2 -2
- package/templates/template/pnpm-workspace.yaml +1 -0
package/dist/index.es.js
CHANGED
|
@@ -3,6 +3,7 @@ import arg from "arg";
|
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import fs from "fs";
|
|
6
|
+
import net from "net";
|
|
6
7
|
import { promisify } from "util";
|
|
7
8
|
import { execa, execaCommandSync } from "execa";
|
|
8
9
|
import { cp } from "fs/promises";
|
|
@@ -200,7 +201,7 @@ async function createProject(options) {
|
|
|
200
201
|
process.exit(1);
|
|
201
202
|
}
|
|
202
203
|
await replacePlaceholders(options);
|
|
203
|
-
configureEnvFile(options.targetDirectory, options.databaseUrl);
|
|
204
|
+
await configureEnvFile(options.targetDirectory, options.databaseUrl);
|
|
204
205
|
if (options.git) {
|
|
205
206
|
console.log(chalk.gray(" Initializing git repository..."));
|
|
206
207
|
try {
|
|
@@ -260,8 +261,8 @@ async function createProject(options) {
|
|
|
260
261
|
console.log(chalk.gray(" # Your database is configured! Start the dev server:"));
|
|
261
262
|
} else {
|
|
262
263
|
console.log(chalk.gray(" # A local database configuration has been generated in .env."));
|
|
263
|
-
console.log(chalk.gray(" # If using the included docker-compose.yml, start
|
|
264
|
-
console.log(` ${chalk.cyan("docker compose up -d")}`);
|
|
264
|
+
console.log(chalk.gray(" # If using the included docker-compose.yml, start the database with:"));
|
|
265
|
+
console.log(` ${chalk.cyan("docker compose up -d db")}`);
|
|
265
266
|
console.log("");
|
|
266
267
|
console.log(chalk.gray(" # Then start the dev server:"));
|
|
267
268
|
}
|
|
@@ -281,6 +282,7 @@ async function replacePlaceholders(options) {
|
|
|
281
282
|
"backend/package.json",
|
|
282
283
|
"config/package.json",
|
|
283
284
|
"frontend/index.html",
|
|
285
|
+
"pnpm-workspace.yaml",
|
|
284
286
|
"README.md"
|
|
285
287
|
];
|
|
286
288
|
const packageJsonPath = path.resolve(cliRoot, "package.json");
|
|
@@ -345,7 +347,26 @@ async function replacePlaceholders(options) {
|
|
|
345
347
|
fs.writeFileSync(fullPath, content, "utf-8");
|
|
346
348
|
}
|
|
347
349
|
}
|
|
348
|
-
function
|
|
350
|
+
async function isPortAvailable(port) {
|
|
351
|
+
return new Promise((resolve) => {
|
|
352
|
+
const server = net.createServer();
|
|
353
|
+
server.once("error", () => {
|
|
354
|
+
resolve(false);
|
|
355
|
+
});
|
|
356
|
+
server.once("listening", () => {
|
|
357
|
+
server.close(() => resolve(true));
|
|
358
|
+
});
|
|
359
|
+
server.listen(port);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
async function findAvailablePort(startPort) {
|
|
363
|
+
let port = startPort;
|
|
364
|
+
while (!await isPortAvailable(port)) {
|
|
365
|
+
port++;
|
|
366
|
+
}
|
|
367
|
+
return port;
|
|
368
|
+
}
|
|
369
|
+
async function configureEnvFile(targetDirectory, databaseUrl) {
|
|
349
370
|
const envExamplePath = path.join(targetDirectory, ".env.example");
|
|
350
371
|
const envPath = path.join(targetDirectory, ".env");
|
|
351
372
|
if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
|
|
@@ -363,10 +384,21 @@ function configureEnvFile(targetDirectory, databaseUrl) {
|
|
|
363
384
|
`DATABASE_URL=${databaseUrl}`
|
|
364
385
|
);
|
|
365
386
|
} else {
|
|
387
|
+
const dbPort = await findAvailablePort(5432);
|
|
366
388
|
envContent = envContent.replace(
|
|
367
389
|
/^DATABASE_URL=.*$/m,
|
|
368
|
-
`DATABASE_URL=postgresql://rebase:${dbPassword}@localhost
|
|
390
|
+
`DATABASE_URL=postgresql://rebase:${dbPassword}@localhost:${dbPort}/rebase?options=-c%20search_path=public
|
|
391
|
+
DATABASE_PASSWORD=${dbPassword}`
|
|
369
392
|
);
|
|
393
|
+
const dockerComposePath = path.join(targetDirectory, "docker-compose.yml");
|
|
394
|
+
if (fs.existsSync(dockerComposePath)) {
|
|
395
|
+
let dockerComposeContent = fs.readFileSync(dockerComposePath, "utf-8");
|
|
396
|
+
dockerComposeContent = dockerComposeContent.replace(
|
|
397
|
+
/-\s*"5432:5432"/g,
|
|
398
|
+
`- "${dbPort}:5432"`
|
|
399
|
+
);
|
|
400
|
+
fs.writeFileSync(dockerComposePath, dockerComposeContent, "utf-8");
|
|
401
|
+
}
|
|
370
402
|
}
|
|
371
403
|
fs.writeFileSync(envPath, envContent, "utf-8");
|
|
372
404
|
}
|