@engjts/nexus 0.1.3 → 0.1.4
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/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +3 -0
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/add.d.ts +14 -0
- package/dist/cli/commands/add.d.ts.map +1 -0
- package/dist/cli/commands/add.js +150 -0
- package/dist/cli/commands/add.js.map +1 -0
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +4 -2
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/templates/generators.d.ts +2 -1
- package/dist/cli/templates/generators.d.ts.map +1 -1
- package/dist/cli/templates/generators.js +46 -2
- package/dist/cli/templates/generators.js.map +1 -1
- package/dist/cli/templates/index.js +2 -2
- package/package.json +1 -1
- package/src/cli/cli.ts +3 -0
- package/src/cli/commands/add.ts +178 -0
- package/src/cli/commands/generate.ts +5 -3
- package/src/cli/templates/generators.ts +50 -3
- package/src/cli/templates/index.ts +2 -2
package/dist/cli/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnF;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED,qBAAa,GAAG;IACd,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,MAAM,CAAgB;;IAM9B,OAAO,CAAC,gBAAgB;IAiBlB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwCxC,OAAO,CAAC,SAAS;IAkCjB,OAAO,CAAC,WAAW;CAgCpB"}
|
package/dist/cli/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.CLI = void 0;
|
|
|
4
4
|
const create_1 = require("./commands/create");
|
|
5
5
|
const init_1 = require("./commands/init");
|
|
6
6
|
const generate_1 = require("./commands/generate");
|
|
7
|
+
const add_1 = require("./commands/add");
|
|
7
8
|
const dev_1 = require("./commands/dev");
|
|
8
9
|
const build_1 = require("./commands/build");
|
|
9
10
|
const help_1 = require("./commands/help");
|
|
@@ -20,6 +21,7 @@ class CLI {
|
|
|
20
21
|
new create_1.CreateCommand(),
|
|
21
22
|
new init_1.InitCommand(),
|
|
22
23
|
new generate_1.GenerateCommand(),
|
|
24
|
+
new add_1.AddCommand(),
|
|
23
25
|
new dev_1.DevCommand(),
|
|
24
26
|
new build_1.BuildCommand(),
|
|
25
27
|
new help_1.HelpCommand(() => this.commands),
|
|
@@ -116,6 +118,7 @@ class CLI {
|
|
|
116
118
|
create <name> Create a new Nexus project
|
|
117
119
|
init Initialize Nexus in current directory
|
|
118
120
|
generate <type> Generate components (route, middleware, etc.)
|
|
121
|
+
add <plugin> Add plugins (swagger, playground, postman)
|
|
119
122
|
dev Start development server
|
|
120
123
|
build Build for production
|
|
121
124
|
|
package/dist/cli/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","s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,GAAG,CAAC,GAAG,IAAI,CAAC;gBACtB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;IACrC,CAAC;IAEO,WAAW;QACjB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;IAcZ,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;IAExD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;;;;;;IAQ3D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;;QAItD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,yBAAyB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;CAChF,CAAC,CAAC;IACD,CAAC;CACF;AAnID,kBAmIC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command, CommandOption } from '../cli';
|
|
2
|
+
export declare class AddCommand implements Command {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
usage: string;
|
|
6
|
+
options: CommandOption[];
|
|
7
|
+
private logger;
|
|
8
|
+
private validPlugins;
|
|
9
|
+
private pluginConfigs;
|
|
10
|
+
execute(args: string[], options: Record<string, string | boolean>): Promise<void>;
|
|
11
|
+
private addPlugin;
|
|
12
|
+
private showUsage;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=add.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAahD,qBAAa,UAAW,YAAW,OAAO;IACxC,IAAI,SAAS;IACb,WAAW,SAAuC;IAClD,KAAK,SAAkC;IACvC,OAAO,EAAE,aAAa,EAAE,CAOtB;IAEF,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,YAAY,CAAsD;IAE1E,OAAO,CAAC,aAAa,CAmBnB;IAEI,OAAO,CACX,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC;YAkBF,SAAS;IAuFvB,OAAO,CAAC,SAAS;CAmBlB"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddCommand = void 0;
|
|
4
|
+
const logger_1 = require("../utils/logger");
|
|
5
|
+
const file_system_1 = require("../utils/file-system");
|
|
6
|
+
class AddCommand {
|
|
7
|
+
name = 'add';
|
|
8
|
+
description = 'Add plugins to your Nexus project';
|
|
9
|
+
usage = 'nexus add <plugin> [options]';
|
|
10
|
+
options = [
|
|
11
|
+
{
|
|
12
|
+
name: 'path',
|
|
13
|
+
alias: 'p',
|
|
14
|
+
description: 'Path to the entry file (default: src/index.ts)',
|
|
15
|
+
defaultValue: 'src/index.ts',
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
logger = new logger_1.Logger();
|
|
19
|
+
validPlugins = ['playground', 'postman', 'swagger'];
|
|
20
|
+
pluginConfigs = {
|
|
21
|
+
playground: {
|
|
22
|
+
name: 'playground',
|
|
23
|
+
import: 'playground',
|
|
24
|
+
feature: 'playground()',
|
|
25
|
+
description: 'Interactive API playground at /playground',
|
|
26
|
+
},
|
|
27
|
+
postman: {
|
|
28
|
+
name: 'postman',
|
|
29
|
+
import: 'postman',
|
|
30
|
+
feature: 'postman()',
|
|
31
|
+
description: 'Postman collection export at /postman',
|
|
32
|
+
},
|
|
33
|
+
swagger: {
|
|
34
|
+
name: 'swagger',
|
|
35
|
+
import: 'swagger',
|
|
36
|
+
feature: 'swagger()',
|
|
37
|
+
description: 'Swagger/OpenAPI documentation at /docs',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
async execute(args, options) {
|
|
41
|
+
if (args.length < 1) {
|
|
42
|
+
this.showUsage();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const [plugin] = args;
|
|
46
|
+
if (!this.validPlugins.includes(plugin)) {
|
|
47
|
+
this.logger.error(`Invalid plugin: ${plugin}`);
|
|
48
|
+
this.logger.info(`Valid plugins: ${this.validPlugins.join(', ')}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const entryPath = options.path || 'src/index.ts';
|
|
52
|
+
await this.addPlugin(plugin, entryPath);
|
|
53
|
+
}
|
|
54
|
+
async addPlugin(plugin, entryPath) {
|
|
55
|
+
const fullPath = file_system_1.FileSystem.joinPath(process.cwd(), entryPath);
|
|
56
|
+
const config = this.pluginConfigs[plugin];
|
|
57
|
+
// Check if entry file exists
|
|
58
|
+
if (!(await file_system_1.FileSystem.exists(fullPath))) {
|
|
59
|
+
this.logger.error(`Entry file not found: ${fullPath}`);
|
|
60
|
+
this.logger.info('Use --path to specify your entry file');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Read current file
|
|
64
|
+
let content = await file_system_1.FileSystem.readFile(fullPath);
|
|
65
|
+
// Check if plugin is already added
|
|
66
|
+
if (content.includes(`app.feature(${config.feature})`)) {
|
|
67
|
+
this.logger.info(`Plugin "${plugin}" is already added to your project`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Check if import already exists
|
|
71
|
+
const importRegex = new RegExp(`import\\s*{([^}]*)}\\s*from\\s*['"]@engjts/nexus['"]`);
|
|
72
|
+
const importMatch = content.match(importRegex);
|
|
73
|
+
if (importMatch) {
|
|
74
|
+
const currentImports = importMatch[1];
|
|
75
|
+
if (!currentImports.includes(config.import)) {
|
|
76
|
+
// Add to existing import
|
|
77
|
+
const newImports = currentImports.trim() + ', ' + config.import;
|
|
78
|
+
content = content.replace(importRegex, `import {${newImports}} from '@engjts/nexus'`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Add new import at the top
|
|
83
|
+
content = `import { ${config.import} } from '@engjts/nexus';\n${content}`;
|
|
84
|
+
}
|
|
85
|
+
// Find where to add app.feature()
|
|
86
|
+
// Look for existing app.feature() calls or app.use() calls
|
|
87
|
+
const featurePattern = /app\.feature\([^)]+\);?\n?/g;
|
|
88
|
+
const usePattern = /app\.use\([^)]+\);?\n?/;
|
|
89
|
+
const listenPattern = /app\.listen\(/;
|
|
90
|
+
let insertPosition = -1;
|
|
91
|
+
let insertText = `app.feature(${config.feature});\n`;
|
|
92
|
+
// Find last app.feature() call
|
|
93
|
+
let lastFeatureMatch = null;
|
|
94
|
+
let match;
|
|
95
|
+
while ((match = featurePattern.exec(content)) !== null) {
|
|
96
|
+
lastFeatureMatch = match;
|
|
97
|
+
}
|
|
98
|
+
if (lastFeatureMatch) {
|
|
99
|
+
// Insert after last feature
|
|
100
|
+
insertPosition = lastFeatureMatch.index + lastFeatureMatch[0].length;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Find app.use() or app.listen()
|
|
104
|
+
const useMatch = content.match(usePattern);
|
|
105
|
+
const listenMatch = content.match(listenPattern);
|
|
106
|
+
if (useMatch && useMatch.index !== undefined) {
|
|
107
|
+
// Insert before first app.use()
|
|
108
|
+
insertPosition = useMatch.index;
|
|
109
|
+
insertText = `// Features\napp.feature(${config.feature});\n\n`;
|
|
110
|
+
}
|
|
111
|
+
else if (listenMatch && listenMatch.index !== undefined) {
|
|
112
|
+
// Insert before app.listen()
|
|
113
|
+
insertPosition = listenMatch.index;
|
|
114
|
+
insertText = `// Features\napp.feature(${config.feature});\n\n`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (insertPosition === -1) {
|
|
118
|
+
this.logger.error('Could not find a suitable location to add the plugin');
|
|
119
|
+
this.logger.info('Please add manually: app.feature(' + config.feature + ')');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// Insert the feature call
|
|
123
|
+
content = content.slice(0, insertPosition) + insertText + content.slice(insertPosition);
|
|
124
|
+
// Write back
|
|
125
|
+
await file_system_1.FileSystem.writeFile(fullPath, content);
|
|
126
|
+
this.logger.success(`Added "${plugin}" plugin to your project`);
|
|
127
|
+
this.logger.info(` ${config.description}`);
|
|
128
|
+
}
|
|
129
|
+
showUsage() {
|
|
130
|
+
console.log(`
|
|
131
|
+
${this.logger.colors.bright}Usage:${this.logger.colors.reset} nexus add <plugin> [options]
|
|
132
|
+
|
|
133
|
+
${this.logger.colors.bright}Plugins:${this.logger.colors.reset}
|
|
134
|
+
playground Add interactive API playground
|
|
135
|
+
postman Add Postman collection export
|
|
136
|
+
swagger Add Swagger/OpenAPI documentation
|
|
137
|
+
|
|
138
|
+
${this.logger.colors.bright}Examples:${this.logger.colors.reset}
|
|
139
|
+
nexus add swagger
|
|
140
|
+
nexus add playground
|
|
141
|
+
nexus add postman
|
|
142
|
+
nexus add swagger --path src/app.ts
|
|
143
|
+
|
|
144
|
+
${this.logger.colors.bright}Options:${this.logger.colors.reset}
|
|
145
|
+
--path, -p Path to entry file (default: src/index.ts)
|
|
146
|
+
`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.AddCommand = AddCommand;
|
|
150
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +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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,MAAM,CAAC,KAAK;;CAE7D,CAAC,CAAC;IACD,CAAC;CACF;AApKD,gCAoKC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAOhD,qBAAa,eAAgB,YAAW,OAAO;IAC7C,IAAI,SAAc;IAClB,WAAW,SAA+D;IAC1E,KAAK,SAA4C;IACjD,OAAO,EAAE,aAAa,EAAE,CAYtB;IAEF,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAOhD,qBAAa,eAAgB,YAAW,OAAO;IAC7C,IAAI,SAAc;IAClB,WAAW,SAA+D;IAC1E,KAAK,SAA4C;IACjD,OAAO,EAAE,aAAa,EAAE,CAYtB;IAEF,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,UAAU,CAA0G;IAEtH,OAAO,CACX,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC;YAoBF,QAAQ;IAsBtB,OAAO,CAAC,SAAS;CAyBlB"}
|
|
@@ -22,7 +22,7 @@ class GenerateCommand {
|
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
24
|
logger = new logger_1.Logger();
|
|
25
|
-
validTypes = ['route', 'middleware', 'controller', 'service', 'model', 'validator'];
|
|
25
|
+
validTypes = ['route', 'route-class', 'middleware', 'controller', 'service', 'model', 'validator'];
|
|
26
26
|
async execute(args, options) {
|
|
27
27
|
if (args.length < 2) {
|
|
28
28
|
this.showUsage();
|
|
@@ -57,7 +57,8 @@ class GenerateCommand {
|
|
|
57
57
|
${this.logger.colors.bright}Usage:${this.logger.colors.reset} nexus generate <type> <name> [options]
|
|
58
58
|
|
|
59
59
|
${this.logger.colors.bright}Types:${this.logger.colors.reset}
|
|
60
|
-
route Generate a route handler
|
|
60
|
+
route Generate a function-based route handler
|
|
61
|
+
route-class Generate a class-based route (with meta, schema, onBefore)
|
|
61
62
|
middleware Generate a middleware
|
|
62
63
|
controller Generate a controller class
|
|
63
64
|
service Generate a service class
|
|
@@ -66,6 +67,7 @@ ${this.logger.colors.bright}Types:${this.logger.colors.reset}
|
|
|
66
67
|
|
|
67
68
|
${this.logger.colors.bright}Examples:${this.logger.colors.reset}
|
|
68
69
|
nexus generate route users
|
|
70
|
+
nexus generate route-class users
|
|
69
71
|
nexus generate controller UserController
|
|
70
72
|
nexus generate middleware auth
|
|
71
73
|
nexus generate route products --methods get,post,put,delete
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,sDAAkD;AAClD,wDAA6D;AAI7D,MAAa,eAAe;IAC1B,IAAI,GAAG,UAAU,CAAC;IAClB,WAAW,GAAG,2DAA2D,CAAC;IAC1E,KAAK,GAAG,wCAAwC,CAAC;IACjD,OAAO,GAAoB;QACzB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,oCAAoC;SAClD;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,0CAA0C;YACvD,YAAY,EAAE,KAAK;SACpB;KACF,CAAC;IAEM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IACtB,UAAU,GAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file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,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;;;;;;;EAS1D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;;;;;EAO7D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK;;;CAG7D,CAAC,CAAC;IACD,CAAC;CACF;AA3FD,0CA2FC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type GeneratorType = 'route' | 'middleware' | 'controller' | 'service' | 'model' | 'validator';
|
|
1
|
+
type GeneratorType = 'route' | 'route-class' | 'middleware' | 'controller' | 'service' | 'model' | 'validator';
|
|
2
2
|
interface GeneratorResult {
|
|
3
3
|
filePath: string;
|
|
4
4
|
content: string;
|
|
@@ -12,6 +12,7 @@ export declare class GeneratorTemplates {
|
|
|
12
12
|
private toPascalCase;
|
|
13
13
|
private toCamelCase;
|
|
14
14
|
private generateRoute;
|
|
15
|
+
private generateRouteClass;
|
|
15
16
|
private generateMiddleware;
|
|
16
17
|
private generateController;
|
|
17
18
|
private generateService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../src/cli/templates/generators.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAE/
|
|
1
|
+
{"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../src/cli/templates/generators.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAE/G,UAAU,eAAe;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe;IAqBvF,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,kBAAkB;IA6C1B,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,kBAAkB;IA4D1B,OAAO,CAAC,eAAe;IAwEvB,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,iBAAiB;CA8C1B"}
|
|
@@ -6,6 +6,8 @@ class GeneratorTemplates {
|
|
|
6
6
|
switch (type) {
|
|
7
7
|
case 'route':
|
|
8
8
|
return this.generateRoute(name, options.methods);
|
|
9
|
+
case 'route-class':
|
|
10
|
+
return this.generateRouteClass(name, options.methods);
|
|
9
11
|
case 'middleware':
|
|
10
12
|
return this.generateMiddleware(name);
|
|
11
13
|
case 'controller':
|
|
@@ -37,9 +39,9 @@ class GeneratorTemplates {
|
|
|
37
39
|
return `
|
|
38
40
|
// ${method.toUpperCase()} /${name}
|
|
39
41
|
${routeName}Routes.${method}('/', async (ctx) => {
|
|
40
|
-
return
|
|
42
|
+
return {
|
|
41
43
|
message: '${method.toUpperCase()} /${name}',
|
|
42
|
-
}
|
|
44
|
+
};
|
|
43
45
|
});`;
|
|
44
46
|
})
|
|
45
47
|
.join('\n');
|
|
@@ -47,6 +49,48 @@ ${routeName}Routes.${method}('/', async (ctx) => {
|
|
|
47
49
|
|
|
48
50
|
export const ${routeName}Routes = new Router();
|
|
49
51
|
${routeHandlers}
|
|
52
|
+
`;
|
|
53
|
+
return {
|
|
54
|
+
filePath: `src/routes/${name}.ts`,
|
|
55
|
+
content,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
generateRouteClass(name, methods) {
|
|
59
|
+
const className = this.toPascalCase(name);
|
|
60
|
+
const baseName = name.toLowerCase();
|
|
61
|
+
const method = methods[0] || 'get';
|
|
62
|
+
const content = `import { Route, Context, z } from '@engjts/nexus';
|
|
63
|
+
|
|
64
|
+
export class ${className}Route extends Route {
|
|
65
|
+
pathName = '/${baseName}';
|
|
66
|
+
|
|
67
|
+
meta() {
|
|
68
|
+
return {
|
|
69
|
+
summary: '${className} route',
|
|
70
|
+
description: '${className} route description',
|
|
71
|
+
tags: ['${className}'],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
schema() {
|
|
76
|
+
return {
|
|
77
|
+
// params: z.object({}),
|
|
78
|
+
// query: z.object({}),
|
|
79
|
+
// body: z.object({}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async onBefore(ctx: Context) {
|
|
84
|
+
// Hook sebelum handler
|
|
85
|
+
// Return value untuk skip handler dan langsung return response
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async handler(ctx: Context) {
|
|
89
|
+
return {
|
|
90
|
+
message: '${method.toUpperCase()} /${baseName}',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
50
94
|
`;
|
|
51
95
|
return {
|
|
52
96
|
filePath: `src/routes/${name}.ts`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../src/cli/templates/generators.ts"],"names":[],"mappings":";;;AAYA,MAAa,kBAAkB;IAC7B,QAAQ,CAAC,IAAmB,EAAE,IAAY,EAAE,OAAyB;QACnE,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACnD,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,kBAAkB,CAAC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M,OAAO,GAAG;;;qBAGC,UAAU;;;;;;;;qBAQV,UAAU;;;;;;;eAOhB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;;;;;;;;;eAS1B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;;;;;oBAKrB,UAAU,gCAAgC,UAAU;oBACpD,UAAU,gCAAgC,UAAU;cAC1D,UAAU,0BAA0B,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;CAC3E,CAAC;QAEE,OAAO;YACL,QAAQ,EAAE,kBAAkB,IAAI,KAAK;YACrC,OAAO;SACR,CAAC;IACJ,CAAC;CACF;AAvVD,gDAuVC"}
|
|
@@ -61,7 +61,7 @@ class ProjectTemplates {
|
|
|
61
61
|
test: 'jest',
|
|
62
62
|
};
|
|
63
63
|
const dependencies = {
|
|
64
|
-
'@engjts/nexus': '^0.1.
|
|
64
|
+
'@engjts/nexus': '^0.1.3',
|
|
65
65
|
zod: '^3.22.4',
|
|
66
66
|
ws: '^8.16.0',
|
|
67
67
|
};
|
|
@@ -78,7 +78,7 @@ class ProjectTemplates {
|
|
|
78
78
|
}
|
|
79
79
|
return JSON.stringify({
|
|
80
80
|
name: this.projectName,
|
|
81
|
-
version: '1.0
|
|
81
|
+
version: '0.1.0',
|
|
82
82
|
description: `${this.projectName} - Powered by Nexus`,
|
|
83
83
|
main: 'dist/index.js',
|
|
84
84
|
scripts,
|
package/package.json
CHANGED
package/src/cli/cli.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CreateCommand } from './commands/create';
|
|
2
2
|
import { InitCommand } from './commands/init';
|
|
3
3
|
import { GenerateCommand } from './commands/generate';
|
|
4
|
+
import { AddCommand } from './commands/add';
|
|
4
5
|
import { DevCommand } from './commands/dev';
|
|
5
6
|
import { BuildCommand } from './commands/build';
|
|
6
7
|
import { HelpCommand } from './commands/help';
|
|
@@ -36,6 +37,7 @@ export class CLI {
|
|
|
36
37
|
new CreateCommand(),
|
|
37
38
|
new InitCommand(),
|
|
38
39
|
new GenerateCommand(),
|
|
40
|
+
new AddCommand(),
|
|
39
41
|
new DevCommand(),
|
|
40
42
|
new BuildCommand(),
|
|
41
43
|
new HelpCommand(() => this.commands),
|
|
@@ -142,6 +144,7 @@ export class CLI {
|
|
|
142
144
|
create <name> Create a new Nexus project
|
|
143
145
|
init Initialize Nexus in current directory
|
|
144
146
|
generate <type> Generate components (route, middleware, etc.)
|
|
147
|
+
add <plugin> Add plugins (swagger, playground, postman)
|
|
145
148
|
dev Start development server
|
|
146
149
|
build Build for production
|
|
147
150
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Command, CommandOption } from '../cli';
|
|
2
|
+
import { Logger } from '../utils/logger';
|
|
3
|
+
import { FileSystem } from '../utils/file-system';
|
|
4
|
+
|
|
5
|
+
type PluginType = 'playground' | 'postman' | 'swagger';
|
|
6
|
+
|
|
7
|
+
interface PluginConfig {
|
|
8
|
+
name: string;
|
|
9
|
+
import: string;
|
|
10
|
+
feature: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class AddCommand implements Command {
|
|
15
|
+
name = 'add';
|
|
16
|
+
description = 'Add plugins to your Nexus project';
|
|
17
|
+
usage = 'nexus add <plugin> [options]';
|
|
18
|
+
options: CommandOption[] = [
|
|
19
|
+
{
|
|
20
|
+
name: 'path',
|
|
21
|
+
alias: 'p',
|
|
22
|
+
description: 'Path to the entry file (default: src/index.ts)',
|
|
23
|
+
defaultValue: 'src/index.ts',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
private logger = new Logger();
|
|
28
|
+
private validPlugins: PluginType[] = ['playground', 'postman', 'swagger'];
|
|
29
|
+
|
|
30
|
+
private pluginConfigs: Record<PluginType, PluginConfig> = {
|
|
31
|
+
playground: {
|
|
32
|
+
name: 'playground',
|
|
33
|
+
import: 'playground',
|
|
34
|
+
feature: 'playground()',
|
|
35
|
+
description: 'Interactive API playground at /playground',
|
|
36
|
+
},
|
|
37
|
+
postman: {
|
|
38
|
+
name: 'postman',
|
|
39
|
+
import: 'postman',
|
|
40
|
+
feature: 'postman()',
|
|
41
|
+
description: 'Postman collection export at /postman',
|
|
42
|
+
},
|
|
43
|
+
swagger: {
|
|
44
|
+
name: 'swagger',
|
|
45
|
+
import: 'swagger',
|
|
46
|
+
feature: 'swagger()',
|
|
47
|
+
description: 'Swagger/OpenAPI documentation at /docs',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async execute(
|
|
52
|
+
args: string[],
|
|
53
|
+
options: Record<string, string | boolean>
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
if (args.length < 1) {
|
|
56
|
+
this.showUsage();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const [plugin] = args;
|
|
61
|
+
|
|
62
|
+
if (!this.validPlugins.includes(plugin as PluginType)) {
|
|
63
|
+
this.logger.error(`Invalid plugin: ${plugin}`);
|
|
64
|
+
this.logger.info(`Valid plugins: ${this.validPlugins.join(', ')}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const entryPath = (options.path as string) || 'src/index.ts';
|
|
69
|
+
await this.addPlugin(plugin as PluginType, entryPath);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private async addPlugin(plugin: PluginType, entryPath: string): Promise<void> {
|
|
73
|
+
const fullPath = FileSystem.joinPath(process.cwd(), entryPath);
|
|
74
|
+
const config = this.pluginConfigs[plugin];
|
|
75
|
+
|
|
76
|
+
// Check if entry file exists
|
|
77
|
+
if (!(await FileSystem.exists(fullPath))) {
|
|
78
|
+
this.logger.error(`Entry file not found: ${fullPath}`);
|
|
79
|
+
this.logger.info('Use --path to specify your entry file');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Read current file
|
|
84
|
+
let content = await FileSystem.readFile(fullPath);
|
|
85
|
+
|
|
86
|
+
// Check if plugin is already added
|
|
87
|
+
if (content.includes(`app.feature(${config.feature})`)) {
|
|
88
|
+
this.logger.info(`Plugin "${plugin}" is already added to your project`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Check if import already exists
|
|
93
|
+
const importRegex = new RegExp(`import\\s*{([^}]*)}\\s*from\\s*['"]@engjts/nexus['"]`);
|
|
94
|
+
const importMatch = content.match(importRegex);
|
|
95
|
+
|
|
96
|
+
if (importMatch) {
|
|
97
|
+
const currentImports = importMatch[1];
|
|
98
|
+
if (!currentImports.includes(config.import)) {
|
|
99
|
+
// Add to existing import
|
|
100
|
+
const newImports = currentImports.trim() + ', ' + config.import;
|
|
101
|
+
content = content.replace(importRegex, `import {${newImports}} from '@engjts/nexus'`);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
// Add new import at the top
|
|
105
|
+
content = `import { ${config.import} } from '@engjts/nexus';\n${content}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Find where to add app.feature()
|
|
109
|
+
// Look for existing app.feature() calls or app.use() calls
|
|
110
|
+
const featurePattern = /app\.feature\([^)]+\);?\n?/g;
|
|
111
|
+
const usePattern = /app\.use\([^)]+\);?\n?/;
|
|
112
|
+
const listenPattern = /app\.listen\(/;
|
|
113
|
+
|
|
114
|
+
let insertPosition = -1;
|
|
115
|
+
let insertText = `app.feature(${config.feature});\n`;
|
|
116
|
+
|
|
117
|
+
// Find last app.feature() call
|
|
118
|
+
let lastFeatureMatch: RegExpExecArray | null = null;
|
|
119
|
+
let match;
|
|
120
|
+
while ((match = featurePattern.exec(content)) !== null) {
|
|
121
|
+
lastFeatureMatch = match;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (lastFeatureMatch) {
|
|
125
|
+
// Insert after last feature
|
|
126
|
+
insertPosition = lastFeatureMatch.index + lastFeatureMatch[0].length;
|
|
127
|
+
} else {
|
|
128
|
+
// Find app.use() or app.listen()
|
|
129
|
+
const useMatch = content.match(usePattern);
|
|
130
|
+
const listenMatch = content.match(listenPattern);
|
|
131
|
+
|
|
132
|
+
if (useMatch && useMatch.index !== undefined) {
|
|
133
|
+
// Insert before first app.use()
|
|
134
|
+
insertPosition = useMatch.index;
|
|
135
|
+
insertText = `// Features\napp.feature(${config.feature});\n\n`;
|
|
136
|
+
} else if (listenMatch && listenMatch.index !== undefined) {
|
|
137
|
+
// Insert before app.listen()
|
|
138
|
+
insertPosition = listenMatch.index;
|
|
139
|
+
insertText = `// Features\napp.feature(${config.feature});\n\n`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (insertPosition === -1) {
|
|
144
|
+
this.logger.error('Could not find a suitable location to add the plugin');
|
|
145
|
+
this.logger.info('Please add manually: app.feature(' + config.feature + ')');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Insert the feature call
|
|
150
|
+
content = content.slice(0, insertPosition) + insertText + content.slice(insertPosition);
|
|
151
|
+
|
|
152
|
+
// Write back
|
|
153
|
+
await FileSystem.writeFile(fullPath, content);
|
|
154
|
+
|
|
155
|
+
this.logger.success(`Added "${plugin}" plugin to your project`);
|
|
156
|
+
this.logger.info(` ${config.description}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private showUsage(): void {
|
|
160
|
+
console.log(`
|
|
161
|
+
${this.logger.colors.bright}Usage:${this.logger.colors.reset} nexus add <plugin> [options]
|
|
162
|
+
|
|
163
|
+
${this.logger.colors.bright}Plugins:${this.logger.colors.reset}
|
|
164
|
+
playground Add interactive API playground
|
|
165
|
+
postman Add Postman collection export
|
|
166
|
+
swagger Add Swagger/OpenAPI documentation
|
|
167
|
+
|
|
168
|
+
${this.logger.colors.bright}Examples:${this.logger.colors.reset}
|
|
169
|
+
nexus add swagger
|
|
170
|
+
nexus add playground
|
|
171
|
+
nexus add postman
|
|
172
|
+
nexus add swagger --path src/app.ts
|
|
173
|
+
|
|
174
|
+
${this.logger.colors.bright}Options:${this.logger.colors.reset}
|
|
175
|
+
--path, -p Path to entry file (default: src/index.ts)
|
|
176
|
+
`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -3,7 +3,7 @@ import { Logger } from '../utils/logger';
|
|
|
3
3
|
import { FileSystem } from '../utils/file-system';
|
|
4
4
|
import { GeneratorTemplates } from '../templates/generators';
|
|
5
5
|
|
|
6
|
-
type GeneratorType = 'route' | 'middleware' | 'controller' | 'service' | 'model' | 'validator';
|
|
6
|
+
type GeneratorType = 'route' | 'route-class' | 'middleware' | 'controller' | 'service' | 'model' | 'validator';
|
|
7
7
|
|
|
8
8
|
export class GenerateCommand implements Command {
|
|
9
9
|
name = 'generate';
|
|
@@ -24,7 +24,7 @@ export class GenerateCommand implements Command {
|
|
|
24
24
|
];
|
|
25
25
|
|
|
26
26
|
private logger = new Logger();
|
|
27
|
-
private validTypes: GeneratorType[] = ['route', 'middleware', 'controller', 'service', 'model', 'validator'];
|
|
27
|
+
private validTypes: GeneratorType[] = ['route', 'route-class', 'middleware', 'controller', 'service', 'model', 'validator'];
|
|
28
28
|
|
|
29
29
|
async execute(
|
|
30
30
|
args: string[],
|
|
@@ -76,7 +76,8 @@ export class GenerateCommand implements Command {
|
|
|
76
76
|
${this.logger.colors.bright}Usage:${this.logger.colors.reset} nexus generate <type> <name> [options]
|
|
77
77
|
|
|
78
78
|
${this.logger.colors.bright}Types:${this.logger.colors.reset}
|
|
79
|
-
route Generate a route handler
|
|
79
|
+
route Generate a function-based route handler
|
|
80
|
+
route-class Generate a class-based route (with meta, schema, onBefore)
|
|
80
81
|
middleware Generate a middleware
|
|
81
82
|
controller Generate a controller class
|
|
82
83
|
service Generate a service class
|
|
@@ -85,6 +86,7 @@ ${this.logger.colors.bright}Types:${this.logger.colors.reset}
|
|
|
85
86
|
|
|
86
87
|
${this.logger.colors.bright}Examples:${this.logger.colors.reset}
|
|
87
88
|
nexus generate route users
|
|
89
|
+
nexus generate route-class users
|
|
88
90
|
nexus generate controller UserController
|
|
89
91
|
nexus generate middleware auth
|
|
90
92
|
nexus generate route products --methods get,post,put,delete
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type GeneratorType = 'route' | 'middleware' | 'controller' | 'service' | 'model' | 'validator';
|
|
1
|
+
type GeneratorType = 'route' | 'route-class' | 'middleware' | 'controller' | 'service' | 'model' | 'validator';
|
|
2
2
|
|
|
3
3
|
interface GeneratorResult {
|
|
4
4
|
filePath: string;
|
|
@@ -15,6 +15,8 @@ export class GeneratorTemplates {
|
|
|
15
15
|
switch (type) {
|
|
16
16
|
case 'route':
|
|
17
17
|
return this.generateRoute(name, options.methods);
|
|
18
|
+
case 'route-class':
|
|
19
|
+
return this.generateRouteClass(name, options.methods);
|
|
18
20
|
case 'middleware':
|
|
19
21
|
return this.generateMiddleware(name);
|
|
20
22
|
case 'controller':
|
|
@@ -49,9 +51,9 @@ export class GeneratorTemplates {
|
|
|
49
51
|
return `
|
|
50
52
|
// ${method.toUpperCase()} /${name}
|
|
51
53
|
${routeName}Routes.${method}('/', async (ctx) => {
|
|
52
|
-
return
|
|
54
|
+
return {
|
|
53
55
|
message: '${method.toUpperCase()} /${name}',
|
|
54
|
-
}
|
|
56
|
+
};
|
|
55
57
|
});`;
|
|
56
58
|
})
|
|
57
59
|
.join('\n');
|
|
@@ -68,6 +70,51 @@ ${routeHandlers}
|
|
|
68
70
|
};
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
private generateRouteClass(name: string, methods: string[]): GeneratorResult {
|
|
74
|
+
const className = this.toPascalCase(name);
|
|
75
|
+
const baseName = name.toLowerCase();
|
|
76
|
+
const method = methods[0] || 'get';
|
|
77
|
+
|
|
78
|
+
const content = `import { Route, Context, z } from '@engjts/nexus';
|
|
79
|
+
|
|
80
|
+
export class ${className}Route extends Route {
|
|
81
|
+
pathName = '/${baseName}';
|
|
82
|
+
|
|
83
|
+
meta() {
|
|
84
|
+
return {
|
|
85
|
+
summary: '${className} route',
|
|
86
|
+
description: '${className} route description',
|
|
87
|
+
tags: ['${className}'],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
schema() {
|
|
92
|
+
return {
|
|
93
|
+
// params: z.object({}),
|
|
94
|
+
// query: z.object({}),
|
|
95
|
+
// body: z.object({}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async onBefore(ctx: Context) {
|
|
100
|
+
// Hook sebelum handler
|
|
101
|
+
// Return value untuk skip handler dan langsung return response
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async handler(ctx: Context) {
|
|
105
|
+
return {
|
|
106
|
+
message: '${method.toUpperCase()} /${baseName}',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
filePath: `src/routes/${name}.ts`,
|
|
114
|
+
content,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
71
118
|
private generateMiddleware(name: string): GeneratorResult {
|
|
72
119
|
const middlewareName = this.toCamelCase(name);
|
|
73
120
|
|
|
@@ -61,7 +61,7 @@ export class ProjectTemplates {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const dependencies: Record<string, string> = {
|
|
64
|
-
'@engjts/nexus': '^0.1.
|
|
64
|
+
'@engjts/nexus': '^0.1.3',
|
|
65
65
|
zod: '^3.22.4',
|
|
66
66
|
ws: '^8.16.0',
|
|
67
67
|
};
|
|
@@ -82,7 +82,7 @@ export class ProjectTemplates {
|
|
|
82
82
|
return JSON.stringify(
|
|
83
83
|
{
|
|
84
84
|
name: this.projectName,
|
|
85
|
-
version: '1.0
|
|
85
|
+
version: '0.1.0',
|
|
86
86
|
description: `${this.projectName} - Powered by Nexus`,
|
|
87
87
|
main: 'dist/index.js',
|
|
88
88
|
scripts,
|