├── .all-contributorsrc ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── code-of-conduct.md ├── package.json ├── rollup.config.ts ├── src └── library.ts ├── test └── library.test.ts ├── tools ├── gh-pages-publish.ts ├── init.ts └── semantic-release-prepare.ts ├── tsconfig.json └── tslint.json /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "typescript-library-starter", 3 | "projectOwner": "alexjoverm", 4 | "files": [ 5 | "README.md" 6 | ], 7 | "imageSize": 100, 8 | "commit": true, 9 | "contributors": [ 10 | { 11 | "login": "k1r0s", 12 | "name": "Ciro", 13 | "avatar_url": "https://avatars.githubusercontent.com/u/6052309?v=3", 14 | "profile": "https://www.linkedin.com/in/ciro-ivan-agulló-guarinos-42109376", 15 | "contributions": [ 16 | "code", 17 | "tool" 18 | ] 19 | }, 20 | { 21 | "login": "mariusschulz", 22 | "name": "Marius Schulz", 23 | "avatar_url": "https://avatars.githubusercontent.com/u/947523?v=3", 24 | "profile": "https://blog.mariusschulz.com", 25 | "contributions": [ 26 | "doc" 27 | ] 28 | }, 29 | { 30 | "login": "alextrastero", 31 | "name": "Alexander Odell", 32 | "avatar_url": "https://avatars.githubusercontent.com/u/4152819?v=3", 33 | "profile": "https://github.com/alextrastero", 34 | "contributions": [ 35 | "doc" 36 | ] 37 | }, 38 | { 39 | "login": "superamadeus", 40 | "name": "Ryan Ham", 41 | "avatar_url": "https://avatars1.githubusercontent.com/u/8728882?v=3", 42 | "profile": "https://github.com/superamadeus", 43 | "contributions": [ 44 | "code" 45 | ] 46 | }, 47 | { 48 | "login": "ChinW", 49 | "name": "Chi", 50 | "avatar_url": "https://avatars1.githubusercontent.com/u/8458838?v=3", 51 | "profile": "https://consiiii.me", 52 | "contributions": [ 53 | "code", 54 | "tool", 55 | "doc" 56 | ] 57 | }, 58 | { 59 | "login": "mattmazzola", 60 | "name": "Matt Mazzola", 61 | "avatar_url": "https://avatars2.githubusercontent.com/u/2856501?v=3", 62 | "profile": "https://github.com/mattmazzola", 63 | "contributions": [ 64 | "code", 65 | "tool" 66 | ] 67 | }, 68 | { 69 | "login": "Leefrost", 70 | "name": "Sergii Lischuk", 71 | "avatar_url": "https://avatars0.githubusercontent.com/u/2664047?v=3", 72 | "profile": "http://leefrost.github.io", 73 | "contributions": [ 74 | "code" 75 | ] 76 | }, 77 | { 78 | "login": "SteveALee", 79 | "name": "Steve Lee", 80 | "avatar_url": "https://avatars1.githubusercontent.com/u/618922?v=3", 81 | "profile": "http;//opendirective.com", 82 | "contributions": [ 83 | "tool" 84 | ] 85 | }, 86 | { 87 | "login": "kutyel", 88 | "name": "Flavio Corpa", 89 | "avatar_url": "https://avatars0.githubusercontent.com/u/5127501?v=3", 90 | "profile": "http://flaviocorpa.com", 91 | "contributions": [ 92 | "code" 93 | ] 94 | }, 95 | { 96 | "login": "foreggs", 97 | "name": "Dom", 98 | "avatar_url": "https://avatars2.githubusercontent.com/u/22561997?v=3", 99 | "profile": "https://github.com/foreggs", 100 | "contributions": [ 101 | "tool" 102 | ] 103 | }, 104 | { 105 | "login": "myabc", 106 | "name": "Alex Coles", 107 | "avatar_url": "https://avatars1.githubusercontent.com/u/755?v=4", 108 | "profile": "http://alexbcoles.com", 109 | "contributions": [ 110 | "doc" 111 | ] 112 | }, 113 | { 114 | "login": "davidkpiano", 115 | "name": "David Khourshid", 116 | "avatar_url": "https://avatars2.githubusercontent.com/u/1093738?v=4", 117 | "profile": "https://github.com/davidkpiano", 118 | "contributions": [ 119 | "tool" 120 | ] 121 | }, 122 | { 123 | "login": "aarongarciah", 124 | "name": "Aarón García Hervás", 125 | "avatar_url": "https://avatars0.githubusercontent.com/u/7225802?v=4", 126 | "profile": "https://aarongarciah.com", 127 | "contributions": [ 128 | "doc" 129 | ] 130 | }, 131 | { 132 | "login": "stuajnht", 133 | "name": "Jonathan Hart", 134 | "avatar_url": "https://avatars2.githubusercontent.com/u/13683986?v=4", 135 | "profile": "https://www.stuajnht.co.uk", 136 | "contributions": [ 137 | "code" 138 | ] 139 | }, 140 | { 141 | "login": "Xndr7", 142 | "name": "Sanjiv Lobo", 143 | "avatar_url": "https://avatars0.githubusercontent.com/u/13509204?v=4", 144 | "profile": "https://github.com/Xndr7", 145 | "contributions": [ 146 | "doc" 147 | ] 148 | }, 149 | { 150 | "login": "sAleksovski", 151 | "name": "Stefan Aleksovski", 152 | "avatar_url": "https://avatars3.githubusercontent.com/u/7473800?v=4", 153 | "profile": "https://github.com/sAleksovski", 154 | "contributions": [ 155 | "code" 156 | ] 157 | }, 158 | { 159 | "login": "devpeerapong", 160 | "name": "dev.peerapong", 161 | "avatar_url": "https://avatars2.githubusercontent.com/u/8853426?v=4", 162 | "profile": "https://github.com/devpeerapong", 163 | "contributions": [ 164 | "code" 165 | ] 166 | }, 167 | { 168 | "login": "Racing5372", 169 | "name": "Aaron Groome", 170 | "avatar_url": "https://avatars0.githubusercontent.com/u/22260722?v=4", 171 | "profile": "http://twitter.com/Racing5372", 172 | "contributions": [ 173 | "doc" 174 | ] 175 | }, 176 | { 177 | "login": "lifeiscontent", 178 | "name": "Aaron Reisman", 179 | "avatar_url": "https://avatars3.githubusercontent.com/u/180963?v=4", 180 | "profile": "https://github.com/lifeiscontent", 181 | "contributions": [ 182 | "code" 183 | ] 184 | }, 185 | { 186 | "login": "kid-sk", 187 | "name": "kid-sk", 188 | "avatar_url": "https://avatars1.githubusercontent.com/u/32557482?v=4", 189 | "profile": "https://github.com/kid-sk", 190 | "contributions": [ 191 | "doc" 192 | ] 193 | }, 194 | { 195 | "login": "AndreaGot", 196 | "name": "Andrea Gottardi", 197 | "avatar_url": "https://avatars0.githubusercontent.com/u/1503089?v=4", 198 | "profile": "http://about.me/andreagot", 199 | "contributions": [ 200 | "doc" 201 | ] 202 | }, 203 | { 204 | "login": "Yogendra0Sharma", 205 | "name": "Yogendra Sharma", 206 | "avatar_url": "https://avatars3.githubusercontent.com/u/1375860?v=4", 207 | "profile": "http://TechiesEyes.com", 208 | "contributions": [ 209 | "doc" 210 | ] 211 | }, 212 | { 213 | "login": "cyphercodes", 214 | "name": "Rayan Salhab", 215 | "avatar_url": "https://avatars3.githubusercontent.com/u/7407177?v=4", 216 | "profile": "http://linkedin.com/in/rayan-salhab/", 217 | "contributions": [ 218 | "code" 219 | ] 220 | } 221 | ], 222 | "repoType": "github" 223 | } 224 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | #root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | max_line_length = 100 10 | indent_size = 2 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | tools/* linguist-vendored=false 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .nyc_output 4 | .DS_Store 5 | *.log 6 | .vscode 7 | .idea 8 | dist 9 | compiled 10 | .awcache 11 | .rpt2_cache 12 | docs 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | cache: 3 | directories: 4 | - ~/.npm 5 | notifications: 6 | email: false 7 | node_js: 8 | - '10' 9 | - '11' 10 | - '8' 11 | - '6' 12 | script: 13 | - npm run test:prod && npm run build 14 | after_success: 15 | - npm run travis-deploy-once "npm run report-coverage" 16 | - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run travis-deploy-once "npm run deploy-docs"; fi 17 | - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run travis-deploy-once "npm run semantic-release"; fi 18 | branches: 19 | except: 20 | - /^v\d+\.\d+\.\d+$/ 21 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | We're really glad you're reading this, because we need volunteer developers to help this project come to fruition. 👏 2 | 3 | ## Instructions 4 | 5 | These steps will guide you through contributing to this project: 6 | 7 | - Fork the repo 8 | - Clone it and install dependencies 9 | 10 | git clone https://github.com/YOUR-USERNAME/typescript-library-starter 11 | npm install 12 | 13 | Keep in mind that after running `npm install` the git repo is reset. So a good way to cope with this is to have a copy of the folder to push the changes, and the other to try them. 14 | 15 | Make and commit your changes. Make sure the commands npm run build and npm run test:prod are working. 16 | 17 | Finally send a [GitHub Pull Request](https://github.com/alexjoverm/typescript-library-starter/compare?expand=1) with a clear list of what you've done (read more [about pull requests](https://help.github.com/articles/about-pull-requests/)). Make sure all of your commits are atomic (one feature per commit). 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 --username-- <--usermail--> 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TypeScript library starter 2 | 3 | [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) 4 | [![Greenkeeper badge](https://badges.greenkeeper.io/alexjoverm/typescript-library-starter.svg)](https://greenkeeper.io/) 5 | [![Travis](https://img.shields.io/travis/alexjoverm/typescript-library-starter.svg)](https://travis-ci.org/alexjoverm/typescript-library-starter) 6 | [![Coveralls](https://img.shields.io/coveralls/alexjoverm/typescript-library-starter.svg)](https://coveralls.io/github/alexjoverm/typescript-library-starter) 7 | [![Dev Dependencies](https://david-dm.org/alexjoverm/typescript-library-starter/dev-status.svg)](https://david-dm.org/alexjoverm/typescript-library-starter?type=dev) 8 | [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://paypal.me/AJoverMorales) 9 | 10 | A starter project that makes creating a TypeScript library extremely easy. 11 | 12 | ![](https://i.imgur.com/opUmHp0.png) 13 | 14 | ### Usage 15 | 16 | ```bash 17 | git clone https://github.com/alexjoverm/typescript-library-starter.git YOURFOLDERNAME 18 | cd YOURFOLDERNAME 19 | 20 | # Run npm install and write your library name when asked. That's all! 21 | npm install 22 | ``` 23 | 24 | **Start coding!** `package.json` and entry files are already set up for you, so don't worry about linking to your main file, typings, etc. Just keep those files with the same name. 25 | 26 | ### Features 27 | 28 | - Zero-setup. After running `npm install` things will setup for you :wink: 29 | - **[RollupJS](https://rollupjs.org/)** for multiple optimized bundles following the [standard convention](http://2ality.com/2017/04/setting-up-multi-platform-packages.html) and [Tree-shaking](https://alexjoverm.github.io/2017/03/06/Tree-shaking-with-Webpack-2-TypeScript-and-Babel/) 30 | - Tests, coverage and interactive watch mode using **[Jest](http://facebook.github.io/jest/)** 31 | - **[Prettier](https://github.com/prettier/prettier)** and **[TSLint](https://palantir.github.io/tslint/)** for code formatting and consistency 32 | - **Docs automatic generation and deployment** to `gh-pages`, using **[TypeDoc](http://typedoc.org/)** 33 | - Automatic types `(*.d.ts)` file generation 34 | - **[Travis](https://travis-ci.org)** integration and **[Coveralls](https://coveralls.io/)** report 35 | - (Optional) **Automatic releases and changelog**, using [Semantic release](https://github.com/semantic-release/semantic-release), [Commitizen](https://github.com/commitizen/cz-cli), [Conventional changelog](https://github.com/conventional-changelog/conventional-changelog) and [Husky](https://github.com/typicode/husky) (for the git hooks) 36 | 37 | ### Importing library 38 | 39 | You can import the generated bundle to use the whole library generated by this starter: 40 | 41 | ```javascript 42 | import myLib from 'mylib' 43 | ``` 44 | 45 | Additionally, you can import the transpiled modules from `dist/lib` in case you have a modular library: 46 | 47 | ```javascript 48 | import something from 'mylib/dist/lib/something' 49 | ``` 50 | 51 | ### NPM scripts 52 | 53 | - `npm t`: Run test suite 54 | - `npm start`: Run `npm run build` in watch mode 55 | - `npm run test:watch`: Run test suite in [interactive watch mode](http://facebook.github.io/jest/docs/cli.html#watch) 56 | - `npm run test:prod`: Run linting and generate coverage 57 | - `npm run build`: Generate bundles and typings, create docs 58 | - `npm run lint`: Lints code 59 | - `npm run commit`: Commit using conventional commit style ([husky](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:) 60 | 61 | ### Excluding peerDependencies 62 | 63 | On library development, one might want to set some peer dependencies, and thus remove those from the final bundle. You can see in [Rollup docs](https://rollupjs.org/#peer-dependencies) how to do that. 64 | 65 | Good news: the setup is here for you, you must only include the dependency name in `external` property within `rollup.config.js`. For example, if you want to exclude `lodash`, just write there `external: ['lodash']`. 66 | 67 | ### Automatic releases 68 | 69 | _**Prerequisites**: you need to create/login accounts and add your project to:_ 70 | - [npm](https://www.npmjs.com/) 71 | - [Travis CI](https://travis-ci.org) 72 | - [Coveralls](https://coveralls.io) 73 | 74 | _**Prerequisite for Windows**: Semantic-release uses 75 | **[node-gyp](https://github.com/nodejs/node-gyp)** so you will need to 76 | install 77 | [Microsoft's windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) 78 | using this command:_ 79 | 80 | ```bash 81 | npm install --global --production windows-build-tools 82 | ``` 83 | 84 | #### Setup steps 85 | 86 | Follow the console instructions to install semantic release and run it (answer NO to "Do you want a `.travis.yml` file with semantic-release setup?"). 87 | 88 | _Note: make sure you've setup `repository.url` in your `package.json` file_ 89 | 90 | ```bash 91 | npm install -g semantic-release-cli 92 | semantic-release-cli setup 93 | # IMPORTANT!! Answer NO to "Do you want a `.travis.yml` file with semantic-release setup?" question. It is already prepared for you :P 94 | ``` 95 | 96 | From now on, you'll need to use `npm run commit`, which is a convenient way to create conventional commits. 97 | 98 | Automatic releases are possible thanks to [semantic release](https://github.com/semantic-release/semantic-release), which publishes your code automatically on [github](https://github.com/) and [npm](https://www.npmjs.com/), plus generates automatically a changelog. This setup is highly influenced by [Kent C. Dodds course on egghead.io](https://egghead.io/courses/how-to-write-an-open-source-javascript-library) 99 | 100 | ### Git Hooks 101 | 102 | There is already set a `precommit` hook for formatting your code with Prettier :nail_care: 103 | 104 | By default, there are two disabled git hooks. They're set up when you run the `npm run semantic-release-prepare` script. They make sure: 105 | - You follow a [conventional commit message](https://github.com/conventional-changelog/conventional-changelog) 106 | - Your build is not going to fail in [Travis](https://travis-ci.org) (or your CI server), since it's runned locally before `git push` 107 | 108 | This makes more sense in combination with [automatic releases](#automatic-releases) 109 | 110 | ### FAQ 111 | 112 | #### `Array.prototype.from`, `Promise`, `Map`... is undefined? 113 | 114 | TypeScript or Babel only provides down-emits on syntactical features (`class`, `let`, `async/await`...), but not on functional features (`Array.prototype.find`, `Set`, `Promise`...), . For that, you need Polyfills, such as [`core-js`](https://github.com/zloirock/core-js) or [`babel-polyfill`](https://babeljs.io/docs/usage/polyfill/) (which extends `core-js`). 115 | 116 | For a library, `core-js` plays very nicely, since you can import just the polyfills you need: 117 | 118 | ```javascript 119 | import "core-js/fn/array/find" 120 | import "core-js/fn/string/includes" 121 | import "core-js/fn/promise" 122 | ... 123 | ``` 124 | 125 | #### What is `npm install` doing on first run? 126 | 127 | It runs the script `tools/init` which sets up everything for you. In short, it: 128 | - Configures RollupJS for the build, which creates the bundles 129 | - Configures `package.json` (typings file, main file, etc) 130 | - Renames main src and test files 131 | 132 | #### What if I don't want git-hooks, automatic releases or semantic-release? 133 | 134 | Then you may want to: 135 | - Remove `commitmsg`, `postinstall` scripts from `package.json`. That will not use those git hooks to make sure you make a conventional commit 136 | - Remove `npm run semantic-release` from `.travis.yml` 137 | 138 | #### What if I don't want to use coveralls or report my coverage? 139 | 140 | Remove `npm run report-coverage` from `.travis.yml` 141 | 142 | ## Resources 143 | 144 | - [Write a library using TypeScript library starter](https://dev.to/alexjoverm/write-a-library-using-typescript-library-starter) by [@alexjoverm](https://github.com/alexjoverm/) 145 | - [📺 Create a TypeScript Library using typescript-library-starter](https://egghead.io/lessons/typescript-create-a-typescript-library-using-typescript-library-starter) by [@alexjoverm](https://github.com/alexjoverm/) 146 | - [Introducing TypeScript Library Starter Lite](https://blog.tonysneed.com/2017/09/15/introducing-typescript-library-starter-lite/) by [@tonysneed](https://github.com/tonysneed) 147 | 148 | ## Projects using `typescript-library-starter` 149 | 150 | Here are some projects that use `typescript-library-starter`: 151 | 152 | - [NOEL - A universal, human-centric, replayable event emitter](https://github.com/lifenautjoe/noel) 153 | - [droppable - A library to give file dropping super-powers to any HTML element.](https://github.com/lifenautjoe/droppable) 154 | - [redis-messaging-manager - Pubsub messaging library, using redis and rxjs](https://github.com/tomyitav/redis-messaging-manager) 155 | 156 | ## Credits 157 | 158 | Made with :heart: by [@alexjoverm](https://twitter.com/alexjoverm) and all these wonderful contributors ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): 159 | 160 | 161 | 162 | | [
Ciro](https://www.linkedin.com/in/ciro-ivan-agulló-guarinos-42109376)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=k1r0s "Code") [🔧](#tool-k1r0s "Tools") | [
Marius Schulz](https://blog.mariusschulz.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=mariusschulz "Documentation") | [
Alexander Odell](https://github.com/alextrastero)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=alextrastero "Documentation") | [
Ryan Ham](https://github.com/superamadeus)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=superamadeus "Code") | [
Chi](https://consiiii.me)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=ChinW "Code") [🔧](#tool-ChinW "Tools") [📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=ChinW "Documentation") | [
Matt Mazzola](https://github.com/mattmazzola)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=mattmazzola "Code") [🔧](#tool-mattmazzola "Tools") | [
Sergii Lischuk](http://leefrost.github.io)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=Leefrost "Code") | 163 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | 164 | | [
Steve Lee](http;//opendirective.com)
[🔧](#tool-SteveALee "Tools") | [
Flavio Corpa](http://flaviocorpa.com)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=kutyel "Code") | [
Dom](https://github.com/foreggs)
[🔧](#tool-foreggs "Tools") | [
Alex Coles](http://alexbcoles.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=myabc "Documentation") | [
David Khourshid](https://github.com/davidkpiano)
[🔧](#tool-davidkpiano "Tools") | [
Aarón García Hervás](https://aarongarciah.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=aarongarciah "Documentation") | [
Jonathan Hart](https://www.stuajnht.co.uk)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=stuajnht "Code") | 165 | | [
Sanjiv Lobo](https://github.com/Xndr7)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=Xndr7 "Documentation") | [
Stefan Aleksovski](https://github.com/sAleksovski)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=sAleksovski "Code") | [
dev.peerapong](https://github.com/devpeerapong)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=devpeerapong "Code") | [
Aaron Groome](http://twitter.com/Racing5372)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=Racing5372 "Documentation") | [
Aaron Reisman](https://github.com/lifeiscontent)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=lifeiscontent "Code") | [
kid-sk](https://github.com/kid-sk)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=kid-sk "Documentation") | [
Andrea Gottardi](http://about.me/andreagot)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=AndreaGot "Documentation") | 166 | | [
Yogendra Sharma](http://TechiesEyes.com)
[📖](https://github.com/alexjoverm/typescript-library-starter/commits?author=Yogendra0Sharma "Documentation") | [
Rayan Salhab](http://linkedin.com/in/rayan-salhab/)
[💻](https://github.com/alexjoverm/typescript-library-starter/commits?author=cyphercodes "Code") | 167 | 168 | 169 | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! 170 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at alexjovermorales@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "--libraryname--", 3 | "version": "0.0.0", 4 | "description": "", 5 | "keywords": [], 6 | "main": "dist/--libraryname--.umd.js", 7 | "module": "dist/--libraryname--.es5.js", 8 | "typings": "dist/types/--libraryname--.d.ts", 9 | "files": [ 10 | "dist" 11 | ], 12 | "author": "--username-- <--usermail-->", 13 | "repository": { 14 | "type": "git", 15 | "url": "" 16 | }, 17 | "license": "MIT", 18 | "engines": { 19 | "node": ">=6.0.0" 20 | }, 21 | "scripts": { 22 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 23 | "prebuild": "rimraf dist", 24 | "build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src", 25 | "start": "rollup -c rollup.config.ts -w", 26 | "test": "jest --coverage", 27 | "test:watch": "jest --coverage --watch", 28 | "test:prod": "npm run lint && npm run test -- --no-cache", 29 | "deploy-docs": "ts-node tools/gh-pages-publish", 30 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 31 | "commit": "git-cz", 32 | "semantic-release": "semantic-release", 33 | "semantic-release-prepare": "ts-node tools/semantic-release-prepare", 34 | "precommit": "lint-staged", 35 | "postinstall": "ts-node tools/init", 36 | "travis-deploy-once": "travis-deploy-once" 37 | }, 38 | "lint-staged": { 39 | "{src,test}/**/*.ts": [ 40 | "prettier --write", 41 | "git add" 42 | ] 43 | }, 44 | "config": { 45 | "commitizen": { 46 | "path": "node_modules/cz-conventional-changelog" 47 | } 48 | }, 49 | "jest": { 50 | "transform": { 51 | ".(ts|tsx)": "ts-jest" 52 | }, 53 | "testEnvironment": "node", 54 | "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", 55 | "moduleFileExtensions": [ 56 | "ts", 57 | "tsx", 58 | "js" 59 | ], 60 | "coveragePathIgnorePatterns": [ 61 | "/node_modules/", 62 | "/test/" 63 | ], 64 | "coverageThreshold": { 65 | "global": { 66 | "branches": 90, 67 | "functions": 95, 68 | "lines": 95, 69 | "statements": 95 70 | } 71 | }, 72 | "collectCoverageFrom": [ 73 | "src/*.{js,ts}" 74 | ] 75 | }, 76 | "prettier": { 77 | "semi": false, 78 | "singleQuote": true 79 | }, 80 | "commitlint": { 81 | "extends": [ 82 | "@commitlint/config-conventional" 83 | ] 84 | }, 85 | "devDependencies": { 86 | "@commitlint/cli": "^7.1.2", 87 | "@commitlint/config-conventional": "^7.1.2", 88 | "@types/jest": "^23.3.2", 89 | "@types/node": "^10.11.0", 90 | "colors": "^1.3.2", 91 | "commitizen": "^3.0.0", 92 | "coveralls": "^3.0.2", 93 | "cross-env": "^5.2.0", 94 | "cz-conventional-changelog": "^2.1.0", 95 | "husky": "^1.0.1", 96 | "jest": "^23.6.0", 97 | "jest-config": "^23.6.0", 98 | "lint-staged": "^8.0.0", 99 | "lodash.camelcase": "^4.3.0", 100 | "prettier": "^1.14.3", 101 | "prompt": "^1.0.0", 102 | "replace-in-file": "^3.4.2", 103 | "rimraf": "^2.6.2", 104 | "rollup": "^0.67.0", 105 | "rollup-plugin-commonjs": "^9.1.8", 106 | "rollup-plugin-json": "^3.1.0", 107 | "rollup-plugin-node-resolve": "^3.4.0", 108 | "rollup-plugin-sourcemaps": "^0.4.2", 109 | "rollup-plugin-typescript2": "^0.18.0", 110 | "semantic-release": "^15.9.16", 111 | "shelljs": "^0.8.3", 112 | "travis-deploy-once": "^5.0.9", 113 | "ts-jest": "^23.10.2", 114 | "ts-node": "^7.0.1", 115 | "tslint": "^5.11.0", 116 | "tslint-config-prettier": "^1.15.0", 117 | "tslint-config-standard": "^8.0.1", 118 | "typedoc": "^0.12.0", 119 | "typescript": "^3.0.3" 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /rollup.config.ts: -------------------------------------------------------------------------------- 1 | import resolve from 'rollup-plugin-node-resolve' 2 | import commonjs from 'rollup-plugin-commonjs' 3 | import sourceMaps from 'rollup-plugin-sourcemaps' 4 | import camelCase from 'lodash.camelcase' 5 | import typescript from 'rollup-plugin-typescript2' 6 | import json from 'rollup-plugin-json' 7 | 8 | const pkg = require('./package.json') 9 | 10 | const libraryName = '--libraryname--' 11 | 12 | export default { 13 | input: `src/${libraryName}.ts`, 14 | output: [ 15 | { file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true }, 16 | { file: pkg.module, format: 'es', sourcemap: true }, 17 | ], 18 | // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash') 19 | external: [], 20 | watch: { 21 | include: 'src/**', 22 | }, 23 | plugins: [ 24 | // Allow json resolution 25 | json(), 26 | // Compile TypeScript files 27 | typescript({ useTsconfigDeclarationDir: true }), 28 | // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) 29 | commonjs(), 30 | // Allow node_modules resolution, so you can use 'external' to control 31 | // which external modules to include in the bundle 32 | // https://github.com/rollup/rollup-plugin-node-resolve#usage 33 | resolve(), 34 | 35 | // Resolve source maps to the original source 36 | sourceMaps(), 37 | ], 38 | } 39 | -------------------------------------------------------------------------------- /src/library.ts: -------------------------------------------------------------------------------- 1 | // Import here Polyfills if needed. Recommended core-js (npm i -D core-js) 2 | // import "core-js/fn/array.find" 3 | // ... 4 | export default class DummyClass { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /test/library.test.ts: -------------------------------------------------------------------------------- 1 | import DummyClass from "../src/--libraryname--" 2 | 3 | /** 4 | * Dummy test 5 | */ 6 | describe("Dummy test", () => { 7 | it("works if true is truthy", () => { 8 | expect(true).toBeTruthy() 9 | }) 10 | 11 | it("DummyClass is instantiable", () => { 12 | expect(new DummyClass()).toBeInstanceOf(DummyClass) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /tools/gh-pages-publish.ts: -------------------------------------------------------------------------------- 1 | const { cd, exec, echo, touch } = require("shelljs") 2 | const { readFileSync } = require("fs") 3 | const url = require("url") 4 | 5 | let repoUrl 6 | let pkg = JSON.parse(readFileSync("package.json") as any) 7 | if (typeof pkg.repository === "object") { 8 | if (!pkg.repository.hasOwnProperty("url")) { 9 | throw new Error("URL does not exist in repository section") 10 | } 11 | repoUrl = pkg.repository.url 12 | } else { 13 | repoUrl = pkg.repository 14 | } 15 | 16 | let parsedUrl = url.parse(repoUrl) 17 | let repository = (parsedUrl.host || "") + (parsedUrl.path || "") 18 | let ghToken = process.env.GH_TOKEN 19 | 20 | echo("Deploying docs!!!") 21 | cd("docs") 22 | touch(".nojekyll") 23 | exec("git init") 24 | exec("git add .") 25 | exec('git config user.name "--username--"') 26 | exec('git config user.email "--usermail--"') 27 | exec('git commit -m "docs(docs): update gh-pages"') 28 | exec( 29 | `git push --force --quiet "https://${ghToken}@${repository}" master:gh-pages` 30 | ) 31 | echo("Docs deployed!!") 32 | -------------------------------------------------------------------------------- /tools/init.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This script runs automatically after your first npm-install. 3 | */ 4 | const _prompt = require("prompt") 5 | const { mv, rm, which, exec } = require("shelljs") 6 | const replace = require("replace-in-file") 7 | const colors = require("colors") 8 | const path = require("path") 9 | const { readFileSync, writeFileSync } = require("fs") 10 | const { fork } = require("child_process") 11 | 12 | // Note: These should all be relative to the project root directory 13 | const rmDirs = [ 14 | ".git" 15 | ] 16 | const rmFiles = [ 17 | ".all-contributorsrc", 18 | ".gitattributes", 19 | "tools/init.ts" 20 | ] 21 | const modifyFiles = [ 22 | "LICENSE", 23 | "package.json", 24 | "rollup.config.ts", 25 | "test/library.test.ts", 26 | "tools/gh-pages-publish.ts" 27 | ] 28 | const renameFiles = [ 29 | ["src/library.ts", "src/--libraryname--.ts"], 30 | ["test/library.test.ts", "test/--libraryname--.test.ts"] 31 | ] 32 | 33 | const _promptSchemaLibraryName = { 34 | properties: { 35 | library: { 36 | description: colors.cyan( 37 | "What do you want the library to be called? (use kebab-case)" 38 | ), 39 | pattern: /^[a-z]+(\-[a-z]+)*$/, 40 | type: "string", 41 | required: true, 42 | message: 43 | '"kebab-case" uses lowercase letters, and hyphens for any punctuation' 44 | } 45 | } 46 | } 47 | 48 | const _promptSchemaLibrarySuggest = { 49 | properties: { 50 | useSuggestedName: { 51 | description: colors.cyan( 52 | 'Would you like it to be called "' + 53 | libraryNameSuggested() + 54 | '"? [Yes/No]' 55 | ), 56 | pattern: /^(y(es)?|n(o)?)$/i, 57 | type: "string", 58 | required: true, 59 | message: 'You need to type "Yes" or "No" to continue...' 60 | } 61 | } 62 | } 63 | 64 | _prompt.start() 65 | _prompt.message = "" 66 | 67 | // Clear console 68 | process.stdout.write('\x1B[2J\x1B[0f'); 69 | 70 | if (!which("git")) { 71 | console.log(colors.red("Sorry, this script requires git")) 72 | removeItems() 73 | process.exit(1) 74 | } 75 | 76 | // Say hi! 77 | console.log( 78 | colors.cyan("Hi! You're almost ready to make the next great TypeScript library.") 79 | ) 80 | 81 | // Generate the library name and start the tasks 82 | if (process.env.CI == null) { 83 | if (!libraryNameSuggestedIsDefault()) { 84 | libraryNameSuggestedAccept() 85 | } else { 86 | libraryNameCreate() 87 | } 88 | } else { 89 | // This is being run in a CI environment, so don't ask any questions 90 | setupLibrary(libraryNameSuggested()) 91 | } 92 | 93 | 94 | 95 | /** 96 | * Asks the user for the name of the library if it has been cloned into the 97 | * default directory, or if they want a different name to the one suggested 98 | */ 99 | function libraryNameCreate() { 100 | _prompt.get(_promptSchemaLibraryName, (err: any, res: any) => { 101 | if (err) { 102 | console.log(colors.red("Sorry, there was an error building the workspace :(")) 103 | removeItems() 104 | process.exit(1) 105 | return 106 | } 107 | 108 | setupLibrary(res.library) 109 | }) 110 | } 111 | 112 | /** 113 | * Sees if the users wants to accept the suggested library name if the project 114 | * has been cloned into a custom directory (i.e. it's not 'typescript-library-starter') 115 | */ 116 | function libraryNameSuggestedAccept() { 117 | _prompt.get(_promptSchemaLibrarySuggest, (err: any, res: any) => { 118 | if (err) { 119 | console.log(colors.red("Sorry, you'll need to type the library name")) 120 | libraryNameCreate() 121 | } 122 | 123 | if (res.useSuggestedName.toLowerCase().charAt(0) === "y") { 124 | setupLibrary(libraryNameSuggested()) 125 | } else { 126 | libraryNameCreate() 127 | } 128 | }) 129 | } 130 | 131 | /** 132 | * The library name is suggested by looking at the directory name of the 133 | * tools parent directory and converting it to kebab-case 134 | * 135 | * The regex for this looks for any non-word or non-digit character, or 136 | * an underscore (as it's a word character), and replaces it with a dash. 137 | * Any leading or trailing dashes are then removed, before the string is 138 | * lowercased and returned 139 | */ 140 | function libraryNameSuggested() { 141 | return path 142 | .basename(path.resolve(__dirname, "..")) 143 | .replace(/[^\w\d]|_/g, "-") 144 | .replace(/^-+|-+$/g, "") 145 | .toLowerCase() 146 | } 147 | 148 | /** 149 | * Checks if the suggested library name is the default, which is 'typescript-library-starter' 150 | */ 151 | function libraryNameSuggestedIsDefault() { 152 | if (libraryNameSuggested() === "typescript-library-starter") { 153 | return true 154 | } 155 | 156 | return false 157 | } 158 | 159 | 160 | 161 | /** 162 | * Calls all of the functions needed to setup the library 163 | * 164 | * @param libraryName 165 | */ 166 | function setupLibrary(libraryName: string) { 167 | console.log( 168 | colors.cyan( 169 | "\nThanks for the info. The last few changes are being made... hang tight!\n\n" 170 | ) 171 | ) 172 | 173 | // Get the Git username and email before the .git directory is removed 174 | let username = exec("git config user.name").stdout.trim() 175 | let usermail = exec("git config user.email").stdout.trim() 176 | 177 | removeItems() 178 | 179 | modifyContents(libraryName, username, usermail) 180 | 181 | renameItems(libraryName) 182 | 183 | finalize() 184 | 185 | console.log(colors.cyan("OK, you're all set. Happy coding!! ;)\n")) 186 | } 187 | 188 | /** 189 | * Removes items from the project that aren't needed after the initial setup 190 | */ 191 | function removeItems() { 192 | console.log(colors.underline.white("Removed")) 193 | 194 | // The directories and files are combined here, to simplify the function, 195 | // as the 'rm' command checks the item type before attempting to remove it 196 | let rmItems = rmDirs.concat(rmFiles) 197 | rm("-rf", rmItems.map(f => path.resolve(__dirname, "..", f))) 198 | console.log(colors.red(rmItems.join("\n"))) 199 | 200 | console.log("\n") 201 | } 202 | 203 | /** 204 | * Updates the contents of the template files with the library name or user details 205 | * 206 | * @param libraryName 207 | * @param username 208 | * @param usermail 209 | */ 210 | function modifyContents(libraryName: string, username: string, usermail: string) { 211 | console.log(colors.underline.white("Modified")) 212 | 213 | let files = modifyFiles.map(f => path.resolve(__dirname, "..", f)) 214 | try { 215 | const changes = replace.sync({ 216 | files, 217 | from: [/--libraryname--/g, /--username--/g, /--usermail--/g], 218 | to: [libraryName, username, usermail] 219 | }) 220 | console.log(colors.yellow(modifyFiles.join("\n"))) 221 | } catch (error) { 222 | console.error("An error occurred modifying the file: ", error) 223 | } 224 | 225 | console.log("\n") 226 | } 227 | 228 | /** 229 | * Renames any template files to the new library name 230 | * 231 | * @param libraryName 232 | */ 233 | function renameItems(libraryName: string) { 234 | console.log(colors.underline.white("Renamed")) 235 | 236 | renameFiles.forEach(function(files) { 237 | // Files[0] is the current filename 238 | // Files[1] is the new name 239 | let newFilename = files[1].replace(/--libraryname--/g, libraryName) 240 | mv( 241 | path.resolve(__dirname, "..", files[0]), 242 | path.resolve(__dirname, "..", newFilename) 243 | ) 244 | console.log(colors.cyan(files[0] + " => " + newFilename)) 245 | }) 246 | 247 | console.log("\n") 248 | } 249 | 250 | /** 251 | * Calls any external programs to finish setting up the library 252 | */ 253 | function finalize() { 254 | console.log(colors.underline.white("Finalizing")) 255 | 256 | // Recreate Git folder 257 | let gitInitOutput = exec('git init "' + path.resolve(__dirname, "..") + '"', { 258 | silent: true 259 | }).stdout 260 | console.log(colors.green(gitInitOutput.replace(/(\n|\r)+/g, ""))) 261 | 262 | // Remove post-install command 263 | let jsonPackage = path.resolve(__dirname, "..", "package.json") 264 | const pkg = JSON.parse(readFileSync(jsonPackage) as any) 265 | 266 | // Note: Add items to remove from the package file here 267 | delete pkg.scripts.postinstall 268 | 269 | writeFileSync(jsonPackage, JSON.stringify(pkg, null, 2)) 270 | console.log(colors.green("Postinstall script has been removed")) 271 | 272 | // Initialize Husky 273 | fork( 274 | path.resolve(__dirname, "..", "node_modules", "husky", "bin", "install"), 275 | { silent: true } 276 | ); 277 | console.log(colors.green("Git hooks set up")) 278 | 279 | console.log("\n") 280 | } 281 | -------------------------------------------------------------------------------- /tools/semantic-release-prepare.ts: -------------------------------------------------------------------------------- 1 | const path = require("path") 2 | const { fork } = require("child_process") 3 | const colors = require("colors") 4 | 5 | const { readFileSync, writeFileSync } = require("fs") 6 | const pkg = JSON.parse( 7 | readFileSync(path.resolve(__dirname, "..", "package.json")) 8 | ) 9 | 10 | pkg.scripts.prepush = "npm run test:prod && npm run build" 11 | pkg.scripts.commitmsg = "commitlint -E HUSKY_GIT_PARAMS" 12 | 13 | writeFileSync( 14 | path.resolve(__dirname, "..", "package.json"), 15 | JSON.stringify(pkg, null, 2) 16 | ) 17 | 18 | // Call husky to set up the hooks 19 | fork(path.resolve(__dirname, "..", "node_modules", "husky", "lib", "installer", 'bin'), ['install']) 20 | 21 | console.log() 22 | console.log(colors.green("Done!!")) 23 | console.log() 24 | 25 | if (pkg.repository.url.trim()) { 26 | console.log(colors.cyan("Now run:")) 27 | console.log(colors.cyan(" npm install -g semantic-release-cli")) 28 | console.log(colors.cyan(" semantic-release-cli setup")) 29 | console.log() 30 | console.log( 31 | colors.cyan('Important! Answer NO to "Generate travis.yml" question') 32 | ) 33 | console.log() 34 | console.log( 35 | colors.gray( 36 | 'Note: Make sure "repository.url" in your package.json is correct before' 37 | ) 38 | ) 39 | } else { 40 | console.log( 41 | colors.red( 42 | 'First you need to set the "repository.url" property in package.json' 43 | ) 44 | ) 45 | console.log(colors.cyan("Then run:")) 46 | console.log(colors.cyan(" npm install -g semantic-release-cli")) 47 | console.log(colors.cyan(" semantic-release-cli setup")) 48 | console.log() 49 | console.log( 50 | colors.cyan('Important! Answer NO to "Generate travis.yml" question') 51 | ) 52 | } 53 | 54 | console.log() 55 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "node", 4 | "target": "es5", 5 | "module":"es2015", 6 | "lib": ["es2015", "es2016", "es2017", "dom"], 7 | "strict": true, 8 | "sourceMap": true, 9 | "declaration": true, 10 | "allowSyntheticDefaultImports": true, 11 | "experimentalDecorators": true, 12 | "emitDecoratorMetadata": true, 13 | "declarationDir": "dist/types", 14 | "outDir": "dist/lib", 15 | "typeRoots": [ 16 | "node_modules/@types" 17 | ] 18 | }, 19 | "include": [ 20 | "src" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint-config-standard", 4 | "tslint-config-prettier" 5 | ] 6 | } --------------------------------------------------------------------------------