Skip to content

Commit 4b22ba1

Browse files
committed
feat(typescript): build typescript incrementally
1 parent 3d67001 commit 4b22ba1

File tree

5 files changed

+60
-57
lines changed

5 files changed

+60
-57
lines changed

.gitignore

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
node_modules
1+
.cache
2+
.idea/*
3+
.nyc_output
24
build
5+
node_modules
36
test
47
src/**.js
5-
.idea/*
6-
78
coverage
8-
.nyc_output
99
*.log
10-
11-
yarn.lock
10+
yarn.lock

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
Run one simple command to install and use the interactive project generator. You'll need [Node](https://nodejs.org/) `v10` or later.
1717

18-
```bash
18+
```sh
1919
npx typescript-starter
2020
```
2121

@@ -56,15 +56,21 @@ Also consider installing editor extensions for [ESLint](https://github.com/Micro
5656

5757
## Development zen
5858

59-
To start working, run the `watch` task using [`npm`](https://docs.npmjs.com/getting-started/what-is-npm) or [`yarn`](https://yarnpkg.com/).
59+
To start working, run the `watch:build` task using [`npm`](https://docs.npmjs.com/getting-started/what-is-npm) or [`yarn`](https://yarnpkg.com/).
6060

61-
```bash
62-
npm run watch
61+
```sh
62+
npm run watch:build
6363
```
6464

65-
This starter includes a watch task which makes development faster and more interactive. It's particularly helpful for [TDD](https://en.wikipedia.org/wiki/Test-driven_development)/[BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) workflows.
65+
In another terminal tab/window, run the `watch:test` task:
6666

67-
The watch task will build and watch the entire project for changes (to both the library source files and test source files). As you develop, you can add tests for new functionality – which will initially fail – before developing the new functionality. Each time you save, any changes will be rebuilt and retested.
67+
```sh
68+
npm run watch:test
69+
```
70+
71+
These watch tasks make development much faster and more interactive. They're particularly helpful for [TDD](https://en.wikipedia.org/wiki/Test-driven_development)/[BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) workflows.
72+
73+
These watch tasks will build and watch the entire project for changes (to both the library source files and test source files). As you develop, you can add tests for new functionality – which will initially fail – before developing the new functionality. Each time you save, any changes will be rebuilt and retested.
6874

6975
<p align="center">
7076
<!-- PR request: capture the magic of using a test-running watch task for development -->
@@ -83,15 +89,15 @@ To enable additional Typescript type checking features (a good idea for mission-
8389

8490
To automatically fix `eslint` and `prettier` formatting issues, run:
8591

86-
```
92+
```sh
8793
npm run fix
8894
```
8995

9096
## View test coverage
9197

9298
To generate and view test coverage, run:
9399

94-
```bash
100+
```sh
95101
npm run cov
96102
```
97103

@@ -105,7 +111,7 @@ This will create an HTML report of test coverage – source-mapped back to Types
105111

106112
The src folder is analyzed and documentation is automatically generated using [TypeDoc](https://github.com/TypeStrong/typedoc).
107113

108-
```bash
114+
```sh
109115
npm run doc
110116
```
111117

@@ -115,7 +121,7 @@ Since types are tracked by Typescript, there's no need to indicate types in JSDo
115121

116122
To generate and publish your documentation to [GitHub Pages](https://pages.github.com/) use the following command:
117123

118-
```bash
124+
```sh
119125
npm run doc:publish
120126
```
121127

@@ -127,15 +133,15 @@ Once published, your documentation should be available at the proper GitHub Page
127133

128134
For more advanced documentation generation, you can provide your own [TypeDoc theme](http://typedoc.org/guides/themes/), or [build your own documentation](https://blog.cloudflare.com/generating-documentation-for-typescript-projects/) using the JSON TypeDoc export:
129135

130-
```bash
136+
```sh
131137
npm run doc:json
132138
```
133139

134140
## Bump version, update changelog, commit, & tag release
135141

136142
It's recommended that you install [`commitizen`](https://github.com/commitizen/cz-cli) to make commits to your project.
137143

138-
```bash
144+
```sh
139145
npm install -g commitizen
140146

141147
# commit your changes:
@@ -144,7 +150,7 @@ git cz
144150

145151
This project is tooled for [conventional changelog](https://github.com/conventional-changelog/conventional-changelog) to make managing releases easier. See the [standard-version](https://github.com/conventional-changelog/standard-version) documentation for more information on the workflow, or [`CHANGELOG.md`](CHANGELOG.md) for an example.
146152

147-
```bash
153+
```sh
148154
# bump package.json version, update CHANGELOG.md, git tag the release
149155
npm run version
150156
```
@@ -155,7 +161,7 @@ You may find a tool like [**`wip`**](https://github.com/bitjson/wip) helpful for
155161

156162
Bringing together many of the steps above, this repo includes a one-step release preparation command.
157163

158-
```bash
164+
```sh
159165
# Prepare a standard release:
160166
npm run prepare-release
161167
```
@@ -170,15 +176,15 @@ This command runs the following tasks:
170176

171177
When the script finishes, it will log the final command needed to push the release commit to the repo and publish the package on the `npm` registry:
172178

173-
```bash
179+
```sh
174180
git push --follow-tags origin master; npm publish
175181
```
176182

177183
Look over the release if you'd like, then execute the command to publish everything.
178184

179185
You can also prepare a non-standard release:
180186

181-
```bash
187+
```sh
182188
# Or a non-standard release:
183189

184190
# Reset the repo to the latest commit and build everything

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@
2929
"appveyor"
3030
],
3131
"scripts": {
32-
"build": "run-s clean && run-p build:*",
32+
"build": "run-p build:*",
3333
"build:main": "tsc -p tsconfig.json",
3434
"build:module": "tsc -p tsconfig.module.json",
3535
"fix": "run-s fix:*",
3636
"fix:prettier": "prettier \"src/**/*.ts\" --write",
3737
"fix:lint": "eslint . --ext .ts --fix",
3838
"test": "run-s build test:*",
39-
"test:lint": "eslint . --ext .ts",
39+
"test:lint": "eslint src --ext .ts",
4040
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
4141
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
4242
"test:unit": "nyc --silent ava",
43-
"watch": "run-s clean build:main && run-p \"build:main -- -w\" \"test:unit -- --watch\"",
43+
"watch:build": "tsc -p tsconfig.json -w",
44+
"watch:test": "nyc --silent ava --watch",
4445
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
4546
"cov:html": "nyc report --reporter=html",
4647
"cov:lcov": "nyc report --reporter=lcov",
@@ -52,7 +53,6 @@
5253
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
5354
"version": "standard-version",
5455
"reset-hard": "git clean -dfx && git reset --hard && npm i",
55-
"clean": "trash build test",
5656
"prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish"
5757
},
5858
"engines": {
@@ -126,7 +126,11 @@
126126
}
127127
},
128128
"files": [
129+
"!test",
129130
"!build/module/**"
131+
],
132+
"ignoredByWatcher": [
133+
"test"
130134
]
131135
},
132136
"config": {

src/cli/tests/cli.integration.spec.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* `diff build/test-one/package.json build/test-two/package.json`
1414
*/
1515

16+
import { existsSync, mkdirSync } from 'fs';
1617
import { join, relative } from 'path';
1718

1819
import test, { ExecutionContext } from 'ava';
@@ -45,7 +46,11 @@ const repoInfo = {
4546
branch: branch === 'HEAD' ? '.' : branch,
4647
repo: process.cwd(),
4748
};
48-
const buildDir = join(process.cwd(), 'build');
49+
const testDir = join(process.cwd(), 'test');
50+
if (existsSync(testDir)) {
51+
del.sync(testDir);
52+
}
53+
mkdirSync(testDir);
4954
const env = {
5055
TYPESCRIPT_STARTER_REPO_BRANCH: repoInfo.branch,
5156
TYPESCRIPT_STARTER_REPO_URL: repoInfo.repo,
@@ -60,18 +65,6 @@ enum TestDirectories {
6065
six = 'test-6',
6166
}
6267

63-
// If the tests all pass, the TestDirectories will automatically be cleaned up.
64-
test.after(async () => {
65-
await del([
66-
`./build/${TestDirectories.one}`,
67-
`./build/${TestDirectories.two}`,
68-
`./build/${TestDirectories.three}`,
69-
`./build/${TestDirectories.four}`,
70-
`./build/${TestDirectories.five}`,
71-
`./build/${TestDirectories.six}`,
72-
]);
73-
});
74-
7568
test('returns version', async (t) => {
7669
const expected = meow('').pkg.version;
7770
t.truthy(typeof expected === 'string');
@@ -103,7 +96,7 @@ async function hashAllTheThings(
10396
projectName: string,
10497
sandboxed = false
10598
): Promise<{ readonly [filename: string]: string }> {
106-
const projectDir = normalizePath(join(buildDir, projectName));
99+
const projectDir = normalizePath(join(testDir, projectName));
107100
const rawFilePaths: ReadonlyArray<string> = await globby(
108101
[projectDir, `!${projectDir}/.git`],
109102
{
@@ -122,7 +115,7 @@ async function hashAllTheThings(
122115
return hashes.reduce<{ readonly [filename: string]: string }>(
123116
(acc, hash, i) => {
124117
const trimmedNormalizedFilePath = normalizePath(
125-
relative(buildDir, filePaths[i])
118+
relative(testDir, filePaths[i])
126119
);
127120
return {
128121
...acc,
@@ -157,7 +150,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
157150
'--no-install',
158151
],
159152
{
160-
cwd: buildDir,
153+
cwd: testDir,
161154
env,
162155
}
163156
);
@@ -172,7 +165,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
172165
'test-1/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
173166
'test-1/.github/PULL_REQUEST_TEMPLATE.md':
174167
'70f4b97f3914e2f399bcc5868e072c29',
175-
'test-1/.gitignore': '892227b7f662b74410e9bf6fb2ae887f',
168+
'test-1/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
176169
'test-1/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
177170
'test-1/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
178171
'test-1/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -182,7 +175,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
182175
'test-1/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
183176
'test-1/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
184177
'test-1/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
185-
'test-1/tsconfig.json': '0e04adfce2f26c6473f079f6dabd108a',
178+
'test-1/tsconfig.json': '741e6fa9f78712a6f276ba33fc2c798b',
186179
'test-1/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
187180
});
188181
});
@@ -202,7 +195,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
202195
'--no-install',
203196
],
204197
{
205-
cwd: buildDir,
198+
cwd: testDir,
206199
env,
207200
}
208201
);
@@ -217,7 +210,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
217210
'test-2/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
218211
'test-2/.github/PULL_REQUEST_TEMPLATE.md':
219212
'70f4b97f3914e2f399bcc5868e072c29',
220-
'test-2/.gitignore': 'af817565c661f1b15514584c8ea9e469',
213+
'test-2/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
221214
'test-2/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
222215
'test-2/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
223216
'test-2/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -231,7 +224,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
231224
'test-2/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
232225
'test-2/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
233226
'test-2/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
234-
'test-2/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4',
227+
'test-2/tsconfig.json': 'eadf0f5640c5000ceabf242d157861e4',
235228
'test-2/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
236229
});
237230
});
@@ -248,7 +241,7 @@ async function testInteractive(
248241
): Promise<execa.ExecaReturnValue<string>> {
249242
const typeDefs = entry[3] !== '';
250243
const proc = execa(`../bin/typescript-starter`, ['--no-install'], {
251-
cwd: buildDir,
244+
cwd: testDir,
252245
env,
253246
});
254247

@@ -302,7 +295,7 @@ test(`${TestDirectories.three}: interactive mode: javascript library`, async (t)
302295
'test-3/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
303296
'test-3/.github/PULL_REQUEST_TEMPLATE.md':
304297
'70f4b97f3914e2f399bcc5868e072c29',
305-
'test-3/.gitignore': 'af817565c661f1b15514584c8ea9e469',
298+
'test-3/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
306299
'test-3/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
307300
'test-3/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
308301
'test-3/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -316,7 +309,7 @@ test(`${TestDirectories.three}: interactive mode: javascript library`, async (t)
316309
'test-3/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
317310
'test-3/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
318311
'test-3/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
319-
'test-3/tsconfig.json': '43817952d399db9e44977b3703edd7cf',
312+
'test-3/tsconfig.json': '25e6e53cdc0b9194c5ba862b275afc37',
320313
'test-3/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
321314
});
322315
});
@@ -340,7 +333,7 @@ test(`${TestDirectories.four}: interactive mode: node.js application`, async (t)
340333
'test-4/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
341334
'test-4/.github/PULL_REQUEST_TEMPLATE.md':
342335
'70f4b97f3914e2f399bcc5868e072c29',
343-
'test-4/.gitignore': '892227b7f662b74410e9bf6fb2ae887f',
336+
'test-4/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
344337
'test-4/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
345338
'test-4/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
346339
'test-4/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
@@ -354,7 +347,7 @@ test(`${TestDirectories.four}: interactive mode: node.js application`, async (t)
354347
'test-4/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
355348
'test-4/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
356349
'test-4/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
357-
'test-4/tsconfig.json': 'e41d08f0aca16cb05430b61e4b6286db',
350+
'test-4/tsconfig.json': '0256ae9ca8952a1125c461392b69ce06',
358351
'test-4/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
359352
});
360353
});
@@ -379,7 +372,7 @@ const sandboxOptions = {
379372
description: 'this is an example description',
380373
githubUsername: 'SOME_GITHUB_USERNAME',
381374
repoInfo,
382-
workingDirectory: buildDir,
375+
workingDirectory: testDir,
383376
};
384377

385378
const silenceConsole = (console: Console) => {
@@ -420,15 +413,15 @@ test(`${TestDirectories.five}: Sandboxed: npm install, initial commit`, async (t
420413
'test-5/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
421414
'test-5/.github/PULL_REQUEST_TEMPLATE.md':
422415
'70f4b97f3914e2f399bcc5868e072c29',
423-
'test-5/.gitignore': '892227b7f662b74410e9bf6fb2ae887f',
416+
'test-5/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
424417
'test-5/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
425418
'test-5/LICENSE': '317693126d229a3cdd19725a624a56fc',
426419
'test-5/README.md': '8fc7ecb21d7d47289e4b2469eea4db39',
427420
'test-5/src/index.ts': '5025093b4dc30524d349fd1cc465ed30',
428421
'test-5/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
429422
'test-5/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
430423
'test-5/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
431-
'test-5/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
424+
'test-5/tsconfig.json': '24a7b8aff2651d9a1920e33459d8c346',
432425
'test-5/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
433426
});
434427
});
@@ -464,7 +457,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async (t) =>
464457
'test-6/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
465458
'test-6/.github/PULL_REQUEST_TEMPLATE.md':
466459
'70f4b97f3914e2f399bcc5868e072c29',
467-
'test-6/.gitignore': 'af817565c661f1b15514584c8ea9e469',
460+
'test-6/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
468461
'test-6/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
469462
'test-6/.travis.yml': '91976af7b86cffb6960db8c35b27b7d0',
470463
'test-6/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
@@ -481,7 +474,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async (t) =>
481474
'test-6/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
482475
'test-6/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
483476
'test-6/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
484-
'test-6/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4',
477+
'test-6/tsconfig.json': 'eadf0f5640c5000ceabf242d157861e4',
485478
'test-6/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
486479
});
487480
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"incremental": true,
34
"target": "es2017",
45
"outDir": "build/main",
56
"rootDir": "src",

0 commit comments

Comments
 (0)