├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .flowconfig
├── .gitignore
├── .npmrc
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── package.json
├── src
└── index.js
├── test
└── index.test.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/preset-env",
5 | {
6 | "targets": {
7 | "node": 6
8 | }
9 | }
10 | ],
11 | "@babel/preset-flow"
12 | ],
13 | "plugins": [
14 | "@babel/plugin-proposal-class-properties"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | # Change these settings to your own preference
10 | indent_style = space
11 | indent_size = 2
12 |
13 | # We recommend you to keep these unchanged
14 | end_of_line = lf
15 | charset = utf-8
16 | trim_trailing_whitespace = true
17 | insert_final_newline = true
18 |
19 | [*.md]
20 | trim_trailing_whitespace = false
21 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | coverage
2 | dist
3 | node_modules
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "extends": [
4 | "airbnb-base",
5 | "plugin:flowtype/recommended",
6 | "plugin:prettier/recommended",
7 | "prettier/flowtype"
8 | ],
9 | "plugins": [
10 | "flowtype",
11 | "flowtype-errors"
12 | ],
13 | "env": {
14 | "jest": true
15 | },
16 | "rules": {
17 | "flowtype-errors/show-errors": "error"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/dist
3 | .*/coverage
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | coverage
3 | dist
4 | node_modules
5 | *.log
6 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | save-exact = true
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - v8
4 | script:
5 | - yarn lint
6 | - yarn test --coverage
7 | cache:
8 | - yarn
9 | after_success:
10 | - bash <(curl -s https://codecov.io/bash)
11 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Diego Haz
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.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # nod
2 |
3 | [](https://npmjs.org/package/generator-nod)
4 | [](https://travis-ci.org/diegohaz/nod) [](https://codecov.io/gh/diegohaz/nod/branch/master)
5 |
6 | NodeJS module generator/boilerplate.
7 |
8 |

9 |
10 | ## Features
11 |
12 | - [**Babel**](https://babeljs.io/) - Write next generation JavaScript today.
13 | - [**Jest**](https://facebook.github.io/jest) - JavaScript testing framework used by Facebook.
14 | - [**ESLint**](http://eslint.org/) - Make sure you are writing a quality code.
15 | - [**Prettier**](https://prettier.io/) - Enforces a consistent style by parsing your code and re-printing it.
16 | - [**Flow**](https://flowtype.org/) - A static type checker for JavaScript used heavily within Facebook.
17 | - [**Travis CI**](https://travis-ci.org) - Automate tests and linting for every push or pull request.
18 | - [**Documentation**](http://documentation.js.org/) - A documentation system so good, you'll actually write documentation.
19 | - [**Standard Version**](https://github.com/conventional-changelog/standard-version) - Automate versioning and CHANGELOG generation.
20 |
21 | ## Install
22 |
23 | The easiest way to use **nod** is through the Yeoman Generator.
24 |
25 | ```sh
26 | $ npm install -g yo generator-nod
27 | $ yo nod
28 | ```
29 |
30 | If you don't want to use the generator, you can also download or `git clone` this repo
31 |
32 | ```sh
33 | $ git clone https://github.com/diegohaz/nod my-module
34 | $ cd my-module
35 | $ rm -rf .git
36 | $ npm install # or yarn
37 | ```
38 |
39 | Just make sure to edit `package.json`, `README.md` and `LICENSE` files accordingly with your module's info.
40 |
41 | ## Commands
42 |
43 | ```sh
44 | $ npm test # run tests with Jest
45 | $ npm run coverage # run tests with coverage and open it on browser
46 | $ npm run lint # lint code
47 | $ npm run docs # generate docs
48 | $ npm run build # generate docs and transpile code
49 | ```
50 |
51 | ### Publish
52 |
53 | ```sh
54 | $ npm release
55 | $ npm publish
56 | ```
57 |
58 | It'll automatically run `test`, `lint`, `docs`, `build`, generate `CHANGELOG.md`, and push commits and tags to the remote repository.
59 |
60 | ## Removing stuff
61 |
62 | Flow
63 |
64 | 1. Remove `.flowconfig` file.
65 |
66 | 2. Remove `flow` from `package.json`:
67 |
68 | ```diff
69 | "scripts": {
70 | - "flow": "flow check",
71 | - "flowbuild": "flow-copy-source src dist",
72 | - "prebuild": "npm run docs && npm run clean && npm run flowbuild",
73 | + "prebuild": "npm run docs && npm run clean",
74 | },
75 | "devDependencies": {
76 | - "@babel/preset-flow": "^7.0.0",
77 | - "eslint-plugin-flowtype": "^2.50.0",
78 | - "eslint-plugin-flowtype-errors": "^3.5.1",
79 | - "flow-bin": "^0.81.0",
80 | - "flow-copy-source": "^2.0.2",
81 | }
82 | ```
83 |
84 | 3. Remove `flow` from `.babelrc`:
85 |
86 | ```diff
87 | "presets": [
88 | - "@babel/preset-flow"
89 | ]
90 | ```
91 |
92 | 4. Remove `flow` from `.eslintrc`:
93 |
94 | ```diff
95 | "extends": [
96 | - "plugin:flowtype/recommended",
97 | - "prettier/flowtype"
98 | ],
99 | "plugins": [
100 | - "flowtype",
101 | - "flowtype-errors"
102 | ],
103 | "rules": {
104 | - "flowtype-errors/show-errors": "error"
105 | }
106 | ```
107 |
108 | 5. Run `yarn`.
109 |
110 |
111 |
112 | Documentation
113 |
114 | 1. Remove `documentation` from `package.json`:
115 |
116 | ```diff
117 | "scripts": {
118 | - "docs": "documentation readme src --section=API",
119 | - "postdocs": "git add README.md",
120 | - "prebuild": "npm run docs && npm run clean",
121 | + "prebuild": "npm run clean",
122 | },
123 | "devDependencies": {
124 | - "documentation": "^8.0.0",
125 | }
126 | ```
127 |
128 | 2. Run `yarn`.
129 |
130 |
131 |
132 | ## Adding stuff
133 |
134 | TypeScript
135 |
136 | 1. Install dependencies:
137 |
138 | ```sh
139 | yarn add -D @babel/preset-typescript @types/jest @typescript-eslint/eslint-plugin @typescript-eslint/parser typescript
140 | ```
141 |
142 | 2. Update `package.json`:
143 |
144 | ```diff
145 | + "types": "dist/ts/src",
146 | "scripts": {
147 | + "type-check": "tsc --noEmit",
148 | - "lint": "eslint .",
149 | + "lint": "eslint . --ext js,ts,tsx",
150 | - "build": "babel src -d dist",
151 | + "build": "tsc --emitDeclarationOnly && babel src -d dist -x .js,.ts,.tsx",
152 | },
153 | "lint-staged": {
154 | - "*.js": [
155 | + "*.{js,ts,tsx}": [
156 | - "eslint --fix",
157 | + "eslint --fix --ext js,ts,tsx",
158 | "git add"
159 | ]
160 | }
161 | ```
162 |
163 | 3. Create `tsconfig.json`
164 |
165 | ```json
166 | {
167 | "compilerOptions": {
168 | "outDir": "dist/ts",
169 | "target": "esnext",
170 | "module": "esnext",
171 | "moduleResolution": "node",
172 | "jsx": "react",
173 | "strict": true,
174 | "declaration": true,
175 | "noFallthroughCasesInSwitch": true,
176 | "noImplicitReturns": true,
177 | "noUnusedLocals": true,
178 | "noUnusedParameters": true,
179 | "stripInternal": true
180 | }
181 | }
182 | ```
183 |
184 | 4. Update `.babelrc`:
185 |
186 | ```diff
187 | "presets": [
188 | + "@babel/preset-typescript"
189 | ]
190 | ```
191 |
192 | 5. Update `.eslintrc` with these settings:
193 |
194 | ```json
195 | "settings": {
196 | "import/resolver": {
197 | "node": {
198 | "extensions": [".js", ".jsx", ".ts", ".tsx"]
199 | }
200 | }
201 | },
202 | "overrides": [
203 | {
204 | "files": ["**/*.ts", "**/*.tsx"],
205 | "parser": "@typescript-eslint/parser",
206 | "parserOptions": {
207 | "project": "./tsconfig.json"
208 | },
209 | "plugins": [
210 | "@typescript-eslint"
211 | ],
212 | "rules": {
213 | "no-undef": "off",
214 | "no-unused-vars": "off",
215 | "no-restricted-globals": "off"
216 | }
217 | }
218 | ]
219 | ```
220 |
221 |
222 |
223 | ## API
224 |
225 |
226 |
227 | #### Table of Contents
228 |
229 | - [sayHello](#sayhello)
230 | - [Parameters](#parameters)
231 |
232 | ### sayHello
233 |
234 | This function says hello.
235 |
236 | #### Parameters
237 |
238 | - `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Some name to say hello for. (optional, default `"Haz"`)
239 |
240 | Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The hello.
241 |
242 | ## License
243 |
244 | MIT © [Diego Haz](https://github.com/diegohaz)
245 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generator-nod",
3 | "version": "0.0.1",
4 | "description": "My node module",
5 | "license": "MIT",
6 | "repository": "diegohaz/nod",
7 | "main": "dist/index.js",
8 | "author": {
9 | "name": "Diego Haz",
10 | "email": "hazdiego@gmail.com",
11 | "url": "https://github.com/diegohaz"
12 | },
13 | "files": [
14 | "dist",
15 | "src"
16 | ],
17 | "scripts": {
18 | "test": "jest",
19 | "coverage": "npm test -- --coverage",
20 | "postcoverage": "open-cli coverage/lcov-report/index.html",
21 | "lint": "eslint .",
22 | "flow": "flow check",
23 | "docs": "documentation readme src --section=API",
24 | "postdocs": "git add README.md",
25 | "clean": "rimraf dist",
26 | "flowbuild": "flow-copy-source src dist",
27 | "prebuild": "npm run docs && npm run clean && npm run flowbuild",
28 | "build": "babel src -d dist",
29 | "prerelease": "npm run lint && npm test && npm run build",
30 | "release": "standard-version",
31 | "postpublish": "git push origin master --follow-tags"
32 | },
33 | "husky": {
34 | "hooks": {
35 | "pre-commit": "lint-staged"
36 | }
37 | },
38 | "lint-staged": {
39 | "*.js": [
40 | "eslint --fix",
41 | "git add"
42 | ]
43 | },
44 | "keywords": [
45 | "generator-nod"
46 | ],
47 | "dependencies": {},
48 | "devDependencies": {
49 | "@babel/cli": "7.4.4",
50 | "@babel/core": "7.4.5",
51 | "@babel/plugin-proposal-class-properties": "7.4.4",
52 | "@babel/preset-env": "7.4.5",
53 | "@babel/preset-flow": "7.0.0",
54 | "babel-eslint": "10.0.2",
55 | "babel-jest": "24.8.0",
56 | "documentation": "11.0.1",
57 | "eslint": "6.0.0",
58 | "eslint-config-airbnb-base": "13.1.0",
59 | "eslint-config-prettier": "5.0.0",
60 | "eslint-plugin-flowtype": "3.10.5",
61 | "eslint-plugin-flowtype-errors": "4.1.0",
62 | "eslint-plugin-import": "2.17.3",
63 | "eslint-plugin-prettier": "3.1.0",
64 | "flow-bin": "0.101.1",
65 | "flow-copy-source": "2.0.6",
66 | "husky": "2.4.1",
67 | "jest": "24.8.0",
68 | "lint-staged": "8.2.1",
69 | "open-cli": "5.0.0",
70 | "prettier": "1.18.2",
71 | "rimraf": "2.6.3",
72 | "standard-version": "6.0.1"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | // @flow
2 |
3 | /**
4 | * This function says hello.
5 | * @param name Some name to say hello for.
6 | * @returns The hello.
7 | */
8 | const sayHello = (name: string = "Haz"): string => `Hello, ${name}!`;
9 |
10 | export default sayHello;
11 |
--------------------------------------------------------------------------------
/test/index.test.js:
--------------------------------------------------------------------------------
1 | import sayHello from "../src";
2 |
3 | test("sayHello", () => {
4 | expect(sayHello()).toBe("Hello, Haz!");
5 | expect(sayHello("foo")).toBe("Hello, foo!");
6 | });
7 |
--------------------------------------------------------------------------------