Skip to content

Commit 6a8b68e

Browse files
authored
feat(scripts): implement file-size script (#162)
* build(scripts): implement file-size script * fix(config): tweak missing types * refactor(scripts): tweak file-size * feat(scripts): add migrate v4 to v5 scripts * chore(vscode): remove prettier config as plugin works now * refactor: move prettier from config/ to root * fix(prettier): ignore node_modules * chore(npm-scripts): apply new prettier config * feat(scripts): update migrate v4 to v5 scripts * ci: fix build * fix(scripts): don't run init on CI and fix build * refactor(npm-scripts): remove .js extension and use absolute path to commitizen adapter * docs: rewrite/cleanup docs * ci: fix build * feat(config): extend processEnv types
1 parent 358011e commit 6a8b68e

File tree

15 files changed

+928
-319
lines changed

15 files changed

+928
-319
lines changed

.github/CONTRIBUTING.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,47 @@ This library uses following libraries for development:
1515
- [yarn](https://yarnpkg.com/lang/en/) for package management
1616
- [npm scripts](https://docs.npmjs.com/misc/scripts) for executing tasks
1717

18+
### 🧪 Tests
19+
20+
Test are written and run via Jest 💪
21+
22+
```sh
23+
# Run whole test suite once
24+
yarn test
25+
# Run test in watch mode
26+
yarn test:watch
27+
# Ged code coverage
28+
yarn test:coverage
29+
```
30+
31+
### 💅 Style guides
32+
33+
Style guides are enforced by robots _(I meant prettier and tslint of course 🤖 )_, so they'll let you know if you screwed something, but most of the time, they'll autofix things for you. Magic right ?
34+
35+
Lint and format codebase via npm-script:
36+
37+
```sh
38+
#Format and fix lint errors
39+
yarn ts:style:fix
40+
```
41+
42+
#### Commit conventions (via commitizen)
43+
44+
- this is preferred way how to create conventional-changelog valid commits
45+
- if you prefer your custom tool we provide a commit hook linter which will error out, it you provide invalid commit message
46+
- 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 )
47+
48+
```sh
49+
# invoke [commitizen CLI](https://github.com/commitizen/cz-cli)
50+
yarn commit
51+
```
52+
53+
### 📖 Documentation
54+
55+
```sh
56+
yarn docs
57+
```
58+
1859
## Getting started
1960

2061
### Creating a Pull Request
@@ -33,9 +74,63 @@ If you've never submitted a Pull request before please visit http://makeapullreq
3374
1. If there is a `*.spec.ts` file, update it to include a test for your change, if needed. If this file doesn't exist, please create it.
3475
1. Run `yarn test` or `yarn test:watch` to make sure all tests are working, regardless if a test was added.
3576

36-
### Commit Message Format
77+
---
78+
79+
## 🚀 Publishing
80+
81+
> releases are handled by awesome [standard-version](https://github.com/conventional-changelog/standard-version)
82+
83+
> #### NOTE:
84+
>
85+
> you have to create npm account and register token on your machine
86+
> 👉 `npm adduser`
87+
>
88+
> If you are using scope (you definitely should 👌) don't forget to [`--scope`](https://docs.npmjs.com/cli/adduser#scope)
89+
90+
Execute `yarn release` which will handle following tasks:
91+
92+
- bump package version and git tag
93+
- update/(create if it doesn't exist) CHANGELOG.md
94+
- push to github master branch + push tags
95+
- publish build packages to npm
96+
97+
> releases are handled by awesome [standard-version](https://github.com/conventional-changelog/standard-version)
98+
99+
### Initial Release (no package.json version bump):
100+
101+
```sh
102+
yarn release --first-release
103+
```
104+
105+
### Pre-release
106+
107+
- To get from `1.1.2` to `1.1.2-0`:
108+
109+
`yarn release --prerelease`
110+
111+
- **Alpha**: To get from `1.1.2` to `1.1.2-alpha.0`:
112+
113+
`yarn release --prerelease alpha`
114+
115+
- **Beta**: To get from `1.1.2` to `1.1.2-beta.0`:
116+
117+
`yarn release --prerelease beta`
118+
119+
### Dry run
120+
121+
#### version bump + changelog
122+
123+
```sh
124+
# See what next release version would be with updated changelog
125+
yarn standard-version --dry-run
126+
```
127+
128+
#### npm publish
37129

38-
We use https://conventionalcommits.org/ message format. you can use `yarn commit` to invoke a CLI tool which will guide you through the process.
130+
```sh
131+
# check what files are gonna be published to npm
132+
yarn release:preflight
133+
```
39134

40135
## License
41136

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
node_modules
12
dist

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"singleQuote": true,
3+
"arrowParens": "always",
4+
"semi": false,
5+
"bracketSpacing": true,
6+
"trailingComma": "es5",
7+
"printWidth": 80
8+
}

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ node_js: '8'
33
cache: yarn
44
notifications:
55
email: false
6+
env:
7+
- CI=true
68
before_install:
7-
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.12.3
8-
- export PATH="$HOME/.yarn/bin:$PATH"
9+
- npm config set scripts-prepend-node-path true
10+
- npm i -g yarn
911
install:
10-
- yarn --ignore-scripts
12+
- yarn
1113
script:
1214
- yarn build

.vscode/settings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
"editor.rulers": [
1212
80,100
1313
],
14-
// This needs to be here as prettier plugin has problems with consumning prettier config outside of root
15-
"prettier.arrowParens": "always"
1614
}

README.md

Lines changed: 19 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Typescript lib starter
1+
<p align="center">
2+
<img src="https://user-images.githubusercontent.com/1223799/50992071-73562500-1516-11e9-99fa-9f73b0f0eee2.png" width="597" alt="{library-name}">
3+
</p>
4+
5+
# TypeScript lib starter
26

37
[![Greenkeeper badge](https://badges.greenkeeper.io/Hotell/typescript-lib-starter.svg)](https://greenkeeper.io/)
48

@@ -9,7 +13,7 @@
913
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
1014
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
1115

12-
This npm library starter:
16+
## ✨ Features
1317

1418
- creates package for both Node and Browser
1519
- build will creates 4 standard "package" formats:
@@ -26,7 +30,7 @@ This npm library starter:
2630
- > `types` field in package.json
2731
- `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!
2832

29-
## Start coding in 2 steps !
33+
## ✌️ start coding in 2 steps
3034

3135
1. `git clone https://github.com/Hotell/typescript-lib-starter <your-libary-folder-name> && cd $_`
3236

@@ -36,7 +40,7 @@ This npm library starter:
3640

3741
Yes that's it. Happy coding ! 🖖
3842

39-
## Consumption of published library:
43+
## 💉 Consumption of published library:
4044

4145
1. install it 🤖
4246

@@ -85,7 +89,7 @@ render(App, mountPoint)
8589
</html>
8690
```
8791

88-
### UMD/ES2015 module aware browsers ( no bundler )
92+
### UMD/ES2015 module aware browsers (no bundler)
8993

9094
```html
9195
<html>
@@ -133,91 +137,29 @@ render(App, mountPoint)
133137
</html>
134138
```
135139

136-
## Publish your library
137-
138-
> #### NOTE:
139-
>
140-
> you have to create npm account and register token on your machine
141-
> 👉 `npm adduser`
142-
>
143-
> If you are using scope ( you definitely should 👌) don't forget to [`--scope`](https://docs.npmjs.com/cli/adduser#scope)
144-
145-
Execute `yarn release` which will handle following tasks:
146-
147-
- bump package version and git tag
148-
- update/(create if it doesn't exist) CHANGELOG.md
149-
- push to github master branch + push tags
150-
- publish build packages to npm
151-
152-
> **NOTE:**
153-
>
154-
> all package files are gonna be within `/dist` folder from where `npm publish` will be executed
155-
156-
> releases are handled by awesome [standard-version](https://github.com/conventional-changelog/standard-version)
157-
158-
### Initial Release (without bumping package.json version):
159-
160-
`yarn release --first-release`
161-
162-
### Pre-release
163-
164-
- To get from `1.1.2` to `1.1.2-0`:
165-
166-
`yarn release --prerelease`
167-
168-
- **Alpha**: To get from `1.1.2` to `1.1.2-alpha.0`:
169-
170-
`yarn release --prerelease alpha`
140+
## [👨‍🔧 Technical overview](./.github/CONTRIBUTING.md#technical-overview)
171141

172-
- **Beta**: To get from `1.1.2` to `1.1.2-beta.0`:
142+
### [💅 Style guides](./.github/CONTRIBUTING.md#style-guides)
173143

174-
`yarn release --prerelease beta`
144+
## [🚀 Publishing](./.github/CONTRIBUTING.md#publishing)
175145

176-
### Dry run mode
177-
178-
See what commands would be run, without committing to git or updating files
179-
180-
`yarn release --dry-run`
181-
182-
## Check what files are gonna be published to npm
183-
184-
- `cd dist && yarn pack` OR `yarn release:preflight` which will create a tarball with everything that would get published to NPM
185-
186-
## Check size of your published NPM bundle
187-
188-
`yarn size`
189-
190-
## Format and fix lint errors
191-
192-
`yarn ts:style:fix`
193-
194-
## Generate documentation
195-
196-
`yarn docs`
197-
198-
## Commit ( via commitizen )
199-
200-
- this is preferred way how to create conventional-changelog valid commits
201-
- if you prefer your custom tool we provide a commit hook linter which will error out, it you provide invalid commit message
202-
- 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 )
203-
204-
`yarn commit` - will invoke [commitizen CLI](https://github.com/commitizen/cz-cli)
205-
206-
### Troubleshooting
146+
## 🕵️‍♀️ Troubleshooting
207147

208148
#### dynamic `import()`
209149

210-
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)
150+
This starter uses latest **TypeScript >=3.x** 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)
211151

212152
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 ❤️ !
213153

214-
---
215-
216-
> ### Before TS 2.9
154+
> #### Before TS 2.9
217155
>
218156
> 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 )
219157
>
220158
> **How to solve this:**
221159
>
222160
> - turn of type checking and don't generate types for that lazy import: `import('./components/button') as any`
223161
> - or you can use this [temporary workaround](https://github.com/Microsoft/TypeScript/issues/16603#issuecomment-310208259)
162+
163+
## 🥂 License
164+
165+
[MIT](./LICENSE.md) as always

config/global.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// ============================
22
// extend existing types
33
// ============================
4+
declare namespace NodeJS {
5+
interface ProcessEnv {
6+
CI: 'true' | 'false'
7+
}
8+
}
49

510
// ============================
611
// Rollup plugins without types
@@ -97,3 +102,48 @@ declare module 'replace-in-file' {
97102
const api: API
98103
export = api
99104
}
105+
106+
declare module 'gzip-size' {
107+
type Options = import('zlib').ZlibOptions
108+
type Input = string | Buffer
109+
110+
function gzipSize(input: Input, options?: Options): Promise<number>
111+
namespace gzipSize {
112+
function sync(input: Input, options?: Options): number
113+
function stream(options?: Options): import('stream').PassThrough
114+
function file(path: string, options?: Options): Promise<number>
115+
function fileSync(path: string, options?: Options): number
116+
}
117+
118+
export = gzipSize
119+
}
120+
121+
declare module 'brotli-size' {
122+
type Input = string | Buffer
123+
124+
namespace brotliSize {
125+
function sync(input: Input): number
126+
function stream(): import('stream').PassThrough
127+
}
128+
129+
function brotliSize(input: Input): Promise<number>
130+
131+
export = brotliSize
132+
}
133+
134+
declare module 'pretty-bytes' {
135+
type Options = {
136+
/**
137+
* @default false
138+
*/
139+
signed: boolean
140+
/**
141+
* @default false
142+
*/
143+
locale: string | boolean
144+
}
145+
146+
function prettyBytes(input: number, options?: Partial<Options>): string
147+
148+
export = prettyBytes
149+
}

config/prettier.config.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)