2
2
/* eslint-disable @typescript-eslint/no-var-requires*/
3
3
4
4
const Path = require ( 'path' ) ;
5
- const ChildProcess = require ( 'child_process ' ) ;
5
+ const fsp = require ( 'fs/promises ' ) ;
6
6
7
7
const LIBS = [ '@lit/reactive-element' , 'lit' , 'lit-element' , 'lit-html' ] ;
8
8
@@ -16,26 +16,26 @@ function getLibPath(lib) {
16
16
return Path . join ( split [ 0 ] , 'node_modules' , modulePath ) ;
17
17
}
18
18
19
+ async function copyTsDefFiles ( lib ) {
20
+ const srcDir = getLibPath ( lib ) ;
21
+ const destDir = Path . resolve ( Path . join ( 'lib' , 'node_modules' , lib ) ) ;
22
+
23
+ await fsp . mkdir ( destDir , { recursive : true } ) ;
24
+
25
+ const files = await fsp . readdir ( srcDir ) ;
26
+
27
+ const tsDefFiles = files . filter ( ( file ) => file . endsWith ( '.d.ts' ) ) ;
28
+
29
+ const copyPromises = tsDefFiles . map ( ( file ) => {
30
+ const srcFile = Path . join ( srcDir , file ) ;
31
+ const destFile = Path . join ( destDir , file ) ;
32
+ return fsp . copyFile ( srcFile , destFile ) ;
33
+ } ) ;
34
+ await Promise . all ( copyPromises ) ;
35
+ }
36
+
19
37
async function main ( ) {
20
- await Promise . all (
21
- LIBS . map (
22
- ( lib ) =>
23
- new Promise ( ( resolve , reject ) => {
24
- ChildProcess . exec (
25
- `cp ${ Path . join ( getLibPath ( lib ) , '*.d.ts' ) } ${ Path . resolve (
26
- Path . join ( 'lib' , 'node_modules' , lib )
27
- ) } `,
28
- ( error , stdout , stderr ) => {
29
- if ( error || stderr ) {
30
- reject ( error || new Error ( stderr ) ) ;
31
- return ;
32
- }
33
- resolve ( stdout ) ;
34
- }
35
- ) ;
36
- } )
37
- )
38
- ) ;
38
+ await Promise . all ( LIBS . map ( ( lib ) => copyTsDefFiles ( lib ) ) ) ;
39
39
}
40
40
41
41
process . on ( 'unhandledRejection' , ( reason ) => {
0 commit comments