diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..9549f55 --- /dev/null +++ b/.babelrc @@ -0,0 +1,6 @@ +{ + "presets": [ + "@babel/preset-env", + "@babel/preset-flow" + ] +} \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..34fcd17 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] + +# change these settings to your own preference +indent_style = space +indent_size = 2 + +# we recommend you to keep these unchanged +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[{package,bower}.json] +indent_style = space +indent_size = 2 diff --git a/.esdoc.json b/.esdoc.json new file mode 100644 index 0000000..9b4d07d --- /dev/null +++ b/.esdoc.json @@ -0,0 +1,48 @@ +{ + "source": "./src", + "destination": "./docs", + "includes": [ + "\\.js$" + ], + "excludes": [ + "\\.config\\.js$" + ], + "plugins": [ + { + "name": "esdoc-standard-plugin" + }, + { + "name": "esdoc-flow-type-plugin", + "option": { + "enable": true + } + }, + { + "name": "esdoc-brand-plugin" + } + ], + "option": { + "lint": { + "enable": true + }, + "coverage": { + "enable": true + }, + "test": { + "source": "./test/", + "interfaces": [ + "describe", + "it", + "context", + "suite", + "test" + ], + "includes": [ + "(spec|Spec|test|Test)\\.js$" + ], + "excludes": [ + "\\.config\\.js$" + ] + } + } +} \ No newline at end of file diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..2c944ac --- /dev/null +++ b/.eslintignore @@ -0,0 +1,9 @@ +node_modules +flow-typed +dist +doc +.DS_Store + +\#*# + +.vscode diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..81f10e5 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,12 @@ +{ + "parser": "babel-eslint", + "extends": [ + "standard", + "plugin:flowtype/recommended" + ], + "rules": {}, + "parserOptions": {}, + "plugins": [ + "flowtype" + ] +} diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..f1057fa --- /dev/null +++ b/.flowconfig @@ -0,0 +1,14 @@ +[ignore] +.*/node_modules/npm/node_modules/config-chain/.* +.*/dist/.* + + +[include] + +[libs] + +[lints] + +[options] + +[strict] diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cbdcbbc --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.js text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18c5f8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +node_modules +doc +dist +.DS_Store +coverage/lcov-report +coverage/coverage-summary.json +coverage/lcov.info +package.json.save +package-lock.json +yarn.lock + +\#*# + +.vscode \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..36f6d15 --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +node_modules/ +.DS_Store/ +doc/ +flow-typed +package.json.save +package-lock.json +yarn.lock +.vscode diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..50083cf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js + +node_js: 8 + +deploy: + provider: script + skip_cleanup: true + script: + - npm run release diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..e69de29 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..d86e874 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,19 @@ +# Contributing + +- Fork the project and clone your fork. +- Create a local feature branch: + +```bash +git checkout -b +``` + +- Please add tests in '__tests__/' for each new function that you're adding. +- Make one or more atomic commits using either 'yarn commit' or 'npm run commit' ONLY (this project is commitizen friendly). Do not commit changes to the `dist/` folder. +- Run 'yarn test', 'yarn lint' and 'yarn flow' and address any errors. Preferably, fix commits in place using `git rebase` or `git commit --amend` to make the changes easier to review and to keep the history tidy. +- Push to your fork: + +```bash +git push origin +``` + +- Open a pull request. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..755f26f --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +library-boilerplate +Copyright (c) 2018 Ziv Barber, contributors. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a4b358 --- /dev/null +++ b/README.md @@ -0,0 +1,167 @@ +# library-boilerplate + +Rollup based javascript library boilerplate + babel 7, eslint, flow, jest, esdoc and live editing. + +[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) +[![coverage statements](./coverage/badge-statements.svg)](https://github.com/pamepeixinho/jest-coverage-badges) +[![coverage lines](./coverage/badge-lines.svg)](https://github.com/pamepeixinho/jest-coverage-badges) +[![coverage functions](./coverage/badge-functions.svg)](https://github.com/pamepeixinho/jest-coverage-badges) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) + +![library-boilerplate logo](https://cdn-images-1.medium.com/max/1500/1*LQbS9RgHy93y9JH8ltejuQ.jpeg) + +- [Getting Started](#getstart) +- [Features](#features) +- [Installation](#inst) +- [Running](#run) +- [API](#ref) +- [The source code](#code) +- [Variations](#other) +- [Credit](#credit) + + +## Getting Started: ## + +This boilerplate including a basic code to start creating a js based library. + +Start with cloning the project: + +```bash +$ git clone --depth=1 git://github.com/Ziv-Barber/library-boilerplate.git your-project-name +``` + +Then: + +- Remove the .git directory. +- Edit package.json: + - Change the name of the project to your project name. + - Change the version to 0.1.0 + - If you want to release a npm package then change: + "release": "npx run-s test release:pre release:post" + to: + "release": "npx run-s test release:pre release:publish release:post" + +The boilerplate without any changes supporting creating a library for both CommonJS, es6 modules, amd and browser. If you don't need all of this then just edit the rollup.config.js file and remove the inputs that you don't need. + +Now, create a new github project and do: + +```bash +$ git init +$ git remote add origin https://github.com/your-name/your-project-name.git +$ git add -A +$ npm run commit +$ git push -u origin master +``` + +This project is using semantic-release to automatic handling of the version of your library. + + +## Features: ## + +This project is using the following awesome libraries/utilities/services: + +- [babel 7][https://babeljs.io/] +- [better-npm-run][https://github.com/benoror/better-npm-run] +- [commitizen][http://commitizen.github.io/cz-cli] +- [esdoc][https://esdoc.org/] +- [eslint][https://eslint.org/] +- [flow][https://flow.org/] +- [jest][https://jestjs.io/] +- [npm-run-all][https://github.com/mysticatea/npm-run-all] +- [rollup][https://rollupjs.org/] +- [semantic-release][https://github.com/semantic-release/semantic-release] + + +## Installation: ## + +via Git: + +```bash +$ git clone git://github.com/Ziv-Barber/library-boilerplate.git +``` + +via yarn: + +```bash +$ yarn add library-boilerplate +``` + +via npm: + +```bash +$ npm install library-boilerplate +``` + + +## API: ## + +???. + + +## The source code: ## + +- lib - all the sources. + - types - put here all the flow type declarations. +- __tests__ - all the tests. +- .editorconfig - coding style for this project. + +### Scripts: ### + +- start +- build +- clean +- test +- flow +- lint +### Tests: ### + +Tests: + +```bash +yarn test +``` + +or: + +```bash +npm test +``` + +### Flow: ### + +Flow check (if you don't have a flow plugin in your IDE): + +```bash +yarn flow +``` + +or: + +```bash +npm flow +``` + +### Lint: ### + +Lint check (if you don't have a plugin in your IDE): + +```bash +yarn lint +``` + +or: + +```bash +npm lint +``` + + +## Variations: ## + +- library-boilerplate (this project) - Rollup based javascript library boilerplate + babel 7, eslint, flow, jest, esdoc and live editing. +- [react-boilerplate](https://github.com/Ziv-Barber/react-boilerplate) - React 16.5.2 + babel 7 + jest + webpack 4 + flow + eslint + esdoc + live editing boilerplate. + + +## Credit: ## + +- Created by Ziv Barber. diff --git a/__tests__/.eslintrc b/__tests__/.eslintrc new file mode 100644 index 0000000..23b72bd --- /dev/null +++ b/__tests__/.eslintrc @@ -0,0 +1,8 @@ +{ + "extends": [ + "../.eslintrc" + ], + "env": { + "jest": true + } +} diff --git a/__tests__/someModule-test.js b/__tests__/someModule-test.js new file mode 100644 index 0000000..d527c0e --- /dev/null +++ b/__tests__/someModule-test.js @@ -0,0 +1,15 @@ +import * as someModule from '../lib/someModule' + +/** @test {someModule} */ +describe('someModule test suits', function () { + // Executed before each test: + beforeEach(done => { + done() + }) + + test('#test ()', done => { + expect(someModule).toBeDefined() + // assert(123 === 123) + done() + }) +}) diff --git a/coverage/badge-branches.svg b/coverage/badge-branches.svg new file mode 100644 index 0000000..7db6c38 --- /dev/null +++ b/coverage/badge-branches.svg @@ -0,0 +1 @@ + coveragecoverage100%100% \ No newline at end of file diff --git a/coverage/badge-functions.svg b/coverage/badge-functions.svg new file mode 100644 index 0000000..7d3f6e9 --- /dev/null +++ b/coverage/badge-functions.svg @@ -0,0 +1 @@ + coveragecoverage0%0% \ No newline at end of file diff --git a/coverage/badge-lines.svg b/coverage/badge-lines.svg new file mode 100644 index 0000000..7db6c38 --- /dev/null +++ b/coverage/badge-lines.svg @@ -0,0 +1 @@ + coveragecoverage100%100% \ No newline at end of file diff --git a/coverage/badge-statements.svg b/coverage/badge-statements.svg new file mode 100644 index 0000000..7db6c38 --- /dev/null +++ b/coverage/badge-statements.svg @@ -0,0 +1 @@ + coveragecoverage100%100% \ No newline at end of file diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..61e27ae --- /dev/null +++ b/lib/index.js @@ -0,0 +1,5 @@ +// @flow + +import {someApi} from './someModule' + +module.exports = {someApi} diff --git a/lib/someModule.js b/lib/someModule.js new file mode 100644 index 0000000..985ddd0 --- /dev/null +++ b/lib/someModule.js @@ -0,0 +1,6 @@ +// @flow + +const someApi = () => { +} + +export {someApi} diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..b4f44e6 --- /dev/null +++ b/logo.svg @@ -0,0 +1,12 @@ + + + + +]> + + + + L + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..758cf18 --- /dev/null +++ b/package.json @@ -0,0 +1,111 @@ +{ + "name": "library-boilerplate", + "version": "0.1.0", + "description": "Rollup based javascript library boilerplate + babel 7, eslint, flow, jest, esdoc and live editing.", + "scripts": { + "start": "better-npm-run start", + "test": "npx jest", + "pretest": "npx run-s clean build", + "test:badges": "npx run-s test:coverage test:badgesOnly", + "test:badgesOnly": "npx jest-coverage-badges", + "test:coverage": "npx jest --coverage", + "test:watch": "npx jest --watch", + "build": "npx rollup -c --environment BUILD:production", + "clean": "npx rimraf dist doc", + "commit": "npx git-cz", + "dev": "npx rollup -c --environment BUILD:development", + "dev:watch": "npx rollup -c --environment BUILD:development -w", + "esdoc": "npx esdoc", + "lint": "better-npm-run lint", + "release": "npx run-s test release:pre release:post", + "release:post": "npx semantic-release post", + "release:pre": "npx semantic-release pre", + "release:publish": "npm publish" + }, + "keywords": [ + "boilerplate", + "starter", + "kit", + "starter kit", + "template", + "quickstart", + "library", + "javascript", + "babel", + "eslint", + "esdoc", + "jest", + "webpack", + "commitizen" + ], + "dependencies": {}, + "devDependencies": { + "@babel/core": "^7.1.2", + "@babel/node": "^7.0.0", + "@babel/preset-env": "^7.1.0", + "@babel/preset-flow": "^7.0.0", + "babel-core": "^7.0.0-bridge.0", + "babel-eslint": "^10.0.1", + "babel-jest": "^23.6.0", + "better-npm-run": "^0.1.1", + "commitizen": "^2.10.1", + "cz-conventional-changelog": "^2.1.0", + "esdoc": "^1.1.0", + "esdoc-brand-plugin": "^1.0.1", + "esdoc-flow-type-plugin": "^1.1.0", + "esdoc-standard-plugin": "^1.0.0", + "eslint": "^4.1.18", + "eslint-config-standard": "^11.0.0", + "eslint-plugin-flowtype": "^2.47.1", + "eslint-plugin-import": "^2.8.0", + "eslint-plugin-node": "^5.2.1", + "eslint-plugin-promise": "^3.6.0", + "eslint-plugin-standard": "^3.0.1", + "flow-bin": "^0.73.0", + "flow-typed": "^2.4.0", + "jest": "^23.6.0", + "jest-coverage-badges": "^1.0.0", + "npm-run-all": "^4.1.2", + "regenerator-runtime": "^0.12.1", + "rimraf": "^2.6.2", + "rollup": "^0.66.4", + "rollup-plugin-babel": "^4.0.3", + "rollup-plugin-commonjs": "^9.1.8", + "rollup-plugin-json": "^3.1.0", + "rollup-plugin-node-resolve": "^3.4.0", + "rollup-plugin-terser": "^3.0.0", + "semantic-release": "^15.9.17" + }, + "author": "Ziv Barber", + "license": "MIT", + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + }, + "jest": { + "coverageReporters": [ + "json-summary", + "text", + "lcov" + ] + }, + "browser": "dist/library-boilerplate.iife.js", + "amd": "dist/library-boilerplate.amd.js", + "main": "dist/library-boilerplate.cjs.js", + "module": "dist/library-boilerplate.esm.js", + "betterScripts": { + "start": { + "command": "npx babel-node lib/index.js", + "env": { + "NODE_ENV": "development" + } + }, + "lint": { + "command": "npx eslint **/*.js", + "env": { + "NODE_ENV": "development" + } + } + } +} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..0b10ec4 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,125 @@ +import babel from 'rollup-plugin-babel' +import commonjs from 'rollup-plugin-commonjs' +import json from 'rollup-plugin-json' +import packageJson from './package.json' +import resolve from 'rollup-plugin-node-resolve' +import {terser as uglify} from 'rollup-plugin-terser' +var inputFile = 'lib/index.js' + +let config = [ + { + input: inputFile, + output: { + file: packageJson.amd, + format: 'amd', + amd: { + id: packageJson.name + } + }, + plugins: [ + babel({ + exclude: 'node_modules/**' + }), + commonjs(), + json({ + preferConst: true, + indent: ' ' + }), + resolve({ + customResolveOptions: { + moduleDirectory: 'node_modules' + } + }) + ] + }, + { + input: inputFile, + output: { + file: packageJson.main, + format: 'cjs' + }, + plugins: [ + babel({ + exclude: 'node_modules/**' + }), + json({ + preferConst: true, + indent: ' ' + }), + resolve({ + customResolveOptions: { + moduleDirectory: 'node_modules' + } + }) + ] + }, + { + input: inputFile, + output: { + file: packageJson.module, + format: 'esm' + }, + plugins: [ + babel({ + exclude: 'node_modules/**' + }), + json({ + preferConst: true, + indent: ' ' + }), + resolve({ + customResolveOptions: { + moduleDirectory: 'node_modules' + } + }) + ] + }, + { + input: inputFile, + output: { + file: packageJson.browser, + format: 'iife', + name: packageJson.name.replace(/-/, '_') + }, + plugins: [ + babel({ + exclude: 'node_modules/**' + }), + commonjs(), + json({ + preferConst: true, + indent: ' ' + }), + resolve({ + customResolveOptions: { + moduleDirectory: 'node_modules' + } + }) + ] + } +] + +if (process.env.BUILD === 'production') { + for (let i = 0; i < config.length; i++) { + config[i].plugins.push( + uglify({ + compress: { + pure_getters: true, + unsafe: true, + unsafe_comps: true, + warnings: false + } + }) + ) + + if (Object.prototype.toString.call(config[i].output) === '[object Array]') { + for (let j = 0; j < config.length; j++) { + config[i].output[j].sourcemap = true + } // End of for loop. + } else { + config[i].output.sourcemap = true + } // Endif. + } // End of for loop. +} // Endif. + +export default config