@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.
Files changed (2) hide show
  1. package/index.js +60 -21
  2. package/package.json +9 -8
package/index.js CHANGED
@@ -1,28 +1,67 @@
1
1
  #!/usr/bin/env node
2
- import inquirer from 'inquirer';
3
- import fs from 'fs-extra';
4
- import { execSync } from 'child_process';
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
- async function run() {
7
- const projectName = process.argv[2] || 'my-app';
8
+ const projectName = process.argv[2] || 'my-app';
9
+ const projectPath = path.join(process.cwd(), projectName);
8
10
 
9
- // 1. Ask DB Questions
10
- const answers = await inquirer.prompt([
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
- // 2. Create the folder
16
- fs.mkdirSync(projectName);
14
+ // CLI
15
+ const rl = readline.createInterface({ input, output });
17
16
 
18
- // 3. Create the .env file
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
- // 4. Download your source code (e.g., from a GitHub repo)
23
- console.log('Downloading template...');
24
- execSync(`npx degit your-github-username/projectx-template ${projectName}`);
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
- console.log('Done! Now run: cd ' + projectName + ' && npm install');
27
- }
28
- run();
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.1",
4
- "description": "",
3
+ "version": "1.0.4",
4
+ "description": "CLI to scaffold ProjectX",
5
5
  "license": "ISC",
6
- "author": "",
7
- "type": "commonjs",
8
- "main": "index.js",
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- }
6
+ "type": "module",
7
+ "bin": {
8
+ "create-projectx": "index.js"
9
+ },
10
+ "files": [
11
+ "index.js"
12
+ ]
12
13
  }