create-express-kickstart 1.1.1 → 1.1.3

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/bin/cli.js CHANGED
@@ -72,6 +72,8 @@ async function init() {
72
72
 
73
73
  const initGit = (await question('\nšŸ‘‰ Initialize a git repository? [Y/n] ')).toLowerCase() !== 'n';
74
74
  const initDocker = (await question('šŸ‘‰ Include Dockerfile & docker-compose.yml? [Y/n] ')).toLowerCase() !== 'n';
75
+ const initAuth = (await question('šŸ‘‰ Include basic JWT Auth boilerplate? [Y/n] ')).toLowerCase() !== 'n';
76
+ const useESM = (await question('šŸ‘‰ Use ECMAScript Modules (ESM) over CommonJS? [Y/n] ')).toLowerCase() !== 'n';
75
77
 
76
78
  rl.close();
77
79
 
@@ -124,6 +126,32 @@ async function init() {
124
126
  }
125
127
  }
126
128
 
129
+ if (initAuth) {
130
+ console.log(`šŸ” Adding Auth templates...`);
131
+ // Need to ensure directories exist
132
+ fs.mkdirSync(path.join(projectPath, 'src', 'controllers'), { recursive: true });
133
+ fs.mkdirSync(path.join(projectPath, 'src', 'middlewares'), { recursive: true });
134
+ fs.mkdirSync(path.join(projectPath, 'src', 'routes'), { recursive: true });
135
+
136
+ // Copy the templates
137
+ fs.copyFileSync(
138
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.controller.js'),
139
+ path.join(projectPath, 'src', 'controllers', 'auth.controller.js')
140
+ );
141
+ fs.copyFileSync(
142
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.middleware.js'),
143
+ path.join(projectPath, 'src', 'middlewares', 'auth.middleware.js')
144
+ );
145
+ fs.copyFileSync(
146
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.routes.js'),
147
+ path.join(projectPath, 'src', 'routes', 'auth.routes.js')
148
+ );
149
+
150
+ // Append JWT secret to env example
151
+ fs.appendFileSync(path.join(projectPath, '.env.example'), '\nJWT_SECRET=supersecretjwtkey123\n');
152
+ fs.appendFileSync(path.join(projectPath, '.env'), '\nJWT_SECRET=supersecretjwtkey123\n');
153
+ }
154
+
127
155
  // 3. Create package.json
128
156
  console.log(`šŸ“¦ Setting up package.json...`);
129
157
  const packageJsonTemplate = {
@@ -131,7 +159,7 @@ async function init() {
131
159
  version: "1.0.0",
132
160
  description: description || "A production-ready Node.js Express API",
133
161
  main: "src/server.js",
134
- type: "module",
162
+ type: useESM ? "module" : "commonjs",
135
163
  scripts: {
136
164
  "start": "node src/server.js",
137
165
  "dev": "nodemon src/server.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-express-kickstart",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Production-ready CLI starter for Express APIs",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {
@@ -0,0 +1,5 @@
1
+ export const authController = {
2
+ login: (req, res) => res.json({ message: "Login logic goes here." }),
3
+ register: (req, res) => res.json({ message: "Register logic goes here." }),
4
+ profile: (req, res) => res.json({ message: "Protected profile data." })
5
+ };
@@ -0,0 +1,5 @@
1
+ export const authMiddleware = (req, res, next) => {
2
+ // Add JWT verification logic here
3
+ console.log('Verifying token...');
4
+ next();
5
+ };
@@ -0,0 +1,11 @@
1
+ import { Router } from 'express';
2
+ import { authController } from '../controllers/auth.controller.js';
3
+ import { authMiddleware } from '../middlewares/auth.middleware.js';
4
+
5
+ const router = Router();
6
+
7
+ router.post('/login', authController.login);
8
+ router.post('/register', authController.register);
9
+ router.get('/profile', authMiddleware, authController.profile);
10
+
11
+ export default router;