Skip to content

Commit 97f7337

Browse files
committed
Adds docs + scripts for deployment to TypeScript
1 parent 292e4a2 commit 97f7337

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

README.md

+30-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ This tool is used to generate the web-based `lib.dom.d.ts` file which is include
44

55
## Why is my fancy API still not available here?
66

7-
A feature needs to be supported by more than two major browser engines to be included here, to make sure there is a good consensus among vendors: __Gecko__ (Firefox), __Blink__ (Chrome/Edge), and __WebKit__ (Safari).
7+
A feature needs to be supported by two or more major browser engines to be included here, to make sure there is a good consensus among vendors: __Gecko__ (Firefox), __Blink__ (Chrome/Edge), and __WebKit__ (Safari).
88

9-
If the condition is met but still is not available here, please [file an issue](hthttps://github.com/microsoft/TypeScript-DOM-lib-generator/issues/new).
9+
If the condition is met but still is not available here, first check the heuristics below and then please [file an issue](hthttps://github.com/microsoft/TypeScript-DOM-lib-generator/issues/new).
1010

1111
## Build Instructions
1212

@@ -28,13 +28,13 @@ To test:
2828
npm run test
2929
```
3030

31-
To deploy:
3231

33-
```sh
34-
npm run migrate
35-
```
32+
## `@types/[lib]` to TypeScript Versions
3633

37-
The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in.
34+
| `@types/[lib]` version | TypeScript Version | Minimum TypeScript Support |
35+
| ---------------------------------------------------------------------- | ----------- | -------------- |
36+
| `@types/web` [0.0.1](https://www.npmjs.com/package/@types/web/v/0.0.1) | ~4.3 | 4.4 |
37+
| `@types/web` [0.0.2](https://www.npmjs.com/package/@types/web/v/0.0.2) | ~4.4 beta | 4.4 |
3838

3939
## Contribution Guidelines
4040

@@ -116,3 +116,26 @@ To give you a sense of whether we will accept changes, you can use these heurist
116116
- `removedTypes.json`: types that are defined in the spec file but should be removed.
117117
- `comments.json`: comment strings to be embedded in the generated .js files.
118118
- `deprecatedMessage.json`: the reason why one type is deprecated. The reason why it is a separate file rather than merge in comment.json is mdn/apiDescriptions.json would also possibly be deprecated.
119+
120+
## Deployment to TypeScript
121+
122+
To migrate the *.d.ts files into TypeScript:
123+
124+
1. Run:
125+
126+
```sh
127+
npm run migrate -- [previous_types_web_version]
128+
```
129+
130+
The script will look in for a clone of the TypeScript repo in "../TypeScript", or "./TypeScript" to move the generated files in. Or migrate the files manually, you do you.
131+
132+
1. Update the README table with the mappings for versions in the `@types/[lib]`. E.g. TS 4.5 -> `@types/web` `0.0.23`.
133+
134+
1. Generate a CHANGELOG for the releases:
135+
136+
```sh
137+
# lib from to
138+
npm run ts-changelog -- @types/web 0.0.2 0.0.23
139+
```
140+
141+
1. Add the CHANGELOG to the release issue

src/migrate.ts deploy/migrate.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (!tscWD)
1616

1717
const generatedFiles = readdirSync("generated");
1818
generatedFiles.forEach((file) => {
19+
if (file == ".DS_Store") return;
1920
const contents = readFileSync(join("generated", file), "utf8");
2021
const newFilePath = join(tscWD, "src", "lib", file);
2122
writeFileSync(newFilePath, contents);

deploy/versionChangelog.mjs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
3+
// npm run ts-changelog @types/web 0.0.1 0.0.3
4+
5+
import { generateChangelogFrom } from "../lib/changelog.js";
6+
import fetch from "node-fetch";
7+
8+
const [name, before, to] = process.argv.slice(2);
9+
if (!name || !before || !to) {
10+
throw new Error(
11+
"Expected three arguments: package name, version before, version to"
12+
);
13+
}
14+
15+
const go = async () => {
16+
const allFiles = `https://unpkg.com/${name}/?meta`;
17+
const npmFileReq = await fetch(allFiles);
18+
const npmDTSFiles = await npmFileReq.json();
19+
const dtsFiles = npmDTSFiles.files.filter((f) => f.path.endsWith(".d.ts"));
20+
21+
for (const file of dtsFiles) {
22+
const beforeURI = `https://unpkg.com/${name}@${before}${file.path}`;
23+
const npmBeforeFileReq = await fetch(beforeURI);
24+
const npmBeforeFileText = await npmBeforeFileReq.text();
25+
26+
const toURI = `https://unpkg.com/${name}@${to}${file.path}`;
27+
const npmToFileReq = await fetch(toURI);
28+
const npmToFileText = await npmToFileReq.text();
29+
30+
const title = `\n## \`${file.path.slice(1)}\`\n`;
31+
const notes = generateChangelogFrom(npmBeforeFileText, npmToFileText);
32+
33+
console.log(title);
34+
console.log(notes.trim() === "" ? "No changes" : notes);
35+
}
36+
};
37+
go();

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"lint": "eslint --max-warnings 0 src",
2121
"test": "npm run lint && npm run build && node ./lib/test.js && node ./unittests/index.js",
2222
"changelog": "tsc && node ./lib/changelog.js",
23-
"migrate": "node ./lib/migrate.js",
23+
"ts-changelog": "node ./deploy/versionChangelog.mjs",
24+
"migrate": "node ./deploy/migrate.mjs",
2425
"version": "npm i && tsc && node ./lib/version.js"
2526
},
2627
"author": {

0 commit comments

Comments
 (0)