@nishant0121/set-it-up 0.0.7 → 0.0.11

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.
@@ -0,0 +1,63 @@
1
+ export const getPackageJson = (projectName, isTypescript) => {
2
+ const commonScripts = {
3
+ "start": "node src/index.js",
4
+ "dev": "nodemon src/index.js"
5
+ };
6
+
7
+ const tsScripts = {
8
+ "start": "tsx src/index.ts",
9
+ "dev": "tsx watch src/index.ts",
10
+ "build": "tsc"
11
+ };
12
+
13
+ const dependencies = {
14
+ "express": "^4.18.2",
15
+ "cors": "^2.8.5",
16
+ "dotenv": "^16.3.1",
17
+ "helmet": "^7.1.0",
18
+ "morgan": "^1.10.0"
19
+ };
20
+
21
+ const devDependencies = isTypescript ? {
22
+ "typescript": "^5.3.3",
23
+ "tsx": "^4.7.0",
24
+ "@types/node": "^20.10.6",
25
+ "@types/express": "^4.17.21",
26
+ "@types/cors": "^2.8.17",
27
+ "@types/morgan": "^1.9.9"
28
+ } : {
29
+ "nodemon": "^3.0.2"
30
+ };
31
+
32
+ return JSON.stringify({
33
+ name: projectName,
34
+ version: "1.0.0",
35
+ description: "Express.js application generated by set-it-up",
36
+ main: isTypescript ? "src/index.ts" : "src/index.js",
37
+ type: "module",
38
+ scripts: isTypescript ? tsScripts : commonScripts,
39
+ dependencies,
40
+ devDependencies,
41
+ keywords: [],
42
+ author: "",
43
+ license: "ISC"
44
+ }, null, 2);
45
+ };
46
+
47
+ export const getTsConfig = () => {
48
+ return JSON.stringify({
49
+ "compilerOptions": {
50
+ "target": "es2020",
51
+ "module": "esnext",
52
+ "moduleResolution": "node",
53
+ "outDir": "./dist",
54
+ "rootDir": "./src",
55
+ "strict": true,
56
+ "esModuleInterop": true,
57
+ "skipLibCheck": true,
58
+ "forceConsistentCasingInFileNames": true
59
+ },
60
+ "include": ["src/**/*"],
61
+ "exclude": ["node_modules"]
62
+ }, null, 2);
63
+ };
@@ -0,0 +1,9 @@
1
+ export const getController = (isTypescript) => {
2
+ const importStatement = isTypescript ? "import { Request, Response } from 'express';\n" : "";
3
+ return `${importStatement}
4
+ export const getExample = (req${isTypescript ? ': Request' : ''}, res${isTypescript ? ': Response' : ''}) => {
5
+ res.json({ message: 'This is an example controller response' });
6
+ };
7
+ `;
8
+ };
9
+
@@ -0,0 +1,42 @@
1
+ export const getIndex = (isTypescript) => {
2
+ const portVar = isTypescript ? 'const PORT: number | string = process.env.PORT || 3000;' : 'const PORT = process.env.PORT || 3000;';
3
+
4
+ return `import express${isTypescript ? ', { Express, Request, Response }' : ''} from 'express';
5
+ import cors from 'cors';
6
+ import helmet from 'helmet';
7
+ import morgan from 'morgan';
8
+ import dotenv from 'dotenv';
9
+ import router from './routes/index.js';
10
+
11
+ dotenv.config();
12
+
13
+ const app${isTypescript ? ': Express' : ''} = express();
14
+ ${portVar}
15
+
16
+ // Middleware
17
+ app.use(express.json());
18
+ app.use(express.urlencoded({ extended: true }));
19
+ app.use(cors());
20
+ app.use(helmet());
21
+ app.use(morgan('dev'));
22
+
23
+ // Routes
24
+ app.use('/api', router);
25
+
26
+ app.get('/', (req${isTypescript ? ': Request' : ''}, res${isTypescript ? ': Response' : ''}) => {
27
+ res.send('Welcome to your Express.js API!');
28
+ });
29
+
30
+ // Error handling middleware
31
+ app.use((err${isTypescript ? ': any' : ''}, req${isTypescript ? ': Request' : ''}, res${isTypescript ? ': Response' : ''}, next${isTypescript ? ': Function' : ''}) => {
32
+ console.error(err.stack);
33
+ res.status(500).send('Something broke!');
34
+ });
35
+
36
+ app.listen(PORT, () => {
37
+ console.log(\`Server is running on port \${PORT}\`);
38
+ console.log('Visit http://localhost:' + PORT);
39
+ console.log('Press CTRL+C to stop the server');
40
+ });
41
+ `
42
+ };
@@ -0,0 +1,4 @@
1
+ export * from './configuration.js';
2
+ export * from './entry.js';
3
+ export * from './routes.js';
4
+ export * from './controllers.js';
@@ -0,0 +1,11 @@
1
+ export const getRouteIndex = (isTypescript) => {
2
+ return `import { Router } from 'express';
3
+ import { getExample } from '../controllers/exampleController.js';
4
+
5
+ const router = Router();
6
+
7
+ router.get('/example', getExample);
8
+
9
+ export default router;
10
+ `;
11
+ };
@@ -51,8 +51,8 @@ export default App;
51
51
  };
52
52
 
53
53
  export const getAppContext = (options) => {
54
- const { isTypescript, addShadcn } = options;
55
- const useTs = isTypescript || addShadcn;
54
+ const { isTypescript } = options;
55
+ const useTs = isTypescript;
56
56
 
57
57
  return `import React, { createContext, useContext, useState${useTs ? ', ReactNode' : ''} } from 'react';
58
58
 
package/src/wizard.js CHANGED
@@ -1,124 +1,137 @@
1
- import inquirer from 'inquirer';
2
- import chalk from 'chalk';
3
- import gradient from 'gradient-string';
4
- import boxen from 'boxen';
5
- import { checkPrerequisites } from './utils/checkEnv.js';
6
- import { setupReactNative } from './engines/reactNative.js';
7
- import { setupReact } from './engines/react.js';
8
-
9
- export async function mainWizard() {
10
- // Clear the console for a fresh start
11
- console.clear();
12
-
13
- // Create a beautiful header
14
- const title = `
15
- SET - IT - UP
16
- `;
17
-
18
- const boxenOptions = {
19
- padding: 1,
20
- margin: 1,
21
- borderStyle: 'round',
22
- borderColor: 'cyan',
23
- backgroundColor: '#1b1b1b'
24
- };
25
-
26
- const welcomeMessage = boxen(
27
- gradient.pastel.multiline(title) +
28
- '\n' +
29
- chalk.white('šŸš€ Ready to launch your next idea?'),
30
- boxenOptions
31
- );
32
-
33
- console.log(welcomeMessage);
34
-
35
- console.log(chalk.hex('#4285F4')(' Hi there! Let\'s configure your new project.\n'));
36
-
37
- const answers = await inquirer.prompt([
38
- {
39
- type: 'rawlist',
40
- name: 'projectType',
41
- message: 'What do you want to build today?',
42
- choices: ['React', 'React Native', 'Next.js (Coming Soon)', 'Custom GitHub Template'],
43
- },
44
- {
45
- type: 'input',
46
- name: 'projectName',
47
- message: 'Enter your project name:',
48
- default: 'my-awesome-app',
49
- validate: (input) => {
50
- if (/^([a-z0-9\-\_])+$/.test(input)) return true;
51
- return 'Project name may only include lowercase letters, numbers, underscores and hashes.';
52
- }
53
- },
54
- {
55
- type: 'rawlist',
56
- name: 'packageManager',
57
- message: 'Select your preferred package manager:',
58
- choices: ['npm', 'yarn', 'pnpm'],
59
- }
60
- ]);
61
-
62
- if (answers.projectType === 'React Native') {
63
- const platformAnswer = await inquirer.prompt([
64
- {
65
- type: 'rawlist',
66
- name: 'targetPlatform',
67
- message: 'Which platform do you want to target?',
68
- choices: ['Android', 'iOS', 'Both'],
69
- }
70
- ]);
71
-
72
- await checkPrerequisites('React Native', { targetPlatform: platformAnswer.targetPlatform });
73
-
74
- // Additional RN specific questions
75
- const rnAnswers = await inquirer.prompt([
76
- {
77
- type: 'rawlist',
78
- name: 'language',
79
- message: 'Which language do you want to use?',
80
- choices: ['TypeScript', 'JavaScript'],
81
- },
82
- {
83
- type: 'confirm',
84
- name: 'addNavigation',
85
- message: 'Would you like to add React Navigation setup?',
86
- }
87
- ]);
88
-
89
- Object.assign(rnAnswers, platformAnswer);
90
-
91
- await setupReactNative(answers, rnAnswers);
92
- } else if (answers.projectType === 'React') {
93
- await checkPrerequisites('React');
94
-
95
- const reactAnswers = await inquirer.prompt([
96
- {
97
- type: 'rawlist',
98
- name: 'language',
99
- message: 'Which language do you want to use?',
100
- choices: ['TypeScript', 'JavaScript'],
101
- },
102
- {
103
- type: 'confirm',
104
- name: 'addShadcn',
105
- message: 'Would you like to setup Shadcn UI (install utils & dependencies)?',
106
- },
107
- {
108
- type: 'confirm',
109
- name: 'addRouter',
110
- message: 'Would you like to add React Router DOM?',
111
- },
112
- {
113
- type: 'confirm',
114
- name: 'addContext',
115
- message: 'Would you like to setup a global AppContext?',
116
- }
117
- ]);
118
-
119
- await setupReact(answers, reactAnswers);
120
-
121
- } else {
122
- console.log(chalk.yellow('\n🚧 This feature is coming soon! Stay tuned.\n'));
123
- }
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import gradient from 'gradient-string';
4
+ import boxen from 'boxen';
5
+ import { checkPrerequisites } from './utils/checkEnv.js';
6
+ import { setupReactNative } from './engines/reactNative.js';
7
+ import { setupReact } from './engines/react.js';
8
+ import { setupExpress } from './engines/express.js';
9
+
10
+ export async function mainWizard() {
11
+ // Clear the console for a fresh start
12
+ console.clear();
13
+
14
+ // Create a beautiful header
15
+ const title = `
16
+ SET - IT - UP
17
+ `;
18
+
19
+ const boxenOptions = {
20
+ padding: 1,
21
+ margin: 1,
22
+ borderStyle: 'round',
23
+ borderColor: 'cyan',
24
+ backgroundColor: '#1b1b1b'
25
+ };
26
+
27
+ const welcomeMessage = boxen(
28
+ gradient.pastel.multiline(title) +
29
+ '\n' +
30
+ chalk.white('šŸš€ Ready to launch your next idea?'),
31
+ boxenOptions
32
+ );
33
+
34
+ console.log(welcomeMessage);
35
+
36
+ console.log(chalk.hex('#4285F4')(' Hi there! Let\'s configure your new project.\n'));
37
+
38
+ const answers = await inquirer.prompt([
39
+ {
40
+ type: 'rawlist',
41
+ name: 'projectType',
42
+ message: 'What do you want to build today?',
43
+ choices: ['React', 'React Native', 'Express.js', 'Next.js (Coming Soon)', 'Custom GitHub Template'],
44
+ },
45
+ {
46
+ type: 'input',
47
+ name: 'projectName',
48
+ message: 'Enter your project name:',
49
+ default: 'my-awesome-app',
50
+ validate: (input) => {
51
+ if (/^([a-z0-9\-\_])+$/.test(input)) return true;
52
+ return 'Project name may only include lowercase letters, numbers, underscores and hashes.';
53
+ }
54
+ },
55
+ {
56
+ type: 'rawlist',
57
+ name: 'packageManager',
58
+ message: 'Select your preferred package manager:',
59
+ choices: ['npm', 'yarn', 'pnpm'],
60
+ }
61
+ ]);
62
+
63
+ if (answers.projectType === 'React Native') {
64
+ const platformAnswer = await inquirer.prompt([
65
+ {
66
+ type: 'rawlist',
67
+ name: 'targetPlatform',
68
+ message: 'Which platform do you want to target?',
69
+ choices: ['Android', 'iOS', 'Both'],
70
+ }
71
+ ]);
72
+
73
+ await checkPrerequisites('React Native', { targetPlatform: platformAnswer.targetPlatform });
74
+
75
+ // Additional RN specific questions
76
+ const rnAnswers = await inquirer.prompt([
77
+ {
78
+ type: 'rawlist',
79
+ name: 'language',
80
+ message: 'Which language do you want to use?',
81
+ choices: ['TypeScript', 'JavaScript'],
82
+ },
83
+ {
84
+ type: 'confirm',
85
+ name: 'addNavigation',
86
+ message: 'Would you like to add React Navigation setup?',
87
+ }
88
+ ]);
89
+
90
+ Object.assign(rnAnswers, platformAnswer);
91
+
92
+ await setupReactNative(answers, rnAnswers);
93
+ } else if (answers.projectType === 'React') {
94
+ await checkPrerequisites('React');
95
+
96
+ const reactAnswers = await inquirer.prompt([
97
+ {
98
+ type: 'rawlist',
99
+ name: 'language',
100
+ message: 'Which language do you want to use?',
101
+ choices: ['TypeScript', 'JavaScript'],
102
+ },
103
+ {
104
+ type: 'confirm',
105
+ name: 'addShadcn',
106
+ message: 'Would you like to setup Shadcn UI (install utils & dependencies)?',
107
+ },
108
+ {
109
+ type: 'confirm',
110
+ name: 'addRouter',
111
+ message: 'Would you like to add React Router DOM?',
112
+ },
113
+ {
114
+ type: 'confirm',
115
+ name: 'addContext',
116
+ message: 'Would you like to setup a global AppContext?',
117
+ }
118
+ ]);
119
+
120
+ await setupReact(answers, reactAnswers);
121
+
122
+ } else if (answers.projectType === 'Express.js') {
123
+ const expressAnswers = await inquirer.prompt([
124
+ {
125
+ type: 'rawlist',
126
+ name: 'language',
127
+ message: 'Which language do you want to use?',
128
+ choices: ['TypeScript', 'JavaScript'],
129
+ }
130
+ ]);
131
+
132
+ await setupExpress(answers, expressAnswers);
133
+
134
+ } else {
135
+ console.log(chalk.yellow('\n🚧 This feature is coming soon! Stay tuned.\n'));
136
+ }
124
137
  }