diff --git a/README.md b/README.md index 710325b..c91eeaa 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ Lumie is a lightweight module that allows you to set up a scalable controllers architecture for your nodejs project. -✅ Maintainable
-✅ Scalable
-✅ Quick setup
-✅ Easily testable
+✅ Maintainable`
` +✅ Scalable`
` +✅ Quick setup`
` +✅ Easily testable`
` ## 💾 INSTALLATION @@ -19,12 +19,12 @@ npm install lumie ## 🔩 HOW IT WORKS -**Lumie** goes through the files and folders inside your controllers directory to find what we call "routing definitions".
-Each controllers are defined in files, which export their routing definitions [( example )](https://github.com/Alex-Levacher/Lumie/tree/master/example)

+**Lumie** goes through the files and folders inside your controllers directory to find what we call "routing definitions".`
` +Each controllers are defined in files, which export their routing definitions [( example )](https://github.com/Alex-Levacher/Lumie/tree/master/example)`

` By default, we use the name of the file that exports the routing definition to name the route -`/` > `controllers` > `cars.js` will create the endpoints `/cars/*`
-`/` > `controllers` > `admin` > `rules.js` will create the endpoints `/admin/rules/*`
+`/` > `controllers` > `cars.js` will create the endpoints `/cars/*
` +`/` > `controllers` > `admin` > `rules.js` will create the endpoints `/admin/rules/*
` `/` > `controllers` > `users` > `users.routing.js` will create the endpoints `/users/*` ## ⚙️ CONFIGURATION @@ -51,14 +51,14 @@ const server = app.listen(3000, "127.0.0.1", () => { ### Options -| Name | type | default value | Description | -| -------------------- | ---------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| **verbose** | `boolean` | `false` | Will print or not the routes name in the console | -| **preURL** | `string` | `/` | Prefix your route URLs | -| **ignore** | `string[]` | `null` | Lumie will not try to find a routing definition in those files. | -| **controllers_path** | `string` | none, this option is required | The path of your controllers folder. | -| **routing_files** | `string` | `*.routing` | How you want to name routing files. | -| **permissions** | `function` | `null` | A function that takes in parameter a **level access** and returns an [**express middleware**](https://expressjs.com/en/guide/using-middleware.html). This is useful if you want to restrict access for some URLs. With this option enabled, you will be able to set in each route configuration an option level that will be passed to your permission function [( example )](https://github.com/Alex-Levacher/Lumie/blob/master/example/permissions.js) | +| Name | type | default value | Description | +| -------------------------- | ------------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **verbose** | `boolean` | `false` | Will print or not the routes name in the console | +| **preURL** | `string` | `/` | Prefix your route URLs | +| **ignore** | `string[]` | `null` | Lumie will not try to find a routing definition in those files. | +| **controllers_path** | `string` | none, this option is required | The path of your controllers folder. | +| **routing_files** | `string` | `*.routing` | How you want to name routing files. | +| **permissions** | `function` | `null` | A function that takes in parameter a**level access** and returns an [**express middleware**](https://expressjs.com/en/guide/using-middleware.html). This is useful if you want to restrict access for some URLs. With this option enabled, you will be able to set in each route configuration an option level that will be passed to your permission function [( example )](https://github.com/Alex-Levacher/Lumie/blob/master/example/permissions.js) | ## 🌲FILE STRUCTURE @@ -97,7 +97,8 @@ module.exports = { post: { middlewares: postCars.middlewares, action: postCars.action, - level: 'public' + level: 'public', + comment: "This ia a comment" }, get: { action: getCars.getAll, @@ -119,6 +120,7 @@ module.exports = { action: < function(req, res) >, level: < parameters of you permission function >, // Optional middlewares: < Array(function(req, res, next)) >// Optional + comment: < string < // Optional } } ``` @@ -128,7 +130,7 @@ module.exports = { There is **2** common way to create a controller with Lumie, you can take a look [here](https://github.com/Alex-Levacher/Lumie/blob/master/example/controllers) to learn how to implement them. * **Minimal** ([sample](https://github.com/Alex-Levacher/Lumie/blob/master/example/controllers/simple-ctrl.js)): You only create one file which takes as name, the name of the controller you want to create. Then you define the routing definition and the functions. This method is recommended if you plan to have a small controller with few actions. -* **Structured** ([sample](https://github.com/Alex-Levacher/Lumie/tree/master/example/controllers/users)): You create a new directory with the name of the controller. Inside, you create:
+* **Structured** ([sample](https://github.com/Alex-Levacher/Lumie/tree/master/example/controllers/users)): You create a new directory with the name of the controller. Inside, you create:`
` * `[your-controller-name].routing.js` which contains the routing definition * `[your-controller-name].actions.js` which contains the action functions of the controller. * `[your-controller-name].spec.js` This one is optional @@ -149,12 +151,13 @@ Here are the next features planned, let me know if you have some ideas * Create a CLI to generate new controllers / projects ## ☕️ SUPPORT + You can support the project by + * Star our GitHub repo ⭐️ * [Suggest ideas](https://github.com/Alex-Levacher/Lumie/issues) to help me promote Lumie 🌎 -If you are struggling to setup Lumie, you found a bug or if you have some improvement ideas, feel free to [create an issue](https://github.com/Alex-Levacher/Lumie/issues)

- +If you are struggling to setup Lumie, you found a bug or if you have some improvement ideas, feel free to [create an issue](https://github.com/Alex-Levacher/Lumie/issues)`

` ## ⚖️ LICENSE diff --git a/example/controllers/users/users.routing.js b/example/controllers/users/users.routing.js index 1d87c3a..9fd6384 100644 --- a/example/controllers/users/users.routing.js +++ b/example/controllers/users/users.routing.js @@ -14,7 +14,8 @@ module.exports = { '/:id': { get: { action: getOne, - level: 'public' + level: 'public', + comment: "This is a comment" } } }; diff --git a/package.json b/package.json index 678a671..9905ba7 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ }, "license": "MIT", "dependencies": { + "express": "^4.17.2", "micromatch": "^3.1.10" }, "devDependencies": { @@ -56,4 +57,4 @@ "test:src", "test:example" ] -} \ No newline at end of file +} diff --git a/src/index.js b/src/index.js index 657019c..32574b4 100644 --- a/src/index.js +++ b/src/index.js @@ -28,7 +28,8 @@ function browseControllerObject(ctrlDefinition, path) { level: action[verbName].level, path: cpath.join(path, actionName), permissions: _options.permissions, - middlewares: action[verbName].middlewares + middlewares: action[verbName].middlewares, + comment: action[verbName].comment }); } } diff --git a/src/route.js b/src/route.js index 9722b40..2fb9cf5 100644 --- a/src/route.js +++ b/src/route.js @@ -8,6 +8,7 @@ class Route { this.path = options.path; this.permissions = options.permissions; this.middlewares = options.middlewares || []; + this.comment = options.comment || ''; } create(app) { @@ -24,7 +25,7 @@ class Route { } desc() { - return `\t${this.level}\t${this.verb}\t[${joinPathSlash(this.path)}]`; + return `\t${this.level}\t${this.verb}\t[${joinPathSlash(this.path)}]\t${this.comment}`; } } diff --git a/test/route.spec.js b/test/route.spec.js index 2f0fcd7..a87d261 100644 --- a/test/route.spec.js +++ b/test/route.spec.js @@ -49,9 +49,10 @@ test('desc should work', (t) => { level: 'public', path: '/test/', permissions: level => level, - middlewares: undefined + middlewares: undefined, + comment: 'This is a comment' }; const route = new Route(prepareRoute); const desc = route.desc(); - t.is(desc, '\tpublic\tget\t[/test/]'); + t.is(desc, '\tpublic\tget\t[/test/]\tThis is a comment'); });