UNPKG

5.15 kBMarkdownView Raw
1<h1 align="center">
2 ts-deps
3 <p align="center" style="font-size: 0.5em">
4 <a href="https://www.npmjs.com/package/ts-deps">
5 <img src="https://img.shields.io/npm/v/ts-deps.svg" >
6 </a>
7 <a href="https://travis-ci.com/zaripych/ts-deps">
8 <img src="https://travis-ci.com/zaripych/ts-deps.svg?branch=master" alt="Travis Build Status">
9 </a>
10 <a href="https://codecov.io/gh/zaripych/ts-deps">
11 <img src="https://codecov.io/gh/zaripych/ts-deps/branch/master/graph/badge.svg" />
12 </a>
13 <a href="https://greenkeeper.io/">
14 <img src="https://badges.greenkeeper.io/zaripych/ts-deps.svg" />
15 </a>
16 </p>
17 <p align="center">dev dependency for your simple TypeScript projects</p>
18</h1>
19
20### Installation
21
22```
23npm add ts-deps --save-dev
24npx ts-deps init
25```
26
27The `init` command will scaffold config files for your project. The typical output would be:
28
29```
30scripts/
31scripts/build.js
32scripts/clean.js
33scripts/combineCoverage.js
34src/
35src/__integration-tests__
36src/__tests__
37.eslintrc.js
38babel.config.js
39commitlint.config.js
40jest.config.integration.js
41jest.config.js
42package.json
43prettier.config.js
44release.config.js
45tsconfig.json
46tsconfig.declarations.json
47```
48
49Following packages already included for you:
50
51- babel - Babel 7 to build `.js` or `.ts` which brings more transformation options and speed
52- typescript - TypeScript used for type checking and declarations
53- jest - Jest uses same babel config as build pipeline
54- eslint
55- prettier https://prettier.io/
56- semantic-release https://github.com/semantic-release/semantic-release
57- husky
58- pretty-quick
59- commitlint https://conventional-changelog.github.io/commitlint
60
61The `init` command can be run on an existing project, it will change your `package.json` and remove superfluous dev dependencies.
62
63### Building your code
64
65All the source code should be located in `src` directory. Extensions for the code should be `.ts` or `.js`.
66You can add `// @ts-check` in the beginning of `.js` files to make TypeScript check those files as well.
67
68For a Web app, please consider using `create-react-app`, however, `.tsx` and `.jsx` extensions are still allowed, but not well-tested.
69
70```
71npm build
72```
73
74The code will be transformed by Babel and put into `lib` folder. In addition to that `.json` and `.d.ts` files are copied over as well.
75
76### Declarations
77
78If declarations are required, we can generate them by running:
79
80```
81npm run declarations
82```
83
84This will use `tsconfig.declarations.json` config to write declarations to the same `lib` folder as transformed `.js` or `.ts` files.
85
86### Checking your code
87
88To run all builds and compilation checks we can use the `check` command which is automatically executed by husky on push.
89
90```
91npm run check
92```
93
94The `build` and other commands listed below are included into `check`.
95
96So, to check your code for Type Script errors we can run:
97
98```
99npm run type-check
100```
101
102Linting:
103
104```
105npm run lint
106```
107
108### Aliases
109
110Current configuration supports aliases. Sometimes we need to be able to alias a path to a module in order to require it by that alias name like so:
111
112```
113import { db } from '@shared'
114```
115
116The above becomes possible with aliases. The setup of aliases is tedious and requires multiple configuration changes that span across Babel, TypeScript and Jest.
117
118With `ts-deps` it should be as simple as creating a `ts-deps.config.js` file at the root of your project and executing `ts-deps patch` to patch `tsconfig.json`:
119
120```
121module.exports = {
122 aliases: {
123 '@core-lib': './src/shared/core-lib',
124 '@feature-1': './src/shared/features/feature-1',
125 },
126}
127
128```
129
130In the above example, in order to reference files within `core-lib` directory we can just use:
131
132```
133import Module from '@core-lib'
134```
135
136That saves us from having to backward slash to that directory if we have a module in `feature-1` directory that requires it.
137
138### Testing
139
140The library supports two categories of tests: _unit-tests_ and _integration-tests_.
141
142Unit tests should be located within `__tests__` directory anywhere under `src` directory. Deep nesting is supported. Every test should have `.test.` suffix. This is to ensure that the tests can also have test-only related helper files that can be required by the test but not included into result of `build`.
143
144Integration tests should be located within `./src/__integration-tests__` at the root. Similarly, every test should have `.test.` suffix.
145
146Integration and unit tests can be ran separately. If integration tests generate any coverage information we can combine it with unit tests using `combine-coverage` script.
147
148```
149npm run test --coverage
150npm run integration --coverage
151npm run combine-coverage
152```
153
154### Release
155
156To use `semantic-release` for release process we could run:
157
158```
159npm run release
160```
161
162To setup follow the link at the top and follow the steps in documentation. With current config we only need to declare environment variables to make
163`semantic-release` push changes to GitHub Releases, git repo and npm.
164
165```
166export GH_TOKEN=
167export NPM_TOKEN=
168export GIT_AUTHOR_EMAIL=
169export GIT_AUTHOR_NAME=
170export GIT_COMMITTER_EMAIL=
171export GIT_COMMITTER_NAME
172```
173
174### Happy coding!