leaf-machine
v1.0.1
Published
My node module
Downloads
2
Readme
nod
NodeJS module generator/boilerplate.
Features
- Babel - Write next generation JavaScript today.
- Jest - JavaScript testing framework used by Facebook.
- ESLint - Make sure you are writing a quality code.
- Prettier - Enforces a consistent style by parsing your code and re-printing it.
- Flow - A static type checker for JavaScript used heavily within Facebook.
- Travis CI - Automate tests and linting for every push or pull request.
- Documentation - A documentation system so good, you'll actually write documentation.
- Conventional Changelog - Generate a changelog from git metadata.
Install
The easiest way to use nod is through the Yeoman Generator.
$ npm install -g yo generator-nod
$ yo nod
If you don't want to use the generator, you can also download or git clone
this repo
$ git clone https://github.com/diegohaz/nod my-module
$ cd my-module
$ rm -rf .git
$ npm install # or yarn
Just make sure to edit package.json
, README.md
and LICENSE
files accordingly with your module's info.
Commands
$ npm test # run tests with Jest
$ npm run coverage # run tests with coverage and open it on browser
$ npm run lint # lint code
$ npm run docs # generate docs
$ npm run build # generate docs and transpile code
Publish
$ npm version patch|minor|major
$ npm publish
It'll automatically run test
, lint
, docs
, build
, generate CHANGELOG.md
, and push commits and tags to the remote repository.
Removing stuff
Remove
.flowconfig
file.Remove
flow
frompackage.json
:"scripts": { - "flow": "flow check", - "flowbuild": "flow-copy-source src dist", - "prebuild": "npm run docs && npm run clean && npm run flowbuild", + "prebuild": "npm run docs && npm run clean", }, "devDependencies": { - "@babel/preset-flow": "^7.0.0", - "eslint-plugin-flowtype": "^2.50.0", - "eslint-plugin-flowtype-errors": "^3.5.1", - "flow-bin": "^0.81.0", - "flow-copy-source": "^2.0.2", }
Remove
flow
from.babelrc
:"presets": [ - "@babel/preset-flow" ]
Remove
flow
from.eslintrc
:"extends": [ - "plugin:flowtype/recommended", - "prettier/flowtype" ], "plugins": [ - "flowtype", - "flowtype-errors" ], "rules": { - "flowtype-errors/show-errors": "error" }
Run
yarn
.
Remove
documentation
frompackage.json
:"scripts": { - "docs": "documentation readme src --section=API", - "postdocs": "git add README.md", - "prebuild": "npm run docs && npm run clean", + "prebuild": "npm run clean", }, "devDependencies": { - "documentation": "^8.0.0", }
Run
yarn
.
Adding stuff
Install dependencies:
yarn add -D @babel/preset-typescript @types/jest eslint-plugin-typescript typescript typescript-eslint-parser
Update
package.json
:+ "types": "dist/ts/src", "scripts": { + "type-check": "tsc --noEmit", - "lint": "eslint .", + "lint": "eslint . --ext js,ts,tsx", - "build": "babel src -d dist", + "build": "tsc --emitDeclarationOnly && babel src -d dist -x .js,.ts,.tsx", }, "lint-staged": { - "*.js": [ + "*.{js,ts,tsx}": [ - "eslint --fix", + "eslint --fix --ext js,ts,tsx", "git add" ] }
Create
tsconfig.json
{ "compilerOptions": { "outDir": "dist/ts", "target": "esnext", "module": "esnext", "moduleResolution": "node", "jsx": "react", "strict": true, "declaration": true, "noFallthroughCasesInSwitch": true, "noImplicitReturns": true, "noUnusedLocals": true, "noUnusedParameters": true, "stripInternal": true } }
Update
.babelrc
:"presets": [ + "@babel/preset-typescript" ]
Update
.eslintrc
with these settings:"settings": { "import/resolver": { "node": { "extensions": [".js", ".jsx", ".ts", ".tsx"] } } }, "overrides": [ { "files": ["**/*.ts", "**/*.tsx"], "parser": "typescript-eslint-parser", "plugins": [ "typescript" ], "rules": { "no-undef": "off", "no-unused-vars": "off", "no-restricted-globals": "off" } } ]
Create
jest.config.js
:module.exports = { moduleFileExtensions: ["js", "jsx", "ts", "tsx"], testMatch: ["**/?(*.)+(spec|test).(j|t)s?(x)"], transform: { "\\.(j|t)sx?$": "babel-jest" } };
API
Table of Contents
sayHello
This function says hello.
Parameters
name
string Some name to say hello for.
Returns string The hello.
License
MIT © Diego Haz