@anthonylzq/simba.js 1.4.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.
- package/.eslintrc +64 -0
- package/CHANGELOG.md +68 -0
- package/LICENSE +21 -0
- package/README.md +234 -0
- package/bin/index.js +5 -0
- package/lib/index.js +285 -0
- package/lib/src/functions/changelog.js +15 -0
- package/lib/src/functions/docker.js +25 -0
- package/lib/src/functions/eslint.js +104 -0
- package/lib/src/functions/express.js +1225 -0
- package/lib/src/functions/gitignore.js +140 -0
- package/lib/src/functions/heroku.js +16 -0
- package/lib/src/functions/license.js +85 -0
- package/lib/src/functions/nodemon.js +25 -0
- package/lib/src/functions/packageJson.js +53 -0
- package/lib/src/functions/readme.js +16 -0
- package/lib/src/functions/tsconfig.js +89 -0
- package/lib/src/functions/webpack.js +45 -0
- package/lib/src/installation.js +161 -0
- package/lib/src/utils/titleCase.js +16 -0
- package/lib/src/utils/writeFile.js +15 -0
- package/package.json +56 -0
package/.eslintrc
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true
|
|
4
|
+
},
|
|
5
|
+
"root": true,
|
|
6
|
+
"plugins": [
|
|
7
|
+
"import",
|
|
8
|
+
"prettier"
|
|
9
|
+
],
|
|
10
|
+
"extends": [
|
|
11
|
+
"standard",
|
|
12
|
+
"eslint:recommended",
|
|
13
|
+
"prettier"
|
|
14
|
+
],
|
|
15
|
+
"rules": {
|
|
16
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
17
|
+
"arrow-parens": [
|
|
18
|
+
"error",
|
|
19
|
+
"as-needed"
|
|
20
|
+
],
|
|
21
|
+
"import/no-extraneous-dependencies": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"devDependencies": true
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"max-len": [
|
|
28
|
+
"error",
|
|
29
|
+
{
|
|
30
|
+
"code": 80,
|
|
31
|
+
"ignoreComments": true,
|
|
32
|
+
"ignoreRegExpLiterals": true,
|
|
33
|
+
"ignoreTemplateLiterals": true,
|
|
34
|
+
"ignoreTrailingComments": true,
|
|
35
|
+
"ignoreStrings": true,
|
|
36
|
+
"ignoreUrls": true
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"newline-before-return": "error",
|
|
40
|
+
"object-curly-spacing": [
|
|
41
|
+
"error",
|
|
42
|
+
"always"
|
|
43
|
+
],
|
|
44
|
+
"prefer-const": "error",
|
|
45
|
+
"prettier/prettier": [
|
|
46
|
+
"error",
|
|
47
|
+
{
|
|
48
|
+
"arrowParens": "avoid",
|
|
49
|
+
"bracketSpacing": true,
|
|
50
|
+
"printWidth": 80,
|
|
51
|
+
"quoteProps": "as-needed",
|
|
52
|
+
"semi": false,
|
|
53
|
+
"singleQuote": true,
|
|
54
|
+
"tabWidth": 2,
|
|
55
|
+
"trailingComma": "none"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"radix": [
|
|
59
|
+
"error",
|
|
60
|
+
"as-needed"
|
|
61
|
+
],
|
|
62
|
+
"spaced-comment": ["error", "always"]
|
|
63
|
+
}
|
|
64
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## [1.4.0](https://github.com/AnthonyLzq/simba.js/compare/v1.3.1...v1.4.0) (2021-12-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* simplified the code ([dde8f2e](https://github.com/AnthonyLzq/simba.js/commit/dde8f2e27f86f60321af2f12b53546227d0ffe64))
|
|
11
|
+
|
|
12
|
+
### [1.3.1](https://github.com/AnthonyLzq/simba.js/compare/v1.3.0...v1.3.1) (2021-12-12)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* updated docs ([809afaa](https://github.com/AnthonyLzq/simba.js/commit/809afaad2c1c3046fab509842118064ec6a61d5f))
|
|
18
|
+
|
|
19
|
+
## [1.3.0](https://github.com/AnthonyLzq/simba.js/compare/v1.2.0...v1.3.0) (2021-12-12)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* implemented eslint rules ([748fb91](https://github.com/AnthonyLzq/simba.js/commit/748fb91a031102855dd7ba08344cc1ec3e181a4f))
|
|
25
|
+
* implemented support for global variables (Node.js v16), linted all the code, fixed unlicensed project bug and simplified project structure ([ae4876f](https://github.com/AnthonyLzq/simba.js/commit/ae4876f249ff7dfd16fd4af7e41b3388c7de0f6a))
|
|
26
|
+
|
|
27
|
+
## [1.2.0](https://github.com/AnthonyLzq/simba.js/compare/v1.1.3...v1.2.0) (2021-10-18)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* implemented support for project names with more than a word and updated dependencies ([2600413](https://github.com/AnthonyLzq/simba.js/commit/2600413bf7a5ef92e554738066e9bc4aea892f6f))
|
|
33
|
+
|
|
34
|
+
### [1.1.3](https://github.com/AnthonyLzq/simba.js/compare/v1.1.2...v1.1.3) (2021-10-17)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* fixed bin path ([bf194ff](https://github.com/AnthonyLzq/simba.js/commit/bf194ff21e6aaf63dd1a80c104b8a3567f0887b1))
|
|
40
|
+
|
|
41
|
+
### [1.1.2](https://github.com/AnthonyLzq/simba.js/compare/v1.1.1...v1.1.2) (2021-10-17)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Bug Fixes
|
|
45
|
+
|
|
46
|
+
* updated eslint package (eslint-config-airbnb -> eslint-config-airbnb-base) ([06547bc](https://github.com/AnthonyLzq/simba.js/commit/06547bc618e79f9f6e47e3b0fbd188358befe408))
|
|
47
|
+
|
|
48
|
+
### [1.1.1](https://github.com/AnthonyLzq/simba.js/compare/v1.0.1...v1.1.1) (2021-10-17)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Features
|
|
52
|
+
|
|
53
|
+
* added new eslint package and some new rules ([d79426c](https://github.com/AnthonyLzq/simba.js/commit/d79426c23fc899128d68c8b2e79ed7c5c0e4b18b))
|
|
54
|
+
|
|
55
|
+
### [1.0.1](https://github.com/AnthonyLzq/simba.js/compare/v1.0.0...v1.0.1) (2021-10-01)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
* flag for unlicensed ([6b20a5b](https://github.com/AnthonyLzq/simba.js/commit/6b20a5b8a9ad60e5278b38252849fe5c3b2d54a4))
|
|
61
|
+
|
|
62
|
+
## 1.0.0 (2021-09-28)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Features
|
|
66
|
+
|
|
67
|
+
* first simba.js release ([d10fa01](https://github.com/AnthonyLzq/simba.js/commit/d10fa0199a8bff941da186c33fc16b512295a037))
|
|
68
|
+
* updated package name and added standard-version command ([d0d0906](https://github.com/AnthonyLzq/simba.js/commit/d0d09064587a814f97d7a63b865b28a6f05030ad))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 AnthonyLzq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# Simba.js
|
|
2
|
+
|
|
3
|
+
Set up a modern backend app by running one command. This project has the goal to create a complete setup for a backend application using `TypeScript` and `Express`. It will create many files that are usually created manually. Currently the following files are being created:
|
|
4
|
+
|
|
5
|
+
- `.env`
|
|
6
|
+
- `.eslintignore`
|
|
7
|
+
- `.eslintrc.js`
|
|
8
|
+
- `.gitignore`
|
|
9
|
+
- `CHANGELOG.md`
|
|
10
|
+
- `Dockerfile`
|
|
11
|
+
- `heroku.yml` (optional)
|
|
12
|
+
- `LICENSE` (optional, `MIT` as example)
|
|
13
|
+
- `nodemon.json`
|
|
14
|
+
- `package.json`
|
|
15
|
+
- `README.md`
|
|
16
|
+
- `tsconfig.json`
|
|
17
|
+
- `webpack.config.js`
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
This package is meant to be installed globally in your computer by using:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm i -g simba.js
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
<!-- Also, if you don't want to install it globally, you can use npx as follows:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx simba.js
|
|
33
|
+
``` -->
|
|
34
|
+
|
|
35
|
+
As developer you have two main options to create your new project, one is by running:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
simba -q
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
By doing this your prompt will ask you the following questions:
|
|
42
|
+
|
|
43
|
+
- `Yarn or npm?`, only one of them is valid.
|
|
44
|
+
- `Project name:`, at least one character must be provided.
|
|
45
|
+
- `Project description:`, at least one character must be provided.
|
|
46
|
+
- `Author:`, at least one character must be provided.
|
|
47
|
+
- `Email:`, a correct email address must be provided.
|
|
48
|
+
- `Project version (0.1.0):` the initial version of the project, `0.1.0` as default.
|
|
49
|
+
- `Select your license [1...7]:`, the license you have chosen for the project.
|
|
50
|
+
- `License year (current year):`, the year where your license starts, current year as default.
|
|
51
|
+
- `Will this project be deployed with Heroku? [y/n]:`, yes or no question, only **y** or **n** is accepted. This is not case sensitive.
|
|
52
|
+
|
|
53
|
+
The second option you have is by passing flags in one single command. If you need help, please run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
simba -h
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This will generate the following output:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
Usage: npx simba [options] or simba [options] (if you it installed globally) or
|
|
63
|
+
only simba if you want to be asked for the options one by one
|
|
64
|
+
|
|
65
|
+
Options:
|
|
66
|
+
-a, --author Author of the project
|
|
67
|
+
-e, --email Email of the author
|
|
68
|
+
-N, --projectName Project name
|
|
69
|
+
-D, --projectDescription Project description
|
|
70
|
+
-H, --heroku Whether or not the project will be deployed using
|
|
71
|
+
Heroku [boolean] [default: false]
|
|
72
|
+
-l, --license Type of license for the project, it can be one of:
|
|
73
|
+
MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL
|
|
74
|
+
3.0, in lowercase without its version
|
|
75
|
+
[default: "unlicensed"]
|
|
76
|
+
-v, --version Project initial version [default: "0.1.0"]
|
|
77
|
+
-y, --licenseYear Year when the license starts [default: "2021"]
|
|
78
|
+
-n, --npm Whether or not the project should use npm as package
|
|
79
|
+
manager [boolean] [default: false]
|
|
80
|
+
-f, --mainFile Main file of the project [default: "src/index.ts"]
|
|
81
|
+
-q, --questions Whether or not you want to be asked to answer the
|
|
82
|
+
questions related to the project one by one
|
|
83
|
+
[boolean] [default: false]
|
|
84
|
+
-h, --help Show help [boolean]
|
|
85
|
+
|
|
86
|
+
Examples:
|
|
87
|
+
simba -a Anthony -e sluzquinosa@uni.pe -N "Project Name" -D "Project
|
|
88
|
+
description"
|
|
89
|
+
|
|
90
|
+
Developed by AnthonyLzq
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Regardless of the option chosen, a new folder will be generated with the name of the project, it will contain the following structure:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
📦node_modules
|
|
97
|
+
📦src
|
|
98
|
+
┣ 📂@types
|
|
99
|
+
┃ ┣ 📜index.d.ts
|
|
100
|
+
┣ 📂controllers
|
|
101
|
+
┃ ┣ 📜index.ts
|
|
102
|
+
┃ ┗ 📜user.ts
|
|
103
|
+
┣ 📂dto-interfaces
|
|
104
|
+
┃ ┣ 📜index.ts
|
|
105
|
+
┃ ┗ 📜user.dto.ts
|
|
106
|
+
┣ 📂models
|
|
107
|
+
┃ ┣ 📜index.ts
|
|
108
|
+
┃ ┗ 📜user.ts
|
|
109
|
+
┣ 📂network
|
|
110
|
+
┃ ┣ 📜index.ts
|
|
111
|
+
┃ ┣ 📜routes.ts
|
|
112
|
+
┃ ┗ 📜server.ts
|
|
113
|
+
┣ 📂routes
|
|
114
|
+
┃ ┣ 📜home.ts
|
|
115
|
+
┃ ┣ 📜index.ts
|
|
116
|
+
┃ ┗ 📜user.ts
|
|
117
|
+
┣ 📂utils
|
|
118
|
+
┃ ┣ 📜index.ts
|
|
119
|
+
┃ ┗ 📜response.ts
|
|
120
|
+
┗ 📜index.ts
|
|
121
|
+
📜.env
|
|
122
|
+
📜.eslintignore
|
|
123
|
+
📜.eslintrc.js
|
|
124
|
+
📜.gitignore
|
|
125
|
+
📜CHANGELOG.md
|
|
126
|
+
📜Dockerfile
|
|
127
|
+
📜heroku.yml
|
|
128
|
+
📜LICENSE
|
|
129
|
+
📜nodemon.json
|
|
130
|
+
📜package.json
|
|
131
|
+
📜README.md
|
|
132
|
+
📜tsconfig.json
|
|
133
|
+
📜webpack.config.js
|
|
134
|
+
📜yarn.lock (or package-lock.json)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Examples
|
|
138
|
+
|
|
139
|
+
Let's suppose you want to build a project that will be deployed to Heroku, so should run:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
simba -a myName -e myEmail@email.com -N myProject -D 'This is a test' -H -l mit
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Here we are specifying that we want to create a new project called `myProject` using the `MIT` license, and my name and my email are respectively: `myName` and `myEmail@email.com`.
|
|
146
|
+
|
|
147
|
+
As default, `yarn` is selected as package manager, but you don't want to use it, so you can pass the flag `-n` or `--npm` as follows:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
simba -a myName -e myEmail@email.com -N myProject -D 'This is a test' -H -l mit -n
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Finally, you may not want to use a license or one of the available licenses, don't worry, just don't pass the flag `-l` neither `--license` as follows:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
simba -a myName -e myEmail@email.com -N myProject -D 'This is a test' -H
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Some considerations
|
|
160
|
+
|
|
161
|
+
- This project is based in other project from my own, [`typescript-project-generator`](https://www.npmjs.com/package/typescript-project-generator), but only considering the `express-mongoose-node` part.
|
|
162
|
+
- You are able to run a server that has one main route, `home` (`/`), and another one, `user` (`/user` or `/user/:userId`).
|
|
163
|
+
- To connect your server with your `MongoDB` database, you need to provide your `uri` in the `.env`.
|
|
164
|
+
- Once you have done that, now you can perform the following `HTTP REQUEST`: `GET`, `POST`, `PATCH` and `DELETE`.
|
|
165
|
+
- In order to use global variables, just add the one you need in the `src/@types/index.d.ts` file, and add a new `var` with its type to the `global` interface, as follows:
|
|
166
|
+
```ts
|
|
167
|
+
// src/@types/index.d.ts
|
|
168
|
+
|
|
169
|
+
// Some code...
|
|
170
|
+
declare global {
|
|
171
|
+
var globalStringVariable: string
|
|
172
|
+
// Some more code...
|
|
173
|
+
}
|
|
174
|
+
// Some more code...
|
|
175
|
+
|
|
176
|
+
// another file
|
|
177
|
+
globalStringVariable = 'Hi mom, I am global'
|
|
178
|
+
console.log({ globalStringVariable })
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- The provided project structure is inspired in my personal experience as [`Node.js`](https://nodejs.org/en/) developer and the [`Nest`](https://nestjs.com/) framework.
|
|
182
|
+
- The server is fully tested and has no errors (at least for now), feel free to report one [here](https://github.com/AnthonyLzq/simba.js/issues).
|
|
183
|
+
- Support for windows and linux platforms is available.
|
|
184
|
+
- To check the content of the files generated, please check the `example` folder.
|
|
185
|
+
- If you provide a project name that contains spaces, something like 'My awesome Project', every space will be replaced with a hyphen. So at the end your project name will be 'My-awesome-project', but in its README.md file, the hyphens will be removed and the project name will be parsed to title case (My Awesome Project).
|
|
186
|
+
- Finally, `git` will be initialized and a list of libraries will be installed. Check the [**notes**](#notes).
|
|
187
|
+
|
|
188
|
+
## What is new?
|
|
189
|
+
|
|
190
|
+
Please check the `changelog.md` file.
|
|
191
|
+
|
|
192
|
+
## <a name="notes"></a>Notes
|
|
193
|
+
|
|
194
|
+
Here is the list of the packages that are being installed, as `devDependencies`:
|
|
195
|
+
|
|
196
|
+
- [`@types/express`](https://www.npmjs.com/package/@types/express)
|
|
197
|
+
- [`@types/http-errors`](https://www.npmjs.com/package/@types/http-errors)
|
|
198
|
+
- [`@types/morgan`](https://www.npmjs.com/package/@types/morgan)
|
|
199
|
+
- [`@types/node`](https://www.npmjs.com/package/@types/node/v/14.17.5)
|
|
200
|
+
- [`@types/swagger-ui-express`](https://www.npmjs.com/package/@types/swagger-ui-express)
|
|
201
|
+
- [`@typescript-eslint/eslint-plugin`](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)
|
|
202
|
+
- [`@typescript-eslint/parser`](https://www.npmjs.com/package/@typescript-eslint/parser)
|
|
203
|
+
- [`dotenv`](https://www.npmjs.com/package/dotenv)
|
|
204
|
+
- [`eslint`](https://www.npmjs.com/package/eslint)
|
|
205
|
+
- [`eslint-config-airbnb-typescript`](https://www.npmjs.com/package/eslint-config-airbnb-typescript)
|
|
206
|
+
- [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier)
|
|
207
|
+
- [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import)
|
|
208
|
+
- [`eslint-plugin-prettier`](https://www.npmjs.com/package/eslint-plugin-prettier)
|
|
209
|
+
- [`eslint-plugin-sort-keys-fix`](https://www.npmjs.com/package/eslint-plugin-sort-keys-fix)
|
|
210
|
+
- [`eslint-plugin-typescript-sort-keys`](https://www.npmjs.com/package/eslint-plugin-typescript-sort-keys)
|
|
211
|
+
- [`nodemon`](https://www.npmjs.com/package/nodemon)
|
|
212
|
+
- [`prettier`](https://www.npmjs.com/package/prettier)
|
|
213
|
+
- [`standard-version`](https://www.npmjs.com/package/standard-version)
|
|
214
|
+
- [`ts-loader`](https://www.npmjs.com/package/ts-loader)
|
|
215
|
+
- [`ts-node`](https://www.npmjs.com/package/ts-node)
|
|
216
|
+
- [`typescript`](https://www.npmjs.com/package/typescript)
|
|
217
|
+
- [`webpack`](https://www.npmjs.com/package/webpack)
|
|
218
|
+
- [`webpack-cli`](https://www.npmjs.com/package/webpack-cli)
|
|
219
|
+
- [`webpack-node-externals`](https://www.npmjs.com/package/webpack-node-externals)
|
|
220
|
+
|
|
221
|
+
As `dependencies`:
|
|
222
|
+
|
|
223
|
+
- [`express`](https://expressjs.com/)
|
|
224
|
+
- [`http-errors`](https://www.npmjs.com/package/http-errors)
|
|
225
|
+
- [`joi`](https://joi.dev/api/?v=17.4.2)
|
|
226
|
+
- [`mongoose`](https://mongoosejs.com/)
|
|
227
|
+
- [`morgan`](https://www.npmjs.com/package/morgan)
|
|
228
|
+
- [`swagger-ui-express`](https://www.npmjs.com/package/swagger-ui-express)
|
|
229
|
+
|
|
230
|
+
Feel free to contribute to this project. Every contribution will be appreciated.
|
|
231
|
+
|
|
232
|
+
## Author
|
|
233
|
+
|
|
234
|
+
- **Anthony Luzquiños** - _Initial Work_ - _Documentation_ - [AnthonyLzq](https://github.com/AnthonyLzq).
|
package/bin/index.js
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
const readLineSync = require('readline-sync')
|
|
2
|
+
const yargs = require('yargs/yargs')
|
|
3
|
+
const { hideBin } = require('yargs/helpers')
|
|
4
|
+
|
|
5
|
+
const installation = require('./src/installation')
|
|
6
|
+
|
|
7
|
+
const CURRENT_YEAR = `${new Date().getFullYear()}`
|
|
8
|
+
const argv = yargs(hideBin(process.argv))
|
|
9
|
+
.version(false)
|
|
10
|
+
.usage(
|
|
11
|
+
'Usage: npx simba [options] or simba [options] (if you it installed globally) or only simba if you want to be asked for the options one by one'
|
|
12
|
+
)
|
|
13
|
+
.example(
|
|
14
|
+
'simba -a Anthony -e sluzquinosa@uni.pe -N "Project Name" -D "Project description"'
|
|
15
|
+
)
|
|
16
|
+
.alias('a', 'author')
|
|
17
|
+
.nargs('a', 1)
|
|
18
|
+
.describe('a', 'Author of the project')
|
|
19
|
+
.alias('e', 'email')
|
|
20
|
+
.nargs('e', 1)
|
|
21
|
+
.describe('e', 'Email of the author')
|
|
22
|
+
.alias('N', 'projectName')
|
|
23
|
+
.nargs('N', 1)
|
|
24
|
+
.describe('N', 'Project name')
|
|
25
|
+
.alias('D', 'projectDescription')
|
|
26
|
+
.nargs('D', 1)
|
|
27
|
+
.describe('D', 'Project description')
|
|
28
|
+
.alias('H', 'heroku')
|
|
29
|
+
.describe('H', 'Whether or not the project will be deployed using Heroku')
|
|
30
|
+
.alias('l', 'license')
|
|
31
|
+
.nargs('l', 1)
|
|
32
|
+
.describe(
|
|
33
|
+
'l',
|
|
34
|
+
'Type of license for the project, it can be one of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL 3.0, in lowercase without its version'
|
|
35
|
+
)
|
|
36
|
+
.alias('v', 'version')
|
|
37
|
+
.nargs('v', 1)
|
|
38
|
+
.describe('v', 'Project initial version')
|
|
39
|
+
.alias('y', 'licenseYear')
|
|
40
|
+
.nargs('y', 1)
|
|
41
|
+
.describe('y', 'Year when the license starts')
|
|
42
|
+
.alias('n', 'npm')
|
|
43
|
+
.describe('n', 'Whether or not the project should use npm as package manager')
|
|
44
|
+
.alias('f', 'mainFile')
|
|
45
|
+
.nargs('f', 1)
|
|
46
|
+
.describe('f', 'Main file of the project')
|
|
47
|
+
.alias('q', 'questions')
|
|
48
|
+
.describe(
|
|
49
|
+
'q',
|
|
50
|
+
'Whether or not you want to be asked to answer the questions related to the project one by one'
|
|
51
|
+
)
|
|
52
|
+
.default({
|
|
53
|
+
H: false,
|
|
54
|
+
n: false,
|
|
55
|
+
y: CURRENT_YEAR,
|
|
56
|
+
l: 'unlicensed',
|
|
57
|
+
v: '0.1.0',
|
|
58
|
+
f: 'src/index.ts',
|
|
59
|
+
q: false
|
|
60
|
+
})
|
|
61
|
+
.boolean(['H', 'n', 'q'])
|
|
62
|
+
.help('h')
|
|
63
|
+
.alias('h', 'help')
|
|
64
|
+
.epilog('Developed by AnthonyLzq').argv
|
|
65
|
+
|
|
66
|
+
/** @type {Config} */
|
|
67
|
+
const config = {
|
|
68
|
+
author: '',
|
|
69
|
+
email: '',
|
|
70
|
+
projectName: '',
|
|
71
|
+
projectDescription: '',
|
|
72
|
+
heroku: false,
|
|
73
|
+
license: 'unlicensed',
|
|
74
|
+
version: '0.1.0',
|
|
75
|
+
licenseYear: CURRENT_YEAR,
|
|
76
|
+
npm: false,
|
|
77
|
+
manager: 'yarn add',
|
|
78
|
+
mainFile: 'src/index.ts'
|
|
79
|
+
}
|
|
80
|
+
const UNLICENSED = 'unlicensed'
|
|
81
|
+
const LICENSES = [
|
|
82
|
+
'MIT',
|
|
83
|
+
'Apache 2.0',
|
|
84
|
+
'MPL 2.0',
|
|
85
|
+
'LGPL 3.0',
|
|
86
|
+
'GPL 3.0',
|
|
87
|
+
'AGPL 3.0'
|
|
88
|
+
]
|
|
89
|
+
const POSSIBLE_LICENSES = ['mit', 'apache', 'mpl', 'lgpl', 'gpl', 'agpl']
|
|
90
|
+
const ONE_CHARACTER_REGEXP = /^\w/
|
|
91
|
+
const YEAR_REGEXP = /^\d{4}$/
|
|
92
|
+
const EMAIL_REGEXP =
|
|
93
|
+
/^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i
|
|
94
|
+
|
|
95
|
+
const main = async () => {
|
|
96
|
+
if (argv.q) {
|
|
97
|
+
readLineSync.promptCLLoop(
|
|
98
|
+
{
|
|
99
|
+
npm: () => {
|
|
100
|
+
config.npm = true
|
|
101
|
+
|
|
102
|
+
return true
|
|
103
|
+
},
|
|
104
|
+
yarn: () => true
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
caseSensitive: false,
|
|
108
|
+
limitMessage: 'That is not a valid option',
|
|
109
|
+
prompt: '> Yarn or npm? '
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
if (config.npm) config.manager = 'npm i'
|
|
114
|
+
|
|
115
|
+
readLineSync.promptLoop(
|
|
116
|
+
input => {
|
|
117
|
+
config.projectName = input.toLowerCase()
|
|
118
|
+
|
|
119
|
+
return config.projectName !== ''
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
limit: ONE_CHARACTER_REGEXP,
|
|
123
|
+
limitMessage: 'The project must have a name!',
|
|
124
|
+
prompt: '> Project name: '
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
readLineSync.promptLoop(
|
|
129
|
+
input => {
|
|
130
|
+
config.projectDescription = input
|
|
131
|
+
|
|
132
|
+
return config.projectDescription !== ''
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
limit: ONE_CHARACTER_REGEXP,
|
|
136
|
+
limitMessage: 'The project must have a description!',
|
|
137
|
+
prompt: '> Project description: '
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
readLineSync.promptLoop(
|
|
142
|
+
input => {
|
|
143
|
+
config.author = input
|
|
144
|
+
|
|
145
|
+
return config.author !== ''
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
limit: ONE_CHARACTER_REGEXP,
|
|
149
|
+
limitMessage: 'The project must have an author!',
|
|
150
|
+
prompt: '> Author: '
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
config.email = readLineSync.questionEMail('> Email: ', {
|
|
155
|
+
limit: EMAIL_REGEXP,
|
|
156
|
+
limitMessage: 'That is not a valid email!'
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
config.version = readLineSync.question('> Project version (0.1.0): ')
|
|
160
|
+
config.version = config.version === '' ? '0.1.0' : config.version
|
|
161
|
+
|
|
162
|
+
const licensePos = readLineSync.keyInSelect(
|
|
163
|
+
LICENSES,
|
|
164
|
+
'> Select your license: ',
|
|
165
|
+
{
|
|
166
|
+
cancel: false
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
config.license = LICENSES[licensePos]
|
|
171
|
+
.toLowerCase()
|
|
172
|
+
.replace(/ /g, '-')
|
|
173
|
+
.replace('d', '')
|
|
174
|
+
|
|
175
|
+
readLineSync.promptLoop(
|
|
176
|
+
input => {
|
|
177
|
+
if (input !== '') config.licenseYear = input
|
|
178
|
+
|
|
179
|
+
return YEAR_REGEXP.test(config.licenseYear)
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
limit: [YEAR_REGEXP, ''],
|
|
183
|
+
limitMessage: 'That is not a valid license year!',
|
|
184
|
+
prompt: `> License year (${config.licenseYear}): `
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
config.heroku = readLineSync.keyInYNStrict(
|
|
189
|
+
'> Will this project be deployed with Heroku? ',
|
|
190
|
+
{
|
|
191
|
+
caseSensitive: false
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
config.mainFile = readLineSync.question('> Main file (src/index.ts): ')
|
|
196
|
+
} else {
|
|
197
|
+
if (!argv.author) return console.log('Error! An author is required!')
|
|
198
|
+
else config.author = argv.author
|
|
199
|
+
|
|
200
|
+
if (!argv.email) return console.log('Error! An email is required!')
|
|
201
|
+
else {
|
|
202
|
+
if (!EMAIL_REGEXP.test(argv.email))
|
|
203
|
+
return console.log('That is not a valid email!')
|
|
204
|
+
|
|
205
|
+
config.email = argv.email
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!argv.projectName)
|
|
209
|
+
return console.log('Error! A project name is required!')
|
|
210
|
+
else if (argv.projectName.includes(' '))
|
|
211
|
+
config.projectName = argv.projectName.replace(/ /g, '-')
|
|
212
|
+
else config.projectName = argv.projectName
|
|
213
|
+
|
|
214
|
+
if (!argv.projectDescription)
|
|
215
|
+
return console.log('Error! A project description is required')
|
|
216
|
+
else config.projectDescription = argv.projectDescription
|
|
217
|
+
|
|
218
|
+
if (argv.heroku) config.heroku = true
|
|
219
|
+
|
|
220
|
+
if (!argv.license || argv.license === UNLICENSED)
|
|
221
|
+
console.log('License was not provided')
|
|
222
|
+
else {
|
|
223
|
+
if (!POSSIBLE_LICENSES.includes(argv.license.toLowerCase()))
|
|
224
|
+
return console.log(
|
|
225
|
+
'Wrong license, licenses available are: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL 3.0. Please, provide one of then in lowercase without its version in case you want to have a license, otherwise skip license argument'
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
switch (argv.license) {
|
|
229
|
+
case POSSIBLE_LICENSES[0]:
|
|
230
|
+
config.license = argv.license
|
|
231
|
+
break
|
|
232
|
+
case POSSIBLE_LICENSES[1]:
|
|
233
|
+
case POSSIBLE_LICENSES[2]:
|
|
234
|
+
config.license = `${argv.license}-2.0`
|
|
235
|
+
break
|
|
236
|
+
case POSSIBLE_LICENSES[3]:
|
|
237
|
+
case POSSIBLE_LICENSES[4]:
|
|
238
|
+
case POSSIBLE_LICENSES[5]:
|
|
239
|
+
config.license = `${argv.license}-3.0`
|
|
240
|
+
break
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!argv.licenseYear)
|
|
245
|
+
console.log(
|
|
246
|
+
`Year license was not provided, using ${config.licenseYear} as default`
|
|
247
|
+
)
|
|
248
|
+
else if (!YEAR_REGEXP.test(config.licenseYear))
|
|
249
|
+
return console.log(
|
|
250
|
+
'Year license format was wrong, please provide a YYYY format'
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
if (!argv.version)
|
|
254
|
+
console.log('Initial version wa not provided, using 0.1.0 as default')
|
|
255
|
+
else config.version = argv.version
|
|
256
|
+
|
|
257
|
+
if (!argv.npm) console.log('Using yarn as default package manager')
|
|
258
|
+
else {
|
|
259
|
+
config.npm = true
|
|
260
|
+
config.manager = 'npm i'
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (!argv.mainFile) console.log('Using src/index.ts as default main file')
|
|
264
|
+
else config.mainFile = argv.mainFile
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
await installation(config)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
module.exports = main
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @typedef {Object} Config configuration to initialize a project
|
|
274
|
+
* @property {String} author author of the project
|
|
275
|
+
* @property {String} email email of the project author
|
|
276
|
+
* @property {String} projectName project name
|
|
277
|
+
* @property {String} projectDescription project description
|
|
278
|
+
* @property {Boolean} heroku true if the project will be deployed in heroku
|
|
279
|
+
* @property {'unlicensed'|'mit'|'apache-2.0'|'mpl-2.0'|'lgpl-3.0'|'gpl-3.0'|'agpl-3.0'} license project license
|
|
280
|
+
* @property {String} version project initial version
|
|
281
|
+
* @property {String} licenseYear year when the license starts in format YYYY
|
|
282
|
+
* @property {Boolean} npm true means that the package manager will be npm, otherwise yarn
|
|
283
|
+
* @property {'yarn add'|'npm i'} manager command that will be used to install packages
|
|
284
|
+
* @property {String} mainFile main file of the project
|
|
285
|
+
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const writeFile = require('../utils/writeFile')
|
|
2
|
+
const titleCase = require('../utils/titleCase')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {String} projectName
|
|
6
|
+
* @returns {Promise<void>}
|
|
7
|
+
*/
|
|
8
|
+
module.exports = async projectName => {
|
|
9
|
+
const data = {
|
|
10
|
+
changelogContent: `# ${titleCase(projectName)}`,
|
|
11
|
+
changelogFile: 'CHANGELOG.md'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
await writeFile(`${projectName}/${data.changelogFile}`, data.changelogContent)
|
|
15
|
+
}
|