1
1
// @ts -check
2
2
3
- // node deploy/createTypesPackages.mjs
4
-
3
+ // node deploy/createTypesPackages.js
4
+
5
+ /**
6
+ * @template T
7
+ * @typedef {T extends (infer U)[] ? U : T } ArrayInner
8
+ */
9
+ /**
10
+ * @typedef {ArrayInner<typeof packages> } Package
11
+ */
5
12
// prettier-ignore
6
13
export const packages = [
7
14
{
@@ -52,11 +59,8 @@ import { fileURLToPath } from "url";
52
59
import semver from "semver" ;
53
60
import pkg from "prettier" ;
54
61
const { format } = pkg ;
55
- import { execSync } from "child_process" ;
56
62
57
63
const go = async ( ) => {
58
- const gitSha = execSync ( "git rev-parse HEAD" ) . toString ( ) . trim ( ) . slice ( 0 , 7 ) ;
59
-
60
64
const generatedDir = new URL ( "generated/" , import . meta. url ) ;
61
65
const templateDir = new URL ( "template/" , import . meta. url ) ;
62
66
@@ -88,25 +92,30 @@ const go = async () => {
88
92
prependAutoImports ( pkg , packagePath ) ;
89
93
90
94
// Setup the files in the repo
91
- const newPkgJSON = await updatePackageJSON ( pkg , packagePath , gitSha ) ;
95
+ const newPkgJSON = await updatePackageJSON ( pkg , packagePath ) ;
92
96
copyREADME ( pkg , newPkgJSON , new URL ( "README.md" , packagePath ) ) ;
93
97
94
98
// Done
95
99
console . log ( "Built:" , pkg . name ) ;
96
100
}
97
101
} ;
98
102
99
- async function updatePackageJSON ( pkg , packagePath , gitSha ) {
103
+ /**
104
+ * @param {Package } pkg
105
+ * @param {URL } packagePath
106
+ */
107
+ async function updatePackageJSON ( pkg , packagePath ) {
100
108
const pkgJSONPath = new URL ( "package.json" , packagePath ) ;
101
109
const packageText = fs . readFileSync ( pkgJSONPath , "utf8" ) ;
110
+ /** @type {import("./template/package.json") } */
102
111
const packageJSON = JSON . parse ( packageText ) ;
103
112
packageJSON . name = pkg . name ;
104
113
packageJSON . description = pkg . description ;
105
114
106
115
// Bump the last version of the number from npm,
107
116
// or use the _version in tsconfig if it's higher,
108
117
// or default to 0.0.1
109
- let version = pkg . version || "0.0.1" ;
118
+ let version = "0.0.1" ;
110
119
try {
111
120
const npmResponse = await fetch (
112
121
`https://registry.npmjs.org/${ packageJSON . name } `
@@ -128,7 +137,6 @@ async function updatePackageJSON(pkg, packagePath, gitSha) {
128
137
}
129
138
130
139
packageJSON . version = version ;
131
- packageJSON . domLibGeneratorSha = gitSha ;
132
140
133
141
fs . writeFileSync (
134
142
pkgJSONPath ,
@@ -140,7 +148,12 @@ async function updatePackageJSON(pkg, packagePath, gitSha) {
140
148
return packageJSON ;
141
149
}
142
150
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
+ */
144
157
function copyREADME ( pkg , pkgJSON , writePath ) {
145
158
let readme = fs . readFileSync ( new URL ( pkg . readme , import . meta. url ) , "utf-8" ) ;
146
159
@@ -157,7 +170,11 @@ function copyREADME(pkg, pkgJSON, writePath) {
157
170
fs . writeFileSync ( writePath , readme ) ;
158
171
}
159
172
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
+ */
161
178
function prependAutoImports ( pkg , packagePath ) {
162
179
const index = new URL ( "index.d.ts" , packagePath ) ;
163
180
if ( ! fs . existsSync ( index ) ) return ;
0 commit comments