@dolphjs/cli 0.1.1 → 1.0.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/dist/generators/generate_controller.js +65 -0
  3. package/dist/generators/generate_model.js +61 -0
  4. package/dist/generators/generate_mysql.js +63 -0
  5. package/dist/generators/generate_routes.js +59 -0
  6. package/dist/generators/generate_service.js +63 -0
  7. package/dist/generators/resolvers/resolve_controller_content.js +19 -0
  8. package/dist/generators/resolvers/resolve_model_content.js +37 -0
  9. package/dist/generators/resolvers/resolve_routes_content.js +19 -0
  10. package/dist/generators/resolvers/resolve_service_content.js +19 -0
  11. package/dist/generators/templates/controller_template.js +83 -0
  12. package/dist/generators/templates/model_template.js +168 -0
  13. package/dist/generators/templates/mysql_config_template.js +59 -0
  14. package/dist/generators/templates/routes_template.js +86 -0
  15. package/dist/generators/templates/service_template.js +172 -0
  16. package/dist/index.js +30 -0
  17. package/dist/registers/register_routes.js +145 -0
  18. package/dist/registers/server_file_routes.js +74 -0
  19. package/dist/types/config.js +1 -0
  20. package/dist/utils/get_root_dir_path.js +11 -0
  21. package/dist/utils/get_user_config_path.js +10 -0
  22. package/dist/utils/init_helper_function.js +90 -0
  23. package/dist/utils/package_description.js +6 -0
  24. package/dist/utils/package_generator.js +73 -0
  25. package/dist/utils/package_init.js +11 -0
  26. package/dist/utils/read_package_json.js +9 -0
  27. package/dist/utils/read_user_config.js +67 -0
  28. package/dist/utils/read_user_config_path.js +19 -0
  29. package/dist/utils/write_dolph_config.js +9 -0
  30. package/dist/utils/write_gitignore.js +12 -0
  31. package/dist/utils/write_package_json.js +68 -0
  32. package/dist/utils/write_swrcc.js +48 -0
  33. package/dist/utils/write_tsconfig.js +45 -0
  34. package/dist/utils/write_user_config.js +16 -0
  35. package/package.json +47 -40
  36. package/CODE_OF_CONDUCT.md +0 -76
  37. package/CONTRIBUTING.md +0 -91
  38. package/new-app.mjs +0 -209
  39. package/readme.md +0 -25
  40. package/utils/constants/packageManagers.mjs +0 -3
  41. package/utils/constants/types.mjs +0 -4
  42. package/utils/dependencies.mjs +0 -24
  43. package/utils/js-func/packageData.mjs +0 -20
  44. package/utils/js-func/writeSubFile.mjs +0 -96
  45. package/utils/js-oop/packageData.mjs +0 -19
  46. package/utils/js-oop/writeSubFileJsOop.mjs +0 -94
  47. package/utils/ts-func/copySubFolder.mjs +0 -58
  48. package/utils/ts-func/gitignoreData.mjs +0 -11
  49. package/utils/ts-func/nodemonData.mjs +0 -12
  50. package/utils/ts-func/packageData.mjs +0 -23
  51. package/utils/ts-func/readmeData.mjs +0 -293
  52. package/utils/ts-func/swcrcData.mjs +0 -49
  53. package/utils/ts-func/tsconfigFile.mjs +0 -55
  54. package/utils/ts-oop/copySubFolder.mjs +0 -71
  55. package/utils/ts-oop/gitignoreData.mjs +0 -11
  56. package/utils/ts-oop/nodemonData.mjs +0 -12
  57. package/utils/ts-oop/packageData.mjs +0 -23
  58. package/utils/ts-oop/readmeData.mjs +0 -292
  59. package/utils/ts-oop/swcrcData.mjs +0 -49
  60. package/utils/ts-oop/tsconfigFile.mjs +0 -55
@@ -1,23 +0,0 @@
1
- import { writeFileSync } from "fs";
2
-
3
- export default function writeFilePackage(appName) {
4
- const packageJsonData = {
5
- name: appName,
6
- version: "1.0.0",
7
- description: "",
8
- main: "src/index.ts",
9
- scripts: {
10
- dev: "cross-env NODE_ENV=development nodemon",
11
- build: "swc src -d dist --source-maps --copy-files",
12
- "build:tsc": "tsc && tsc-alias",
13
- start:
14
- "npm run build && cross-env NODE_ENV=production node/dist/index.js",
15
- },
16
- keywords: [],
17
- author: "",
18
- license: "ISC",
19
- dependencies: {},
20
- devDependencies: {},
21
- };
22
- writeFileSync(`./package.json`, JSON.stringify(packageJsonData, null, 2));
23
- }
@@ -1,292 +0,0 @@
1
- import { writeFileSync } from "fs";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
-
5
- const readme = `
6
- # DolphJs
7
-
8
- DolphJs is an express.js library for making software development easier. It takes care of setup tasks developers need to go about for every project.
9
-
10
- DolphJs makes it possible for junior developers to write code in an environment set-up as if they are seniors. It supports robust codebase system and the best error handling middlewares.
11
-
12
- With dolphJs, code is minimized as many repetitive features are taken account of and put into the engine which is then exposed to the developer.
13
-
14
- ## Installation
15
-
16
- To install the package, run:
17
-
18
- \`npm install @dolphjs/core\`
19
-
20
- or \`npm install dolph-cli -g\` to make use of the CLI tool (recommended). [https://github.com/dolphjs/cli]
21
-
22
- ## Usage
23
-
24
- To use the package, you'll need to require it in your project and then set up your routes.
25
-
26
- Here's an example of how you can use it:
27
-
28
- \`\`\`javascript
29
- const Dolph, { catchAsync, AppRes httpStatus, Router } = require('@dolphjs/core');
30
-
31
- class TestController {
32
- constructor() {}
33
-
34
- getMsg = catchAsync(async (req, res, next) => {
35
- res.send('welcome to this endpoint');
36
- });
37
- sendMsg = catchAsync(async (req, res, next) => {
38
- const { body } = req;
39
- if (!body.name)
40
- return next(
41
- new AppRes(
42
- httpStatus.BAD_REQUEST,
43
- 'error, provide name in json'
44
- )
45
- );
46
-
47
- res.status(httpStatus.OK).json(body);
48
- });
49
- }
50
-
51
- class TestRoute {
52
- path = '/test';
53
- router = Router();
54
- controller = new TestController();
55
- constructor() {
56
- this.initializeRoutes();
57
- }
58
- initializeRoutes() {
59
- this.router.get(\`\${this.path}\`, this.controller.getMsg);
60
- this.router.post(\`\${this.path}\`, this.controller.sendMsg);
61
- }
62
- }
63
-
64
- const dolph = new Dolph([new TestRoute()], '1919', "development", { url: null }, []);
65
-
66
- dolph.listen();
67
- \`\`\`
68
-
69
- or
70
-
71
- \`\`\`javascript
72
- const { Router } = require('@dolphjs/core');
73
- const router = Router();
74
-
75
- router.get('/', (req, res) => {
76
- res.send('Heyoooo!!');
77
- });
78
-
79
- const routes = [{ path: '/api/v1', router }];
80
-
81
- const dolph = new Dolph(routes, '1919', 'development', null, []);
82
- dolph.listen();
83
- \`\`\`
84
-
85
- The \`Dolph\` class takes 5 arguments when instantiated: \`\routes\`,\`port\` ,\`node_env\`, \`mongodb connection params\` and \`middleware\`
86
-
87
- - \`routes\` is an array of the applications routes
88
- - \`port\` is the port you want your server to run on
89
- - \`node_env\` is your node environment which is set to "development" by default when you run \`node run dev\` . This env can be imported thus:
90
-
91
- \`\`\`javascript
92
- require('dotenv').config({});
93
- const nodeEnv = process.env.NODE_ENV;
94
- \`\`\`
95
-
96
- - \`mongodb connection params\` is only used if your making use of a mongodb database. It is an object with two fields: \`url\` and \`options\` which are the mongodb url and mongodb options respectively. If your making use of another databse or don't want to connect it through mongodb, you can connect it outside the function and also set the \`url\` param to \`false\`.
97
-
98
- \`\`\`javascript
99
- const mongoConfig = {
100
- url: 'mongodb://127.0.0.1:27017/dolphjs',
101
- options: {
102
- useNewUrlParser: true,
103
- useUnifiedTopology: true,
104
- autoIndex: true,
105
- dbName: 'dolphjs',
106
- },
107
- };
108
- new Dolph(routes, '1313', 'development', { url: mongoConfig.url, options: mongoConfig.options }, []);
109
- \`\`\`
110
-
111
- or
112
-
113
- \`\`\`javascript
114
- const mongoConfig = {
115
- url: 'mongodb://127.0.0.1:27017/dolphjs',
116
- options: {
117
- useNewUrlParser: true,
118
- useUnifiedTopology: true,
119
- autoIndex: true,
120
- dbName: 'dolphjs',
121
- },
122
- };
123
- new Dolph(routes, '1313', 'development', { url: null }, []);
124
- mongoose.connect(mongoConfig.url, mongoConfig.options).then().catch();
125
- \`\`\`
126
-
127
- - \`middlewares\` is an array of middlewares you want to pass to the \`express.app\` function embedded inside of dolphjs' engine.
128
-
129
- Here's an example:
130
-
131
- \`\`\`javascript
132
- const cors = require('cors');
133
- new Dolph(routes, '1313', 'development', { url: null }, [cors({ origin: '*' })]);
134
- \`\`\`
135
-
136
- ## CatchAsync
137
-
138
- The \`catchAsync\` function is a utility function that wraps your route handler functions and catches any errors that may occur inside them. This is useful for handling errors in an async route handler without having to use try-catch blocks.
139
-
140
- Here's an example of how you can use it:
141
-
142
- \`\`\`javascript
143
- const { catchAsync } = require('@dolphjs/core');
144
- const routeHandler = catchAsync(async (req, res, next) => {
145
- // your route code here
146
- });
147
- module.exports = routerHandler;
148
- \`\`\`
149
-
150
- ## AppRes
151
-
152
- The \`AppRes\` class is a custom error class that you can use to return custom error responses to the client. It takes two arguments: an HTTP status code and a message.
153
-
154
- Here's an example of how you can use it:
155
-
156
- \`\`\`javascript
157
- if (!body.name) return next(new Dolph.AppRes(httpStatus.BAD_REQUEST, 'error, provide name in json'));
158
- \`\`\`
159
-
160
- ## HttpStatus
161
-
162
- The \`httpStatus\` object is an object containing commonly used HTTP status codes as properties. You can use this to set the status code of your custom error responses.
163
- It is just an export of the original http-status package, here [https://github.com/adaltas/node-http-status]
164
-
165
- Here's an example of how you can use it:
166
-
167
- \`\`\`javascript
168
- const { AppRes } = require('@dolphjs/core');
169
- new AppRes(Dolph.httpStatus.BAD_REQUEST, 'error message');
170
- \`\`\`
171
-
172
- ## MediaParser
173
-
174
- The \`mediaParser\` function uses the \`multer\` package under the hood to parse media files. Thus freeing you from the stress of setting up the package.
175
-
176
- Here's an example of how you can use it:
177
-
178
- \`\`\`javascript
179
- const { Router, mediaParser } = require('@dolphjs/core');
180
- const TestController = require('@/controllers/test.controller');
181
-
182
- class TestRoute {
183
- path = '/test';
184
- router = Router();
185
- controller = new TestController();
186
- constructor() {
187
- this.initializeRoutes();
188
- }
189
- initializeRoutes() {
190
- this.router.get(\`\${this.path}\`, this.controller.getMsg);
191
- this.router.post(
192
- \`\${this.path}\`,
193
- mediaParser({ type: 'single', storage: {}, fieldname: 'upload' }),
194
- this.controller.sendMsg
195
- );
196
- }
197
- }
198
- \`\`\`
199
-
200
- alternatively,
201
-
202
- \`\`\`javascript
203
- const { Router, mediaParser } = require('@dolphjs/core');
204
- const TestController = require('@/controllers/test.controller');
205
-
206
- const router = Router();
207
-
208
- router.get(\`\${this.path}\`, new TestController().getMsg);
209
- router.post(\`\${this.path}\`, mediaParser({ type: 'single', storage: {}, fieldname: 'upload' }), new TestController().sendMsg);
210
-
211
- const routes = [{ path: '/', router }];
212
- \`\`\`
213
-
214
- It accepts five arguments: \`type\`, \`storage\`, \`fieldname\`, \`limit\`
215
-
216
- - the current version of dolphjs supports two types => \`single\` && \`array\`
217
-
218
- - the \`single\` type is used for uploading a single media file
219
- - the \`array\` type is used to upload an array of files with a common fieldname
220
-
221
- - the storage parameter defaults to an empty object but takes the same fields you would pass to the \`diskStorage\` function in multer [https://github.com/expressjs/multer] which means files wouldn't be stored in the filesystem.
222
- Leaving it empty is ideal when you want to get the file path and store in a cloud service like \`AWS\` or \`Cloudinary\`.
223
-
224
- - the fieldname parameter specifies the name that would be used to identify the file(s) from the frontend or API tetsing tool.
225
-
226
- - the limit parameter is only used when the \`type\` paramter is set to \`array\`. This tells the function the max amount of files it's allowed to parse.
227
-
228
- ## Usage With Websockets
229
-
230
- Incase you wonder how you'll attach a websocket server to the dolph engine then this would be of help:
231
- using socket.io -
232
-
233
- \`\`\`javascript
234
- const io = require('socket.io');
235
-
236
- const dolph = new Dolph(routes, '1313', 'development', { url: mongoConfig.url, options: mongoConfig.options }, middlewares);
237
- const server = dolph.listen();
238
-
239
- const socket = io(server, {
240
- cors: {
241
- origin: '*',
242
- credentials: true,
243
- },
244
- });
245
-
246
- global.onlineUsers = new Map();
247
-
248
- socket.on('connection', (socket) => {
249
- socket.on('add-user', (userId) => {
250
- onlineUsers.set(userId, socket.id);
251
-
252
- if (onlineUsers.get(userId)) {
253
- socket.emit('active', userId);
254
- }
255
- });
256
- });
257
- \`\`\`
258
-
259
- ## Note
260
-
261
- Dolphjs makes use of the following middleware packages so you don't need to install them again:
262
-
263
- - helmet
264
- - httpStatus
265
- - express
266
-
267
- If you need a better guide on how to setup a dolphjs application is best you view an example application built with dolphjs [https://github.com/dolphjs/example]
268
-
269
- ## License
270
-
271
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
272
-
273
- ### Please note that this package is still in it's beta stage and a lot of features would be added in later versions will be released in the future. Stay tuned for updates and new features
274
-
275
- ### BENCHMARK
276
-
277
- DolphJS is very performant, to run benchmarks is very simple:
278
-
279
- \`\`\`bash
280
- yarn benchmark
281
- \`\`\`
282
-
283
- or
284
-
285
- \`\`\`bash
286
- npm run benchmark
287
- \`\`\`
288
- `;
289
-
290
- export default function writeReadmeFile() {
291
- writeFileSync("readme.md", readme);
292
- }
@@ -1,49 +0,0 @@
1
- import { writeFileSync } from "fs";
2
-
3
- export default function writeFileSwcrc() {
4
- const swrc = {
5
- jsc: {
6
- parser: {
7
- syntax: "typescript",
8
- tsx: false,
9
- dynamicImport: true,
10
- decorators: true,
11
- },
12
- transform: {
13
- legacyDecorator: true,
14
- decoratorMetadata: true,
15
- },
16
- target: "es2017",
17
- externalHelpers: false,
18
- keepClassNames: true,
19
- loose: false,
20
- minify: {
21
- compress: false,
22
- mangle: false,
23
- },
24
- baseUrl: "src",
25
- paths: {
26
- "@/*": ["*"],
27
- "@config/*": ["config/*"],
28
- "@controllers/*": ["controllers/*"],
29
- "@database/*": ["database/*"],
30
- "@dtos/*": ["dtos/*"],
31
- "@exceptions/*": ["exceptions/*"],
32
- "@interfaces/*": ["interfaces/*"],
33
- "@middlewares/*": ["middlewares/*"],
34
- "@models/*": ["models/*"],
35
- "@routes/*": ["routes/*"],
36
- "@services/*": ["services/*"],
37
- "@util/*": ["util/*"],
38
- "@lib/*": ["lib/*"],
39
- "@constants/*": ["constants/*"],
40
- "@validations/*": ["validations/*"],
41
- },
42
- },
43
- module: {
44
- type: "commonjs",
45
- },
46
- };
47
-
48
- writeFileSync(".swcrc", JSON.stringify(swrc, null, 2));
49
- }
@@ -1,55 +0,0 @@
1
- import { writeFileSync } from "fs";
2
-
3
- const tsconfig = {
4
- compileOnSave: false,
5
- compilerOptions: {
6
- target: "es2017",
7
- lib: ["es2017", "esnext.asynciterable"],
8
- typeRoots: ["node_modules/@types"],
9
- allowSyntheticDefaultImports: true,
10
- experimentalDecorators: true,
11
- emitDecoratorMetadata: true,
12
- forceConsistentCasingInFileNames: true,
13
- moduleResolution: "node",
14
- module: "commonjs",
15
- pretty: true,
16
- sourceMap: true,
17
- declaration: true,
18
- outDir: "dist",
19
- allowJs: true,
20
- noEmit: false,
21
- esModuleInterop: true,
22
- resolveJsonModule: true,
23
- importHelpers: true,
24
- baseUrl: "src",
25
- paths: {
26
- "@/*": ["*"],
27
- "@config/*": ["config/*"],
28
- "@controllers/*": ["controllers/*"],
29
- "@database/*": ["database/*"],
30
- "@dtos/*": ["dtos/*"],
31
- "@exceptions/*": ["exceptions/*"],
32
- "@interfaces/*": ["interfaces/*"],
33
- "@middlewares/*": ["middlewares/*"],
34
- "@models/*": ["models/*"],
35
- "@routes/*": ["routes/*"],
36
- "@services/*": ["services/*"],
37
- "@util/*": ["util/*"],
38
- "@lib/*": ["lib/*"],
39
- "@servers/*": ["servers/*"],
40
- "@constants/*": ["constants/*"],
41
- "@validations/*": ["validations/*"],
42
- },
43
- },
44
- include: ["src/", ".env"],
45
- exclude: ["node_modules", "src/http", "src/logs", "src/tests"],
46
- "ts-node": {
47
- compilerOptions: {
48
- module: "CommonJS",
49
- },
50
- },
51
- };
52
-
53
- export default function writeTsconfigFile() {
54
- writeFileSync("tsconfig.json", JSON.stringify(tsconfig, null, 2));
55
- }