create-express-kickstart 1.1.1 โ†’ 1.2.0

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,9 @@ 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';
77
+ const initTests = (await question('๐Ÿ‘‰ Include Jest setup and boilerplate tests? [Y/n] ')).toLowerCase() !== 'n';
75
78
 
76
79
  rl.close();
77
80
 
@@ -124,6 +127,41 @@ async function init() {
124
127
  }
125
128
  }
126
129
 
130
+ if (initAuth) {
131
+ console.log(`๐Ÿ” Adding Auth templates...`);
132
+ // Need to ensure directories exist
133
+ fs.mkdirSync(path.join(projectPath, 'src', 'controllers'), { recursive: true });
134
+ fs.mkdirSync(path.join(projectPath, 'src', 'middlewares'), { recursive: true });
135
+ fs.mkdirSync(path.join(projectPath, 'src', 'routes'), { recursive: true });
136
+
137
+ // Copy the templates
138
+ fs.copyFileSync(
139
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.controller.js'),
140
+ path.join(projectPath, 'src', 'controllers', 'auth.controller.js')
141
+ );
142
+ fs.copyFileSync(
143
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.middleware.js'),
144
+ path.join(projectPath, 'src', 'middlewares', 'auth.middleware.js')
145
+ );
146
+ fs.copyFileSync(
147
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.routes.js'),
148
+ path.join(projectPath, 'src', 'routes', 'auth.routes.js')
149
+ );
150
+
151
+ // Append JWT secret to env example
152
+ fs.appendFileSync(path.join(projectPath, '.env.example'), '\nJWT_SECRET=supersecretjwtkey123\n');
153
+ fs.appendFileSync(path.join(projectPath, '.env'), '\nJWT_SECRET=supersecretjwtkey123\n');
154
+ }
155
+
156
+ if (initTests) {
157
+ console.log(`๐Ÿงช Adding Jest test templates...`);
158
+ fs.mkdirSync(path.join(projectPath, 'tests'), { recursive: true });
159
+ fs.copyFileSync(
160
+ path.join(__dirname, '..', 'templates', 'tests', 'healthcheck.test.js'),
161
+ path.join(projectPath, 'tests', 'healthcheck.test.js')
162
+ );
163
+ }
164
+
127
165
  // 3. Create package.json
128
166
  console.log(`๐Ÿ“ฆ Setting up package.json...`);
129
167
  const packageJsonTemplate = {
@@ -131,7 +169,7 @@ async function init() {
131
169
  version: "1.0.0",
132
170
  description: description || "A production-ready Node.js Express API",
133
171
  main: "src/server.js",
134
- type: "module",
172
+ type: useESM ? "module" : "commonjs",
135
173
  scripts: {
136
174
  "start": "node src/server.js",
137
175
  "dev": "nodemon src/server.js"
@@ -148,6 +186,12 @@ async function init() {
148
186
  packageJsonTemplate.scripts.format = "prettier --write \"src/**/*.{js,json}\"";
149
187
  }
150
188
 
189
+ if (initTests) {
190
+ packageJsonTemplate.scripts.test = useESM
191
+ ? "node --experimental-vm-modules node_modules/jest/bin/jest.js"
192
+ : "jest";
193
+ }
194
+
151
195
  // Write package.json
152
196
  fs.writeFileSync(
153
197
  path.join(projectPath, 'package.json'),
@@ -164,6 +208,9 @@ async function init() {
164
208
  const devDependenciesToInstall = ['nodemon'];
165
209
  if (deps.prettier) devDependenciesToInstall.push('prettier');
166
210
  if (installPinoPretty) devDependenciesToInstall.push('pino-pretty');
211
+ if (initTests) {
212
+ devDependenciesToInstall.push('jest', 'supertest');
213
+ }
167
214
  const devDepString = devDependenciesToInstall.join(' ');
168
215
 
169
216
  console.log(`\nโณ Installing selected core dependencies (${dependenciesToInstall.join(', ')}). This might take a minute...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-express-kickstart",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
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;
@@ -0,0 +1,12 @@
1
+ import request from 'supertest';
2
+ import { app } from '../src/app.js';
3
+
4
+ describe('Healthcheck API', () => {
5
+ it('should return 200 OK', async () => {
6
+ const response = await request(app).get('/api/v1/healthcheck');
7
+
8
+ expect(response.status).toBe(200);
9
+ expect(response.body.success).toBe(true);
10
+ expect(response.body.message).toBe('Api is runing properly');
11
+ });
12
+ });