@suryasairus/create-projectx 1.0.4 → 1.0.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/index.js +21 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,17 +5,26 @@ import readline from 'readline/promises';
|
|
|
5
5
|
import { stdin as input, stdout as output } from 'process';
|
|
6
6
|
import crypto from 'crypto';
|
|
7
7
|
|
|
8
|
+
// ANSI colors
|
|
9
|
+
const colors = {
|
|
10
|
+
reset: "\x1b[0m",
|
|
11
|
+
bright: "\x1b[1m",
|
|
12
|
+
dim: "\x1b[2m",
|
|
13
|
+
green: "\x1b[32m",
|
|
14
|
+
cyan: "\x1b[36m",
|
|
15
|
+
yellow: "\x1b[33m",
|
|
16
|
+
magenta: "\x1b[35m"
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
const projectName = process.argv[2] || 'my-app';
|
|
9
20
|
const projectPath = path.join(process.cwd(), projectName);
|
|
10
21
|
|
|
11
|
-
// Create
|
|
22
|
+
// Create folder
|
|
12
23
|
fs.mkdirSync(projectPath, { recursive: true });
|
|
13
24
|
|
|
14
25
|
// CLI
|
|
15
26
|
const rl = readline.createInterface({ input, output });
|
|
16
|
-
|
|
17
|
-
const ask = async (q) => (await rl.question(`${q}: `)).trim();
|
|
18
|
-
|
|
27
|
+
const ask = async (q) => (await rl.question(`${colors.cyan}${q}${colors.reset}: `)).trim();
|
|
19
28
|
const randomSecret = (length = 26) =>
|
|
20
29
|
crypto.randomBytes(length)
|
|
21
30
|
.toString('base64')
|
|
@@ -23,6 +32,8 @@ const randomSecret = (length = 26) =>
|
|
|
23
32
|
.slice(0, length);
|
|
24
33
|
|
|
25
34
|
// Ask values
|
|
35
|
+
console.log(`${colors.bright}${colors.magenta}Configure your environment variables:${colors.reset}\n`);
|
|
36
|
+
|
|
26
37
|
const env = {
|
|
27
38
|
DBNAME: await ask('DBNAME'),
|
|
28
39
|
DBCLIENT: await ask('DBCLIENT'),
|
|
@@ -42,10 +53,9 @@ rl.close();
|
|
|
42
53
|
const envFile = Object.entries(env)
|
|
43
54
|
.map(([k, v]) => `${k}=${v}`)
|
|
44
55
|
.join('\n');
|
|
45
|
-
|
|
46
56
|
fs.writeFileSync(path.join(projectPath, '.env'), envFile);
|
|
47
57
|
|
|
48
|
-
// package.json
|
|
58
|
+
// Write package.json
|
|
49
59
|
const pkgJson = {
|
|
50
60
|
name: projectName,
|
|
51
61
|
version: "1.0.0",
|
|
@@ -57,11 +67,13 @@ const pkgJson = {
|
|
|
57
67
|
"@suryasairus/projectx-core": "latest"
|
|
58
68
|
}
|
|
59
69
|
};
|
|
60
|
-
|
|
61
70
|
fs.writeFileSync(
|
|
62
71
|
path.join(projectPath, 'package.json'),
|
|
63
72
|
JSON.stringify(pkgJson, null, 2)
|
|
64
73
|
);
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
console.log(
|
|
75
|
+
// Done message
|
|
76
|
+
console.log(`\n${colors.green}Project ${projectName} created successfully!${colors.reset}`);
|
|
77
|
+
console.log(`${colors.yellow}Next steps:${colors.reset}`);
|
|
78
|
+
console.log(` cd ${projectName}`);
|
|
79
|
+
console.log(` npm install\n`);
|