22
33// node deploy/createTypesPackages.js
44
5+ /**
6+ * @template T
7+ * @typedef {T extends (infer U)[] ? U : T } ArrayInner
8+ */
9+ /**
10+ * @typedef {ArrayInner<typeof packages> } Package
11+ */
512// prettier-ignore
613export const packages = [
714 {
@@ -52,11 +59,8 @@ import { fileURLToPath } from "url";
5259import semver from "semver" ;
5360import pkg from "prettier" ;
5461const { format } = pkg ;
55- import { execSync } from "child_process" ;
5662
5763const go = async ( ) => {
58- const gitSha = execSync ( "git rev-parse HEAD" ) . toString ( ) . trim ( ) . slice ( 0 , 7 ) ;
59-
6064 const generatedDir = new URL ( "generated/" , import . meta. url ) ;
6165 const templateDir = new URL ( "template/" , import . meta. url ) ;
6266
@@ -88,25 +92,30 @@ const go = async () => {
8892 prependAutoImports ( pkg , packagePath ) ;
8993
9094 // Setup the files in the repo
91- const newPkgJSON = await updatePackageJSON ( pkg , packagePath , gitSha ) ;
95+ const newPkgJSON = await updatePackageJSON ( pkg , packagePath ) ;
9296 copyREADME ( pkg , newPkgJSON , new URL ( "README.md" , packagePath ) ) ;
9397
9498 // Done
9599 console . log ( "Built:" , pkg . name ) ;
96100 }
97101} ;
98102
99- async function updatePackageJSON ( pkg , packagePath , gitSha ) {
103+ /**
104+ * @param {Package } pkg
105+ * @param {URL } packagePath
106+ */
107+ async function updatePackageJSON ( pkg , packagePath ) {
100108 const pkgJSONPath = new URL ( "package.json" , packagePath ) ;
101109 const packageText = fs . readFileSync ( pkgJSONPath , "utf8" ) ;
110+ /** @type {import("./template/package.json") } */
102111 const packageJSON = JSON . parse ( packageText ) ;
103112 packageJSON . name = pkg . name ;
104113 packageJSON . description = pkg . description ;
105114
106115 // Bump the last version of the number from npm,
107116 // or use the _version in tsconfig if it's higher,
108117 // or default to 0.0.1
109- let version = pkg . version || "0.0.1" ;
118+ let version = "0.0.1" ;
110119 try {
111120 const npmResponse = await fetch (
112121 `https://registry.npmjs.org/${ packageJSON . name } `
@@ -128,7 +137,6 @@ async function updatePackageJSON(pkg, packagePath, gitSha) {
128137 }
129138
130139 packageJSON . version = version ;
131- packageJSON . domLibGeneratorSha = gitSha ;
132140
133141 fs . writeFileSync (
134142 pkgJSONPath ,
@@ -140,7 +148,12 @@ async function updatePackageJSON(pkg, packagePath, gitSha) {
140148 return packageJSON ;
141149}
142150
143- // Copies the README and adds some rudimentary templating to the file.
151+ /**
152+ * Copies the README and adds some rudimentary templating to the file.
153+ * @param {Package } pkg
154+ * @param {import("./template/package.json") } pkgJSON
155+ * @param {URL } writePath
156+ */
144157function copyREADME ( pkg , pkgJSON , writePath ) {
145158 let readme = fs . readFileSync ( new URL ( pkg . readme , import . meta. url ) , "utf-8" ) ;
146159
@@ -157,7 +170,11 @@ function copyREADME(pkg, pkgJSON, writePath) {
157170 fs . writeFileSync ( writePath , readme ) ;
158171}
159172
160- // Appends any files marked as autoImport in the metadata.
173+ /**
174+ * Appends any files marked as autoImport in the metadata.
175+ * @param {Package } pkg
176+ * @param {URL } packagePath
177+ */
161178function prependAutoImports ( pkg , packagePath ) {
162179 const index = new URL ( "index.d.ts" , packagePath ) ;
163180 if ( ! fs . existsSync ( index ) ) return ;
0 commit comments