@suryasairus/create-projectx 1.0.5 → 1.0.7

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 +85 -63
  2. package/package.json +16 -3
package/index.js CHANGED
@@ -1,11 +1,18 @@
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;
12
+
13
+ const projectName = process.argv[2] || 'my-app';
14
+ const projectPath = path.resolve(process.cwd(), projectName);
7
15
 
8
- // ANSI colors
9
16
  const colors = {
10
17
  reset: "\x1b[0m",
11
18
  bright: "\x1b[1m",
@@ -16,64 +23,79 @@ const colors = {
16
23
  magenta: "\x1b[35m"
17
24
  };
18
25
 
19
- const projectName = process.argv[2] || 'my-app';
20
- const projectPath = path.join(process.cwd(), projectName);
21
-
22
- // Create folder
23
- fs.mkdirSync(projectPath, { recursive: true });
24
-
25
- // CLI
26
- const rl = readline.createInterface({ input, output });
27
- const ask = async (q) => (await rl.question(`${colors.cyan}${q}${colors.reset}: `)).trim();
28
- const randomSecret = (length = 26) =>
29
- crypto.randomBytes(length)
30
- .toString('base64')
31
- .replace(/[^a-zA-Z0-9]/g, '')
32
- .slice(0, length);
33
-
34
- // Ask values
35
- console.log(`${colors.bright}${colors.magenta}Configure your environment variables:${colors.reset}\n`);
36
-
37
- const env = {
38
- DBNAME: await ask('DBNAME'),
39
- DBCLIENT: await ask('DBCLIENT'),
40
- DBHOST: await ask('DBHOST'),
41
- DBPORT: await ask('DBPORT'),
42
- DBUSER: await ask('DBUSER'),
43
- DBPASS: await ask('DBPASS'),
44
- NEXT_PUBLIC_SITE_URL: await ask('NEXT_PUBLIC_SITE_URL'),
45
- SECRET_PROJECT_PASSPHRASE_SALT: randomSecret(26),
46
- NEXTAUTH_URL: await ask('NEXTAUTH_URL'),
47
- NEXTAUTH_SECRET: randomSecret(26)
48
- };
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();
49
43
 
50
- rl.close();
51
-
52
- // Write .env
53
- const envFile = Object.entries(env)
54
- .map(([k, v]) => `${k}=${v}`)
55
- .join('\n');
56
- fs.writeFileSync(path.join(projectPath, '.env'), envFile);
57
-
58
- // Write package.json
59
- const pkgJson = {
60
- name: projectName,
61
- version: "1.0.0",
62
- scripts: {
63
- "build": "next build node_modules/@suryasairus/projectx-core"
64
- },
65
- dependencies: {
66
- "next": "latest",
67
- "@suryasairus/projectx-core": "latest"
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);
68
98
  }
69
- };
70
- fs.writeFileSync(
71
- path.join(projectPath, 'package.json'),
72
- JSON.stringify(pkgJson, null, 2)
73
- );
74
-
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`);
99
+ }
100
+
101
+ init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suryasairus/create-projectx",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "CLI to scaffold ProjectX",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -9,5 +9,18 @@
9
9
  },
10
10
  "files": [
11
11
  "index.js"
12
- ]
13
- }
12
+ ],
13
+ "main": "index.js",
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "keywords": [],
18
+ "author": "",
19
+ "dependencies": {
20
+ "@suryasairus/create-projectx": "^1.0.5",
21
+ "enquirer": "^2.4.1",
22
+ "gradient-string": "^3.0.0",
23
+ "nanospinner": "^1.2.2",
24
+ "picocolors": "^1.1.1"
25
+ }
26
+ }