3
3
// npm run ts-changelog @types/web 0.0.1 0.0.3
4
4
5
5
import { generateChangelogFrom } from "../lib/changelog.js" ;
6
- import fetch from "node-fetch" ;
6
+ import { packages } from "./createTypesPackages.mjs" ;
7
+ import { execSync } from "child_process" ;
8
+ import { basename } from "path" ;
7
9
8
10
const [ name , before , to ] = process . argv . slice ( 2 ) ;
9
11
if ( ! name || ! before || ! to ) {
@@ -12,26 +14,26 @@ if (!name || !before || !to) {
12
14
) ;
13
15
}
14
16
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" ) ) ;
17
+ const go = ( ) => {
18
+ // We'll need to map back from the filename in the npm package to the
19
+ // generated file in baselines inside the git tag
20
+ const thisPackageMeta = packages . find ( ( p ) => p . name === name ) ;
21
+ if ( ! thisPackageMeta )
22
+ throw new Error ( `Could not find ${ name } in ${ packages . map ( ( p ) => p . name ) } ` ) ;
20
23
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 ( ) ;
24
+ for ( const file of thisPackageMeta . files ) {
25
+ const filename = `baselines/ ${ basename ( file . from ) } ` ;
26
+ const beforeFileText = gitShowFile ( ` ${ name } @ ${ before } ` , filename ) ;
27
+ const toFileText = gitShowFile ( ` ${ name } @ ${ to } ` , filename ) ;
25
28
26
- const toURI = `https://unpkg.com/${ name } @${ to } ${ file . path } ` ;
27
- const npmToFileReq = await fetch ( toURI ) ;
28
- const npmToFileText = await npmToFileReq . text ( ) ;
29
+ const notes = generateChangelogFrom ( beforeFileText , toFileText ) ;
29
30
30
- const title = `\n## \`${ file . path . slice ( 1 ) } \`\n` ;
31
- const notes = generateChangelogFrom ( npmBeforeFileText , npmToFileText ) ;
32
-
33
- console . log ( title ) ;
31
+ console . log ( `\n## \`${ file . to } \`\n` ) ;
34
32
console . log ( notes . trim ( ) === "" ? "No changes" : notes ) ;
35
33
}
36
34
} ;
35
+
36
+ const gitShowFile = ( commitish , path ) =>
37
+ execSync ( `git show "${ commitish } ":${ path } ` , { encoding : "utf-8" } ) ;
38
+
37
39
go ( ) ;
0 commit comments