Skip to content

Commit 53be637

Browse files
authored
feat(scripts): implement init script (#143)
* feat(scripts): use init on postinstall * feat(scripts): add vscode settings prompt * ci: use latest yarn * ci: don't run postinstall on CI * chore: bump deps * refactor: use ambient fiels for local types * feat(templates): add templates and their setup * feat(config): add replace-in-file types * fix(scripts): fix init files modifications * fix(scripts): fix templates setup * feat(scripts): add additional prompt questions * fix(scripts): properly handle vscode setup * fix(scripts): initialize hooks properly * ci: fix yarn install * fix(scripts): resolve ts errors * feat(vscode): add more settings * fix(scripts): use githubName in readme template * docs: add setup video * feat: add index barrel tsd like header * refactor(scripts): reorder modifyFiles array BREAKING CHANGE: Now TS >= 3 is used which may break some packages that desperately need to support lower versions Closes #142 #145 #130
1 parent 2e16c3f commit 53be637

16 files changed

+2604
-1375
lines changed

Diff for: .github/CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ If you've never submitted a Pull request before please visit http://makeapullreq
2626
1. Fork the repo.
2727
1. `git clone` your fork.
2828
1. Make a `git checkout -b branch-name` branch for your change.
29-
1. Run `yarn install` (make sure you have node and npm installed first)
29+
1. Run `yarn install --ignore-scripts` (make sure you have node and yarn installed first)
3030
Updates
3131

32-
1. make sure to add unit tests
32+
1. Make sure to add unit tests
3333
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.
3434
1. Run `yarn test` or `yarn test:watch` to make sure all tests are working, regardless if a test was added.
3535

Diff for: .github/ISSUE_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Bug report
66

7-
- {library-name} version: _x.x.x_ (<!-- (run `npm list {library-name}` from a terminal/cmd prompt): -->)
7+
- {package-name} version: _x.x.x_ (<!-- (run `npm list {package-name}` from a terminal/cmd prompt): -->)
88
- Affected browsers (and versions): _IE 10_
99

1010
### Current behaviour

Diff for: .travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ node_js: '8'
33
cache: yarn
44
notifications:
55
email: false
6+
before_install:
7+
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.12.3
8+
- export PATH="$HOME/.yarn/bin:$PATH"
69
install:
7-
- yarn
10+
- yarn --ignore-scripts
811
script:
912
- yarn build

Diff for: .vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
"editor.formatOnSave": true,
66
"typescript.format.enable": false,
77
"javascript.format.enable": false,
8+
"typescript.implementationsCodeLens.enabled": true,
89
"typescript.referencesCodeLens.enabled": true,
910
"javascript.referencesCodeLens.enabled": true,
1011
"editor.rulers": [
1112
80,100
1213
],
14+
// This needs to be here as prettier plugin has problems with consumning prettier config outside of root
15+
"prettier.arrowParens": "always"
1316
}

Diff for: README.md

+4-28
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,15 @@ This npm library starter:
2626
- > `types` field in package.json
2727
- `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!
2828

29-
## Start coding in 4 steps !
29+
## Start coding in 2 steps !
3030

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

33-
2. `rm -rf .git && git init`
34-
35-
3. in `package.json` reset following fields:
36-
37-
```diff
38-
{
39-
- "name": "@next-gen/typescript-lib-starter",
40-
+ "name": "{yourLibraryPackageName}",
41-
- "version": "1.7.0",
42-
+ "version": "1.0.0",
43-
- "description": "TypeScript library setup for multiple compilation targets using tsc and webpack",
44-
+ "description": "What is your library all about...",
45-
- "keywords": [ "typescript", "library-starter", "rollup", "jest" ]
46-
+ "keywords": [ "typescript", "your library keyowrds" ]
47-
- "author": "Martin Hochel",
48-
+ "author": "{yourName}",
49-
- "license": "MIT",
50-
+ "license": "{yourLicense}",
51-
"repository": {
52-
"type": "git",
53-
- "url": "https://www.github.com/Hotell/typescript-lib-starter"
54-
+ "url": "https://www.github.com/{yourAccountName}/{yourLibraryPackageName}"
55-
}
56-
}
57-
```
33+
1. `yarn`
5834

59-
4. Install all dependencies `yarn install`
35+
![setting-up-your-library](https://user-images.githubusercontent.com/1223799/49905150-fd09c880-fe6c-11e8-9ad8-425c3a38b1b4.gif)
6036

61-
Happy coding ! 🖖
37+
Yes that's it. Happy coding ! 🖖
6238

6339
## Consumption of published library:
6440

Diff for: config/global.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,25 @@ declare module 'sort-object-keys' {
7373
) => T
7474
export = sortPackageJson
7575
}
76+
77+
declare module 'prompt'
78+
declare module 'replace-in-file' {
79+
interface Options {
80+
files: string | string[]
81+
from: Array<string | RegExp>
82+
to: string | string[]
83+
ignore: string | string[]
84+
dry: boolean
85+
encoding: string
86+
disableGlobs: boolean
87+
allowEmptyPaths: boolean
88+
}
89+
90+
interface API {
91+
(options: Partial<Options>): string[]
92+
sync(options: Partial<Options>): string[]
93+
}
94+
95+
const api: API
96+
export = api
97+
}

Diff for: config/types.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// ===== JEST ====
2+
export type TsJestConfig = import('ts-jest/dist/types').TsJestConfig
3+
export type JestConfig = Partial<jest.ProjectConfig & jest.GlobalConfig>
4+
5+
// ==== PRETTIER ====
6+
export type PrettierConfig = import('prettier').Options
7+
8+
// ==== ROLLUP ====
9+
export type RollupConfig = import('rollup').InputOptions & {
10+
output:
11+
| import('rollup').OutputOptions
12+
| Array<import('rollup').OutputOptions | null>
13+
}
14+
export type RollupPlugin = import('rollup').Plugin

Diff for: config/types.js

-30
This file was deleted.

Diff for: package.json

+14-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"node": ">=8.5"
2424
},
2525
"scripts": {
26+
"postinstall": "node scripts/init.js",
2627
"cleanup": "shx rm -rf dist",
2728
"prebuild": "npm run cleanup && npm run verify",
2829
"build": "tsc && tsc --target es2018 --outDir dist/esm2015 && rollup -c config/rollup.config.js && rollup -c config/rollup.config.js --environment NODE_ENV:production",
@@ -81,10 +82,11 @@
8182
"@commitlint/cli": "7.2.1",
8283
"@commitlint/config-conventional": "7.1.2",
8384
"@types/chokidar": "1.7.5",
84-
"@types/jest": "23.3.9",
85+
"@types/jest": "23.3.10",
8586
"@types/json5": "0.0.30",
86-
"@types/node": "10.12.10",
87-
"@types/prettier": "1.15.1",
87+
"@types/node": "8.10.*",
88+
"@types/prettier": "1.15.2",
89+
"@types/prompts": "1.1.1",
8890
"@types/webpack-config-utils": "2.3.0",
8991
"commitizen": "3.0.5",
9092
"cross-var": "1.1.0",
@@ -94,29 +96,33 @@
9496
"jest": "23.6.0",
9597
"jest-watch-typeahead": "0.2.0",
9698
"json5": "2.1.0",
99+
"kleur": "3.0.1",
97100
"lint-staged": "8.1.0",
98-
"prettier": "1.15.2",
99-
"rollup": "0.67.3",
101+
"prettier": "1.15.3",
102+
"prompts": "2.0.0",
103+
"replace-in-file": "3.4.2",
104+
"rollup": "0.67.4",
100105
"rollup-plugin-commonjs": "9.2.0",
101106
"rollup-plugin-json": "3.1.0",
102-
"rollup-plugin-node-resolve": "3.4.0",
107+
"rollup-plugin-node-resolve": "4.0.0",
103108
"rollup-plugin-replace": "2.1.0",
104109
"rollup-plugin-sourcemaps": "0.4.2",
105110
"rollup-plugin-terser": "3.0.0",
106111
"rollup-plugin-uglify": "6.0.0",
112+
"shelljs": "0.8.3",
107113
"shx": "0.3.2",
108114
"sort-object-keys": "1.1.2",
109115
"standard-version": "4.4.0",
110116
"strip-json-comments-cli": "1.0.1",
111117
"ts-jest": "23.10.5",
112118
"tslib": "1.9.3",
113119
"tslint": "5.11.0",
114-
"tslint-config-prettier": "1.16.0",
120+
"tslint-config-prettier": "1.17.0",
115121
"tslint-config-standard": "8.0.1",
116122
"tslint-etc": "1.2.7",
117123
"tslint-react": "3.6.0",
118124
"typedoc": "0.13.0",
119-
"typescript": "2.9.2",
125+
"typescript": "3.2.2",
120126
"webpack-config-utils": "2.3.1"
121127
}
122128
}

Diff for: scripts/copy.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* This file only purpose is to copy files before npm publish and strip churn/security sensitive metadata from package.json
3+
*
4+
* **NOTE:**
5+
* 👉 This file should not use any 3rd party dependency
6+
*/
17
const { writeFileSync, copyFileSync } = require('fs')
28
const { resolve } = require('path')
39
const packageJson = require('../package.json')

0 commit comments

Comments
 (0)