1
1
/// <reference types="node"/>
2
2
import { join } from 'path' ;
3
- import { rm , cp } from 'fs/promises' ;
3
+ import { rm , cp , readFile , writeFile } from 'fs/promises' ;
4
4
import yargs from 'yargs' ;
5
5
import { hideBin } from 'yargs/helpers' ;
6
6
import { globSync as glob } from 'tinyglobby' ;
@@ -31,41 +31,48 @@ const args = yargs(hideBin(process.argv))
31
31
forwardStderrToParent : true ,
32
32
} ) ;
33
33
34
- // Copy the package.json into `dist`.
35
- cp ( join ( root , 'package.json' ) , join ( targetDirectory , 'package.json' ) ) ;
34
+ // Generate the package.json.
35
+ await writeFile (
36
+ join ( targetDirectory , 'package.json' ) ,
37
+ await getPackageJson ( join ( root , 'package.json' ) )
38
+ ) ;
36
39
37
40
// Copy the readme.
38
- cp ( join ( root , 'README.md' ) , join ( targetDirectory , 'README.md' ) ) ;
41
+ await cp ( join ( root , 'README.md' ) , join ( targetDirectory , 'README.md' ) ) ;
39
42
40
43
// Copy all the examples as is.
41
- glob ( '**/*' , {
42
- cwd : join ( root , 'examples' ) ,
43
- dot : true ,
44
- ignore : [
45
- '**/node_modules/**' ,
46
- '**/dist/**' ,
47
- '**/.vinxi/**' ,
48
- '**/.output/**' ,
49
- ] ,
50
- } ) . forEach ( ( agentFile ) => {
51
- cp (
52
- join ( root , 'examples' , agentFile ) ,
53
- join ( targetDirectory , 'examples' , agentFile )
54
- ) ;
55
- } ) ;
44
+ await Promise . all (
45
+ glob ( '**/*' , {
46
+ cwd : join ( root , 'examples' ) ,
47
+ dot : true ,
48
+ ignore : [
49
+ '**/node_modules/**' ,
50
+ '**/dist/**' ,
51
+ '**/.vinxi/**' ,
52
+ '**/.output/**' ,
53
+ ] ,
54
+ } ) . map ( ( agentFile ) =>
55
+ cp (
56
+ join ( root , 'examples' , agentFile ) ,
57
+ join ( targetDirectory , 'examples' , agentFile )
58
+ )
59
+ )
60
+ ) ;
56
61
57
62
// The user journey testing requires various files to work.
58
63
// Copy everything except the source TypeScript.
59
- glob ( '**/*' , {
60
- cwd : join ( root , browserAgentRelativePath ) ,
61
- dot : true ,
62
- ignore : [ '*.ts' , 'README.md' ] ,
63
- } ) . forEach ( ( agentFile ) => {
64
- cp (
65
- join ( root , browserAgentRelativePath , agentFile ) ,
66
- join ( targetDirectory , browserAgentRelativePath , agentFile )
67
- ) ;
68
- } ) ;
64
+ await Promise . all (
65
+ glob ( '**/*' , {
66
+ cwd : join ( root , browserAgentRelativePath ) ,
67
+ dot : true ,
68
+ ignore : [ '*.ts' , 'README.md' ] ,
69
+ } ) . map ( ( agentFile ) =>
70
+ cp (
71
+ join ( root , browserAgentRelativePath , agentFile ) ,
72
+ join ( targetDirectory , browserAgentRelativePath , agentFile )
73
+ )
74
+ )
75
+ ) ;
69
76
70
77
if ( ! args . runnerOnly ) {
71
78
// Build the report app and server.
@@ -81,3 +88,17 @@ const args = yargs(hideBin(process.argv))
81
88
82
89
// TODO: also have `npm publish` here?
83
90
} ) ( ) ;
91
+
92
+ async function getPackageJson ( path : string ) : Promise < string > {
93
+ const content = await readFile ( path , 'utf8' ) ;
94
+ const parsed = JSON . parse ( content ) as {
95
+ scripts ?: unknown ;
96
+ devDependencies ?: unknown ;
97
+ } ;
98
+
99
+ // Delete some fields that aren't relevant for end users.
100
+ delete parsed . scripts ;
101
+ delete parsed . devDependencies ;
102
+
103
+ return JSON . stringify ( parsed , undefined , 2 ) ;
104
+ }
0 commit comments