project initialized

This commit is contained in:
crusader 2018-08-26 23:57:43 +09:00
commit d247aa48d9
52 changed files with 7466 additions and 0 deletions

22
.editorconfig Normal file
View File

@ -0,0 +1,22 @@
# top-most EditorConfig file
root = true
# all files
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
max_line_length = 80
[*.{js,ts}]
quote_type = single
curly_bracket_next_line = false
spaces_around_brackets = inside
indent_brace_style = BSD KNF
# HTML
[*.html]
quote_type = double

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
*.log
.idea
.DS_Store
.cache
node_modules
coverage
lib
esm5
lib-esm
esm2015
lib-fesm
fesm
umd
bundles
typings
types
docs
dist
## this is generated by `npm pack`
*.tgz
package

32
.npmignore Normal file
View File

@ -0,0 +1,32 @@
.*
*.log
# tools configs
**/tsconfig.json
tsconfig.*.json
tslint.json
**/webpack.config.js
**/jest.config.js
**/prettier.config.js
# build scripts
config/
scripts/
# Test files
**/*.spec.js
**/*.test.js
**/*.test.d.ts
**/*.spec.d.ts
__tests__
coverage
# Sources
node_modules
src
docs
examples
## this is generated by `npm pack`
*.tgz
package

2
.npmrc Normal file
View File

@ -0,0 +1,2 @@
access=public
save-exact=true

7
.prettierignore Normal file
View File

@ -0,0 +1,7 @@
bundles
esm5
esm2015
fesm
types
typings
dist

9
.travis.yml Normal file
View File

@ -0,0 +1,9 @@
language: node_js
node_js: '8'
cache: yarn
notifications:
email: false
install:
- yarn
script:
- yarn build

11
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
"eg2.tslint",
"esbenp.prettier-vscode",
"codezombiech.gitignore",
"EditorConfig.EditorConfig"
]
}

13
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,13 @@
// Place your settings in this file to overwrite default and user settings.
{
"tslint.autoFixOnSave": true,
"tslint.enable": true,
"editor.formatOnSave": true,
"typescript.format.enable": false,
"javascript.format.enable": false,
"typescript.referencesCodeLens.enabled": true,
"javascript.referencesCodeLens.enabled": true,
"editor.rulers": [
80,100
],
}

1
.yarnrc Normal file
View File

@ -0,0 +1 @@
save-prefix false

0
CHANGELOG.md Normal file
View File

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Martin Hochel
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.

236
README.md Normal file
View File

@ -0,0 +1,236 @@
# Typescript lib starter
[![Greenkeeper badge](https://badges.greenkeeper.io/Hotell/typescript-lib-starter.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/Hotell/typescript-lib-starter.svg?branch=master)](https://travis-ci.org/Hotell/typescript-lib-starter)
[![NPM version](https://img.shields.io/npm/v/%40martin_hotell%2Ftypescript-lib-starter.svg)](https://www.npmjs.com/package/@martin_hotell/typescript-lib-starter)
![Downloads](https://img.shields.io/npm/dm/@martin_hotell/typescript-lib-starter.svg)
[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
This npm library starter:
- creates package for both Node and Browser
- build will creates 4 standard "package" formats:
- `umd` 👉 UMD bundle for Node and Browser
> `main` field in package.json
- `esm5` 👉 transpiled files to ES5 + es2015 modules for tree shaking
> `module` field in package.json
- `esm2015` 👉 raw javascript files transpiled from typescript to latest ES standard ( es2018 )
> `es2015` field in package.json
>
> this is useful if you wanna transpile everything or just wanna ship untranspiled esNext code for evergreen browsers)
- `fesm` 👉 experimental bundle type introduced by Angular team (TL;DR: it's an es2015 flattened bundle, like UMD but with latest ECMAscript and JS modules)
- type definitions are automatically generated and shipped with your package
- > `types` field in package.json
- `sideEffects` 👉 [support proper tree-shaking](https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free) for whole library ( Webpack >= 4). Turn this off or adjust as needed if your modules are not pure!
## Start coding in 4 steps !
1. `git clone https://github.com/Hotell/typescript-lib-starter <your-libary-folder-name> && cd $_`
2. `rm -rf .git && git init`
3. in `package.json` reset following fields:
```diff
{
- "name": "@next-gen/typescript-lib-starter",
+ "name": "{yourLibraryPackageName}",
- "version": "1.7.0",
+ "version": "1.0.0",
- "description": "TypeScript library setup for multiple compilation targets using tsc and webpack",
+ "description": "What is your library all about...",
- "author": "Martin Hochel",
+ "author": "{yourName}",
- "license": "MIT",
+ "license": "{yourLicense}",
"repository": {
"type": "git",
- "url": "https://www.github.com/Hotell/typescript-lib-starter"
+ "url": "https://www.github.com/{yourAccountName}/{yourLibraryPackageName}"
}
}
```
4. Install all dependencies `yarn install`
Happy coding ! 🖖
## Consumption of published library:
1. install it 🤖
```sh
yarn add my-new-library
# OR
npm install my-new-library
```
1. use it 💪
### Webpack
> #### NOTE:
>
> Don't forget to turn off ES modules transpilation to enable tree-shaking!
>
> - babel: `{"modules": false}`
> - typescript: `{"module": "esnext"}`
```ts
// main.ts or main.js
import { Greeter } from 'my-new-library'
const mountPoint = document.getElementById('app')
const App = () => {
const greeter = new Greeter('Stranger')
return `<h1>${greeter.greet()}</h1>`
}
const render = (Root: Function, where: HTMLElement) => {
where.innerHTML = Root()
}
render(App, mountPoint)
```
```html
<!-- index.htm -->
<html>
<head>
<script src="bundle.js" async></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
```
### UMD/ES2015 module aware browsers ( no bundler )
```html
<html>
<head>
<script type="module">
import {Greeter} from './node_modules/my-lib/esm2015/index.js'
const App = () => {
const greeter = new Greeter('Stranger');
return `<h1>${greeter.greet()}</h1>`
}
const render = (Root, where) => {
where.innerHTML = Root();
}
render(App, mountPoint);
</script>
<script nomodule src="node_modules/my-lib/bundles/my-new-library.umd.min.js"></script>
<script nomodule async>
var Greeter = MyLib.Greeter;
var App = function() {
var greeter = new Greeter('Stranger');
return '<h1>'+greeter.greet()+'</h1>'
}
var render = function(Root, where) {
where.innerHTML = Root();
}
render(App, mountPoint);
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
```
## Publish your library
> #### NOTE:
>
> you have to create npm account and register token on your machine
> 👉 `npm adduser`
>
> If you are using scope ( you definitely should 👌) don't forget to [`--scope`](https://docs.npmjs.com/cli/adduser#scope)
Execute `yarn release` which will handle following tasks:
- bump package version and git tag
- update/(create if it doesn't exist) CHANGELOG.md
- push to github master branch + push tags
- publish build packages to npm
> **NOTE:**
>
> all package files are gonna be within `/dist` folder from where `npm publish` will be executed
> releases are handled by awesome [standard-version](https://github.com/conventional-changelog/standard-version)
### Initial Release (without bumping package.json version):
`yarn release --first-release`
### Pre-release
- To get from `1.1.2` to `1.1.2-0`:
`yarn release --prerelease`
- **Alpha**: To get from `1.1.2` to `1.1.2-alpha.0`:
`yarn release --prerelease alpha`
- **Beta**: To get from `1.1.2` to `1.1.2-beta.0`:
`yarn release --prerelease beta`
### Dry run mode
See what commands would be run, without committing to git or updating files
`yarn release --dry-run`
## Check what files are gonna be published to npm
- `cd dist && yarn pack` OR `yarn release:preflight` which will create a tarball with everything that would get published to NPM
## Check size of your published NPM bundle
`yarn size`
## Format and fix lint errors
`yarn ts:style:fix`
## Generate documentation
`yarn docs`
## Commit ( via commitizen )
- this is preferred way how to create conventional-changelog valid commits
- if you prefer your custom tool we provide a commit hook linter which will error out, it you provide invalid commit message
- if you are in rush and just wanna skip commit message validation just prefix your message with `WIP: something done` ( if you do this please squash your work when you're done with proper commit message so standard-version can create Changelog and bump version of your library appropriately )
`yarn commit` - will invoke [commitizen CLI](https://github.com/commitizen/cz-cli)
### Troubleshooting
#### dynamic `import()`
This starter uses latest **TypeScript >=2.9** which has support for lazy loading chunks/modules via `import()` and also definition acquisition via [`import('../path-to-module').TypeFoo`](http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types)
Before TS 2.9, it wasn't possible to properly generate ambient definitions if you used dynamic `import()`. This works now as expected without any hacks ❤️ !
---
> ### Before TS 2.9
>
> Please note that if you wanna use that feature, compiler will complain because declaration generation is turned on, and currently TS can't handle type generation with types that will be loaded in the future ( lazily )
>
> **How to solve this:**
>
> - turn of type checking and don't generate types for that lazy import: `import('./components/button') as any`
> - or you can use this [temporary workaround](https://github.com/Microsoft/TypeScript/issues/16603#issuecomment-310208259)

66
config/global.d.ts vendored Normal file
View File

@ -0,0 +1,66 @@
// ts-jest types require 'babel-core'
declare module 'babel-core' {
interface TransformOptions {}
}
declare module 'jest-config' {
const defaults: jest.DefaultOptions
}
declare module 'sort-object-keys' {
const sortPackageJson: <T extends {}>(
object: T,
sortWith?: (...args: any[]) => any
) => T
export = sortPackageJson
}
type RollupPluginFn<O extends object = {}> = (
options?: O
) => import('rollup').Plugin
declare module 'rollup-plugin-json' {
export interface Options {
/**
* All JSON files will be parsed by default, but you can also specifically include/exclude files
*/
include?: string | string[]
exclude?: string | string[]
/**
* for tree-shaking, properties will be declared as variables, using either `var` or `const`
* @default false
*/
preferConst?: boolean
/**
* specify indentation for the generated default export defaults to '\t'
* @default '\t'
*/
indent?: string
}
const plugin: RollupPluginFn<Options>
export default plugin
}
declare module 'rollup-plugin-sourcemaps' {
const plugin: RollupPluginFn
export default plugin
}
declare module 'rollup-plugin-node-resolve' {
const plugin: RollupPluginFn
export default plugin
}
declare module 'rollup-plugin-commonjs' {
const plugin: RollupPluginFn
export default plugin
}
declare module 'rollup-plugin-replace' {
const plugin: RollupPluginFn
export default plugin
}
declare module 'rollup-plugin-uglify' {
const uglify: RollupPluginFn
export { uglify }
}
declare module 'rollup-plugin-terser' {
const terser: RollupPluginFn
export { terser }
}

60
config/helpers.js Normal file
View File

@ -0,0 +1,60 @@
// helpers
module.exports = {
camelCaseToDash,
dashToCamelCase,
toUpperCase,
pascalCase,
normalizePackageName,
getOutputFileName,
}
/**
*
* @param {string} myStr
*/
function camelCaseToDash(myStr) {
return myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
}
/**
*
* @param {string} myStr
*/
function dashToCamelCase(myStr) {
return myStr.replace(/-([a-z])/g, (g) => g[1].toUpperCase())
}
/**
*
* @param {string} myStr
*/
function toUpperCase(myStr) {
return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`
}
/**
*
* @param {string} myStr
*/
function pascalCase(myStr) {
return toUpperCase(dashToCamelCase(myStr))
}
/**
*
* @param {string} rawPackageName
*/
function normalizePackageName(rawPackageName) {
const scopeEnd = rawPackageName.indexOf('/') + 1
return rawPackageName.substring(scopeEnd)
}
/**
*
* @param {string} fileName
* @param {boolean?} isProd
*/
function getOutputFileName(fileName, isProd = false) {
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName
}

43
config/jest.config.js Normal file
View File

@ -0,0 +1,43 @@
// @ts-check
const { defaults } = require('jest-config')
/**
* @type {import('./types').TsJestConfig}
*/
const tsJestConfig = {
skipBabel: true,
}
/**
* @type {Partial<jest.InitialOptions>}
*/
const config = {
rootDir: '..',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testMatch: [
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
'<rootDir>/src/**/?(*.)+(spec|test).ts?(x)',
],
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
globals: {
'ts-jest': tsJestConfig,
},
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
setupFiles: ['<rootDir>/config/setup-tests.js'],
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
}
module.exports = config

128
config/rollup.config.js Normal file
View File

@ -0,0 +1,128 @@
import { resolve } from 'path'
import sourceMaps from 'rollup-plugin-sourcemaps'
import nodeResolve from 'rollup-plugin-node-resolve'
import json from 'rollup-plugin-json'
import commonjs from 'rollup-plugin-commonjs'
import replace from 'rollup-plugin-replace'
import { uglify } from 'rollup-plugin-uglify'
import { terser } from 'rollup-plugin-terser'
import { getIfUtils, removeEmpty } from 'webpack-config-utils'
import pkg from '../package.json'
const {
pascalCase,
normalizePackageName,
getOutputFileName,
} = require('./helpers')
/**
* @typedef {import('./types').RollupConfig} Config
*/
/**
* @typedef {import('./types').RollupPlugin} Plugin
*/
const env = process.env.NODE_ENV || 'development'
const { ifProduction } = getIfUtils(env)
const LIB_NAME = pascalCase(normalizePackageName(pkg.name))
const ROOT = resolve(__dirname, '..')
const DIST = resolve(ROOT, 'dist')
/**
* @type {{entry:{esm5: string, esm2015: string},bundles:string}}
*/
const PATHS = {
entry: {
esm5: resolve(DIST, 'esm5'),
esm2015: resolve(DIST, 'esm2015'),
},
bundles: resolve(DIST, 'bundles'),
}
/**
* @type {string[]}
*/
const external = Object.keys(pkg.peerDependencies) || []
/**
* @type {Plugin[]}
*/
const plugins = /** @type {Plugin[]} */ ([
// Allow json resolution
json(),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
nodeResolve(),
// Resolve source maps to the original source
sourceMaps(),
// properly set process.env.NODE_ENV within `./environment.ts`
replace({
exclude: 'node_modules/**',
'process.env.NODE_ENV': JSON.stringify(env),
}),
])
/**
* @type {Config}
*/
const CommonConfig = {
input: {},
output: {},
inlineDynamicImports: true,
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external,
}
/**
* @type {Config}
*/
const UMDconfig = {
...CommonConfig,
input: resolve(PATHS.entry.esm5, 'index.js'),
output: {
file: getOutputFileName(
resolve(PATHS.bundles, 'index.umd.js'),
ifProduction()
),
// file: getOutputFileName('dist/bundles/index.umd.js', ifProduction()),
format: 'umd',
name: LIB_NAME,
sourcemap: true,
},
plugins: /** @type {Plugin[]} */ (removeEmpty([
...plugins,
ifProduction(uglify()),
])),
}
/**
* @type {Config}
*/
const FESMconfig = {
...CommonConfig,
input: resolve(PATHS.entry.esm2015, 'index.js'),
output: [
{
file: getOutputFileName(
resolve(PATHS.bundles, 'index.esm.js'),
ifProduction()
),
format: 'es',
sourcemap: true,
},
],
plugins: /** @type {Plugin[]} */ (removeEmpty([
...plugins,
ifProduction(terser()),
])),
}
export default [UMDconfig, FESMconfig]

4
config/setup-tests.js Normal file
View File

@ -0,0 +1,4 @@
// add here any code that you wanna execute before tests like
// - polyfills
// - some custom code
// for more docs check see https://jestjs.io/docs/en/configuration.html#setupfiles-array

14
config/tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"strict": true,
"allowJs": true,
"checkJs": true,
"target": "es2017",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"noEmit": true
}
}

30
config/types.js Normal file
View File

@ -0,0 +1,30 @@
export {}
// ===== JEST ====
/**
* @typedef {import('ts-jest/dist/jest-types').TsJestConfig} TsJestConfig
*/
// @TODO https://github.com/Microsoft/TypeScript/issues/24916
/**
* @typedef {Partial<jest.ProjectConfig & jest.GlobalConfig>} JestConfig
*/
/**
* @typedef {typeof import('jest-config').defaults} JestDefaultConfig
*/
// ==== PRETTIER ====
/**
* @typedef {import('prettier').Options} PrettierConfig
*/
// ==== ROLLUP ====
/**
* @typedef {import('rollup').InputOptions & { output: import('rollup').OutputOptions | Array<import('rollup').OutputOptions | null> }} RollupConfig
*/
/**
* @typedef {import('rollup').Plugin} RollupPlugin
*/

95
package.json Normal file
View File

@ -0,0 +1,95 @@
{
"name": "@overflow/typescript-library-starter",
"version": "0.0.1",
"description": "TypeScript library setup for multiple compilation targets using tsc and webpack",
"main": "./bundles/index.umd.js",
"module": "./esm5/index.js",
"es2015": "./esm2015/index.js",
"typings": "./types/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://git.loafle.net/overflow/typescript-library-starter"
},
"author": "loafle.com",
"license": "MIT",
"engines": {
"node": ">=8.5"
},
"scripts": {
"cleanup": "shx rm -rf dist",
"prebuild": "yarn cleanup && yarn verify",
"build": "tsc && tsc --target es2018 --outDir dist/esm2015 && rollup -c config/rollup.config.js && rollup -c config/rollup.config.js --environment NODE_ENV:production",
"postbuild": "node scripts/copy.js && yarn size",
"docs": "typedoc -p . --theme minimal --target 'es6' --excludeNotExported --excludePrivate --ignoreCompilerErrors --exclude \"**/src/**/__tests__/*.*\" --out docs src/",
"test": "jest -c ./config/jest.config.js",
"test:watch": "yarn test -- --watch",
"test:coverage": "yarn test -- --coverage",
"test:ci": "yarn test -- --ci",
"validate-js": "tsc -p ./config && tsc -p ./scripts",
"verify": "yarn validate-js && yarn style && yarn test:ci",
"commit": "git-cz",
"style": "yarn lint",
"style:fix": "yarn format:fix && yarn lint:fix",
"lint": "tslint --project tsconfig.json --format codeFrame",
"lint:fix": "yarn lint -- --fix",
"prerelease": "yarn build",
"release": "standard-version",
"postrelease": "node scripts/copy.js && yarn release:github && yarn release:npm",
"release:git": "git push --no-verify --follow-tags origin master",
"release:npm": "cd dist && yarn publish",
"release:preflight": "cd dist && yarn pack",
"size": "yarn size:umd && yarn size:fesm",
"size:umd": "shx echo \"Gzipped+minified UMD bundle Size:\" && cross-var strip-json-comments --no-whitespace \"./dist/bundles/index.umd.min.js\" | gzip-size",
"size:fesm": "shx echo \"Gzipped+minified FESM bundle Size:\" && strip-json-comments --no-whitespace \"./dist/bundles/index.esm.min.js\" | gzip-size"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
},
"validate-commit-msg": {
"types": "conventional-commit-types",
"maxSubjectLength": 120
}
},
"peerDependencies": {
"tslib": ">=1.9.0"
},
"dependencies": {},
"devDependencies": {
"@types/chokidar": "^1.7.5",
"@types/jest": "^23.3.1",
"@types/json5": "^0.0.30",
"@types/node": "^8.10.4",
"@types/webpack-config-utils": "^2.3.0",
"awesome-typescript-loader": "^5.2.0",
"commitizen": "^2.10.1",
"cross-var": "^1.1.0",
"cz-conventional-changelog": "^2.1.0",
"gzip-size-cli": "^3.0.0",
"jest": "^23.5.0",
"jest-watch-typeahead": "^0.2.0",
"json5": "^2.0.1",
"lint-staged": "^7.2.2",
"rollup": "^0.65.0",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^1.0.1",
"rollup-plugin-uglify": "^4.0.0",
"shx": "^0.3.2",
"sort-object-keys": "^1.1.2",
"standard-version": "^4.4.0",
"strip-json-comments-cli": "^1.0.1",
"ts-jest": "^23.1.4",
"tslib": "^1.9.3",
"tslint": "^5.11.0",
"tslint-config-standard": "^7.1.0",
"typedoc": "^0.12.0",
"typescript": "^2.9.2",
"validate-commit-msg": "^2.14.0",
"webpack-config-utils": "^2.3.0"
}
}

45
scripts/copy.js Normal file
View File

@ -0,0 +1,45 @@
const { writeFileSync, copyFileSync } = require('fs')
const { resolve } = require('path')
const packageJson = require('../package.json')
main()
function main() {
const projectRoot = resolve(__dirname, '..')
const distPath = resolve(projectRoot, 'dist')
const distPackageJson = createDistPackageJson(packageJson)
copyFileSync(
resolve(projectRoot, 'README.md'),
resolve(distPath, 'README.md')
)
copyFileSync(
resolve(projectRoot, 'CHANGELOG.md'),
resolve(distPath, 'CHANGELOG.md')
)
copyFileSync(
resolve(projectRoot, 'LICENSE.md'),
resolve(distPath, 'LICENSE.md')
)
copyFileSync(
resolve(projectRoot, '.npmignore'),
resolve(distPath, '.npmignore')
)
writeFileSync(resolve(distPath, 'package.json'), distPackageJson)
}
/**
* @param {typeof packageJson} packageConfig
* @return {string}
*/
function createDistPackageJson(packageConfig) {
const {
devDependencies,
scripts,
engines,
config,
...distPackageJson
} = packageConfig
return JSON.stringify(distPackageJson, null, 2)
}

221
scripts/migrate.js Normal file
View File

@ -0,0 +1,221 @@
/**
* Migrate Typescript-library-starter from 3. -> 4.
*/
const JSON5 = require('json5')
const sortObjectByKeyNameList = require('sort-object-keys')
const {
writeFileSync,
copyFileSync,
readFileSync,
existsSync,
unlinkSync,
} = require('fs')
const { resolve, join } = require('path')
const starterPkg = require('../package.json')
const args = process.argv.slice(2)
const pathToProject = args[0]
/**
* @typedef {typeof projectPkg} Pkg
*/
if (!pathToProject) {
throw new Error(
'you need provide relative path to package that uses ts-lib-starter!'
)
}
const ROOT = resolve(__dirname, '..')
const PACKAGE_ROOT = resolve(ROOT, pathToProject)
main()
function main() {
if (!existsSync(PACKAGE_ROOT)) {
throw new Error(`${PACKAGE_ROOT}, doesn't exists`)
}
console.log('Migration initialized 👀')
console.log('path to Package:', PACKAGE_ROOT)
updatePackageJson()
updateTsConfig()
updateTsLintConfig()
updateConfigDir()
updateScriptsDir()
console.log('DONE ✅')
}
function updatePackageJson() {
const libPackagePkgPath = resolve(PACKAGE_ROOT, 'package.json')
/**
* @type {typeof starterPkg}
*/
const libPackagePkg = JSON5.parse(
readFileSync(libPackagePkgPath, { encoding: 'utf-8' })
)
/**
* @type {typeof starterPkg}
*/
const updatePkg = {
...libPackagePkg,
main: starterPkg.main,
engines: { ...libPackagePkg.engines, ...starterPkg.engines },
scripts: { ...libPackagePkg.scripts, ...starterPkg.scripts },
peerDependencies: sortObjectByKeyNameList({
...libPackagePkg.peerDependencies,
...starterPkg.peerDependencies,
}),
devDependencies: sortObjectByKeyNameList({
...starterPkg.devDependencies,
...libPackagePkg.devDependencies,
}),
}
removePackages(updatePkg.devDependencies)
writePackage(updatePkg)
/**
*
* @param {{[packageName:string]:string}} devDependencies
*/
function removePackages(devDependencies) {
const depsToRemove = [
'@types/uglifyjs-webpack-plugin',
'@types/webpack',
'uglifyjs-webpack-plugin',
'webpack',
'webpack-cli',
// packages needed for this script
'json5',
'@types/json5',
'sort-object-keys',
]
depsToRemove.forEach(
(dependencyName) => delete devDependencies[dependencyName]
)
}
/**
* @param {typeof starterPkg} pkg
*/
function writePackage(pkg) {
const updatedLibPkgToWrite = JSON.stringify(pkg, null, 2)
writeFileSync(join(PACKAGE_ROOT, 'package.json'), updatedLibPkgToWrite)
console.log('\n updated package.json:', updatedLibPkgToWrite, '\n')
}
}
function updateTsConfig() {
/**
* @typedef {typeof import('../tsconfig.json')} TsConfig
*/
const starterConfigPath = resolve(ROOT, 'tsconfig.json')
const libPackageConfigPath = resolve(PACKAGE_ROOT, 'tsconfig.json')
/**
* @type {TsConfig}
*/
const starterConfig = JSON5.parse(
readFileSync(starterConfigPath, { encoding: 'utf-8' })
)
/**
* @type {TsConfig}
*/
const libConfig = JSON5.parse(
readFileSync(libPackageConfigPath, { encoding: 'utf-8' })
)
console.log('starter:', starterConfig)
console.log('library:', libConfig)
console.log('==TS-Config:nothing updated==\n')
}
function updateTsLintConfig() {
/**
* @typedef {typeof import('../tslint.json')} TsLintConfig
*/
const starterConfigPath = resolve(ROOT, 'tslint.json')
const libPackageConfigPath = resolve(PACKAGE_ROOT, 'tslint.json')
/**
* @type {TsLintConfig}
*/
const starterConfig = JSON5.parse(
readFileSync(starterConfigPath, { encoding: 'utf-8' })
)
/**
* @type {TsLintConfig}
*/
const libConfig = JSON5.parse(
readFileSync(libPackageConfigPath, { encoding: 'utf-8' })
)
console.log('starter:', starterConfig)
console.log('library:', libConfig)
console.log('==TS-Lint:nothing updated==\n')
}
function updateConfigDir() {
const starterConfigPathDir = resolve(ROOT, 'config')
const libPackageConfigPathDir = resolve(PACKAGE_ROOT, 'config')
const filesToCopy = [
'global.d.ts',
'helpers.js',
'rollup.config.js',
'tsconfig.json',
'types.js',
]
const filesToRemove = ['webpack.config.js']
filesToCopy.forEach((file) => {
copyFileSync(
resolve(starterConfigPathDir, file),
join(libPackageConfigPathDir, file)
)
})
filesToRemove.forEach((file) => {
unlinkSync(join(libPackageConfigPathDir, file))
})
console.log('==config/ updated==\n')
}
function updateScriptsDir() {
const starterScriptsPathDir = resolve(ROOT, 'scripts')
const libPackageScriptsPathDir = resolve(PACKAGE_ROOT, 'scripts')
const filesToCopy = ['copy.js', 'tsconfig.json']
/**
* @type {string[]}
*/
const filesToRemove = []
filesToCopy.forEach((file) => {
copyFileSync(
resolve(starterScriptsPathDir, file),
join(libPackageScriptsPathDir, file)
)
})
filesToRemove.forEach((file) => {
unlinkSync(join(libPackageScriptsPathDir, file))
})
console.log('==scripts/ updated==\n')
}

8
scripts/tsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "../config/tsconfig.json",
"compilerOptions": {},
"include": [
".",
"../config/global.d.ts"
]
}

View File

@ -0,0 +1,16 @@
jest.mock('../environment.ts', () => ({
IS_DEV: true,
IS_PROD: false,
}));
describe(`Greeter`, () => {
beforeEach(() => {
console.log('');
});
it(`should greet`, () => {
console.log('');
});
});

180
src/client/client.ts Normal file
View File

@ -0,0 +1,180 @@
import { Observable, Subject } from 'rxjs';
import { Message } from '../core/type';
import {
ClientCodec,
ClientNotificationCodec,
ClientResponseCodec
} from '../protocol/client_codec';
import { RPCClientError } from '../protocol/error';
import { ClientRWC } from './client_rwc';
export interface RequestState {
subject: Subject<any>;
request: {
method: string;
params: any[] | null;
};
}
export abstract class Client {
private requestID: number;
private pendingRequestsCount: number;
private pendingRequests: Map<number, RequestState>;
private notiSubject: Subject<ClientNotificationCodec> | undefined;
protected clientCodec: ClientCodec;
protected clientRWC: ClientRWC;
public constructor(
clientCodec: ClientCodec,
clientRWC: ClientRWC,
) {
this.clientCodec = clientCodec;
this.clientRWC = clientRWC;
this.requestID = 0;
this.pendingRequestsCount = 0;
this.pendingRequests = new Map();
}
private getRequestID(): number {
return ++this.requestID;
}
public getPendingRequestsCount(): number {
return this.pendingRequestsCount;
}
/**
* connect
*/
public connect(queryString?: string): void {
this.clientRWC.connect(queryString);
this.clientRWC.read().subscribe(
(value: Message) => {
this.onMessage(value);
},
(error: any) => {
console.error(error);
},
() => {
console.log('');
},
);
}
/**
* close
*/
public disconnect() {
this.clientRWC.disconnect();
}
/**
* notify
*/
public send(method: string, ...args: any[]): void {
this.sendInternal(false, method, args);
}
/**
* call
*/
public call<T>(method: string, ...args: any[]): Observable<T> {
const o = this.sendInternal<T>(true, method, args);
if (undefined === o) {
throw new Error('Error');
}
return o;
}
/**
* callTimeout
*/
public callTimeout<T>(ms: number, method: string, ...args: any[]): Observable<T> | undefined {
return undefined;
}
private sendInternal<T>(hasResponse: boolean, method: string, args?: any[]): Observable<T> | undefined {
let id = -1;
let resSubject: Subject<T> | undefined;
const params = undefined === args ? null : args;
if (hasResponse) {
id = this.getRequestID();
resSubject = new Subject<T>();
const reqState: RequestState = {
subject: resSubject,
request: {
method,
params,
},
};
this.pendingRequests.set(id, reqState);
this.pendingRequestsCount++;
}
this.clientRWC.write(this.clientCodec.request(method, params, id));
if (undefined !== resSubject) {
return resSubject.asObservable();
}
return undefined;
}
private onMessage(message: Message): void {
const resCodec = this.clientCodec.response(message);
if (resCodec.isNotification()) {
const notiCodec = resCodec.notification();
if (undefined !== notiCodec) {
if (undefined !== this.notiSubject) {
this.notiSubject.next(resCodec.notification());
}
}
} else {
this.onResponse(resCodec);
}
}
protected onResponse(resCodec: ClientResponseCodec): void {
const id = resCodec.id();
const result = resCodec.result();
const error = resCodec.error();
if (undefined === id) {
throw new Error(`This is not response because does not have ID. ${resCodec}`);
}
const reqState = this.pendingRequests.get(id);
if (undefined === reqState) {
console.log(`The message does not exist. ${resCodec}`);
return;
}
this.pendingRequests.delete(id);
this.pendingRequestsCount--;
if (undefined !== error) {
const rpcClientError: RPCClientError = {
request: reqState.request,
response: error,
};
console.error(rpcClientError);
reqState.subject.error(rpcClientError);
} else {
reqState.subject.next(result);
}
}
public notification(): Observable<ClientNotificationCodec> {
if (undefined === this.notiSubject) {
this.notiSubject = new Subject<ClientNotificationCodec>();
}
return this.notiSubject.asObservable();
}
}

11
src/client/client_rwc.ts Normal file
View File

@ -0,0 +1,11 @@
import { Observable } from 'rxjs';
import { Message } from '../core/type';
export interface ClientRWC {
connect(queryString?: string): void;
disconnect(): void;
connectionStatus(): Observable<boolean> | undefined;
read(): Observable<Message>;
write(data: Message): void;
}

3
src/client/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './client';
export * from './client_rwc';
export * from './rwc/ws';

View File

@ -0,0 +1 @@
export * from './websocket_rwc';

View File

@ -0,0 +1,85 @@
import { Observable, Subject } from 'rxjs';
import { Message } from '../../../core/type';
import {
RxWebSocketSubject,
RxWebSocketSubjectConfig
} from '../../../dom/rx_websocket_subject';
import { ClientRWC } from '../../client_rwc';
export interface WebSocketClientRWCConfig {
url: string;
protocol?: string | Array<string>;
WebSocketCtor?: { new(url: string, protocols?: string | string[]): WebSocket };
queryString?: string;
reconnectInterval?: 5000;
reconnectRetry?: 10;
}
export class WebSocketClientRWC implements ClientRWC {
private wsSubject: RxWebSocketSubject<Message> | undefined;
private _rxConfig: RxWebSocketSubjectConfig<Message>;
private resSubject: Subject<Message> | undefined;
constructor(private _config: WebSocketClientRWCConfig) {
this._rxConfig = Object.assign({}, this._config);
// this._rxConfig.resultSelector = (e: MessageEvent) => {
// return e.data;
// };
this._rxConfig.serializer = (value: Message) => value;
this._rxConfig.deserializer = (e: MessageEvent) => e.data;
this._rxConfig.binaryType = 'arraybuffer';
}
public connect(queryString?: string): void {
if (undefined === this.wsSubject) {
if (undefined !== queryString) {
this._rxConfig.queryString = queryString;
}
this.wsSubject = new RxWebSocketSubject(this._rxConfig);
}
this.wsSubject.subscribe(
(value: Message) => {
if (undefined !== this.resSubject) {
this.resSubject.next(value);
}
},
(error: any) => {
if (undefined !== this.resSubject) {
this.resSubject.error(error);
}
},
() => {
console.log('sss');
},
);
}
public disconnect(): void {
if (undefined !== this.wsSubject) {
this.wsSubject.disconnect();
}
}
public connectionStatus(): Observable<boolean> | undefined {
if (undefined !== this.wsSubject) {
return this.wsSubject.connectionStatus;
}
return undefined;
}
public read(): Observable<Message> {
if (undefined === this.resSubject) {
this.resSubject = new Subject<Message>();
}
return this.resSubject.asObservable();
}
public write(data: Message): void {
if (undefined !== this.wsSubject) {
this.wsSubject.send(data);
}
}
}

33
src/codec/codec.ts Normal file
View File

@ -0,0 +1,33 @@
import { Message } from '../core/type';
export interface Codec {
encode(message: string): Message;
decode(message: Message): string;
}
export class DefaultCodec implements Codec {
public encode(message: string): Message {
return message;
}
public decode(message: Message): string {
return message as string;
}
}
export const defaultCodec = new DefaultCodec();
export interface CodecSelector {
encode(message: string): Message;
decode(message: Message): string;
}
export class DefaultCodecSelector implements CodecSelector {
public encode(message: string): Message {
return defaultCodec.encode(message);
}
public decode(message: Message): string {
return defaultCodec.decode(message);
}
}
export const defaultCodecSelector = new DefaultCodecSelector();

View File

@ -0,0 +1,39 @@
import { Message } from '../core/type';
import { Codec, CodecSelector, defaultCodec } from './codec';
const { gzip, ungzip } = require('pako');
export class GZipCodec implements Codec {
public encode(message: string): Message {
return gzip(message).buffer as ArrayBuffer;
}
public decode(message: Message): string {
return ungzip(Buffer.from(message as ArrayBuffer), { to: 'string' });
}
}
export const gZipCodec = new GZipCodec();
export class CompressionCodecSelector implements CodecSelector {
private readonly threshold: number;
public constructor(threshold: number) {
this.threshold = threshold;
}
public encode(message: string): Message {
if (this.threshold < Buffer.byteLength(message)) {
return gZipCodec.encode(message);
} else {
return defaultCodec.encode(message);
}
}
public decode(message: Message): string {
if (message instanceof ArrayBuffer) {
return gZipCodec.decode(message);
} else {
return defaultCodec.decode(message);
}
}
}

2
src/codec/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './codec';
export * from './compression_codec';

1
src/core/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './type';

1
src/core/type.ts Normal file
View File

@ -0,0 +1 @@
export type Message = string | ArrayBuffer;

1
src/dom/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './rx_websocket_subject';

View File

@ -0,0 +1,122 @@
import { interval, Observable, Observer, Subject } from 'rxjs';
import { distinctUntilChanged, share, takeWhile } from 'rxjs/operators';
import { WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket';
const urljoin = require('url-join');
export interface RxWebSocketSubjectConfig<T> extends WebSocketSubjectConfig<T> {
queryString?: string;
reconnectInterval?: 5000;
reconnectRetry?: 10;
}
export class RxWebSocketSubject<T> extends Subject<T> {
private reconnectionObservable: Observable<number> | undefined;
private wsSubjectConfig: WebSocketSubjectConfig<T>;
private socket: WebSocketSubject<T> | undefined;
private connectionObserver: Observer<boolean> | undefined;
public connectionStatus: Observable<boolean>;
private readonly reconnectInterval: number;
private readonly reconnectRetry: number;
constructor(private _rxConfig: RxWebSocketSubjectConfig<T>) {
super();
this.reconnectInterval =
undefined !== this._rxConfig.reconnectInterval
? this._rxConfig.reconnectInterval
: 5000;
this.reconnectRetry =
undefined !== this._rxConfig.reconnectRetry
? this._rxConfig.reconnectRetry
: 10;
this.connectionStatus = new Observable((observer: Observer<boolean>) => {
this.connectionObserver = observer;
}).pipe(
share(),
distinctUntilChanged(),
);
this.wsSubjectConfig = Object.assign({}, this._rxConfig);
this.wsSubjectConfig.closeObserver = {
next: (_e: CloseEvent) => {
this.socket = undefined;
if (undefined !== this.connectionObserver) {
this.connectionObserver.next(false);
}
},
};
this.wsSubjectConfig.openObserver = {
next: (_e: Event) => {
if (undefined !== this.connectionObserver) {
this.connectionObserver.next(true);
}
},
};
this.connect();
this.connectionStatus.subscribe(isConnected => {
if (
!this.reconnectionObservable &&
!isConnected
) {
this.reconnect();
}
});
}
private connect(): void {
this.wsSubjectConfig.url =
undefined !== this._rxConfig.queryString
? urljoin(this._rxConfig.url, this._rxConfig.queryString)
: this._rxConfig.url;
this.socket = new WebSocketSubject(this.wsSubjectConfig);
this.socket.subscribe(
m => {
this.next(m);
},
(_error: Event) => {
if (!this.socket) {
this.reconnect();
}
},
);
}
private reconnect(): void {
this.reconnectionObservable = interval(this.reconnectInterval).pipe(
takeWhile((_v, index) => {
return index < this.reconnectRetry && !this.socket;
}),
);
this.reconnectionObservable.subscribe(
() => {
this.connect();
},
undefined,
() => {
this.reconnectionObservable = undefined;
if (!this.socket) {
this.complete();
if (undefined !== this.connectionObserver) {
this.connectionObserver.complete();
}
}
},
);
}
public disconnect(): void {
if (undefined !== this.socket) {
this.socket.complete();
}
}
public send(data: T): void {
if (undefined !== this.socket) {
this.socket.next(data);
}
}
}

5
src/environment.ts Normal file
View File

@ -0,0 +1,5 @@
/** * @internal */
export const IS_DEV = process.env.NODE_ENV === 'development';
/** * @internal */
export const IS_PROD = process.env.NODE_ENV === 'production';

5
src/index.ts Normal file
View File

@ -0,0 +1,5 @@
export * from './client';
export * from './codec';
export * from './core';
export * from './dom';
export * from './protocol';

View File

@ -0,0 +1,19 @@
import { Message } from '../core/type';
import { RPCError } from './error';
import { RegistryCodec } from './registry_codec';
export interface ClientCodec {
request(method: string, args: any[] | null, id: number): Message;
response(res: Message): ClientResponseCodec;
}
export interface ClientResponseCodec {
id(): number | undefined;
error(): RPCError | undefined;
result(): any | undefined;
isNotification(): boolean;
notification(): ClientNotificationCodec | undefined;
}
export interface ClientNotificationCodec extends RegistryCodec { }

41
src/protocol/error.ts Normal file
View File

@ -0,0 +1,41 @@
export interface RPCClientError {
request: {
method: string;
params: any[] | null;
};
response: RPCError;
}
/**
* Error object representation when a method invocation fails.
*/
export interface RPCError {
/** Indicates the error type that occurred. */
code: RPCErrorCode;
/** A short description of the error. */
message: string;
/** Additional information about the error */
data?: any;
} /*
/** Error codes are same as xml-rpc codes. See http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php */
export const enum RPCErrorCode {
/** Parse error Invalid JSON was received by the Server. */
ParseError = -32700,
/** Invalid Request The JSON sent is not a valid Request object. */
InvalidRequest = -32600,
/** The method does not exist / is not available. */
MethodNotFound = -32601,
/** Invalid method parameter(s). */
InvalidParams = -32602,
/** Internal JSON-RPC error. */
InternalError = -32603,
/** -32000 to -32099: Reserved for implementation-defined Server errors. */
}

4
src/protocol/index.ts Normal file
View File

@ -0,0 +1,4 @@
export * from './client_codec';
export * from './error';
export * from './registry_codec';
export * from './json';

View File

@ -0,0 +1,32 @@
import { CodecSelector, defaultCodecSelector } from '../../codec/codec';
import { Message } from '../../core/type';
import { ClientCodec, ClientResponseCodec } from '../client_codec';
import { ClientRequest } from './client_request';
import { JSONClientResponseCodec } from './client_response';
import { version } from './constants';
import { convertParamsToStringArray } from './util';
export class JSONClientCodec implements ClientCodec {
private readonly codecSelector: CodecSelector;
public constructor(codecSelector: CodecSelector = defaultCodecSelector) {
this.codecSelector = codecSelector;
}
public request(method: string, args: any[] | null, id?: number): Message {
const params = convertParamsToStringArray(args);
const req: ClientRequest = {
jsonrpc: version,
method,
params: 0 === params.length ? null : params,
id,
};
return this.codecSelector.encode(JSON.stringify(req));
}
public response(message: Message): ClientResponseCodec {
return new JSONClientResponseCodec(this.codecSelector.decode(message));
}
}

View File

@ -0,0 +1,18 @@
import { ClientNotificationCodec } from '../client_codec';
export interface ClientNotification {
method: string;
params?: string[];
}
export class JSONClientNotificationCodec implements ClientNotificationCodec {
public constructor(private noti: ClientNotification) {
}
public method(): string {
return this.noti.method;
}
public params(): any[] | undefined {
return this.noti.params;
}
}

View File

@ -0,0 +1,6 @@
export interface ClientRequest {
jsonrpc: string;
method: string;
params?: string[] | null;
id?: number;
}

View File

@ -0,0 +1,51 @@
import { ClientNotificationCodec, ClientResponseCodec } from '../client_codec';
import { RPCError } from '../error';
import {
ClientNotification,
JSONClientNotificationCodec,
} from './client_notification';
export interface ClientResponse {
jsonrpc: string;
result?: any;
error?: RPCError;
id?: number;
}
export class JSONClientResponseCodec implements ClientResponseCodec {
private res: ClientResponse;
public constructor(json: string) {
this.res = JSON.parse(json);
}
public id(): number | undefined {
return this.res.id;
}
public error(): RPCError | undefined {
return this.res.error;
}
public result(): any | undefined {
return this.res.result;
}
public isNotification(): boolean {
if (undefined === this.id() && undefined !== this.result()) {
return true;
}
return false;
}
public notification(): ClientNotificationCodec | undefined {
if (undefined !== this.id() || undefined === this.result()) {
return undefined;
}
const noti: ClientNotification = {
method: this.res.result.method,
params: this.res.result.params,
};
return new JSONClientNotificationCodec(noti);
}
}

View File

@ -0,0 +1,2 @@
export const name = 'jsonrpc';
export const version = '2.0';

View File

@ -0,0 +1,6 @@
export * from './client';
export * from './client_notification';
export * from './client_request';
export * from './client_response';
export * from './constants';
export * from './util';

28
src/protocol/json/util.ts Normal file
View File

@ -0,0 +1,28 @@
export function convertParamsToStringArray(args: any[] | null): string[] {
const values: string[] = [];
if (null === args || 0 === args.length) {
return values;
}
for (let indexI = 0; indexI < args.length; indexI++) {
const arg = args[indexI];
switch (typeof arg) {
case 'boolean':
case 'number': // enum
values.push(String(arg));
break;
case 'string':
values.push(arg);
break;
case 'object': // array, map
values.push(JSON.stringify(arg));
break;
default:
throw new Error(`Not supported type[${typeof arg}]`);
}
}
return values;
}

View File

@ -0,0 +1,4 @@
export interface RegistryCodec {
method(): string;
params(): any | undefined;
}

33
tsconfig.json Normal file
View File

@ -0,0 +1,33 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "esnext",
"target": "es5",
"lib": [
"dom",
"es2018"
],
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"suppressImplicitAnyIndexErrors": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"outDir": "dist/esm5",
"declaration": true,
"declarationDir": "dist/types",
"declarationMap": true,
"stripInternal": true,
"resolveJsonModule": true,
"importHelpers": true
},
"include": [
"./src"
],
"exclude": [
"node_modules",
"dist"
],
"compileOnSave": false,
"buildOnSave": false
}

79
tslint.json Normal file
View File

@ -0,0 +1,79 @@
{
"extends": [
"tslint-config-standard"
],
"rules": {
// core ts-lint rules
"await-promise": true,
"no-unused-variable": true,
"forin": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-shadowed-variable": true,
"no-string-literal": true,
"no-inferrable-types": [
true
],
"no-unnecessary-initializer": true,
"no-magic-numbers": false,
"no-require-imports": false,
"no-duplicate-super": true,
"no-boolean-literal-compare": true,
"no-namespace": [
true,
"allow-declarations"
],
"no-invalid-this": [
true,
"check-function-in-method"
],
"ordered-imports": [
true
],
"interface-name": [
false
],
"newline-before-return": true,
"object-literal-shorthand": true,
"arrow-return-shorthand": [
true
],
"unified-signatures": true,
"prefer-for-of": false,
"match-default-export-name": true,
"prefer-const": true,
"semicolon": [
true,
"always"
],
"trailing-comma": [
true,
{
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "always",
"typeLiterals": "ignore"
},
"esSpecCompliant": true
}
],
"space-before-function-paren": [
true,
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
]
}
}

5547
yarn.lock Normal file

File diff suppressed because it is too large Load Diff