@suryasairus/create-projectx 1.0.1 → 1.0.4
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 +60 -21
- package/package.json +9 -8
package/index.js
CHANGED
|
@@ -1,28 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import readline from 'readline/promises';
|
|
5
|
+
import { stdin as input, stdout as output } from 'process';
|
|
6
|
+
import crypto from 'crypto';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const projectName = process.argv[2] || 'my-app';
|
|
9
|
+
const projectPath = path.join(process.cwd(), projectName);
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{ name: 'dbHost', message: 'Database Host:', default: 'localhost' },
|
|
12
|
-
{ name: 'dbUser', message: 'Database User:' }
|
|
13
|
-
]);
|
|
11
|
+
// Create project folder
|
|
12
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// CLI
|
|
15
|
+
const rl = readline.createInterface({ input, output });
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
const envData = `DATABASE_URL=postgresql://${answers.dbUser}@${answers.dbHost}:5432/mydb`;
|
|
20
|
-
fs.writeFileSync(`${projectName}/.env`, envData);
|
|
17
|
+
const ask = async (q) => (await rl.question(`${q}: `)).trim();
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const randomSecret = (length = 26) =>
|
|
20
|
+
crypto.randomBytes(length)
|
|
21
|
+
.toString('base64')
|
|
22
|
+
.replace(/[^a-zA-Z0-9]/g, '')
|
|
23
|
+
.slice(0, length);
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
// Ask values
|
|
26
|
+
const env = {
|
|
27
|
+
DBNAME: await ask('DBNAME'),
|
|
28
|
+
DBCLIENT: await ask('DBCLIENT'),
|
|
29
|
+
DBHOST: await ask('DBHOST'),
|
|
30
|
+
DBPORT: await ask('DBPORT'),
|
|
31
|
+
DBUSER: await ask('DBUSER'),
|
|
32
|
+
DBPASS: await ask('DBPASS'),
|
|
33
|
+
NEXT_PUBLIC_SITE_URL: await ask('NEXT_PUBLIC_SITE_URL'),
|
|
34
|
+
SECRET_PROJECT_PASSPHRASE_SALT: randomSecret(26),
|
|
35
|
+
NEXTAUTH_URL: await ask('NEXTAUTH_URL'),
|
|
36
|
+
NEXTAUTH_SECRET: randomSecret(26)
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
rl.close();
|
|
40
|
+
|
|
41
|
+
// Write .env
|
|
42
|
+
const envFile = Object.entries(env)
|
|
43
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
44
|
+
.join('\n');
|
|
45
|
+
|
|
46
|
+
fs.writeFileSync(path.join(projectPath, '.env'), envFile);
|
|
47
|
+
|
|
48
|
+
// package.json (unchanged)
|
|
49
|
+
const pkgJson = {
|
|
50
|
+
name: projectName,
|
|
51
|
+
version: "1.0.0",
|
|
52
|
+
scripts: {
|
|
53
|
+
"build": "next build node_modules/@suryasairus/projectx-core"
|
|
54
|
+
},
|
|
55
|
+
dependencies: {
|
|
56
|
+
"next": "latest",
|
|
57
|
+
"@suryasairus/projectx-core": "latest"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
fs.writeFileSync(
|
|
62
|
+
path.join(projectPath, 'package.json'),
|
|
63
|
+
JSON.stringify(pkgJson, null, 2)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
console.log(`✅ Project ${projectName} created`);
|
|
67
|
+
console.log(`➡️ cd ${projectName} && npm install`);
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suryasairus/create-projectx",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "CLI to scaffold ProjectX",
|
|
5
5
|
"license": "ISC",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-projectx": "index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js"
|
|
12
|
+
]
|
|
12
13
|
}
|