@suryasairus/create-projectx 1.0.4 → 1.0.6

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 +92 -58
  2. package/package.json +16 -13
package/index.js CHANGED
@@ -1,67 +1,101 @@
1
1
  #!/usr/bin/env node
2
- import fs from 'fs';
2
+
3
+ import fs from 'fs/promises';
3
4
  import path from 'path';
4
- import readline from 'readline/promises';
5
- import { stdin as input, stdout as output } from 'process';
6
5
  import crypto from 'crypto';
6
+ import pkg from 'enquirer';
7
+ import pc from 'picocolors';
8
+ import { createSpinner } from 'nanospinner';
9
+ import gradient from 'gradient-string';
10
+
11
+ const { prompt } = pkg;
7
12
 
8
13
  const projectName = process.argv[2] || 'my-app';
9
- const projectPath = path.join(process.cwd(), projectName);
10
-
11
- // Create project folder
12
- fs.mkdirSync(projectPath, { recursive: true });
13
-
14
- // CLI
15
- const rl = readline.createInterface({ input, output });
16
-
17
- const ask = async (q) => (await rl.question(`${q}: `)).trim();
18
-
19
- const randomSecret = (length = 26) =>
20
- crypto.randomBytes(length)
21
- .toString('base64')
22
- .replace(/[^a-zA-Z0-9]/g, '')
23
- .slice(0, length);
24
-
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
- };
14
+ const projectPath = path.resolve(process.cwd(), projectName);
38
15
 
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
- }
16
+ const colors = {
17
+ reset: "\x1b[0m",
18
+ bright: "\x1b[1m",
19
+ dim: "\x1b[2m",
20
+ green: "\x1b[32m",
21
+ cyan: "\x1b[36m",
22
+ yellow: "\x1b[33m",
23
+ magenta: "\x1b[35m"
59
24
  };
60
25
 
61
- fs.writeFileSync(
62
- path.join(projectPath, 'package.json'),
63
- JSON.stringify(pkgJson, null, 2)
64
- );
26
+ const blueGrad = gradient('cyan', 'blue');
27
+
28
+ async function init() {
29
+ console.log(blueGrad(`\nšŸš€ ProjectX Initializer\n`));
30
+
31
+ // 1. Interactive Questions
32
+ const response = await prompt([
33
+ { type: 'input', name: 'DBNAME', message: 'Database Name', initial: 'project_db' },
34
+ { type: 'select', name: 'DBCLIENT', message: 'DB Client', choices: ['pg', 'mysql', 'sqlite3'] },
35
+ { type: 'input', name: 'DBHOST', message: 'DB Host', initial: '127.0.0.1' },
36
+ { type: 'input', name: 'DBPORT', message: 'DB Port', initial: '5432' },
37
+ { type: 'input', name: 'DBUSER', message: 'DB User', initial: 'postgres' },
38
+ { type: 'password', name: 'DBPASS', message: 'DB Password' },
39
+ { type: 'input', name: 'SITE_URL', message: 'Site URL', initial: 'http://localhost:3000' }
40
+ ]);
41
+
42
+ const spinner = createSpinner('Generating project files...').start();
43
+
44
+ try {
45
+ // 2. Create Directory
46
+ await fs.mkdir(projectPath, { recursive: true });
47
+
48
+ // 3. Prepare Environment Variables
49
+ const randomSecret = () => crypto.randomBytes(26).toString('hex');
50
+ const envVars = {
51
+ ...response,
52
+ NEXT_PUBLIC_SITE_URL: response.SITE_URL,
53
+ NEXTAUTH_URL: response.SITE_URL,
54
+ NEXTAUTH_SECRET: randomSecret(),
55
+ SECRET_PROJECT_PASSPHRASE_SALT: randomSecret(),
56
+ };
57
+
58
+ const envContent = Object.entries(envVars)
59
+ .map(([k, v]) => `${k}=${v}`)
60
+ .join('\n');
61
+
62
+ // 4. Write Files
63
+ await fs.writeFile(path.join(projectPath, '.env'), envContent);
64
+
65
+ const pkgJson = {
66
+ name: projectName,
67
+ version: "1.0.0",
68
+ private: true,
69
+ scripts: {
70
+ "dev": "next dev",
71
+ "build": "next build node_modules/@suryasairus/projectx-core",
72
+ "start": "next start"
73
+ },
74
+ dependencies: {
75
+ "next": "latest",
76
+ "react": "latest",
77
+ "react-dom": "latest",
78
+ "@suryasairus/projectx-core": "latest"
79
+ }
80
+ };
81
+
82
+ await fs.writeFile(
83
+ path.join(projectPath, 'package.json'),
84
+ JSON.stringify(pkgJson, null, 2)
85
+ );
86
+
87
+ spinner.success({ text: 'Project scaffolded!' });
88
+
89
+ console.log(`\n${colors.green}Project ${projectName} created successfully!${colors.reset}`);
90
+ console.log(`${colors.yellow}Next steps:${colors.reset}`);
91
+ console.log(` cd ${projectName}`);
92
+ console.log(` npm install\n`);
93
+
94
+ } catch (err) {
95
+ spinner.error({ text: 'Failed to create project' });
96
+ console.error(pc.red(err));
97
+ process.exit(1);
98
+ }
99
+ }
65
100
 
66
- console.log(`āœ… Project ${projectName} created`);
67
- console.log(`āž”ļø cd ${projectName} && npm install`);
101
+ init();
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
- {
2
- "name": "@suryasairus/create-projectx",
3
- "version": "1.0.4",
4
- "description": "CLI to scaffold ProjectX",
5
- "license": "ISC",
6
- "type": "module",
7
- "bin": {
8
- "create-projectx": "index.js"
9
- },
10
- "files": [
11
- "index.js"
12
- ]
13
- }
1
+ {
2
+ "name": "@suryasairus/create-projectx",
3
+ "version": "1.0.6",
4
+ "description": "Scaffolding CLI for ProjectX",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-projectx": "index.js"
8
+ },
9
+ "files": [
10
+ "index.js"
11
+ ],
12
+ "dependencies": {
13
+ "inquirer": "^9.0.0",
14
+ "fs-extra": "^11.0.0"
15
+ }
16
+ }