Skip to content

Commit 90d5ba1

Browse files
committed
README: add build and test instructions
1 parent cec9616 commit 90d5ba1

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,98 @@ This is not just a simple school project that will be left out once the semester
6464
Therefore, this is a project that has already benefited and will continue to benefit multiple parties. We are really glad to work on a project that has such a long-lasting impact during this semester. Hope you’ve enjoyed our presentation and thank you for listening.
6565

6666

67+
### Getting Started
68+
69+
```bash
70+
# Install dependencies
71+
yarn install
72+
73+
# Now you can run various yarn commands:
74+
yarn cli
75+
yarn lint
76+
yarn test
77+
yarn build-all
78+
yarn ts-node <filename>
79+
yarn esbuild-browser
80+
...
81+
```
82+
83+
* Take a look at all the scripts in package.json
84+
* For publishing to npm, use `yarn publish` (or `npm publish`)
85+
86+
### esbuild
87+
88+
[esbuild](https://esbuild.github.io/) is an extremely fast bundler that supports a [large part of the TypeScript syntax](https://esbuild.github.io/content-types/#typescript). This project uses it to bundle for browsers (and Node.js if you want).
89+
90+
```bash
91+
# Build for browsers
92+
yarn esbuild-browser:dev
93+
yarn esbuild-browser:watch
94+
95+
# Build the cli for node
96+
yarn esbuild-node:dev
97+
yarn esbuild-node:watch
98+
```
99+
100+
You can generate a full clean build with `yarn build-all` (which uses both `tsc` and `esbuild`).
101+
102+
* `package.json` includes `scripts` for various esbuild commands: [see here](https://github.com/metachris/typescript-boilerplate/blob/master/package.json#L23)
103+
* `esbuild` has a `--global-name=xyz` flag, to store the exports from the entry point in a global variable. See also the [esbuild "Global name" docs](https://esbuild.github.io/api/#global-name).
104+
* Read more about the esbuild setup [here](https://www.metachris.com/2021/04/starting-a-typescript-project-in-2021/#esbuild).
105+
* esbuild for the browser uses the IIFE (immediately-invoked function expression) format, which executes the bundled code on load (see also https://github.com/evanw/esbuild/issues/29)
106+
107+
108+
### Tests with Jest
109+
110+
You can write [Jest tests](https://jestjs.io/docs/getting-started) [like this](https://github.com/metachris/typescript-boilerplate/blob/master/src/main.test.ts):
111+
112+
```typescript
113+
import { greet } from './main'
114+
115+
test('the data is peanut butter', () => {
116+
expect(1).toBe(1)
117+
});
118+
119+
test('greeting', () => {
120+
expect(greet('Foo')).toBe('Hello Foo')
121+
});
122+
```
123+
124+
Run the tests with `yarn test`, no separate compile step is necessary.
125+
126+
* See also the [Jest documentation](https://jestjs.io/docs/getting-started).
127+
* The tests can be automatically run in CI (GitHub Actions, GitLab CI): [`.github/workflows/lint-and-test.yml`](https://github.com/metachris/typescript-boilerplate/blob/master/.github/workflows/lint-and-test.yml), [`.gitlab-ci.yml`](https://github.com/metachris/typescript-boilerplate/blob/master/.gitlab-ci.yml)
128+
* Take a look at other modern test runners such as [ava](https://github.com/avajs/ava), [uvu](https://github.com/lukeed/uvu) and [tape](https://github.com/substack/tape)
129+
130+
### Documentation, published with CI
131+
132+
You can auto-generate API documentation from the TypeScript source files using [TypeDoc](https://typedoc.org/guides/doccomments/). The generated documentation can be published to GitHub / GitLab pages through the CI.
133+
134+
Generate the documentation, using `src/main.ts` as entrypoint (configured in package.json):
135+
136+
```bash
137+
yarn docs
138+
```
139+
140+
The resulting HTML is saved in `docs/`.
141+
142+
You can publish the documentation through CI:
143+
* [GitHub pages](https://pages.github.com/): See [`.github/workflows/deploy-gh-pages.yml`](https://github.com/metachris/typescript-boilerplate/blob/master/.github/workflows/deploy-gh-pages.yml)
144+
* [GitLab pages](https://docs.gitlab.com/ee/user/project/pages/): [`.gitlab-ci.yml`](https://github.com/metachris/typescript-boilerplate/blob/master/.gitlab-ci.yml)
145+
146+
This is the documentation for this boilerplate project: https://metachris.github.io/typescript-boilerplate/
147+
148+
### References
149+
150+
* **[TypeScript Boilerplate](https://github.com/metachris/typescript-boilerplate)**
151+
* [Blog post: Starting a TypeScript Project in 2021](https://www.metachris.com/2021/03/bootstrapping-a-typescript-node.js-project/)
152+
* [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
153+
* [tsconfig docs](https://www.typescriptlang.org/tsconfig)
154+
* [esbuild docs](https://esbuild.github.io/)
155+
* [typescript-eslint docs](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md)
156+
* [Jest docs](https://jestjs.io/docs/getting-started)
157+
* [GitHub Actions](https://docs.github.com/en/actions), [GitLab CI](https://docs.gitlab.com/ee/ci/)
158+
67159

68160
## Authors
69161
- Han Guo <alexiland@outlook.com>

0 commit comments

Comments
 (0)