create-seamless 0.0.8 → 0.0.10

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.
Files changed (2) hide show
  1. package/index.js +46 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,12 +7,32 @@ import { promisify } from "util";
7
7
  import { createWriteStream } from "fs";
8
8
  import AdmZip from "adm-zip";
9
9
  import { randomBytes } from "crypto";
10
+ import net from "net";
10
11
 
11
12
  const streamPipeline = promisify(pipeline);
12
13
 
13
14
  const MIN_NODE_MAJOR = 18;
14
15
  const nodeMajor = Number(process.versions.node.split(".")[0]);
15
16
 
17
+ function ensureExecutable(filePath) {
18
+ if (fs.existsSync(filePath)) {
19
+ fs.chmodSync(filePath, 0o755);
20
+ }
21
+ }
22
+
23
+ function isPortAvailable(port) {
24
+ return new Promise((resolve) => {
25
+ const server = net
26
+ .createServer()
27
+ .once("error", () => resolve(false))
28
+ .once("listening", () => {
29
+ server.close();
30
+ resolve(true);
31
+ })
32
+ .listen(port);
33
+ });
34
+ }
35
+
16
36
  function printHelp() {
17
37
  console.log(`
18
38
  create-seamless
@@ -30,7 +50,7 @@ Options:
30
50
 
31
51
  --auth-port <n> Auth server port (default: 5312)
32
52
  --api-port <n> API server port (default: 3000)
33
- --web-port <n> Web server port (default: 5173)
53
+ --web-port <n> Web server port (default: 5001)
34
54
 
35
55
  -h, --help Show this help message
36
56
 
@@ -344,6 +364,16 @@ async function downloadRepo(repo, dest) {
344
364
  console.log(`\nCreating Seamless project: ${projectName}\n`);
345
365
  const API_SERVICE_TOKEN = randomBytes(32).toString("hex");
346
366
 
367
+ let dbHostPort = "5432";
368
+
369
+ if (!(await isPortAvailable(5432))) {
370
+ dbHostPort = "5433";
371
+ console.log(`
372
+ ⚠️ Port 5432 is already in use on your machine.
373
+ Using 5433 for Docker Postgres instead.
374
+ `);
375
+ }
376
+
347
377
  if (AUTH) {
348
378
  const dir = path.join(root, "auth");
349
379
  fs.mkdirSync(dir);
@@ -368,7 +398,7 @@ async function downloadRepo(repo, dest) {
368
398
 
369
399
  DB_LOGGING: "false",
370
400
  DB_HOST: "localhost",
371
- DB_PORT: "5432",
401
+ DB_PORT: dbHostPort,
372
402
  DB_NAME: "seamless_auth",
373
403
  DB_USER: "myuser",
374
404
  DB_PASSWORD: "mypassword",
@@ -401,7 +431,7 @@ async function downloadRepo(repo, dest) {
401
431
  API_SERVICE_TOKEN: API_SERVICE_TOKEN,
402
432
 
403
433
  DB_HOST: "localhost",
404
- DB_PORT: "5432",
434
+ DB_PORT: dbHostPort,
405
435
  DB_NAME: "seamless_api",
406
436
  DB_USER: "myuser",
407
437
  DB_PASSWORD: "mypassword",
@@ -430,10 +460,17 @@ async function downloadRepo(repo, dest) {
430
460
  }
431
461
 
432
462
  if (AUTH && API && WEB) {
433
- fs.writeFileSync(
434
- path.join(root, "Docker-compose.yml"),
435
- GENERATED_DOCKER_COMPOSE,
463
+ const compose = GENERATED_DOCKER_COMPOSE.replace(
464
+ '"5432:5432"',
465
+ `"${dbHostPort}:5432"`,
436
466
  );
467
+
468
+ fs.writeFileSync(path.join(root, "docker-compose.yml"), compose);
469
+ }
470
+
471
+ if (AUTH) {
472
+ const authScriptPath = path.join(root, "auth", "validateEnvs.sh");
473
+ ensureExecutable(authScriptPath);
437
474
  }
438
475
 
439
476
  const pgDir = path.join(root, "postgres_init");
@@ -470,6 +507,9 @@ Start development:
470
507
 
471
508
  docker compose up
472
509
 
510
+ If you already have Postgres running locally,
511
+ the generator may map Docker to port 5433 instead.
512
+
473
513
  Docs: https://docs.seamlessauth.com/docs
474
514
  Happy hacking. 🚀
475
515
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-seamless",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "The starter script for Seamless Auth",
5
5
  "homepage": "https://github.com/fells-code/create-seamless#readme",
6
6
  "bugs": {