@@ -3,20 +3,40 @@ import { existsSync } from "node:fs";
33
44const root = new URL ( "../" , import . meta. url ) ;
55const source = new URL ( "public/wasm/" , root ) ;
6- const destination = new URL ( "dist/wasm/" , root ) ;
6+ const arguments_ = new Set ( process . argv . slice ( 2 ) ) ;
7+ const outdirArgument = process . argv
8+ . slice ( 2 )
9+ . find ( ( value ) => value . startsWith ( "--outdir=" ) ) ;
10+ const outdir = outdirArgument ?. slice ( "--outdir=" . length ) ?? "dist" ;
11+ const includeWasm = ! arguments_ . has ( "--without-wasm" ) ;
12+ const destination = new URL ( `${ outdir } /wasm/` , root ) ;
713
8- for ( const name of [ "clangd.js" , "clangd.wasm" ] ) {
9- if ( ! existsSync ( new URL ( name , source ) ) ) {
10- throw new Error (
11- `Missing public/wasm/${ name } . Run scripts/install-clangd-artifacts first.` ,
12- ) ;
14+ if ( includeWasm ) {
15+ for ( const name of [ "clangd.js" , "clangd.wasm" ] ) {
16+ if ( ! existsSync ( new URL ( name , source ) ) ) {
17+ throw new Error (
18+ `Missing public/wasm/${ name } . Run scripts/install-clangd-artifacts first.` ,
19+ ) ;
20+ }
1321 }
22+ await mkdir ( destination , { recursive : true } ) ;
23+ await cp ( source , destination , {
24+ recursive : true ,
25+ filter : ( path ) => ! path . endsWith ( ".gitignore" ) ,
26+ } ) ;
1427}
1528
16- await mkdir ( destination , { recursive : true } ) ;
17- await cp ( source , destination , { recursive : true , filter : ( path ) => ! path . endsWith ( ".gitignore" ) } ) ;
18- await cp ( new URL ( "public/_headers" , root ) , new URL ( "dist/_headers" , root ) ) ;
29+ await cp ( new URL ( "public/_headers" , root ) , new URL ( `${ outdir } /_headers` , root ) ) ;
1930
20- await cp ( new URL ( "public/codeblocks.js" , root ) , new URL ( "dist/codeblocks.js" , root ) ) ;
21- await cp ( new URL ( "public/index.html" , root ) , new URL ( "dist/index.html" , root ) ) ;
22- await cp ( new URL ( "public/coi-serviceworker.js" , root ) , new URL ( "dist/coi-serviceworker.js" , root ) ) ;
31+ await cp (
32+ new URL ( "public/codeblocks.js" , root ) ,
33+ new URL ( `${ outdir } /codeblocks.js` , root ) ,
34+ ) ;
35+ await cp (
36+ new URL ( "public/coi-serviceworker.js" , root ) ,
37+ new URL ( `${ outdir } /coi-serviceworker.js` , root ) ,
38+ ) ;
39+ await cp (
40+ new URL ( "src/loader-api.d.ts" , root ) ,
41+ new URL ( `${ outdir } /loader.d.ts` , root ) ,
42+ ) ;
0 commit comments