├── .editorconfig ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .prettierrc ├── .taprc ├── LICENSE ├── README.md ├── package.json ├── src └── index.ts ├── test ├── index.ts └── tsconfig.json ├── tsconfig.json └── typings └── .gitkeep /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | end_of_line = lf 10 | # editorconfig-tools is unable to ignore longs strings or urls 11 | max_line_length = 100 12 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ignorePatterns: ['.eslintrc.js'], 3 | extends: [ 4 | 'eslint:recommended', 5 | 'plugin:@typescript-eslint/recommended', 6 | 'plugin:prettier/recommended', 7 | ], 8 | parser: '@typescript-eslint/parser', 9 | parserOptions: { 10 | project: ['./tsconfig.json', './test/tsconfig.json'], 11 | tsconfigRootDir: './', 12 | }, 13 | plugins: ['@typescript-eslint', 'prettier'], 14 | rules: { 15 | '@typescript-eslint/member-delimiter-style': 'off', 16 | '@typescript-eslint/explicit-function-return-type': 'off', 17 | 'no-unused-vars': 'off', 18 | '@typescript-eslint/no-unused-vars': ['error'], 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | npm: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | matrix: 11 | node-version: [10.x, 12.x, 14.x] 12 | os: [ubuntu-latest, windows-latest, macOS-latest] 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Use Node.js 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | 22 | - name: Install with npm 23 | run: | 24 | npm install 25 | - name: Lint and build 26 | run: | 27 | npm run build 28 | - name: Run tests 29 | run: | 30 | npm run test:report && npm run test:reporter 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | *.pid.lock 14 | 15 | # Directory for instrumented libs generated by jscoverage/JSCover 16 | lib-cov 17 | 18 | # Coverage directory used by tools like istanbul 19 | coverage 20 | 21 | # nyc test coverage 22 | .nyc_output 23 | 24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 25 | .grunt 26 | 27 | # Bower dependency directory (https://bower.io/) 28 | bower_components 29 | 30 | # node-waf configuration 31 | .lock-wscript 32 | 33 | # Compiled binary addons (https://nodejs.org/api/addons.html) 34 | build/Release 35 | 36 | # Dependency directories 37 | node_modules/ 38 | jspm_packages/ 39 | 40 | # Optional npm cache directory 41 | .npm 42 | 43 | # Optional eslint cache 44 | .eslintcache 45 | 46 | # Optional REPL history 47 | .node_repl_history 48 | 49 | # Output of 'npm pack' 50 | *.tgz 51 | 52 | # Yarn Integrity file 53 | .yarn-integrity 54 | 55 | # dotenv environment variables file 56 | .env 57 | 58 | # next.js build output 59 | .next 60 | 61 | # compiled lib 62 | dist 63 | 64 | # TAP files 65 | out.tap 66 | junit-testresults.xml 67 | 68 | # Misc 69 | package-lock.json 70 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "tabWidth": 2, 4 | "semi": false, 5 | "singleQuote": true, 6 | "trailingComma": "all", 7 | "bracketSpacing": true, 8 | "jsxBracketSameLine": false, 9 | "arrowParens": "avoid", 10 | "parser": "typescript" 11 | } -------------------------------------------------------------------------------- /.taprc: -------------------------------------------------------------------------------- 1 | test-env: [ 2 | TS_NODE_PROJECT=./test/tsconfig.json 3 | ] 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Maksim Sinik 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 | # TypeScript Lib Starter ![TypeScript Lib Starter](https://user-images.githubusercontent.com/6388707/58274163-9204dc00-7d92-11e9-8746-6cd10e9aa9ea.png) 2 | 3 | [![GitHub CI](https://github.com/fox1t/typescript-lib-starter/workflows/ci/badge.svg)](https://github.com/fox1t/typescript-lib-starter/actions) 4 | [![TypeScript 4.0](https://img.shields.io/badge/TypeScript%20-4.0-blue.svg)](https://github.com/microsoft/TypeScript) 5 | [![prettier](https://img.shields.io/badge/styled%20with-Prettier-blue.svg)](https://github.com/prettier/prettier) 6 | [![ESLlint](https://img.shields.io/badge/linted%20by-ESLint-brightgreen.svg)](https://eslint.org) 7 | [![node-tap](https://img.shields.io/badge/tested%20with-node--tap-green.svg)](https://github.com/tapjs/node-tap) 8 | 9 | Starter kit for modern TypeScript libraries. Generates JavaScript ready to be published on npm. 10 | 11 | Batteries included. Period. 12 | - [Prettier](https://prettier.io/) and [ESLlint](https://eslint.org) for formatting and linting 13 | - [ts-node](https://github.com/TypeStrong/ts-node) for tests execution 14 | - [node-tap](https://github.com/tapjs/node-tap) for testing and code coverage 15 | - [tap-mocha-reporter](https://github.com/tapjs/tap-mocha-reporter) for test reporting 16 | - [GitHub Actions](https://github.com/features/actions) configuration file for github actions workflow 17 | 18 | ## Clone the repo 19 | `$ git clone git@github.com:fox1t/typescript-lib-starter.git {your_project_name}` 20 | 21 | `$ cd {your_project_name}` 22 | 23 | ## Remove reference to this starter and re-init package.json 24 | `$ rm -rf .git && git init && npm init` 25 | 26 | ## Install development dependencies 27 | `$ npm i` 28 | 29 | ## Add remote origin and make initial commit 30 | `$ git remote add origin git@github.com:{your_repository}.git` 31 | 32 | `$ git add .` 33 | 34 | `$ git commit -m "Initial commit"` 35 | 36 | `$ git push -u origin master` 37 | 38 | ## Scripts 39 | - `npm run build`: build TypeScript sources to dist directory 40 | - `npm publish`: builds and publishes lib to [npmjs.com](https://www.npmjs.com) 41 | - `npm test`: run tests in `./test` directory using [tap](https://www.npmjs.com/package/tap) 42 | - `npm run test:watch`: watches `./src/` and `./test/` folders and restarts compilation and tests 43 | - `npm run test:report`: saves test report to `out.tap` file 44 | - `npm run test:reporter`: converts `out.tap` file to junit 45 | 46 | ## External typings augmentation 47 | This starter is already configured to allow you to extend typings of external packages. The logic behind it is based on [this](https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html) official template. To augment a module, just create a folder with the same name as the module you are augmenting and add an index.d.ts in it. [Here](https://github.com/fox1t/fastify-websocket-router/tree/master/typings/fastify) you can find a real world example. 48 | 49 | ## Automatic Test and Code Coverage 50 | Includes `azure-pipelines.yml` configuration file. You can build, test and publish code coverage on [Azure DevOps](https://docs.microsoft.com/en-us/azure/devops/organizations/public/?toc=%2Fazure%2Fdevops%2Forganizations%2Fpublic%2Ftoc.json&bc=%2Fazure%2Fdevops%2Forganizations%2Fpublic%2Fbreadcrumb%2Ftoc.json&view=azure-devops) for free with GitHub integration for OSS projects. 51 | 52 | ## Dev Dependencies 53 | 54 | - `husky`: runs precommit `lint` hook 55 | - `rimraf`: removes `lib` folder crossplatform 56 | - `chokidar-cli`: file watcher 57 | - `tap`: test runner 58 | - `tap-mocha-reporter`: mocha reporter for tap 59 | - `ts-node`: runs tests without compiling 60 | - `prettier` 61 | - `eslint` 62 | - `eslint-config-prettier`: makes ESLint work nice with prettier 63 | - `typescript` 64 | 65 | ## Spread the word 66 | If you use this starter, add this badge to your project to help standardising TS library development. 67 | 68 | `[![built with typescript-lib-starter](https://img.shields.io/badge/built%20with-typescript--lib--starter%20-blue.svg)](https://github.com/fox1t/typescript-lib-starter)` 69 | 70 | [![built with typescript-lib-starter](https://img.shields.io/badge/built%20with-typescript--lib--starter%20-blue.svg)](https://github.com/fox1t/typescript-lib-starter) 71 | 72 | ## Node.js libraries built with TypeScript Lib Starter 73 | - [fastify-flash](https://github.com/fastify/fastify-flash) 74 | - [qs-to-mongo](https://github.com/fox1t/qs-to-mongo) 75 | - [mongo-autoincrement](https://github.com/fox1t/mongo-autoincrement) 76 | - [fastify-websocket-router](https://github.com/fox1t/fastify-websocket-router) 77 | 78 | ## License 79 | 80 | MIT 81 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript-lib-starter", 3 | "version": "0.0.1", 4 | "description": "Put here a description.", 5 | "main": "./dist", 6 | "types": "./dist", 7 | "author": "Maksim Sinik ", 8 | "license": "MIT", 9 | "scripts": { 10 | "prebuild": "npm run lint && npm run clean-build", 11 | "build": "tsc", 12 | "clean-build": "rimraf ./dist && mkdir dist", 13 | "update": "npx npm-check -u", 14 | "prettier": "prettier --loglevel warn --write \"src/**/*.{ts,tsx}\" \"test/**/*.ts\"", 15 | "prelint": "npm run prettier", 16 | "lint": "eslint --fix --ext .ts --no-error-on-unmatched-pattern \"src/**/*.ts\" \"test/**/*.ts\"", 17 | "prepublishOnly": "npm run build", 18 | "test": "tap test/**/*.ts", 19 | "test:watch": "chokidar \"src/**/*.ts\" \"test/**/*.ts\" -c \"npm run test\" --initial", 20 | "test:report": "npm run test | tee out.tap", 21 | "test:reporter": "tap-mocha-reporter xunit < out.tap > junit-testresults.xml" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/fox1t/typescript-lib-starter.git" 26 | }, 27 | "keywords": [], 28 | "bugs": { 29 | "url": "https://github.com/fox1t/typescript-lib-starter/issues" 30 | }, 31 | "homepage": "https://github.com/fox1t/typescript-lib-starter#readme", 32 | "devDependencies": { 33 | "@types/node": "^14.14.31", 34 | "@types/tap": "^14.10.2", 35 | "@typescript-eslint/eslint-plugin": "^4.15.2", 36 | "@typescript-eslint/parser": "^4.15.2", 37 | "chokidar-cli": "^2.1.0", 38 | "eslint": "^7.20.0", 39 | "eslint-config-prettier": "^8.1.0", 40 | "eslint-plugin-prettier": "^3.3.1", 41 | "fox1t-tsconfig": "^0.2.0", 42 | "husky": "^5.1.1", 43 | "prettier": "^2.2.1", 44 | "rimraf": "^3.0.2", 45 | "tap": "^14.11.0", 46 | "tap-mocha-reporter": "^5.0.1", 47 | "ts-node": "^9.1.1", 48 | "typescript": "^4.2.2" 49 | }, 50 | "files": [ 51 | "/dist", 52 | "/typings" 53 | ], 54 | "husky": { 55 | "hooks": { 56 | "pre-commit": "npm run test && npm run build" 57 | } 58 | }, 59 | "dependencies": {} 60 | } 61 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export default (): string => 'put your code here' 2 | -------------------------------------------------------------------------------- /test/index.ts: -------------------------------------------------------------------------------- 1 | import { test } from 'tap' 2 | import main from '../src' 3 | 4 | test(`should return 'put your code here'`, t => { 5 | t.plan(1) 6 | const value = main() 7 | t.equal(value, 'put your code here') 8 | }) 9 | -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "include": ["./**/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "fox1t-tsconfig", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "typeRoots": [ 6 | "./node_modules/@types", 7 | "./typings" 8 | ] 9 | }, 10 | "include": [ 11 | "./src/**/*.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /typings/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fox1t/typescript-lib-starter/349f915ea984ec5e6654a00ed8327b711852689a/typings/.gitkeep --------------------------------------------------------------------------------