alexis-cli 1.0.1 β†’ 1.0.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.
@@ -1,5 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const projectRoot = process.cwd();
4
+ const srcDir = path.join(projectRoot, 'src');
3
5
 
4
6
  module.exports = () => {
5
7
  console.log('πŸ” Generating Auth system...');
@@ -8,7 +10,7 @@ module.exports = () => {
8
10
  1. USER ENTITY
9
11
  ========================= */
10
12
 
11
- const entityDir = path.join(__dirname, '../../src/entities');
13
+ const entityDir = path.join(srcDir, 'entities');
12
14
  const userEntityPath = path.join(entityDir, 'User.entity.js');
13
15
 
14
16
  if (!fs.existsSync(entityDir)) {
@@ -41,7 +43,7 @@ module.exports = new EntitySchema({
41
43
  2. AUTH MODULE
42
44
  ========================= */
43
45
 
44
- const authDir = path.join(__dirname, '../../src/modules/v1/auth');
46
+ const authDir = path.join(srcDir, 'modules/v1/auth');
45
47
 
46
48
  if (!fs.existsSync(authDir)) {
47
49
  fs.mkdirSync(authDir, { recursive: true });
@@ -216,7 +218,7 @@ module.exports = router;
216
218
  3. AUTH MIDDLEWARE
217
219
  ========================= */
218
220
 
219
- const middlewareDir = path.join(__dirname, '../../src/middlewares');
221
+ const middlewareDir = path.join(srcDir, 'middlewares');
220
222
  const middlewarePath = path.join(middlewareDir, 'auth.middleware.js');
221
223
 
222
224
  if (!fs.existsSync(middlewareDir)) {
@@ -250,7 +252,13 @@ module.exports = (req, res, next) => {
250
252
  4. JWT CONFIG
251
253
  ========================= */
252
254
 
253
- const jwtConfigPath = path.join(__dirname, '../../src/config/jwt.js');
255
+ const configDir = path.join(srcDir, 'config');
256
+
257
+ if (!fs.existsSync(configDir)) {
258
+ fs.mkdirSync(configDir, { recursive: true });
259
+ }
260
+
261
+ const jwtConfigPath = path.join(configDir, 'jwt.js');
254
262
 
255
263
  if (!fs.existsSync(jwtConfigPath)) {
256
264
  fs.writeFileSync(
@@ -274,8 +282,8 @@ module.exports = (req, res, next) => {
274
282
  ========================= */
275
283
 
276
284
  const routesIndexPath = path.join(
277
- __dirname,
278
- '../../src/routes/v1/index.js'
285
+ srcDir,
286
+ 'routes/v1/index.js'
279
287
  );
280
288
 
281
289
  if (!fs.existsSync(routesIndexPath)) {
@@ -1,5 +1,8 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const projectRoot = process.cwd();
4
+ const srcDir = path.join(projectRoot, 'src');
5
+
3
6
 
4
7
  module.exports = (entityName) => {
5
8
  if (!entityName) {
@@ -11,24 +14,17 @@ module.exports = (entityName) => {
11
14
  const EntityName =
12
15
  entityName.charAt(0).toUpperCase() + entityName.slice(1);
13
16
 
14
- // πŸ”Ž VΓ©rifier l'Entity
15
- const entityPath = path.join(
16
- __dirname,
17
- '../../src/entities',
18
- `${EntityName}.entity.js`
19
- );
17
+ // VΓ©rifier l'Entity
18
+ const entityPath = path.join(srcDir, 'entities', `${EntityName}.entity.js`);
19
+
20
20
 
21
21
  if (!fs.existsSync(entityPath)) {
22
22
  console.error(`❌ Entity "${EntityName}" not found`);
23
23
  process.exit(1);
24
24
  }
25
25
 
26
- // πŸ“ Module
27
- const moduleDir = path.join(
28
- __dirname,
29
- '../../src/modules/v1',
30
- moduleName
31
- );
26
+ // Module
27
+ const moduleDir = path.join(srcDir, 'modules/v1', moduleName);
32
28
 
33
29
  if (fs.existsSync(moduleDir)) {
34
30
  console.error(`❌ Module "${moduleName}" already exists`);
@@ -244,15 +240,17 @@ module.exports = router;
244
240
  /* ======================
245
241
  AUTO-REGISTER ROUTE
246
242
  ====================== */
247
- const routesIndexPath = path.join(
248
- __dirname,
249
- '../../src/routes/v1/index.js'
250
- );
243
+ const routesIndexPath = path.join(srcDir, 'routes/v1/index.js');
244
+
245
+ if (!fs.existsSync(routesIndexPath)) {
246
+ console.warn('⚠️ routes/v1/index.js not found, skipping route registration');
247
+ return;
248
+ }
251
249
 
252
250
  let index = fs.readFileSync(routesIndexPath, 'utf8');
253
251
 
254
252
  const importLine =
255
- `const ${moduleName}Routes = require('../../../src/modules/v1/${moduleName}/${moduleName}.routes');`;
253
+ `const ${moduleName}Routes = require('../../modules/v1/${moduleName}/${moduleName}.routes');`;
256
254
  const routeLine =
257
255
  `router.use('/${moduleName}', ${moduleName}Routes);`;
258
256
 
@@ -2,6 +2,8 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const readline = require('readline');
4
4
  const entityTypes = require('../bin/cli/entity-types');
5
+ const projectRoot = process.cwd();
6
+ const srcDir = path.join(projectRoot, 'src');
5
7
 
6
8
  module.exports = async (name) => {
7
9
  if (!name) {
@@ -12,7 +14,7 @@ module.exports = async (name) => {
12
14
  const entityName = name.charAt(0).toUpperCase() + name.slice(1);
13
15
  const tableName = name.toLowerCase() + 's';
14
16
 
15
- const entityDir = path.join(__dirname, '../../src/entities');
17
+ const entityDir = path.join(srcDir, 'entities');
16
18
  const entityPath = path.join(entityDir, `${entityName}.entity.js`);
17
19
 
18
20
  if (!fs.existsSync(entityDir)) {
@@ -6,8 +6,31 @@ module.exports = (name) => {
6
6
  process.exit(1);
7
7
  }
8
8
 
9
- execSync(
10
- `npx typeorm migration:generate src/migrations/${name} -d src/config/orm.js --outputJs`,
11
- { stdio: 'inherit' }
12
- );
9
+ console.log(`πŸ“¦ Generating migration "${name}"...`);
10
+
11
+ try {
12
+ execSync(
13
+ `npx typeorm migration:generate src/migrations/${name} -d src/config/orm.js --outputJs`,
14
+ { stdio: 'inherit' }
15
+ );
16
+
17
+ console.log('βœ… Migration generated from schema changes');
18
+ } catch (error) {
19
+ const message = error?.message || '';
20
+
21
+ if (message.includes('No changes in database schema were found')) {
22
+ console.warn('⚠️ No schema changes detected');
23
+ console.log('➑️ Creating empty migration instead');
24
+
25
+ execSync(
26
+ `npx typeorm migration:create src/migrations/${name}`,
27
+ { stdio: 'inherit' }
28
+ );
29
+
30
+ console.log('βœ… Empty migration created');
31
+ } else {
32
+ console.error('❌ Migration generation failed');
33
+ process.exit(1);
34
+ }
35
+ }
13
36
  };
@@ -1,5 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const projectRoot = process.cwd();
4
+ const srcDir = path.join(projectRoot, 'src');
3
5
 
4
6
  module.exports = (moduleName) => {
5
7
  if (!moduleName) {
@@ -10,10 +12,10 @@ module.exports = (moduleName) => {
10
12
  const entityName =
11
13
  moduleName.charAt(0).toUpperCase() + moduleName.slice(1);
12
14
 
13
- // πŸ”Ž VΓ©rifier que l'Entity existe
15
+ // VΓ©rifier que l'Entity existe
14
16
  const entityPath = path.join(
15
- __dirname,
16
- '../../src/entities',
17
+ srcDir,
18
+ 'entities',
17
19
  `${entityName}.entity.js`
18
20
  );
19
21
 
@@ -24,10 +26,10 @@ module.exports = (moduleName) => {
24
26
  process.exit(1);
25
27
  }
26
28
 
27
- // πŸ“ CrΓ©ation du module
29
+ // CrΓ©ation du module
28
30
  const basePath = path.join(
29
- __dirname,
30
- '../../src/modules/v1',
31
+ srcDir,
32
+ 'modules/v1',
31
33
  moduleName
32
34
  );
33
35
 
@@ -138,10 +140,10 @@ module.exports = router;
138
140
 
139
141
  console.log(`βœ… Module v1 "${moduleName}" created and linked to entity "${entityName}"`);
140
142
 
141
- // πŸ”— Auto-register route
143
+ // Auto-register route
142
144
  const routesIndexPath = path.join(
143
- __dirname,
144
- '../../src/routes/v1/index.js'
145
+ srcDir,
146
+ 'routes/v1/index.js'
145
147
  );
146
148
 
147
149
  if (!fs.existsSync(routesIndexPath)) {
@@ -151,7 +153,8 @@ module.exports = router;
151
153
 
152
154
  let indexContent = fs.readFileSync(routesIndexPath, 'utf8');
153
155
 
154
- const importLine = `const ${moduleName}Routes = require('../../../src/modules/v1/${moduleName}/${moduleName}.routes');`;
156
+ const importLine =
157
+ `const ${moduleName}Routes = require('../../modules/v1/${moduleName}/${moduleName}.routes');`;
155
158
  const routeLine = `router.use('/${moduleName}', ${moduleName}Routes);`;
156
159
 
157
160
  if (!indexContent.includes(importLine)) {
@@ -123,7 +123,7 @@ const buildExampleFromEntity = (entity) => {
123
123
  ====================================================== */
124
124
 
125
125
  module.exports = () => {
126
- const projectRoot = path.join(__dirname, '../..');
126
+ const projectRoot = process.cwd();
127
127
  const srcDir = path.join(projectRoot, 'src');
128
128
  const swaggerDir = path.join(srcDir, 'swagger');
129
129
 
@@ -155,6 +155,17 @@ module.exports = () => {
155
155
  /* ========= ENTITIES β†’ SCHEMAS ========= */
156
156
 
157
157
  const entitiesDir = path.join(srcDir, 'entities');
158
+ if (!fs.existsSync(entitiesDir)) {
159
+ console.warn('⚠️ No entities directory found, skipping Swagger generation');
160
+ return;
161
+ }
162
+
163
+ const modulesDir = path.join(srcDir, 'modules/v1');
164
+ if (!fs.existsSync(modulesDir)) {
165
+ console.warn('⚠️ No modules directory found, skipping Swagger generation');
166
+ return;
167
+ }
168
+
158
169
 
159
170
  fs.readdirSync(entitiesDir).forEach((file) => {
160
171
  if (!file.endsWith('.entity.js')) return;
@@ -245,44 +256,11 @@ module.exports = () => {
245
256
  };
246
257
  generateAuthSwagger(swagger);
247
258
 
248
- const modulesDir = path.join(srcDir, 'modules/v1');
249
-
250
259
  fs.readdirSync(modulesDir).forEach((moduleName) => {
251
260
  if (moduleName === 'auth') return;
252
261
  const modulePath = path.join(modulesDir, moduleName);
253
262
  if (!fs.statSync(modulePath).isDirectory()) return;
254
263
 
255
- /* ----- AUTH ----- */
256
- if (moduleName === 'auth') {
257
- swagger.paths['/auth/register'] = {
258
- post: {
259
- tags: ['Auth'],
260
- summary: 'Register',
261
- description: 'Create a new user account',
262
- requestBody: {
263
- required: true,
264
- content: {
265
- 'application/json': {
266
- schema: {
267
- type: 'object',
268
- properties: {
269
- email: { type: 'string' },
270
- password: { type: 'string' }
271
- }
272
- },
273
- example: {
274
- email: 'user@example.com',
275
- password: 'password123'
276
- }
277
- }
278
- }
279
- },
280
- responses: { 201: { description: 'User created' } }
281
- }
282
- };
283
- return;
284
- }
285
-
286
264
  /* ----- CRUD ----- */
287
265
 
288
266
  const entityName =
@@ -1,15 +1,33 @@
1
1
  const { execSync } = require('child_process');
2
2
 
3
3
  exports.run = () => {
4
- execSync(
5
- `npx typeorm migration:run -d src/config/orm.js`,
6
- { stdio: 'inherit' }
7
- );
4
+ console.log('πŸš€ Running database migrations...');
5
+
6
+ try {
7
+ execSync(
8
+ `npx typeorm migration:run -d src/config/orm.js`,
9
+ { stdio: 'inherit' }
10
+ );
11
+
12
+ console.log('βœ… Migrations executed successfully');
13
+ } catch (error) {
14
+ console.error('❌ Migration failed');
15
+ process.exit(1);
16
+ }
8
17
  };
9
18
 
10
19
  exports.rollback = () => {
11
- execSync(
12
- `npx typeorm migration:revert -d src/config/orm.js`,
13
- { stdio: 'inherit' }
14
- );
20
+ console.log('βͺ Reverting last migration...');
21
+
22
+ try {
23
+ execSync(
24
+ `npx typeorm migration:revert -d src/config/orm.js`,
25
+ { stdio: 'inherit' }
26
+ );
27
+
28
+ console.log('βœ… Migration reverted successfully');
29
+ } catch (error) {
30
+ console.error('❌ Rollback failed');
31
+ process.exit(1);
32
+ }
15
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alexis-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "alexis": "bin/alexis.js"