@nishant0121/set-it-up 0.0.9 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nishant0121/set-it-up",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A high-performance CLI tool to bootstrap and forge new projects with pre-configured templates, prerequisite checking, and interactive setup.",
5
5
  "license": "ISC",
6
6
  "author": "Nishant Patil",
@@ -0,0 +1,86 @@
1
+ import { execa } from 'execa';
2
+ import ora from 'ora';
3
+ import chalk from 'chalk';
4
+ import fs from 'fs-extra';
5
+ import path from 'path';
6
+
7
+ import {
8
+ getPackageJson,
9
+ getTsConfig,
10
+ getIndex,
11
+ getRouteIndex,
12
+ getController
13
+ } from '../templates/express/main.js';
14
+
15
+ export async function setupExpress(answers, expressAnswers) {
16
+ const spinner = ora('Initializing Express project...').start();
17
+ try {
18
+ const { projectName, packageManager } = answers;
19
+ const isTypescript = expressAnswers.language === 'TypeScript';
20
+ const projectPath = path.join(process.cwd(), projectName);
21
+
22
+ // 1. Create Project Directory
23
+ await fs.ensureDir(projectPath);
24
+
25
+ // 2. Create package.json
26
+ spinner.text = 'Creating package.json...';
27
+ const packageJsonContent = getPackageJson(projectName, isTypescript);
28
+ await fs.writeFile(path.join(projectPath, 'package.json'), packageJsonContent);
29
+
30
+ // 3. Create tsconfig.json (if TypeScript)
31
+ if (isTypescript) {
32
+ spinner.text = 'Creating tsconfig.json...';
33
+ const tsConfigContent = getTsConfig();
34
+ await fs.writeFile(path.join(projectPath, 'tsconfig.json'), tsConfigContent);
35
+ }
36
+
37
+ // 4. Create Source Directories and Files
38
+ spinner.text = 'Generating project structure...';
39
+ const srcDir = path.join(projectPath, 'src');
40
+ const routesDir = path.join(srcDir, 'routes');
41
+ const controllersDir = path.join(srcDir, 'controllers');
42
+
43
+ await fs.ensureDir(srcDir);
44
+ await fs.ensureDir(routesDir);
45
+ await fs.ensureDir(controllersDir);
46
+
47
+ const ext = isTypescript ? 'ts' : 'js';
48
+
49
+ // src/index.ts or src/index.js
50
+ await fs.writeFile(path.join(srcDir, `index.${ext}`), getIndex(isTypescript));
51
+
52
+ // src/routes/index.ts or src/routes/index.js
53
+ await fs.writeFile(path.join(routesDir, `index.${ext}`), getRouteIndex(isTypescript));
54
+
55
+ // src/controllers/exampleController.ts or src/controllers/exampleController.js
56
+ await fs.writeFile(path.join(controllersDir, `exampleController.${ext}`), getController(isTypescript));
57
+
58
+ // Create .env file
59
+ await fs.writeFile(path.join(projectPath, '.env'), 'PORT=3000\n');
60
+
61
+ // Create .gitignore
62
+ const gitignoreContent = `node_modules
63
+ .env
64
+ dist
65
+ .DS_Store
66
+ coverage
67
+ `;
68
+ await fs.writeFile(path.join(projectPath, '.gitignore'), gitignoreContent);
69
+
70
+
71
+ // 5. Install Dependencies
72
+ spinner.text = 'Installing dependencies...';
73
+ const installCmd = packageManager === 'npm' ? 'install' : 'add';
74
+ await execa(packageManager, [installCmd], { cwd: projectPath });
75
+
76
+ spinner.succeed(chalk.green(`Express project ${projectName} created successfully! šŸš€`));
77
+ console.log(chalk.cyan(`
78
+ To get started:
79
+ cd ${projectName}
80
+ ${packageManager} run dev`));
81
+
82
+ } catch (error) {
83
+ spinner.fail('Setup failed.');
84
+ console.error(error);
85
+ }
86
+ }
@@ -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
+ };
package/src/wizard.js CHANGED
@@ -5,6 +5,7 @@ import boxen from 'boxen';
5
5
  import { checkPrerequisites } from './utils/checkEnv.js';
6
6
  import { setupReactNative } from './engines/reactNative.js';
7
7
  import { setupReact } from './engines/react.js';
8
+ import { setupExpress } from './engines/express.js';
8
9
 
9
10
  export async function mainWizard() {
10
11
  // Clear the console for a fresh start
@@ -39,7 +40,7 @@ export async function mainWizard() {
39
40
  type: 'rawlist',
40
41
  name: 'projectType',
41
42
  message: 'What do you want to build today?',
42
- choices: ['React', 'React Native', 'Next.js (Coming Soon)', 'Custom GitHub Template'],
43
+ choices: ['React', 'React Native', 'Express.js', 'Next.js (Coming Soon)', 'Custom GitHub Template'],
43
44
  },
44
45
  {
45
46
  type: 'input',
@@ -118,6 +119,18 @@ export async function mainWizard() {
118
119
 
119
120
  await setupReact(answers, reactAnswers);
120
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
+
121
134
  } else {
122
135
  console.log(chalk.yellow('\n🚧 This feature is coming soon! Stay tuned.\n'));
123
136
  }