@@ -19,124 +19,109 @@ import { packages } from "./createTypesPackages.mjs";
1919const __filename = fileURLToPath ( import . meta. url ) ;
2020const __dirname = dirname ( __filename ) ;
2121
22- const verify = ( ) => {
23- const authToken = process . env . GITHUB_TOKEN || process . env . GITHUB_API_TOKEN ;
24- if ( ! authToken )
25- throw new Error (
26- "There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN."
22+ verify ( ) ;
23+
24+ const uploaded = [ ] ;
25+
26+ // Loop through generated packages, deploying versions for anything which has different
27+ // .d.ts files from the version available on npm.
28+ const generatedDir = join ( __dirname , "generated" ) ;
29+ for ( const dirName of fs . readdirSync ( generatedDir ) ) {
30+ console . log ( `Looking at ${ dirName } ` ) ;
31+ const localPackageJSONPath = join ( generatedDir , dirName , "package.json" ) ;
32+ const newTSConfig = fs . readFileSync ( localPackageJSONPath , "utf-8" ) ;
33+ const pkgJSON = JSON . parse ( newTSConfig ) ;
34+
35+ // We'll need to map back from the filename in the npm package to the
36+ // generated file in baselines inside the git tag
37+ const thisPackageMeta = packages . find ( ( p ) => p . name === pkgJSON . name ) ;
38+
39+ const dtsFiles = fs
40+ . readdirSync ( join ( generatedDir , dirName ) )
41+ . filter ( ( f ) => f . endsWith ( ".d.ts" ) ) ;
42+
43+ /** @type {string[] } */
44+ let releaseNotes = [ ] ;
45+
46+ // Look through each .d.ts file included in a package to
47+ // determine if anything has changed
48+ let upload = false ;
49+ for ( const file of dtsFiles ) {
50+ const originalFilename = basename (
51+ thisPackageMeta . files . find ( ( f ) => f . to === file ) . from
2752 ) ;
28- } ;
29-
30- const gitShowFile = ( commitish , path ) =>
31- execSync ( `git show "${ commitish } ":${ path } ` , { encoding : "utf-8" } ) ;
32-
33- const go = async ( ) => {
34- verify ( ) ;
35-
36- const uploaded = [ ] ;
37-
38- // Loop through generated packages, deploying versions for anything which has different
39- // .d.ts files from the version available on npm.
40- const generatedDir = join ( __dirname , "generated" ) ;
41- for ( const dirName of fs . readdirSync ( generatedDir ) ) {
42- console . log ( `Looking at ${ dirName } ` ) ;
43- const localPackageJSONPath = join ( generatedDir , dirName , "package.json" ) ;
44- const newTSConfig = fs . readFileSync ( localPackageJSONPath , "utf-8" ) ;
45- const pkgJSON = JSON . parse ( newTSConfig ) ;
46-
47- // We'll need to map back from the filename in the npm package to the
48- // generated file in baselines inside the git tag
49- const thisPackageMeta = packages . find ( ( p ) => p . name === pkgJSON . name ) ;
50-
51- const dtsFiles = fs
52- . readdirSync ( join ( generatedDir , dirName ) )
53- . filter ( ( f ) => f . endsWith ( ".d.ts" ) ) ;
54-
55- /** @type {string[] } */
56- let releaseNotes = [ ] ;
57-
58- // Look through each .d.ts file included in a package to
59- // determine if anything has changed
60- let upload = false ;
61- for ( const file of dtsFiles ) {
62- const originalFilename = basename (
63- thisPackageMeta . files . find ( ( f ) => f . to === file ) . from
64- ) ;
6553
66- const generatedDTSPath = join ( generatedDir , dirName , file ) ;
67- const generatedDTSContent = fs . readFileSync ( generatedDTSPath , "utf8" ) ;
68-
69- // This assumes we'll only _ever_ ship patches, which may change in the
70- // future someday.
71- const [ maj , min , patch ] = pkgJSON . version . split ( "." ) ;
72- const olderVersion = `${ maj } .${ min } .${ patch - 1 } ` ;
73-
74- try {
75- const oldFile = gitShowFile (
76- `${ pkgJSON . name } @${ olderVersion } ` ,
77- `baselines/${ originalFilename } `
78- ) ;
79- console . log ( `Comparing ${ file } from ${ olderVersion } , to now:` ) ;
80- printDiff ( oldFile , generatedDTSContent ) ;
81-
82- const title = `\n## \`${ file } \`\n` ;
83- const notes = generateChangelogFrom ( oldFile , generatedDTSContent ) ;
84- releaseNotes . push ( title ) ;
85- releaseNotes . push ( notes . trim ( ) === "" ? "No changes" : notes ) ;
86-
87- upload = upload || oldFile !== generatedDTSContent ;
88- } catch ( error ) {
89- // Could not find a previous build
90- console . log ( `
54+ const generatedDTSPath = join ( generatedDir , dirName , file ) ;
55+ const generatedDTSContent = fs . readFileSync ( generatedDTSPath , "utf8" ) ;
56+
57+ // This assumes we'll only _ever_ ship patches, which may change in the
58+ // future someday.
59+ const [ maj , min , patch ] = pkgJSON . version . split ( "." ) ;
60+ const olderVersion = `${ maj } .${ min } .${ patch - 1 } ` ;
61+
62+ try {
63+ const oldFile = gitShowFile (
64+ `${ pkgJSON . name } @${ olderVersion } ` ,
65+ `baselines/${ originalFilename } `
66+ ) ;
67+ console . log ( `Comparing ${ file } from ${ olderVersion } , to now:` ) ;
68+ printDiff ( oldFile , generatedDTSContent ) ;
69+
70+ const title = `\n## \`${ file } \`\n` ;
71+ const notes = generateChangelogFrom ( oldFile , generatedDTSContent ) ;
72+ releaseNotes . push ( title ) ;
73+ releaseNotes . push ( notes . trim ( ) === "" ? "No changes" : notes ) ;
74+
75+ upload = upload || oldFile !== generatedDTSContent ;
76+ } catch ( error ) {
77+ // Could not find a previous build
78+ console . log ( `
9179Could not get the file ${ file } inside the npm package ${ pkgJSON . name } from tag ${ olderVersion } .
9280Assuming that this means we need to upload this package.` ) ;
93- upload = true ;
94- }
81+ upload = true ;
9582 }
83+ }
9684
97- // Publish via npm
98- if ( upload ) {
99- if ( process . env . NODE_AUTH_TOKEN ) {
100- const publish = spawnSync ( "npm" , [ "publish" , "--access" , "public" ] , {
101- cwd : join ( generatedDir , dirName ) ,
102- stdio : "inherit" ,
103- } ) ;
104-
105- if ( publish . status ) {
106- console . log ( publish . stdout ?. toString ( ) ) ;
107- console . log ( publish . stderr ?. toString ( ) ) ;
108- process . exit ( publish . status ) ;
109- } else {
110- console . log ( publish . stdout ?. toString ( ) ) ;
111-
112- await createRelease ( `${ pkgJSON . name } @${ pkgJSON . version } ` ) ;
113- }
85+ // Publish via npm
86+ if ( upload ) {
87+ if ( process . env . NODE_AUTH_TOKEN ) {
88+ const publish = spawnSync ( "npm" , [ "publish" , "--access" , "public" ] , {
89+ cwd : join ( generatedDir , dirName ) ,
90+ stdio : "inherit" ,
91+ } ) ;
92+
93+ if ( publish . status ) {
94+ console . log ( publish . stdout ?. toString ( ) ) ;
95+ console . log ( publish . stderr ?. toString ( ) ) ;
96+ process . exit ( publish . status ) ;
11497 } else {
115- console . log (
116- "Wanting to run: 'npm publish --access public' in " +
117- join ( generatedDir , dirName )
118- ) ;
119- }
98+ console . log ( publish . stdout ?. toString ( ) ) ;
12099
121- uploaded . push ( dirName ) ;
100+ await createRelease ( `${ pkgJSON . name } @${ pkgJSON . version } ` ) ;
101+ }
102+ } else {
103+ console . log (
104+ "Wanting to run: 'npm publish --access public' in " +
105+ join ( generatedDir , dirName )
106+ ) ;
122107 }
123108
124- console . log ( "\n# Release notes:" ) ;
125- console . log ( releaseNotes . join ( "\n" ) , "\n\n" ) ;
126- }
127- // Warn if we did a dry run.
128- if ( ! process . env . NODE_AUTH_TOKEN ) {
129- console . log (
130- "Did a dry run because process.env.NODE_AUTH_TOKEN is not set."
131- ) ;
109+ uploaded . push ( dirName ) ;
132110 }
133111
134- if ( uploaded . length ) {
135- console . log ( "Uploaded: " , uploaded . join ( ", " ) ) ;
136- } else {
137- console . log ( "No uploads" ) ;
138- }
139- } ;
112+ console . log ( "\n# Release notes:" ) ;
113+ console . log ( releaseNotes . join ( "\n" ) , "\n\n" ) ;
114+ }
115+ // Warn if we did a dry run.
116+ if ( ! process . env . NODE_AUTH_TOKEN ) {
117+ console . log ( "Did a dry run because process.env.NODE_AUTH_TOKEN is not set." ) ;
118+ }
119+
120+ if ( uploaded . length ) {
121+ console . log ( "Uploaded: " , uploaded . join ( ", " ) ) ;
122+ } else {
123+ console . log ( "No uploads" ) ;
124+ }
140125
141126async function createRelease ( tag , body ) {
142127 const authToken = process . env . GITHUB_TOKEN || process . env . GITHUB_API_TOKEN ;
@@ -158,4 +143,14 @@ async function createRelease(tag, body) {
158143 }
159144}
160145
161- go ( ) ;
146+ function verify ( ) {
147+ const authToken = process . env . GITHUB_TOKEN || process . env . GITHUB_API_TOKEN ;
148+ if ( ! authToken )
149+ throw new Error (
150+ "There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN."
151+ ) ;
152+ }
153+
154+ function gitShowFile ( commitish , path ) {
155+ return execSync ( `git show "${ commitish } ":${ path } ` , { encoding : "utf-8" } ) ;
156+ }
0 commit comments