feat(typescript): build typescript incrementally
This commit is contained in:
11
.gitignore
vendored
11
.gitignore
vendored
@@ -1,11 +1,10 @@
|
||||
node_modules
|
||||
.cache
|
||||
.idea/*
|
||||
.nyc_output
|
||||
build
|
||||
node_modules
|
||||
test
|
||||
src/**.js
|
||||
.idea/*
|
||||
|
||||
coverage
|
||||
.nyc_output
|
||||
*.log
|
||||
|
||||
yarn.lock
|
||||
yarn.lock
|
||||
|
||||
38
README.md
38
README.md
@@ -15,7 +15,7 @@
|
||||
|
||||
Run one simple command to install and use the interactive project generator. You'll need [Node](https://nodejs.org/) `v10` or later.
|
||||
|
||||
```bash
|
||||
```sh
|
||||
npx typescript-starter
|
||||
```
|
||||
|
||||
@@ -56,15 +56,21 @@ Also consider installing editor extensions for [ESLint](https://github.com/Micro
|
||||
|
||||
## Development zen
|
||||
|
||||
To start working, run the `watch` task using [`npm`](https://docs.npmjs.com/getting-started/what-is-npm) or [`yarn`](https://yarnpkg.com/).
|
||||
To start working, run the `watch:build` task using [`npm`](https://docs.npmjs.com/getting-started/what-is-npm) or [`yarn`](https://yarnpkg.com/).
|
||||
|
||||
```bash
|
||||
npm run watch
|
||||
```sh
|
||||
npm run watch:build
|
||||
```
|
||||
|
||||
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.
|
||||
In another terminal tab/window, run the `watch:test` task:
|
||||
|
||||
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.
|
||||
```sh
|
||||
npm run watch:test
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
<p align="center">
|
||||
<!-- PR request: capture the magic of using a test-running watch task for development -->
|
||||
@@ -83,7 +89,7 @@ To enable additional Typescript type checking features (a good idea for mission-
|
||||
|
||||
To automatically fix `eslint` and `prettier` formatting issues, run:
|
||||
|
||||
```
|
||||
```sh
|
||||
npm run fix
|
||||
```
|
||||
|
||||
@@ -91,7 +97,7 @@ npm run fix
|
||||
|
||||
To generate and view test coverage, run:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
npm run cov
|
||||
```
|
||||
|
||||
@@ -105,7 +111,7 @@ This will create an HTML report of test coverage – source-mapped back to Types
|
||||
|
||||
The src folder is analyzed and documentation is automatically generated using [TypeDoc](https://github.com/TypeStrong/typedoc).
|
||||
|
||||
```bash
|
||||
```sh
|
||||
npm run doc
|
||||
```
|
||||
|
||||
@@ -115,7 +121,7 @@ Since types are tracked by Typescript, there's no need to indicate types in JSDo
|
||||
|
||||
To generate and publish your documentation to [GitHub Pages](https://pages.github.com/) use the following command:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
npm run doc:publish
|
||||
```
|
||||
|
||||
@@ -127,7 +133,7 @@ Once published, your documentation should be available at the proper GitHub Page
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
npm run doc:json
|
||||
```
|
||||
|
||||
@@ -135,7 +141,7 @@ npm run doc:json
|
||||
|
||||
It's recommended that you install [`commitizen`](https://github.com/commitizen/cz-cli) to make commits to your project.
|
||||
|
||||
```bash
|
||||
```sh
|
||||
npm install -g commitizen
|
||||
|
||||
# commit your changes:
|
||||
@@ -144,7 +150,7 @@ git cz
|
||||
|
||||
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.
|
||||
|
||||
```bash
|
||||
```sh
|
||||
# bump package.json version, update CHANGELOG.md, git tag the release
|
||||
npm run version
|
||||
```
|
||||
@@ -155,7 +161,7 @@ You may find a tool like [**`wip`**](https://github.com/bitjson/wip) helpful for
|
||||
|
||||
Bringing together many of the steps above, this repo includes a one-step release preparation command.
|
||||
|
||||
```bash
|
||||
```sh
|
||||
# Prepare a standard release:
|
||||
npm run prepare-release
|
||||
```
|
||||
@@ -170,7 +176,7 @@ This command runs the following tasks:
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
git push --follow-tags origin master; npm publish
|
||||
```
|
||||
|
||||
@@ -178,7 +184,7 @@ Look over the release if you'd like, then execute the command to publish everyth
|
||||
|
||||
You can also prepare a non-standard release:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
# Or a non-standard release:
|
||||
|
||||
# Reset the repo to the latest commit and build everything
|
||||
|
||||
12
package.json
12
package.json
@@ -29,18 +29,19 @@
|
||||
"appveyor"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "run-s clean && run-p build:*",
|
||||
"build": "run-p build:*",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
"build:module": "tsc -p tsconfig.module.json",
|
||||
"fix": "run-s fix:*",
|
||||
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
||||
"fix:lint": "eslint . --ext .ts --fix",
|
||||
"test": "run-s build test:*",
|
||||
"test:lint": "eslint . --ext .ts",
|
||||
"test:lint": "eslint src --ext .ts",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
||||
"test:unit": "nyc --silent ava",
|
||||
"watch": "run-s clean build:main && run-p \"build:main -- -w\" \"test:unit -- --watch\"",
|
||||
"watch:build": "tsc -p tsconfig.json -w",
|
||||
"watch:test": "nyc --silent ava --watch",
|
||||
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
|
||||
"cov:html": "nyc report --reporter=html",
|
||||
"cov:lcov": "nyc report --reporter=lcov",
|
||||
@@ -52,7 +53,6 @@
|
||||
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
|
||||
"version": "standard-version",
|
||||
"reset-hard": "git clean -dfx && git reset --hard && npm i",
|
||||
"clean": "trash build test",
|
||||
"prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish"
|
||||
},
|
||||
"engines": {
|
||||
@@ -126,7 +126,11 @@
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"!test",
|
||||
"!build/module/**"
|
||||
],
|
||||
"ignoredByWatcher": [
|
||||
"test"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* `diff build/test-one/package.json build/test-two/package.json`
|
||||
*/
|
||||
|
||||
import { existsSync, mkdirSync } from 'fs';
|
||||
import { join, relative } from 'path';
|
||||
|
||||
import test, { ExecutionContext } from 'ava';
|
||||
@@ -45,7 +46,11 @@ const repoInfo = {
|
||||
branch: branch === 'HEAD' ? '.' : branch,
|
||||
repo: process.cwd(),
|
||||
};
|
||||
const buildDir = join(process.cwd(), 'build');
|
||||
const testDir = join(process.cwd(), 'test');
|
||||
if (existsSync(testDir)) {
|
||||
del.sync(testDir);
|
||||
}
|
||||
mkdirSync(testDir);
|
||||
const env = {
|
||||
TYPESCRIPT_STARTER_REPO_BRANCH: repoInfo.branch,
|
||||
TYPESCRIPT_STARTER_REPO_URL: repoInfo.repo,
|
||||
@@ -60,18 +65,6 @@ enum TestDirectories {
|
||||
six = 'test-6',
|
||||
}
|
||||
|
||||
// If the tests all pass, the TestDirectories will automatically be cleaned up.
|
||||
test.after(async () => {
|
||||
await del([
|
||||
`./build/${TestDirectories.one}`,
|
||||
`./build/${TestDirectories.two}`,
|
||||
`./build/${TestDirectories.three}`,
|
||||
`./build/${TestDirectories.four}`,
|
||||
`./build/${TestDirectories.five}`,
|
||||
`./build/${TestDirectories.six}`,
|
||||
]);
|
||||
});
|
||||
|
||||
test('returns version', async (t) => {
|
||||
const expected = meow('').pkg.version;
|
||||
t.truthy(typeof expected === 'string');
|
||||
@@ -103,7 +96,7 @@ async function hashAllTheThings(
|
||||
projectName: string,
|
||||
sandboxed = false
|
||||
): Promise<{ readonly [filename: string]: string }> {
|
||||
const projectDir = normalizePath(join(buildDir, projectName));
|
||||
const projectDir = normalizePath(join(testDir, projectName));
|
||||
const rawFilePaths: ReadonlyArray<string> = await globby(
|
||||
[projectDir, `!${projectDir}/.git`],
|
||||
{
|
||||
@@ -122,7 +115,7 @@ async function hashAllTheThings(
|
||||
return hashes.reduce<{ readonly [filename: string]: string }>(
|
||||
(acc, hash, i) => {
|
||||
const trimmedNormalizedFilePath = normalizePath(
|
||||
relative(buildDir, filePaths[i])
|
||||
relative(testDir, filePaths[i])
|
||||
);
|
||||
return {
|
||||
...acc,
|
||||
@@ -157,7 +150,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
|
||||
'--no-install',
|
||||
],
|
||||
{
|
||||
cwd: buildDir,
|
||||
cwd: testDir,
|
||||
env,
|
||||
}
|
||||
);
|
||||
@@ -172,7 +165,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
|
||||
'test-1/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
|
||||
'test-1/.github/PULL_REQUEST_TEMPLATE.md':
|
||||
'70f4b97f3914e2f399bcc5868e072c29',
|
||||
'test-1/.gitignore': '892227b7f662b74410e9bf6fb2ae887f',
|
||||
'test-1/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
|
||||
'test-1/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
|
||||
'test-1/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
|
||||
'test-1/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
|
||||
@@ -182,7 +175,7 @@ test(`${TestDirectories.one}: parses CLI arguments, handles default options`, as
|
||||
'test-1/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
|
||||
'test-1/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
|
||||
'test-1/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
|
||||
'test-1/tsconfig.json': '0e04adfce2f26c6473f079f6dabd108a',
|
||||
'test-1/tsconfig.json': '741e6fa9f78712a6f276ba33fc2c798b',
|
||||
'test-1/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
|
||||
});
|
||||
});
|
||||
@@ -202,7 +195,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
|
||||
'--no-install',
|
||||
],
|
||||
{
|
||||
cwd: buildDir,
|
||||
cwd: testDir,
|
||||
env,
|
||||
}
|
||||
);
|
||||
@@ -217,7 +210,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
|
||||
'test-2/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
|
||||
'test-2/.github/PULL_REQUEST_TEMPLATE.md':
|
||||
'70f4b97f3914e2f399bcc5868e072c29',
|
||||
'test-2/.gitignore': 'af817565c661f1b15514584c8ea9e469',
|
||||
'test-2/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
|
||||
'test-2/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
|
||||
'test-2/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
|
||||
'test-2/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
|
||||
@@ -231,7 +224,7 @@ test(`${TestDirectories.two}: parses CLI arguments, handles all options`, async
|
||||
'test-2/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
|
||||
'test-2/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
|
||||
'test-2/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
|
||||
'test-2/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4',
|
||||
'test-2/tsconfig.json': 'eadf0f5640c5000ceabf242d157861e4',
|
||||
'test-2/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
|
||||
});
|
||||
});
|
||||
@@ -248,7 +241,7 @@ async function testInteractive(
|
||||
): Promise<execa.ExecaReturnValue<string>> {
|
||||
const typeDefs = entry[3] !== '';
|
||||
const proc = execa(`../bin/typescript-starter`, ['--no-install'], {
|
||||
cwd: buildDir,
|
||||
cwd: testDir,
|
||||
env,
|
||||
});
|
||||
|
||||
@@ -302,7 +295,7 @@ test(`${TestDirectories.three}: interactive mode: javascript library`, async (t)
|
||||
'test-3/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
|
||||
'test-3/.github/PULL_REQUEST_TEMPLATE.md':
|
||||
'70f4b97f3914e2f399bcc5868e072c29',
|
||||
'test-3/.gitignore': 'af817565c661f1b15514584c8ea9e469',
|
||||
'test-3/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
|
||||
'test-3/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
|
||||
'test-3/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
|
||||
'test-3/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
|
||||
@@ -316,7 +309,7 @@ test(`${TestDirectories.three}: interactive mode: javascript library`, async (t)
|
||||
'test-3/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
|
||||
'test-3/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
|
||||
'test-3/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
|
||||
'test-3/tsconfig.json': '43817952d399db9e44977b3703edd7cf',
|
||||
'test-3/tsconfig.json': '25e6e53cdc0b9194c5ba862b275afc37',
|
||||
'test-3/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
|
||||
});
|
||||
});
|
||||
@@ -340,7 +333,7 @@ test(`${TestDirectories.four}: interactive mode: node.js application`, async (t)
|
||||
'test-4/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
|
||||
'test-4/.github/PULL_REQUEST_TEMPLATE.md':
|
||||
'70f4b97f3914e2f399bcc5868e072c29',
|
||||
'test-4/.gitignore': '892227b7f662b74410e9bf6fb2ae887f',
|
||||
'test-4/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
|
||||
'test-4/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
|
||||
'test-4/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
|
||||
'test-4/.vscode/launch.json': '140e17d591e03b8850c456ade3aefb1f',
|
||||
@@ -354,7 +347,7 @@ test(`${TestDirectories.four}: interactive mode: node.js application`, async (t)
|
||||
'test-4/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
|
||||
'test-4/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
|
||||
'test-4/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
|
||||
'test-4/tsconfig.json': 'e41d08f0aca16cb05430b61e4b6286db',
|
||||
'test-4/tsconfig.json': '0256ae9ca8952a1125c461392b69ce06',
|
||||
'test-4/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
|
||||
});
|
||||
});
|
||||
@@ -379,7 +372,7 @@ const sandboxOptions = {
|
||||
description: 'this is an example description',
|
||||
githubUsername: 'SOME_GITHUB_USERNAME',
|
||||
repoInfo,
|
||||
workingDirectory: buildDir,
|
||||
workingDirectory: testDir,
|
||||
};
|
||||
|
||||
const silenceConsole = (console: Console) => {
|
||||
@@ -420,7 +413,7 @@ test(`${TestDirectories.five}: Sandboxed: npm install, initial commit`, async (t
|
||||
'test-5/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
|
||||
'test-5/.github/PULL_REQUEST_TEMPLATE.md':
|
||||
'70f4b97f3914e2f399bcc5868e072c29',
|
||||
'test-5/.gitignore': '892227b7f662b74410e9bf6fb2ae887f',
|
||||
'test-5/.gitignore': '96abf7aadc9155ba2a5bba1e05563ff0',
|
||||
'test-5/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
|
||||
'test-5/LICENSE': '317693126d229a3cdd19725a624a56fc',
|
||||
'test-5/README.md': '8fc7ecb21d7d47289e4b2469eea4db39',
|
||||
@@ -428,7 +421,7 @@ test(`${TestDirectories.five}: Sandboxed: npm install, initial commit`, async (t
|
||||
'test-5/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
|
||||
'test-5/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
|
||||
'test-5/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
|
||||
'test-5/tsconfig.json': 'f36dc6407fc898f41a23cb620b2f4884',
|
||||
'test-5/tsconfig.json': '24a7b8aff2651d9a1920e33459d8c346',
|
||||
'test-5/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
|
||||
});
|
||||
});
|
||||
@@ -464,7 +457,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async (t) =>
|
||||
'test-6/.github/ISSUE_TEMPLATE.md': 'e70a0b70402765682b1a961af855040e',
|
||||
'test-6/.github/PULL_REQUEST_TEMPLATE.md':
|
||||
'70f4b97f3914e2f399bcc5868e072c29',
|
||||
'test-6/.gitignore': 'af817565c661f1b15514584c8ea9e469',
|
||||
'test-6/.gitignore': '2b90e204ba76e30ec95f946ac7c9787e',
|
||||
'test-6/.prettierignore': '1da1ce4fdb868f0939608fafd38f9683',
|
||||
'test-6/.travis.yml': '91976af7b86cffb6960db8c35b27b7d0',
|
||||
'test-6/.vscode/extensions.json': '2d26a716ba181656faac4cd2d38ec139',
|
||||
@@ -481,7 +474,7 @@ test(`${TestDirectories.six}: Sandboxed: yarn, no initial commit`, async (t) =>
|
||||
'test-6/src/lib/number.spec.ts': '0592001d71aa3b3e6bf72f4cd95dc1b9',
|
||||
'test-6/src/lib/number.ts': 'dcbcc98fea337d07e81728c1a6526a1e',
|
||||
'test-6/src/types/example.d.ts': '76642861732b16754b0110fb1de49823',
|
||||
'test-6/tsconfig.json': '8a55379f60e4e6d4fad1f0b2318b74c4',
|
||||
'test-6/tsconfig.json': 'eadf0f5640c5000ceabf242d157861e4',
|
||||
'test-6/tsconfig.module.json': '2fda4c8760c6cfa3462b40df0645850d',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"target": "es2017",
|
||||
"outDir": "build/main",
|
||||
"rootDir": "src",
|
||||
|
||||
Reference in New Issue
Block a user