11/// <reference types="node"/>
22import { join } from 'path' ;
3- import { rm , cp } from 'fs/promises' ;
3+ import { rm , cp , readFile , writeFile } from 'fs/promises' ;
44import yargs from 'yargs' ;
55import { hideBin } from 'yargs/helpers' ;
66import { globSync as glob } from 'tinyglobby' ;
@@ -31,41 +31,48 @@ const args = yargs(hideBin(process.argv))
3131 forwardStderrToParent : true ,
3232 } ) ;
3333
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+ ) ;
3639
3740 // Copy the readme.
38- cp ( join ( root , 'README.md' ) , join ( targetDirectory , 'README.md' ) ) ;
41+ await cp ( join ( root , 'README.md' ) , join ( targetDirectory , 'README.md' ) ) ;
3942
4043 // 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+ ) ;
5661
5762 // The user journey testing requires various files to work.
5863 // 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+ ) ;
6976
7077 if ( ! args . runnerOnly ) {
7178 // Build the report app and server.
@@ -81,3 +88,17 @@ const args = yargs(hideBin(process.argv))
8188
8289 // TODO: also have `npm publish` here?
8390} ) ( ) ;
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