4
4
5
5
// prettier-ignore
6
6
export const packages = [
7
- {
8
- name : "@types/web" ,
9
- description : "Types for the DOM, and other web technologies in browsers" ,
10
- readme : "./readmes/web.md" ,
11
- files : [
12
- { from : "../generated/dom.generated.d.ts" , to : "index.d.ts" } ,
13
- { from : "../generated/dom.iterable.generated.d.ts" , to : "index.iterable.d.ts" }
14
- ] ,
15
- } ,
16
- ] ;
7
+ {
8
+ name : "@types/web" ,
9
+ description : "Types for the DOM, and other web technologies in browsers" ,
10
+ readme : "./readmes/web.md" ,
11
+ files : [
12
+ { from : "../generated/dom.generated.d.ts" , to : "index.d.ts" } ,
13
+ { from : "../generated/dom.iterable.generated.d.ts" , to : "index.iterable.d.ts" }
14
+ ] ,
15
+ } ,
16
+ ] ;
17
17
18
18
// Note: You can add 'version: "1.0.0"' to a package above
19
19
// to set the major or minor, otherwise it will always bump
20
20
// the patch.
21
21
22
- import { join , dirname } from "path" ;
23
22
import fs from "fs" ;
24
23
import fetch from "node-fetch" ;
25
24
import { fileURLToPath } from "url" ;
@@ -28,51 +27,48 @@ import pkg from "prettier";
28
27
const { format } = pkg ;
29
28
import { execSync } from "child_process" ;
30
29
31
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
- // @ts -ignore
33
- const __filename = fileURLToPath ( import . meta. url ) ;
34
- const __dirname = dirname ( __filename ) ;
35
-
36
30
const go = async ( ) => {
37
31
const gitSha = execSync ( "git rev-parse HEAD" ) . toString ( ) . trim ( ) . slice ( 0 , 7 ) ;
38
32
39
- const generatedDir = join ( __dirname , "generated" ) ;
40
- const templateDir = join ( __dirname , "template" ) ;
33
+ const generatedDir = new URL ( "generated/" , import . meta . url ) ;
34
+ const templateDir = new URL ( "template/" , import . meta . url ) ;
41
35
42
36
for ( const pkg of packages ) {
43
37
const folderName = pkg . name . replace ( "@" , "" ) . replace ( "/" , "-" ) ;
44
- const packagePath = join ( generatedDir , folderName ) ;
38
+ const packagePath = new URL ( ` ${ folderName } /` , generatedDir ) ;
45
39
46
- if ( fs . existsSync ( packagePath ) ) fs . rmSync ( packagePath , { recursive : true } ) ;
40
+ if ( fs . existsSync ( packagePath ) ) {
41
+ await fs . promises . rm ( packagePath , { recursive : true } ) ;
42
+ }
47
43
fs . mkdirSync ( packagePath , { recursive : true } ) ;
48
44
49
45
// Migrate in the template files
50
46
for ( const templateFile of fs . readdirSync ( templateDir ) ) {
51
47
if ( templateFile . startsWith ( "." ) ) continue ;
52
48
53
- const templatedFile = join ( templateDir , templateFile ) ;
54
- fs . copyFileSync ( templatedFile , join ( packagePath , templateFile ) ) ;
49
+ const templatedFile = new URL ( templateFile , templateDir ) ;
50
+ fs . copyFileSync ( templatedFile , new URL ( templateFile , packagePath ) ) ;
55
51
}
56
52
57
53
// Add the reference files in the config above
58
54
pkg . files . forEach ( ( fileRef ) => {
59
55
fs . copyFileSync (
60
- join ( __filename , ".." , fileRef . from ) ,
61
- join ( packagePath , fileRef . to )
56
+ new URL ( fileRef . from , import . meta . url ) ,
57
+ new URL ( fileRef . to , packagePath )
62
58
) ;
63
59
} ) ;
64
60
65
61
// Setup the files in the repo
66
62
const newPkgJSON = await updatePackageJSON ( packagePath , pkg , gitSha ) ;
67
- copyREADME ( pkg , newPkgJSON , join ( packagePath , "README.md" ) ) ;
63
+ copyREADME ( pkg , newPkgJSON , new URL ( "README.md" , packagePath ) ) ;
68
64
69
65
// Done
70
66
console . log ( "Built:" , pkg . name ) ;
71
67
}
72
68
} ;
73
69
74
70
async function updatePackageJSON ( packagePath , pkg , gitSha ) {
75
- const pkgJSONPath = join ( packagePath , "package.json" ) ;
71
+ const pkgJSONPath = new URL ( "package.json" , packagePath ) ;
76
72
const packageText = fs . readFileSync ( pkgJSONPath , "utf8" ) ;
77
73
const packageJSON = JSON . parse ( packageText ) ;
78
74
packageJSON . name = pkg . name ;
@@ -107,15 +103,17 @@ async function updatePackageJSON(packagePath, pkg, gitSha) {
107
103
108
104
fs . writeFileSync (
109
105
pkgJSONPath ,
110
- format ( JSON . stringify ( packageJSON ) , { filepath : pkgJSONPath } )
106
+ format ( JSON . stringify ( packageJSON ) , {
107
+ filepath : fileURLToPath ( pkgJSONPath ) ,
108
+ } )
111
109
) ;
112
110
113
111
return packageJSON ;
114
112
}
115
113
116
114
// Copies the README and adds some rudimentary templating to the file.
117
115
function copyREADME ( pkg , pkgJSON , writePath ) {
118
- let readme = fs . readFileSync ( join ( __filename , ".." , pkg . readme ) , "utf-8" ) ;
116
+ let readme = fs . readFileSync ( new URL ( pkg . readme , import . meta . url ) , "utf-8" ) ;
119
117
120
118
const htmlEncodedTag =
121
119
encodeURIComponent ( pkgJSON . name ) + "%40" + pkgJSON . version ;
0 commit comments