create-nyoworks 3.2.4 → 3.2.5
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/init.js +19 -0
- package/package.json +1 -1
package/dist/init.js
CHANGED
|
@@ -6,6 +6,7 @@ import pc from "picocolors";
|
|
|
6
6
|
import fs from "fs-extra";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import os from "os";
|
|
9
|
+
import crypto from "crypto";
|
|
9
10
|
import { fileURLToPath } from "url";
|
|
10
11
|
import { execa } from "execa";
|
|
11
12
|
import { replacePlaceholders } from "./replace.js";
|
|
@@ -61,6 +62,9 @@ function generateDatabaseName(name) {
|
|
|
61
62
|
.replace(/[^a-z0-9]+/g, "_")
|
|
62
63
|
.replace(/^_|_$/g, "") + "_dev";
|
|
63
64
|
}
|
|
65
|
+
function generateSecureToken(length = 32) {
|
|
66
|
+
return crypto.randomBytes(length).toString("base64url").slice(0, length);
|
|
67
|
+
}
|
|
64
68
|
async function downloadRepo(repo, branch) {
|
|
65
69
|
const url = `https://github.com/${repo}/archive/refs/heads/${branch}.tar.gz`;
|
|
66
70
|
const tempDir = path.join(os.tmpdir(), `nyoworks-${Date.now()}`);
|
|
@@ -413,6 +417,21 @@ export async function createProject(projectName) {
|
|
|
413
417
|
await replacePlaceholders(targetDir, placeholders);
|
|
414
418
|
console.log(pc.green(" done"));
|
|
415
419
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
420
|
+
// Create .env from .env.example
|
|
421
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
422
|
+
const envExamplePath = path.join(targetDir, ".env.example");
|
|
423
|
+
const envPath = path.join(targetDir, ".env");
|
|
424
|
+
if (await fs.pathExists(envExamplePath)) {
|
|
425
|
+
let envContent = await fs.readFile(envExamplePath, "utf8");
|
|
426
|
+
envContent = envContent.replace(/\$\{DATABASE_NAME\}/g, databaseName);
|
|
427
|
+
const jwtSecret = generateSecureToken(48);
|
|
428
|
+
const jwtRefreshSecret = generateSecureToken(48);
|
|
429
|
+
envContent = envContent.replace(/JWT_SECRET=.*/, `JWT_SECRET=${jwtSecret}`);
|
|
430
|
+
envContent = envContent.replace(/JWT_REFRESH_SECRET=.*/, `JWT_REFRESH_SECRET=${jwtRefreshSecret}`);
|
|
431
|
+
await fs.writeFile(envPath, envContent);
|
|
432
|
+
console.log(pc.dim(" Created .env with secure defaults"));
|
|
433
|
+
}
|
|
434
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
416
435
|
// Create Feature Docs
|
|
417
436
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
418
437
|
for (const feature of features) {
|