@@ -3,49 +3,108 @@ import path from 'path'
33
44import writeIfOverrideNotPresent from '../write-if-override-not-present.js'
55
6- function writeSupportFiles ( outputDir , forNode , bindgenResource , packageName , packageDescription ) {
6+ function writeSupportFiles (
7+ outputDir ,
8+ forNode ,
9+ bindgenResource ,
10+ packageName ,
11+ packageDescription
12+ ) {
713 if ( ! forNode ) {
814 try {
915 fs . mkdirSync ( path . join ( outputDir , 'build' ) , { recursive : true } )
1016 } catch ( err ) {
1117 if ( err . code !== 'EEXIST' ) throw err
1218 }
1319 try {
14- fs . mkdirSync ( path . join ( outputDir , 'test' , 'browser' , 'demo-app' ) , { recursive : true } )
20+ fs . mkdirSync ( path . join ( outputDir , 'test' , 'browser' , 'demo-app' ) , {
21+ recursive : true
22+ } )
1523 } catch ( err ) {
1624 if ( err . code !== 'EEXIST' ) throw err
1725 }
1826
19- const pipelinesBaseUrlPath = path . join ( outputDir , 'src' , 'pipelines-base-url.ts' )
27+ const pipelinesBaseUrlPath = path . join (
28+ outputDir ,
29+ 'src' ,
30+ 'pipelines-base-url.ts'
31+ )
2032 if ( ! fs . existsSync ( pipelinesBaseUrlPath ) ) {
21- fs . copyFileSync ( bindgenResource ( 'pipelines-base-url.ts' ) , pipelinesBaseUrlPath )
22- let pipelinesBaseUrlPathContent = fs . readFileSync ( bindgenResource ( 'pipelines-base-url.ts' ) , { encoding : 'utf8' , flag : 'r' } )
23- pipelinesBaseUrlPathContent = pipelinesBaseUrlPathContent . replaceAll ( '<bindgenPackageName>' , packageName )
24- writeIfOverrideNotPresent ( pipelinesBaseUrlPath , pipelinesBaseUrlPathContent )
33+ fs . copyFileSync (
34+ bindgenResource ( 'pipelines-base-url.ts' ) ,
35+ pipelinesBaseUrlPath
36+ )
37+ let pipelinesBaseUrlPathContent = fs . readFileSync (
38+ bindgenResource ( 'pipelines-base-url.ts' ) ,
39+ { encoding : 'utf8' , flag : 'r' }
40+ )
41+ pipelinesBaseUrlPathContent = pipelinesBaseUrlPathContent . replaceAll (
42+ '<bindgenPackageName>' ,
43+ packageName
44+ )
45+ writeIfOverrideNotPresent (
46+ pipelinesBaseUrlPath ,
47+ pipelinesBaseUrlPathContent
48+ )
2549 }
26- const pipelineWorkerUrlPath = path . join ( outputDir , 'src' , 'pipeline-worker-url.ts' )
50+ const pipelineWorkerUrlPath = path . join (
51+ outputDir ,
52+ 'src' ,
53+ 'pipeline-worker-url.ts'
54+ )
2755 if ( ! fs . existsSync ( pipelineWorkerUrlPath ) ) {
28- let pipelineWorkerUrlPathContent = fs . readFileSync ( bindgenResource ( 'pipeline-worker-url.ts' ) , { encoding : 'utf8' , flag : 'r' } )
29- pipelineWorkerUrlPathContent = pipelineWorkerUrlPathContent . replaceAll ( '<bindgenPackageName>' , packageName )
30- writeIfOverrideNotPresent ( pipelineWorkerUrlPath , pipelineWorkerUrlPathContent )
56+ let pipelineWorkerUrlPathContent = fs . readFileSync (
57+ bindgenResource ( 'pipeline-worker-url.ts' ) ,
58+ { encoding : 'utf8' , flag : 'r' }
59+ )
60+ pipelineWorkerUrlPathContent = pipelineWorkerUrlPathContent . replaceAll (
61+ '<bindgenPackageName>' ,
62+ packageName
63+ )
64+ writeIfOverrideNotPresent (
65+ pipelineWorkerUrlPath ,
66+ pipelineWorkerUrlPathContent
67+ )
3168 }
32- const defaultWebWorkerPath = path . join ( outputDir , 'src' , 'default-web-worker.ts' )
69+ const defaultWebWorkerPath = path . join (
70+ outputDir ,
71+ 'src' ,
72+ 'default-web-worker.ts'
73+ )
3374 if ( ! fs . existsSync ( defaultWebWorkerPath ) ) {
34- let defaultWebWorkerContent = fs . readFileSync ( bindgenResource ( 'default-web-worker.ts' ) , { encoding : 'utf8' , flag : 'r' } )
75+ let defaultWebWorkerContent = fs . readFileSync (
76+ bindgenResource ( 'default-web-worker.ts' ) ,
77+ { encoding : 'utf8' , flag : 'r' }
78+ )
3579 writeIfOverrideNotPresent ( defaultWebWorkerPath , defaultWebWorkerContent )
3680 }
3781
38- const indexWorkerEmbeddedPath = path . join ( outputDir , 'src' , 'index-worker-embedded.ts' )
39- const indexWorkerEmbeddedContent = fs . readFileSync ( bindgenResource ( 'index-worker-embedded.ts' ) , { encoding : 'utf8' , flag : 'r' } )
40- writeIfOverrideNotPresent ( indexWorkerEmbeddedPath , indexWorkerEmbeddedContent )
41- const indexWorkerEmbeddedMinPath = path . join ( outputDir , 'src' , 'index-worker-embedded.min.ts' )
42- const indexWorkerEmbeddedMinContent = fs . readFileSync ( bindgenResource ( 'index-worker-embedded.min.ts' ) , { encoding : 'utf8' , flag : 'r' } )
43- writeIfOverrideNotPresent ( indexWorkerEmbeddedMinPath , indexWorkerEmbeddedMinContent )
44-
45- const packageJsonSymlinkPath = path . join ( outputDir , 'src' , 'package.json' )
46- if ( ! fs . existsSync ( packageJsonSymlinkPath ) ) {
47- fs . symlinkSync ( '../package.json' , packageJsonSymlinkPath )
48- }
82+ const indexWorkerEmbeddedPath = path . join (
83+ outputDir ,
84+ 'src' ,
85+ 'index-worker-embedded.ts'
86+ )
87+ const indexWorkerEmbeddedContent = fs . readFileSync (
88+ bindgenResource ( 'index-worker-embedded.ts' ) ,
89+ { encoding : 'utf8' , flag : 'r' }
90+ )
91+ writeIfOverrideNotPresent (
92+ indexWorkerEmbeddedPath ,
93+ indexWorkerEmbeddedContent
94+ )
95+ const indexWorkerEmbeddedMinPath = path . join (
96+ outputDir ,
97+ 'src' ,
98+ 'index-worker-embedded.min.ts'
99+ )
100+ const indexWorkerEmbeddedMinContent = fs . readFileSync (
101+ bindgenResource ( 'index-worker-embedded.min.ts' ) ,
102+ { encoding : 'utf8' , flag : 'r' }
103+ )
104+ writeIfOverrideNotPresent (
105+ indexWorkerEmbeddedMinPath ,
106+ indexWorkerEmbeddedMinContent
107+ )
49108
50109 const npmIgnorePath = path . join ( outputDir , '.npmignore' )
51110 if ( ! fs . existsSync ( npmIgnorePath ) ) {
@@ -54,29 +113,89 @@ function writeSupportFiles(outputDir, forNode, bindgenResource, packageName, pac
54113
55114 const docsIndexPath = path . join ( outputDir , 'index.html' )
56115 if ( ! fs . existsSync ( docsIndexPath ) ) {
57- let docsIndexContent = fs . readFileSync ( bindgenResource ( 'index.html' ) , { encoding : 'utf8' , flag : 'r' } )
58- docsIndexContent = docsIndexContent . replaceAll ( '<bindgenPackageName>' , packageName )
59- docsIndexContent = docsIndexContent . replaceAll ( '<bindgenPackageDescription>' , packageDescription )
116+ let docsIndexContent = fs . readFileSync ( bindgenResource ( 'index.html' ) , {
117+ encoding : 'utf8' ,
118+ flag : 'r'
119+ } )
120+ docsIndexContent = docsIndexContent . replaceAll (
121+ '<bindgenPackageName>' ,
122+ packageName
123+ )
124+ docsIndexContent = docsIndexContent . replaceAll (
125+ '<bindgenPackageDescription>' ,
126+ packageDescription
127+ )
60128 fs . writeFileSync ( docsIndexPath , docsIndexContent )
61- fs . copyFileSync ( bindgenResource ( '.nojekyll' ) , path . join ( outputDir , '.nojekll' ) )
129+ fs . copyFileSync (
130+ bindgenResource ( '.nojekyll' ) ,
131+ path . join ( outputDir , '.nojekll' )
132+ )
62133 }
63134
64- const logoPath = path . join ( outputDir , 'test' , 'browser' , 'demo-app' , 'logo.svg' )
135+ const logoPath = path . join (
136+ outputDir ,
137+ 'test' ,
138+ 'browser' ,
139+ 'demo-app' ,
140+ 'logo.svg'
141+ )
65142 if ( ! fs . existsSync ( logoPath ) ) {
66- fs . copyFileSync ( bindgenResource ( path . join ( 'demo-app' , 'logo.svg' ) ) , logoPath )
67- const jsLogoPath = path . join ( outputDir , 'test' , 'browser' , 'demo-app' , 'javascript-logo.svg' )
68- fs . copyFileSync ( bindgenResource ( path . join ( 'demo-app' , 'javascript-logo.svg' ) ) , jsLogoPath )
69- const tsLogoPath = path . join ( outputDir , 'test' , 'browser' , 'demo-app' , 'typescript-logo.svg' )
70- fs . copyFileSync ( bindgenResource ( path . join ( 'demo-app' , 'typescript-logo.svg' ) ) , tsLogoPath )
143+ fs . copyFileSync (
144+ bindgenResource ( path . join ( 'demo-app' , 'logo.svg' ) ) ,
145+ logoPath
146+ )
147+ const jsLogoPath = path . join (
148+ outputDir ,
149+ 'test' ,
150+ 'browser' ,
151+ 'demo-app' ,
152+ 'javascript-logo.svg'
153+ )
154+ fs . copyFileSync (
155+ bindgenResource ( path . join ( 'demo-app' , 'javascript-logo.svg' ) ) ,
156+ jsLogoPath
157+ )
158+ const tsLogoPath = path . join (
159+ outputDir ,
160+ 'test' ,
161+ 'browser' ,
162+ 'demo-app' ,
163+ 'typescript-logo.svg'
164+ )
165+ fs . copyFileSync (
166+ bindgenResource ( path . join ( 'demo-app' , 'typescript-logo.svg' ) ) ,
167+ tsLogoPath
168+ )
71169 }
72170
73- const demoStylePath = path . join ( outputDir , 'test' , 'browser' , 'demo-app' , 'style.css' )
171+ const demoStylePath = path . join (
172+ outputDir ,
173+ 'test' ,
174+ 'browser' ,
175+ 'demo-app' ,
176+ 'style.css'
177+ )
74178 if ( ! fs . existsSync ( demoStylePath ) ) {
75- fs . copyFileSync ( bindgenResource ( path . join ( 'demo-app' , 'style.css' ) ) , demoStylePath )
179+ fs . copyFileSync (
180+ bindgenResource ( path . join ( 'demo-app' , 'style.css' ) ) ,
181+ demoStylePath
182+ )
76183 }
77184
78- const demoJsUtilities = path . join ( outputDir , 'test' , 'browser' , 'demo-app' , 'utilities.js' )
79- writeIfOverrideNotPresent ( demoJsUtilities , fs . readFileSync ( bindgenResource ( path . join ( 'demo-app' , 'utilities.js' ) ) , { encoding : 'utf8' , flag : 'r' } ) )
185+ const demoJsUtilities = path . join (
186+ outputDir ,
187+ 'test' ,
188+ 'browser' ,
189+ 'demo-app' ,
190+ 'utilities.js'
191+ )
192+ writeIfOverrideNotPresent (
193+ demoJsUtilities ,
194+ fs . readFileSync ( bindgenResource ( path . join ( 'demo-app' , 'utilities.js' ) ) , {
195+ encoding : 'utf8' ,
196+ flag : 'r'
197+ } )
198+ )
80199
81200 const viteConfigPath = path . join ( outputDir , 'vite.config.js' )
82201 if ( ! fs . existsSync ( viteConfigPath ) ) {
0 commit comments