You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+92Lines changed: 92 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,98 @@ This is not just a simple school project that will be left out once the semester
64
64
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.
65
65
66
66
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)
0 commit comments