├── .checklist.md ├── .eslintrc.js ├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── funding.yml └── settings.yml ├── .gitignore ├── .prettierrc.js ├── .release-it.json ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── __tests__ ├── .eslintrc.js └── index.spec.ts ├── circle.yml ├── jest.config.js ├── package.json ├── rollup.config.js ├── src └── index.ts └── tsconfig.json /.checklist.md: -------------------------------------------------------------------------------- 1 | # Checklist of things to do when creating a lib 2 | 3 | ## Copying the project 4 | 5 | - `cp -r lib-boilerplate-ts my-new-lib` (careful copying `node_modules`) 6 | - `rm -rf .git` 7 | - `rm .checklist.md` 8 | - `git init .` 9 | - `git add .` 10 | - `git commit -m 'init'` 11 | - `sed -i '' 's/lib-boilerplate-ts/vue-local-scope/g' README.md package.json` 12 | 13 | ## circle ci 14 | 15 | - Add the project: https://circleci.com/projects/gh/posva 16 | - Check _Build on forked pull requests_: https://circleci.com/gh/posva/vue-tweezing/edit#advanced-settings 17 | - Check _Auto cancel redundant build_ (same place) 18 | 19 | ## Greenkeeper 20 | 21 | - Activate it: https://github.com/settings/installations/5583 22 | - Merge its first pull request 23 | 24 | ## Beerpay 25 | 26 | - Add project: https://beerpay.io/dashboard/projects/add 27 | 28 | ## Github Settings 29 | 30 | - Activate probot/settings: https://github.com/settings/installations/85597 31 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: [ 4 | 'plugin:@typescript-eslint/recommended', 5 | 'prettier', 6 | 'plugin:prettier/recommended', 7 | // "posva" 8 | ], 9 | parserOptions: { 10 | ecmaVersion: 2018, 11 | // allows `import` 12 | sourceType: 'module', 13 | }, 14 | rules: { 15 | '@typescript-eslint/explicit-function-return-type': 'off', 16 | '@typescript-eslint/explicit-module-boundary-types': 'off', 17 | }, 18 | // "env": { 19 | // "jest": true 20 | // } 21 | } 22 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are welcome and will be fully credited! 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/{{ githubAccount }}/{{ name }}). 6 | 7 | ## Pull Requests 8 | 9 | Here are some guidelines to make the process smoother: 10 | 11 | - **Add a test** - New features and bugfixes need tests. If you find it difficult to test, please tell us in the pull request and we will try to help you! 12 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 13 | - **Run `npm test` locally** - This will allow you to go faster 14 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 15 | - **Send coherent history** - Make sure your commits message means something 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | ## Creating issues 19 | 20 | ### Bug reports 21 | 22 | Always try to provide as much information as possible. If you are reporting a bug, try to provide a repro on jsfiddle.net (or anything else) or a stacktrace at the very least. This will help us check the problem quicker. 23 | 24 | ### Feature requests 25 | 26 | Lay out the reasoning behind it and propose an API for it. Ideally, you should have a practical example to prove the utility of the feature you're requesting. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | **What kind of change does this PR introduce?** (check at least one) 10 | 11 | - [ ] Bugfix 12 | - [ ] Feature 13 | - [ ] Code style update 14 | - [ ] Refactor 15 | - [ ] Build-related changes 16 | - [ ] Other, please describe: 17 | 18 | **Does this PR introduce a breaking change?** (check one) 19 | 20 | - [ ] Yes 21 | - [ ] No 22 | 23 | If yes, please describe the impact and migration path for existing applications: 24 | 25 | **The PR fulfills these requirements:** 26 | 27 | - [ ] When resolving a specific issue, it's referenced in the PR's title (e.g. `fix #xxx[,#xxx]`, where "xxx" is the issue number) 28 | - [ ] All tests are passing 29 | - [ ] New/updated tests are included 30 | 31 | If adding a **new feature**, the PR's description includes: 32 | 33 | - [ ] A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it) 34 | 35 | **Other information:** 36 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: posva 2 | custom: https://www.paypal.me/posva 3 | -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | labels: 2 | - name: bug 3 | color: ee0701 4 | - name: contribution welcome 5 | color: 0e8a16 6 | - name: discussion 7 | color: 4935ad 8 | - name: docs 9 | color: 8be281 10 | - name: enhancement 11 | color: a2eeef 12 | - name: good first issue 13 | color: 7057ff 14 | - name: help wanted 15 | color: 008672 16 | - name: question 17 | color: d876e3 18 | - name: wontfix 19 | color: ffffff 20 | - name: WIP 21 | color: ffffff 22 | - name: need repro 23 | color: c9581c 24 | - name: feature request 25 | color: fbca04 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | npm-debug.log 4 | yarn-error.log 5 | .nyc_output 6 | coverage.lcov 7 | dist 8 | package-lock.json 9 | yarn.lock 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: false, 3 | trailingComma: 'es5', 4 | singleQuote: true, 5 | } 6 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "src": { 3 | "tagName": "v%s", 4 | "commitMessage": "chore(release): %s" 5 | }, 6 | "github": { 7 | "release": true, 8 | "releaseName": "🚀 Release %s", 9 | "tokenRef": "GITHUB_TOKEN" 10 | }, 11 | "npm": { 12 | "publish": true 13 | }, 14 | "changelogCommand": "git log --pretty=format:'* %s (%h)' [REV_RANGE]" 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.formatOnSave": false 4 | }, 5 | "[typescript]": { 6 | "editor.formatOnSave": false 7 | }, 8 | "eslint.autoFixOnSave": true, 9 | "eslint.validate": [ 10 | "javascript", 11 | { "language": "typescript", "autoFix": true } 12 | ], 13 | "editor.codeActionsOnSave": { 14 | "source.fixAll.eslint": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Eduardo San Martin Morote 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 | # lib-boilerplate-ts [![Build Status](https://badgen.net/circleci/github/posva/lib-boilerplate-ts/master)](https://circleci.com/gh/posva/lib-boilerplate-ts) [![npm package](https://badgen.net/npm/v/lib-boilerplate-ts)](https://www.npmjs.com/package/lib-boilerplate-ts) [![coverage](https://badgen.net/codecov/c/github/posva/lib-boilerplate-ts/master)](https://codecov.io/github/posva/lib-boilerplate-ts) [![thanks](https://badgen.net/badge/thanks/♥/pink)](https://github.com/posva/thanks) 2 | 3 | > Some awesome description 4 | 5 | Demo (TODO link) 6 | 7 | ## Installation 8 | 9 | ```sh 10 | npm install lib-boilerplate 11 | ``` 12 | 13 | ## Usage 14 | 15 | ## API 16 | 17 | ## Related 18 | 19 | ## License 20 | 21 | [MIT](http://opensource.org/licenses/MIT) 22 | -------------------------------------------------------------------------------- /__tests__/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | jest: true, 4 | }, 5 | } 6 | -------------------------------------------------------------------------------- /__tests__/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { mylib } from '../src' 2 | 3 | describe('mylib', () => { 4 | it('works', () => { 5 | expect(mylib()).toBe(true) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | jobs: 4 | build: 5 | docker: 6 | - image: circleci/node:10 7 | 8 | working_directory: ~/repo 9 | 10 | steps: 11 | - checkout 12 | 13 | - restore_cache: 14 | keys: 15 | - dependencies-cache-v1-{{ checksum "yarn.lock" }} 16 | - dependencies-cache-v1- 17 | 18 | - run: yarn install 19 | 20 | - save_cache: 21 | paths: 22 | - node_modules 23 | key: dependencies-cache-v1-{{ checksum "yarn.lock" }} 24 | 25 | - run: yarn run test 26 | 27 | - run: 28 | name: Send code coverage 29 | command: yarn codecov 30 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | collectCoverage: true, 4 | collectCoverageFrom: ['/src/**/*.ts'], 5 | testMatch: ['/__tests__/**/*.spec.ts'], 6 | globals: { 7 | 'ts-jest': { 8 | diagnostics: { 9 | warnOnly: true, 10 | }, 11 | }, 12 | }, 13 | testURL: 'http://localhost/', 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lib-boilerplate-ts", 3 | "version": "0.0.0", 4 | "description": "Some awesome description", 5 | "main": "dist/lib-boilerplate-ts.common.js", 6 | "module": "dist/lib-boilerplate-ts.esm.js", 7 | "unpkg": "dist/lib-boilerplate-ts.js", 8 | "browser": "dist/lib-boilerplate-ts.esm.js", 9 | "types": "dist/lib-boilerplate-ts/src", 10 | "sideEffects": false, 11 | "author": { 12 | "name": "Eduardo San Martin Morote", 13 | "email": "posva13@gmail.com" 14 | }, 15 | "scripts": { 16 | "lint": "eslint --color --ext=js,html,vue,ts src __tests__ *.js", 17 | "lint:fix": "yarn run lint --fix", 18 | "unit": "jest", 19 | "dev": "yarn run unit --watchAll", 20 | "pretest": "yarn run lint", 21 | "test": "yarn run unit && yarn run build", 22 | "build": "rollup -c rollup.config.js", 23 | "prepublishOnly": "yarn run build" 24 | }, 25 | "files": [ 26 | "dist", 27 | "LICENSE", 28 | "README.md" 29 | ], 30 | "keywords": [], 31 | "license": "MIT", 32 | "devDependencies": { 33 | "@rollup/plugin-alias": "^3.0.0", 34 | "@rollup/plugin-replace": "^2.2.1", 35 | "@types/jest": "^26.0.8", 36 | "@typescript-eslint/eslint-plugin": "^4.15.2", 37 | "@typescript-eslint/parser": "^4.15.2", 38 | "codecov": "^3.7.2", 39 | "eslint": "^7.6.0", 40 | "eslint-config-prettier": "^8.0.0", 41 | "eslint-plugin-prettier": "^3.1.4", 42 | "jest": "^26.2.2", 43 | "pascalcase": "^1.0.0", 44 | "prettier": "^2.0.5", 45 | "rimraf": "^3.0.2", 46 | "rollup": "^2.23.0", 47 | "rollup-plugin-commonjs": "^10.1.0", 48 | "rollup-plugin-node-resolve": "^5.2.0", 49 | "rollup-plugin-terser": "^7.0.2", 50 | "rollup-plugin-typescript2": "^0.30.0", 51 | "ts-jest": "^26.1.4", 52 | "typescript": "^4.1.5" 53 | }, 54 | "repository": { 55 | "type": "git", 56 | "url": "git+https://github.com/posva/lib-boilerplate-ts.git" 57 | }, 58 | "bugs": { 59 | "url": "https://github.com/posva/lib-boilerplate-ts/issues" 60 | }, 61 | "homepage": "https://github.com/posva/lib-boilerplate-ts#readme" 62 | } 63 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import replace from '@rollup/plugin-replace' 2 | import resolve from 'rollup-plugin-node-resolve' 3 | import commonjs from 'rollup-plugin-commonjs' 4 | import ts from 'rollup-plugin-typescript2' 5 | import alias from '@rollup/plugin-alias' 6 | import { terser } from 'rollup-plugin-terser' 7 | import path from 'path' 8 | import rimraf from 'rimraf' 9 | import pascalcase from 'pascalcase' 10 | 11 | const cwd = process.cwd() 12 | // eslint-disable-next-line 13 | const pkg = require(path.join(cwd, 'package.json')) 14 | 15 | rimraf.sync(path.join(cwd, './dist')) 16 | 17 | const banner = `/*! 18 | * ${pkg.name} v${pkg.version} 19 | * (c) ${new Date().getFullYear()} Eduardo San Martin Morote 20 | * @license MIT 21 | */` 22 | 23 | const exportName = pascalcase(pkg.name) 24 | 25 | function createEntry( 26 | { 27 | format, // Rollup format (iife, umd, cjs, es) 28 | external = null, // Rollup external option 29 | input = 'src/index.ts', // entry point 30 | env = 'development', // NODE_ENV variable 31 | minify = false, 32 | isBrowser = false, // produce a browser module version or not 33 | } = { 34 | input: 'src/index.ts', 35 | env: 'development', 36 | minify: false, 37 | isBrowser: false, 38 | } 39 | ) { 40 | // force production mode when minifying 41 | if (minify) env = 'production' 42 | 43 | const config = { 44 | input, 45 | plugins: [ 46 | replace({ 47 | __VERSION__: pkg.version, 48 | preventAssignment: true, 49 | 'process.env.NODE_ENV': `'${env}'`, 50 | }), 51 | alias({ 52 | // entries: [{ find: 'firebase', replacement: path.join(__dirname, './stub') }], 53 | }), 54 | ], 55 | output: { 56 | banner, 57 | file: `dist/${pkg.name}.UNKNOWN.js`, 58 | format, 59 | }, 60 | } 61 | 62 | if (format === 'iife') { 63 | config.output.file = pkg.unpkg 64 | config.output.name = exportName 65 | } else if (format === 'es') { 66 | config.output.file = isBrowser ? pkg.browser : pkg.module 67 | } else if (format === 'cjs') { 68 | config.output.file = pkg.main 69 | } 70 | 71 | if (!external) { 72 | config.plugins.push(resolve(), commonjs()) 73 | } else { 74 | config.external = external 75 | } 76 | 77 | config.plugins.push( 78 | ts({ 79 | // only check once, during the es version with browser (it includes external libs) 80 | check: format === 'es' && isBrowser && !minify, 81 | tsconfigOverride: { 82 | exclude: ['__tests__'], 83 | compilerOptions: { 84 | // same for d.ts files 85 | declaration: format === 'es' && isBrowser && !minify, 86 | target: format === 'es' && !isBrowser ? 'esnext' : 'es5', 87 | }, 88 | }, 89 | }) 90 | ) 91 | 92 | if (minify) { 93 | config.plugins.push( 94 | terser({ 95 | module: format === 'es', 96 | output: { 97 | preamble: banner, 98 | }, 99 | }) 100 | ) 101 | config.output.file = config.output.file.replace(/\.js$/i, '.min.js') 102 | } 103 | 104 | return config 105 | } 106 | 107 | const builds = [ 108 | createEntry({ format: 'cjs' }), 109 | createEntry({ format: 'es', isBrowser: true }), 110 | ] 111 | 112 | if (pkg.unpkg) 113 | builds.push( 114 | createEntry({ format: 'iife' }), 115 | createEntry({ format: 'iife', minify: true }), 116 | createEntry({ format: 'es', isBrowser: true, minify: true }) 117 | ) 118 | 119 | export default builds 120 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export function mylib() { 2 | return true 3 | } 4 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "noEmit": true, 6 | "strict": true, 7 | "composite": true, 8 | "esModuleInterop": true, 9 | "moduleResolution": "node", 10 | 11 | "rootDir": ".", 12 | "baseUrl": "." 13 | }, 14 | "include": ["src", "__tests__"] 15 | } 16 | --------------------------------------------------------------------------------