From e5eb088c6ef435bef344ecedb895fc5f3b8725a7 Mon Sep 17 00:00:00 2001 From: caian-gums Date: Mon, 9 Dec 2019 19:58:53 -0300 Subject: [PATCH] Initial commit --- .babelrc | 12 ++++++++++ .editorconfig | 12 ++++++++++ .eslintignore | 2 ++ .eslintrc | 11 +++++++++ .gitattributes | 1 + .gitignore | 8 +++++++ .huskyrc | 6 +++++ .npmignore | 6 +++++ .npmrc | 1 + .prettierrc | 5 +++++ .travis.yml | 15 +++++++++++++ CONTRIBUTING.md | 10 +++++++++ LICENSE | 21 +++++++++++++++++ README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 54 ++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 3 +++ tests/sum.test.js | 7 ++++++ webpack.config.js | 51 ++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 282 insertions(+) create mode 100644 .babelrc create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .huskyrc create mode 100644 .npmignore create mode 100644 .npmrc create mode 100644 .prettierrc create mode 100644 .travis.yml create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 package.json create mode 100644 src/index.js create mode 100644 tests/sum.test.js create mode 100644 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..394c543 --- /dev/null +++ b/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "current" + } + } + ] + ] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c06f241 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..c8067a1 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +**/node_modules +**/webpack.config.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..97ca13d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,11 @@ +{ + "extends": ["airbnb-base", "prettier"], + "env": { + "browser": true, + "node": true, + "jest": true + }, + "rules": { + "import/prefer-default-export": "off" + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a0e5357 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +node_modules +*.log +.DS_Store +dist +lib +coverage +yarn.lock +package-lock.json diff --git a/.huskyrc b/.huskyrc new file mode 100644 index 0000000..db78ab0 --- /dev/null +++ b/.huskyrc @@ -0,0 +1,6 @@ +{ + "hooks": { + "pre-commit": "yarn lint", + "pre-push": "yarn lint && yarn test" + } +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..c33a79f --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +.DS_Store +*.log +src +tests +examples +coverage diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..38cd4a6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "singleQuote": true, + "semi": true +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2001167 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +sudo: false +language: node_js +node_js: + - '10' +branches: + only: + - master +cache: + directories: + - node_modules +install: + - yarn --ignore-engines +script: + - yarn test + - yarn coveralls diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..bf2d6d7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contributing + +1. Fork it! +2. Create your feature branch: `git checkout -b my-new-feature` +3. Commit your changes: `git commit -m 'Add some feature'` +4. Push to the branch: `git push origin my-new-feature` + +_Remember that we have a pre-push hook with steps that analyzes and prevents mistakes._ + +**After your pull request is merged**, you can safely delete your branch. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d0eb666 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Codevor - js-library-boilerplate + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..dcbb341 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# js-library-boilerplate + +[![License][license-badge]][license-url] [![Travis CI][travis-badge]][travis-url] [![Coverage Status][coverage-badge]][coverage-url] [![Commitizen][commitizen-badge]][commitizen-url] + +> js-library-boilerplate-description. + +## Installation + +js-library-boilerplate is available on npm/yarn: + +```bash +$ npm install js-library-boilerplate --save +$ yarn add js-library-boilerplate +``` + +## Usage + +### With ES6/import + +```js +import { sum } from 'js-library-boilerplate'; + +sum(2, 2); // => 4 +``` + +### With require + +```js +const sum = require('js-library-boilerplate').sum; + +sum(2, 2); // => 4 +``` + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. + +## Changelog + +This project adheres to [Semantic Versioning](https://semver.org/). Every release, along with the migration instructions, is documented on the Github [Releases](https://github.com/codevor/js-library-boilerplate/releases) page. + +## Bugs and Sugestions + +Report bugs or do suggestions using the [issues](https://github.com/codevor/js-library-boilerplate/issues). + +## License + +[MIT License](LICENSE) © [Codevor](https://github.com/codevor) + +[license-badge]: https://img.shields.io/github/license/codevor/js-library-boilerplate.svg +[license-url]: https://opensource.org/licenses/MIT +[coverage-badge]: https://coveralls.io/repos/github/codevor/js-library-boilerplate/badge.svg?branch=master +[coverage-url]: https://coveralls.io/github/codevor/js-library-boilerplate?branch=master +[travis-badge]: https://travis-ci.org/codevor/js-library-boilerplate.svg?branch=master +[travis-url]: https://travis-ci.org/codevor/js-library-boilerplate +[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg +[commitizen-url]: http://commitizen.github.io/cz-cli/ diff --git a/package.json b/package.json new file mode 100644 index 0000000..b90ed61 --- /dev/null +++ b/package.json @@ -0,0 +1,54 @@ +{ + "name": "js-library-boilerplate", + "version": "0.1.0", + "description": "js-library-boilerplate-description", + "main": "dist/js-library-boilerplate.js", + "unpkg": "dist/js-library-boilerplate.min.js", + "scripts": { + "clean": "rimraf dist", + "dev": "NODE_ENV=dev webpack --progress --colors --watch", + "build:umd": "NODE_ENV=production webpack", + "lint": "eslint src tests", + "test": "jest --coverage --expand", + "test:watch": "jest --watch", + "coveralls": "cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", + "prepublish": "yarn lint && yarn test && yarn clean && yarn build:umd", + "commit": "git-cz" + }, + "keywords": [], + "author": "Helder Burato Berto (https://helder.dev/)", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/codevor/js-library-boilerplate.git" + }, + "bugs": { + "url": "https://github.com/codevor/js-library-boilerplate/issues" + }, + "homepage": "https://github.com/codevor/js-library-boilerplate#readme", + "devDependencies": { + "@babel/cli": "^7.6.4", + "@babel/core": "^7.6.4", + "@babel/preset-env": "^7.6.3", + "babel-jest": "^24.9.0", + "babel-loader": "^8.0.6", + "commitizen": "^4.0.3", + "coveralls": "^3.0.7", + "cz-conventional-changelog": "3.0.2", + "eslint": "^6.5.1", + "eslint-config-airbnb-base": "^14.0.0", + "eslint-config-prettier": "^6.4.0", + "eslint-plugin-import": "^2.18.2", + "husky": "^3.0.9", + "jest": "^24.9.0", + "rimraf": "^3.0.0", + "uglifyjs-webpack-plugin": "^2.2.0", + "webpack": "^4.41.1", + "webpack-cli": "^3.3.9" + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..12ee0dd --- /dev/null +++ b/src/index.js @@ -0,0 +1,3 @@ +export function sum(x, y) { + return x + y; +} diff --git a/tests/sum.test.js b/tests/sum.test.js new file mode 100644 index 0000000..6196d62 --- /dev/null +++ b/tests/sum.test.js @@ -0,0 +1,7 @@ +import { sum } from '../src'; + +describe('sum', () => { + test('it should sum 2 + 2', () => { + expect(sum(2, 2)).toBe(4); + }); +}); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..e057bb4 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,51 @@ +const path = require('path'); +const webpack = require('webpack'); +const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); + +const isProduction = process.env.NODE_ENV === 'production'; +const mode = isProduction ? 'production' : 'development'; + +const libraryName = 'js-library-boilerplate'; + +module.exports = { + mode, + entry: { + [libraryName]: path.resolve(__dirname, 'src/index.js'), + [`${libraryName}.min`]: path.resolve(__dirname, 'src/index.js') + }, + devtool: 'source-map', + output: { + path: path.resolve(__dirname, 'dist'), + filename: '[name].js', + library: libraryName, + libraryTarget: 'umd', + umdNamedDefine: true, + globalObject: "typeof self !== 'undefined' ? self : this" + }, + module: { + rules: [ + { + test: /\.js$/, + use: { + loader: 'babel-loader', + options: { + presets: ['@babel/preset-env'] + } + }, + exclude: /node_modules/ + } + ] + }, + optimization: { + minimize: true, + minimizer: [new UglifyJsPlugin({ include: /\.min\.js$/ })] + }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) + }) + ], + resolve: { + extensions: ['.json', '.js'] + } +};