@engjts/nexus 0.1.4 → 0.1.5
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/dist/advanced/postman/index.d.ts +2 -2
- package/dist/advanced/postman/index.js +2 -2
- package/dist/advanced/static/index.d.ts +3 -3
- package/dist/advanced/static/index.js +3 -3
- package/dist/advanced/static/publicDir.d.ts +2 -2
- package/dist/advanced/static/publicDir.js +2 -2
- package/dist/advanced/static/spa.d.ts +2 -2
- package/dist/advanced/static/spa.js +2 -2
- package/dist/advanced/swagger/index.d.ts +2 -2
- package/dist/advanced/swagger/index.js +2 -2
- package/dist/advanced/swagger/swagger.d.ts +3 -3
- package/dist/advanced/swagger/swagger.js +3 -3
- package/dist/cli/commands/add.js +19 -19
- package/dist/cli/commands/add.js.map +1 -1
- package/documentation/19-class-based-routing.md +7 -7
- package/package.json +1 -1
- package/src/advanced/postman/index.ts +2 -2
- package/src/advanced/static/index.ts +3 -3
- package/src/advanced/static/publicDir.ts +2 -2
- package/src/advanced/static/spa.ts +2 -2
- package/src/advanced/swagger/index.ts +2 -2
- package/src/advanced/swagger/swagger.ts +3 -3
- package/src/cli/commands/add.ts +19 -19
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* const app = createApp();
|
|
10
10
|
*
|
|
11
11
|
* // Zero config
|
|
12
|
-
* app.
|
|
12
|
+
* app.plugin(postman());
|
|
13
13
|
*
|
|
14
14
|
* // With config
|
|
15
|
-
* app.
|
|
15
|
+
* app.plugin(postman({
|
|
16
16
|
* path: '/postman',
|
|
17
17
|
* name: 'My API',
|
|
18
18
|
* baseUrl: 'http://localhost:3000'
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* const app = createApp();
|
|
11
11
|
*
|
|
12
12
|
* // Zero config
|
|
13
|
-
* app.
|
|
13
|
+
* app.plugin(postman());
|
|
14
14
|
*
|
|
15
15
|
* // With config
|
|
16
|
-
* app.
|
|
16
|
+
* app.plugin(postman({
|
|
17
17
|
* path: '/postman',
|
|
18
18
|
* name: 'My API',
|
|
19
19
|
* baseUrl: 'http://localhost:3000'
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
* const app = createApp();
|
|
11
11
|
*
|
|
12
12
|
* // Basic usage - serve from ./public
|
|
13
|
-
* app.
|
|
13
|
+
* app.plugin(serveStatic());
|
|
14
14
|
*
|
|
15
15
|
* // Custom directory
|
|
16
|
-
* app.
|
|
16
|
+
* app.plugin(serveStatic({ root: './assets' }));
|
|
17
17
|
*
|
|
18
18
|
* // With prefix
|
|
19
|
-
* app.
|
|
19
|
+
* app.plugin(serveStatic({
|
|
20
20
|
* root: './public',
|
|
21
21
|
* prefix: '/static' // /static/image.png → ./public/image.png
|
|
22
22
|
* }));
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* const app = createApp();
|
|
12
12
|
*
|
|
13
13
|
* // Basic usage - serve from ./public
|
|
14
|
-
* app.
|
|
14
|
+
* app.plugin(serveStatic());
|
|
15
15
|
*
|
|
16
16
|
* // Custom directory
|
|
17
|
-
* app.
|
|
17
|
+
* app.plugin(serveStatic({ root: './assets' }));
|
|
18
18
|
*
|
|
19
19
|
* // With prefix
|
|
20
|
-
* app.
|
|
20
|
+
* app.plugin(serveStatic({
|
|
21
21
|
* root: './public',
|
|
22
22
|
* prefix: '/static' // /static/image.png → ./public/image.png
|
|
23
23
|
* }));
|
|
@@ -4,8 +4,8 @@ import { Plugin } from '../../core/types';
|
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```typescript
|
|
7
|
-
* app.
|
|
8
|
-
* app.
|
|
7
|
+
* app.plugin(publicDir()); // ./public
|
|
8
|
+
* app.plugin(publicDir('./assets')); // ./assets
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
11
|
export declare function publicDir(root?: string): Plugin;
|
|
@@ -7,8 +7,8 @@ const serveStatic_1 = require("./serveStatic");
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
|
-
* app.
|
|
11
|
-
* app.
|
|
10
|
+
* app.plugin(publicDir()); // ./public
|
|
11
|
+
* app.plugin(publicDir('./assets')); // ./assets
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
function publicDir(root = './public') {
|
|
@@ -5,8 +5,8 @@ import { Plugin } from '../../core/types';
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```typescript
|
|
8
|
-
* app.
|
|
9
|
-
* app.
|
|
8
|
+
* app.plugin(spa()); // SPA from ./public
|
|
9
|
+
* app.plugin(spa('./dist')); // SPA from ./dist
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
12
|
export declare function spa(root?: string): Plugin;
|
|
@@ -8,8 +8,8 @@ const serveStatic_1 = require("./serveStatic");
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```typescript
|
|
11
|
-
* app.
|
|
12
|
-
* app.
|
|
11
|
+
* app.plugin(spa()); // SPA from ./public
|
|
12
|
+
* app.plugin(spa('./dist')); // SPA from ./dist
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
function spa(root = './public') {
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* const app = createApp();
|
|
10
10
|
*
|
|
11
11
|
* // Zero config - just works!
|
|
12
|
-
* app.
|
|
12
|
+
* app.plugin(swagger());
|
|
13
13
|
*
|
|
14
14
|
* // With config
|
|
15
|
-
* app.
|
|
15
|
+
* app.plugin(swagger({
|
|
16
16
|
* path: '/docs',
|
|
17
17
|
* info: { title: 'My API', version: '1.0.0' }
|
|
18
18
|
* }));
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* const app = createApp();
|
|
11
11
|
*
|
|
12
12
|
* // Zero config - just works!
|
|
13
|
-
* app.
|
|
13
|
+
* app.plugin(swagger());
|
|
14
14
|
*
|
|
15
15
|
* // With config
|
|
16
|
-
* app.
|
|
16
|
+
* app.plugin(swagger({
|
|
17
17
|
* path: '/docs',
|
|
18
18
|
* info: { title: 'My API', version: '1.0.0' }
|
|
19
19
|
* }));
|
|
@@ -6,10 +6,10 @@ import { SwaggerConfig } from './types';
|
|
|
6
6
|
* @example
|
|
7
7
|
* ```typescript
|
|
8
8
|
* // Minimal setup - auto-detects everything
|
|
9
|
-
* app.
|
|
9
|
+
* app.plugin(swagger());
|
|
10
10
|
*
|
|
11
11
|
* // With custom info
|
|
12
|
-
* app.
|
|
12
|
+
* app.plugin(swagger({
|
|
13
13
|
* info: {
|
|
14
14
|
* title: 'My Awesome API',
|
|
15
15
|
* version: '2.0.0',
|
|
@@ -18,7 +18,7 @@ import { SwaggerConfig } from './types';
|
|
|
18
18
|
* }));
|
|
19
19
|
*
|
|
20
20
|
* // Full configuration
|
|
21
|
-
* app.
|
|
21
|
+
* app.plugin(swagger({
|
|
22
22
|
* path: '/api-docs',
|
|
23
23
|
* specPath: '/swagger.json',
|
|
24
24
|
* theme: 'dark',
|
|
@@ -12,10 +12,10 @@ const generateSpec_1 = require("./generateSpec");
|
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
14
14
|
* // Minimal setup - auto-detects everything
|
|
15
|
-
* app.
|
|
15
|
+
* app.plugin(swagger());
|
|
16
16
|
*
|
|
17
17
|
* // With custom info
|
|
18
|
-
* app.
|
|
18
|
+
* app.plugin(swagger({
|
|
19
19
|
* info: {
|
|
20
20
|
* title: 'My Awesome API',
|
|
21
21
|
* version: '2.0.0',
|
|
@@ -24,7 +24,7 @@ const generateSpec_1 = require("./generateSpec");
|
|
|
24
24
|
* }));
|
|
25
25
|
*
|
|
26
26
|
* // Full configuration
|
|
27
|
-
* app.
|
|
27
|
+
* app.plugin(swagger({
|
|
28
28
|
* path: '/api-docs',
|
|
29
29
|
* specPath: '/swagger.json',
|
|
30
30
|
* theme: 'dark',
|
package/dist/cli/commands/add.js
CHANGED
|
@@ -21,19 +21,19 @@ class AddCommand {
|
|
|
21
21
|
playground: {
|
|
22
22
|
name: 'playground',
|
|
23
23
|
import: 'playground',
|
|
24
|
-
feature: 'playground()',
|
|
24
|
+
feature: 'plugin(playground())',
|
|
25
25
|
description: 'Interactive API playground at /playground',
|
|
26
26
|
},
|
|
27
27
|
postman: {
|
|
28
28
|
name: 'postman',
|
|
29
29
|
import: 'postman',
|
|
30
|
-
feature: 'postman()',
|
|
30
|
+
feature: 'plugin(postman())',
|
|
31
31
|
description: 'Postman collection export at /postman',
|
|
32
32
|
},
|
|
33
33
|
swagger: {
|
|
34
34
|
name: 'swagger',
|
|
35
35
|
import: 'swagger',
|
|
36
|
-
feature: 'swagger()',
|
|
36
|
+
feature: 'plugin(swagger())',
|
|
37
37
|
description: 'Swagger/OpenAPI documentation at /docs',
|
|
38
38
|
},
|
|
39
39
|
};
|
|
@@ -63,7 +63,7 @@ class AddCommand {
|
|
|
63
63
|
// Read current file
|
|
64
64
|
let content = await file_system_1.FileSystem.readFile(fullPath);
|
|
65
65
|
// Check if plugin is already added
|
|
66
|
-
if (content.includes(`app.
|
|
66
|
+
if (content.includes(`app.plugin(${config.feature})`)) {
|
|
67
67
|
this.logger.info(`Plugin "${plugin}" is already added to your project`);
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
@@ -82,22 +82,22 @@ class AddCommand {
|
|
|
82
82
|
// Add new import at the top
|
|
83
83
|
content = `import { ${config.import} } from '@engjts/nexus';\n${content}`;
|
|
84
84
|
}
|
|
85
|
-
// Find where to add app.
|
|
86
|
-
// Look for existing app.
|
|
87
|
-
const
|
|
85
|
+
// Find where to add app.plugin()
|
|
86
|
+
// Look for existing app.plugin() calls or app.use() calls
|
|
87
|
+
const pluginPattern = /app\.plugin\([^)]+\);?\n?/g;
|
|
88
88
|
const usePattern = /app\.use\([^)]+\);?\n?/;
|
|
89
89
|
const listenPattern = /app\.listen\(/;
|
|
90
90
|
let insertPosition = -1;
|
|
91
|
-
let insertText = `app.
|
|
92
|
-
// Find last app.
|
|
93
|
-
let
|
|
91
|
+
let insertText = `app.plugin(${config.feature});\n`;
|
|
92
|
+
// Find last app.plugin() call
|
|
93
|
+
let lastPluginMatch = null;
|
|
94
94
|
let match;
|
|
95
|
-
while ((match =
|
|
96
|
-
|
|
95
|
+
while ((match = pluginPattern.exec(content)) !== null) {
|
|
96
|
+
lastPluginMatch = match;
|
|
97
97
|
}
|
|
98
|
-
if (
|
|
99
|
-
// Insert after last
|
|
100
|
-
insertPosition =
|
|
98
|
+
if (lastPluginMatch) {
|
|
99
|
+
// Insert after last plugin
|
|
100
|
+
insertPosition = lastPluginMatch.index + lastPluginMatch[0].length;
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
103
|
// Find app.use() or app.listen()
|
|
@@ -106,20 +106,20 @@ class AddCommand {
|
|
|
106
106
|
if (useMatch && useMatch.index !== undefined) {
|
|
107
107
|
// Insert before first app.use()
|
|
108
108
|
insertPosition = useMatch.index;
|
|
109
|
-
insertText = `//
|
|
109
|
+
insertText = `// Plugins\napp.plugin(${config.feature});\n\n`;
|
|
110
110
|
}
|
|
111
111
|
else if (listenMatch && listenMatch.index !== undefined) {
|
|
112
112
|
// Insert before app.listen()
|
|
113
113
|
insertPosition = listenMatch.index;
|
|
114
|
-
insertText = `//
|
|
114
|
+
insertText = `// Plugins\napp.plugin(${config.feature});\n\n`;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
if (insertPosition === -1) {
|
|
118
118
|
this.logger.error('Could not find a suitable location to add the plugin');
|
|
119
|
-
this.logger.info('Please add manually: app.
|
|
119
|
+
this.logger.info('Please add manually: app.plugin(' + config.feature + ')');
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
// Insert the
|
|
122
|
+
// Insert the plugin call
|
|
123
123
|
content = content.slice(0, insertPosition) + insertText + content.slice(insertPosition);
|
|
124
124
|
// Write back
|
|
125
125
|
await file_system_1.FileSystem.writeFile(fullPath, content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/cli/commands/add.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,sDAAkD;AAWlD,MAAa,UAAU;IACrB,IAAI,GAAG,KAAK,CAAC;IACb,WAAW,GAAG,mCAAmC,CAAC;IAClD,KAAK,GAAG,8BAA8B,CAAC;IACvC,OAAO,GAAoB;QACzB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,gDAAgD;YAC7D,YAAY,EAAE,cAAc;SAC7B;KACF,CAAC;IAEM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IACtB,YAAY,GAAiB,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAElE,aAAa,GAAqC;QACxD,UAAU,EAAE;YACV,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/cli/commands/add.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,sDAAkD;AAWlD,MAAa,UAAU;IACrB,IAAI,GAAG,KAAK,CAAC;IACb,WAAW,GAAG,mCAAmC,CAAC;IAClD,KAAK,GAAG,8BAA8B,CAAC;IACvC,OAAO,GAAoB;QACzB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,gDAAgD;YAC7D,YAAY,EAAE,cAAc;SAC7B;KACF,CAAC;IAEM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IACtB,YAAY,GAAiB,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAElE,aAAa,GAAqC;QACxD,UAAU,EAAE;YACV,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,sBAAsB;YAC/B,WAAW,EAAE,2CAA2C;SACzD;QACD,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,mBAAmB;YAC5B,WAAW,EAAE,uCA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,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAExF,aAAa;QACb,MAAM,wBAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE9C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,MAAM,0BAA0B,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEO,SAAS;QACf,OAAO,CAAC,GAAG,CAAC;EACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;EAE1D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;;;EAK5D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;;;;EAM7D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;CAE7D,CAAC,CAAC;IACD,CAAC;CACF;AApKD,gCAoKC"}
|
|
@@ -642,10 +642,10 @@ import { registerRoutes } from './routes';
|
|
|
642
642
|
|
|
643
643
|
const app = createApp({ debug: true });
|
|
644
644
|
|
|
645
|
-
//
|
|
646
|
-
app.
|
|
647
|
-
app.
|
|
648
|
-
app.
|
|
645
|
+
// Plugins
|
|
646
|
+
app.plugin(swagger());
|
|
647
|
+
app.plugin(postman());
|
|
648
|
+
app.plugin(playground());
|
|
649
649
|
|
|
650
650
|
// Register all routes
|
|
651
651
|
registerRoutes(app);
|
|
@@ -826,9 +826,9 @@ Class-based routes **otomatis terintegrasi** dengan:
|
|
|
826
826
|
```typescript
|
|
827
827
|
const app = createApp();
|
|
828
828
|
|
|
829
|
-
app.
|
|
830
|
-
app.
|
|
831
|
-
app.
|
|
829
|
+
app.plugin(swagger());
|
|
830
|
+
app.plugin(postman());
|
|
831
|
+
app.plugin(playground());
|
|
832
832
|
|
|
833
833
|
// Routes akan muncul di Swagger, Postman, dan Playground
|
|
834
834
|
app.post(new RegisterRoute());
|
package/package.json
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* const app = createApp();
|
|
10
10
|
*
|
|
11
11
|
* // Zero config
|
|
12
|
-
* app.
|
|
12
|
+
* app.plugin(postman());
|
|
13
13
|
*
|
|
14
14
|
* // With config
|
|
15
|
-
* app.
|
|
15
|
+
* app.plugin(postman({
|
|
16
16
|
* path: '/postman',
|
|
17
17
|
* name: 'My API',
|
|
18
18
|
* baseUrl: 'http://localhost:3000'
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
* const app = createApp();
|
|
11
11
|
*
|
|
12
12
|
* // Basic usage - serve from ./public
|
|
13
|
-
* app.
|
|
13
|
+
* app.plugin(serveStatic());
|
|
14
14
|
*
|
|
15
15
|
* // Custom directory
|
|
16
|
-
* app.
|
|
16
|
+
* app.plugin(serveStatic({ root: './assets' }));
|
|
17
17
|
*
|
|
18
18
|
* // With prefix
|
|
19
|
-
* app.
|
|
19
|
+
* app.plugin(serveStatic({
|
|
20
20
|
* root: './public',
|
|
21
21
|
* prefix: '/static' // /static/image.png → ./public/image.png
|
|
22
22
|
* }));
|
|
@@ -6,8 +6,8 @@ import { serveStatic } from './serveStatic';
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* app.
|
|
10
|
-
* app.
|
|
9
|
+
* app.plugin(publicDir()); // ./public
|
|
10
|
+
* app.plugin(publicDir('./assets')); // ./assets
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -7,8 +7,8 @@ import { serveStatic } from './serveStatic';
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
|
-
* app.
|
|
11
|
-
* app.
|
|
10
|
+
* app.plugin(spa()); // SPA from ./public
|
|
11
|
+
* app.plugin(spa('./dist')); // SPA from ./dist
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* const app = createApp();
|
|
10
10
|
*
|
|
11
11
|
* // Zero config - just works!
|
|
12
|
-
* app.
|
|
12
|
+
* app.plugin(swagger());
|
|
13
13
|
*
|
|
14
14
|
* // With config
|
|
15
|
-
* app.
|
|
15
|
+
* app.plugin(swagger({
|
|
16
16
|
* path: '/docs',
|
|
17
17
|
* info: { title: 'My API', version: '1.0.0' }
|
|
18
18
|
* }));
|
|
@@ -14,10 +14,10 @@ import { SwaggerConfig, StoredRoute, OpenAPISchema, SwaggerApplication } from '.
|
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
16
|
* // Minimal setup - auto-detects everything
|
|
17
|
-
* app.
|
|
17
|
+
* app.plugin(swagger());
|
|
18
18
|
*
|
|
19
19
|
* // With custom info
|
|
20
|
-
* app.
|
|
20
|
+
* app.plugin(swagger({
|
|
21
21
|
* info: {
|
|
22
22
|
* title: 'My Awesome API',
|
|
23
23
|
* version: '2.0.0',
|
|
@@ -26,7 +26,7 @@ import { SwaggerConfig, StoredRoute, OpenAPISchema, SwaggerApplication } from '.
|
|
|
26
26
|
* }));
|
|
27
27
|
*
|
|
28
28
|
* // Full configuration
|
|
29
|
-
* app.
|
|
29
|
+
* app.plugin(swagger({
|
|
30
30
|
* path: '/api-docs',
|
|
31
31
|
* specPath: '/swagger.json',
|
|
32
32
|
* theme: 'dark',
|
package/src/cli/commands/add.ts
CHANGED
|
@@ -31,19 +31,19 @@ export class AddCommand implements Command {
|
|
|
31
31
|
playground: {
|
|
32
32
|
name: 'playground',
|
|
33
33
|
import: 'playground',
|
|
34
|
-
feature: 'playground()',
|
|
34
|
+
feature: 'plugin(playground())',
|
|
35
35
|
description: 'Interactive API playground at /playground',
|
|
36
36
|
},
|
|
37
37
|
postman: {
|
|
38
38
|
name: 'postman',
|
|
39
39
|
import: 'postman',
|
|
40
|
-
feature: 'postman()',
|
|
40
|
+
feature: 'plugin(postman())',
|
|
41
41
|
description: 'Postman collection export at /postman',
|
|
42
42
|
},
|
|
43
43
|
swagger: {
|
|
44
44
|
name: 'swagger',
|
|
45
45
|
import: 'swagger',
|
|
46
|
-
feature: 'swagger()',
|
|
46
|
+
feature: 'plugin(swagger())',
|
|
47
47
|
description: 'Swagger/OpenAPI documentation at /docs',
|
|
48
48
|
},
|
|
49
49
|
};
|
|
@@ -84,7 +84,7 @@ export class AddCommand implements Command {
|
|
|
84
84
|
let content = await FileSystem.readFile(fullPath);
|
|
85
85
|
|
|
86
86
|
// Check if plugin is already added
|
|
87
|
-
if (content.includes(`app.
|
|
87
|
+
if (content.includes(`app.plugin(${config.feature})`)) {
|
|
88
88
|
this.logger.info(`Plugin "${plugin}" is already added to your project`);
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
@@ -105,25 +105,25 @@ export class AddCommand implements Command {
|
|
|
105
105
|
content = `import { ${config.import} } from '@engjts/nexus';\n${content}`;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
// Find where to add app.
|
|
109
|
-
// Look for existing app.
|
|
110
|
-
const
|
|
108
|
+
// Find where to add app.plugin()
|
|
109
|
+
// Look for existing app.plugin() calls or app.use() calls
|
|
110
|
+
const pluginPattern = /app\.plugin\([^)]+\);?\n?/g;
|
|
111
111
|
const usePattern = /app\.use\([^)]+\);?\n?/;
|
|
112
112
|
const listenPattern = /app\.listen\(/;
|
|
113
113
|
|
|
114
114
|
let insertPosition = -1;
|
|
115
|
-
let insertText = `app.
|
|
115
|
+
let insertText = `app.plugin(${config.feature});\n`;
|
|
116
116
|
|
|
117
|
-
// Find last app.
|
|
118
|
-
let
|
|
117
|
+
// Find last app.plugin() call
|
|
118
|
+
let lastPluginMatch: RegExpExecArray | null = null;
|
|
119
119
|
let match;
|
|
120
|
-
while ((match =
|
|
121
|
-
|
|
120
|
+
while ((match = pluginPattern.exec(content)) !== null) {
|
|
121
|
+
lastPluginMatch = match;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
if (
|
|
125
|
-
// Insert after last
|
|
126
|
-
insertPosition =
|
|
124
|
+
if (lastPluginMatch) {
|
|
125
|
+
// Insert after last plugin
|
|
126
|
+
insertPosition = lastPluginMatch.index + lastPluginMatch[0].length;
|
|
127
127
|
} else {
|
|
128
128
|
// Find app.use() or app.listen()
|
|
129
129
|
const useMatch = content.match(usePattern);
|
|
@@ -132,21 +132,21 @@ export class AddCommand implements Command {
|
|
|
132
132
|
if (useMatch && useMatch.index !== undefined) {
|
|
133
133
|
// Insert before first app.use()
|
|
134
134
|
insertPosition = useMatch.index;
|
|
135
|
-
insertText = `//
|
|
135
|
+
insertText = `// Plugins\napp.plugin(${config.feature});\n\n`;
|
|
136
136
|
} else if (listenMatch && listenMatch.index !== undefined) {
|
|
137
137
|
// Insert before app.listen()
|
|
138
138
|
insertPosition = listenMatch.index;
|
|
139
|
-
insertText = `//
|
|
139
|
+
insertText = `// Plugins\napp.plugin(${config.feature});\n\n`;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
if (insertPosition === -1) {
|
|
144
144
|
this.logger.error('Could not find a suitable location to add the plugin');
|
|
145
|
-
this.logger.info('Please add manually: app.
|
|
145
|
+
this.logger.info('Please add manually: app.plugin(' + config.feature + ')');
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
// Insert the
|
|
149
|
+
// Insert the plugin call
|
|
150
150
|
content = content.slice(0, insertPosition) + insertText + content.slice(insertPosition);
|
|
151
151
|
|
|
152
152
|
// Write back
|