@@ -5,6 +5,38 @@ const path = require("path")
55const production = process . argv . includes ( "--production" )
66const watch = process . argv . includes ( "--watch" )
77
8+ /**
9+ * @param {[string, string][] } copyPaths
10+ * @param {string } srcDir
11+ * @param {string } dstDir
12+ * @returns {void }
13+ */
14+ function copyPaths ( copyPaths , srcDir , dstDir ) {
15+ copyPaths . forEach ( ( [ srcRelPath , dstRelPath ] ) => {
16+ const stats = fs . lstatSync ( path . join ( srcDir , srcRelPath ) )
17+
18+ if ( stats . isDirectory ( ) ) {
19+ if ( fs . existsSync ( path . join ( dstDir , dstRelPath ) ) ) {
20+ fs . rmSync ( path . join ( dstDir , dstRelPath ) , { recursive : true } )
21+ }
22+
23+ fs . mkdirSync ( path . join ( dstDir , dstRelPath ) , { recursive : true } )
24+
25+ const count = copyDir ( path . join ( srcDir , srcRelPath ) , path . join ( dstDir , dstRelPath ) , 0 )
26+ console . log ( `[copyPaths] Copied ${ count } files from ${ srcRelPath } to ${ dstRelPath } ` )
27+ } else {
28+ fs . copyFileSync ( path . join ( srcDir , srcRelPath ) , path . join ( dstDir , dstRelPath ) )
29+ console . log ( `[copyPaths] Copied ${ srcRelPath } to ${ dstRelPath } ` )
30+ }
31+ } )
32+ }
33+
34+ /**
35+ * @param {string } srcDir
36+ * @param {string } dstDir
37+ * @param {number } count
38+ * @returns {number }
39+ */
840function copyDir ( srcDir , dstDir , count ) {
941 const entries = fs . readdirSync ( srcDir , { withFileTypes : true } )
1042
@@ -172,27 +204,17 @@ const copyAssets = {
172204 name : "copy-assets" ,
173205 setup ( build ) {
174206 build . onEnd ( ( ) => {
175- const copyPaths = [
176- [ "node_modules/vscode-material-icons/generated" , "assets/vscode-material-icons" ] ,
177- [ "../webview-ui/audio" , "webview-ui/audio" ] ,
178- ]
179-
180- for ( const [ srcRelPath , dstRelPath ] of copyPaths ) {
181- const srcDir = path . join ( __dirname , srcRelPath )
182- const dstDir = path . join ( __dirname , dstRelPath )
183-
184- if ( ! fs . existsSync ( srcDir ) ) {
185- throw new Error ( `Directory does not exist: ${ srcDir } ` )
186- }
187-
188- if ( fs . existsSync ( dstDir ) ) {
189- fs . rmSync ( dstDir , { recursive : true } )
190- }
191-
192- fs . mkdirSync ( dstDir , { recursive : true } )
193- const count = copyDir ( srcDir , dstDir , 0 )
194- console . log ( `[copy-assets] Copied ${ count } assets from ${ srcDir } to ${ dstDir } ` )
195- }
207+ copyPaths (
208+ [
209+ [ "../README.md" , "README.md" ] ,
210+ [ "../CHANGELOG.md" , "CHANGELOG.md" ] ,
211+ [ "../LICENSE" , "LICENSE" ] ,
212+ [ "node_modules/vscode-material-icons/generated" , "assets/vscode-material-icons" ] ,
213+ [ "../webview-ui/audio" , "webview-ui/audio" ] ,
214+ ] ,
215+ __dirname ,
216+ __dirname ,
217+ )
196218 } )
197219 } ,
198220}
0 commit comments