@@ -161,20 +161,84 @@ export default class SquirrelWindowsTarget extends Target {
161161 fs . copyFileSync ( path . join ( vendorDirectory , `7z-${ resolvedArch } .dll` ) , path . join ( vendorDirectory , "7z.dll" ) )
162162 }
163163
164- private async createNuspecTemplateWithProjectUrl ( ) {
164+ private async createNuspecTemplateWithProjectUrl ( additionalFiles : { src : string , target : string } [ ] ) {
165165 const templatePath = path . resolve ( __dirname , ".." , "template.nuspectemplate" )
166166 const projectUrl = await this . packager . appInfo . computePackageUrl ( )
167+
168+ // Always create a customized template to include additionalFiles
169+ const nuspecTemplate = await this . packager . info . tempDirManager . getTempFile ( { prefix : "template" , suffix : ".nuspectemplate" } )
170+ let templateContent = await fs . promises . readFile ( templatePath , "utf8" )
171+
172+ // Add project URL if available
167173 if ( projectUrl != null ) {
168- const nuspecTemplate = await this . packager . info . tempDirManager . getTempFile ( { prefix : "template" , suffix : ".nuspectemplate" } )
169- let templateContent = await fs . promises . readFile ( templatePath , "utf8" )
170174 const searchString = "<copyright><%- copyright %></copyright>"
171175 templateContent = templateContent . replace ( searchString , `${ searchString } \n <projectUrl>${ projectUrl } </projectUrl>` )
172- await fs . promises . writeFile ( nuspecTemplate , templateContent )
173- return nuspecTemplate
174176 }
175- return templatePath
177+
178+ // Replace the additionalFiles loop with the actual files
179+ if ( additionalFiles . length > 0 ) {
180+ const additionalFilesContent = additionalFiles . map ( f => ` <file src="${ f . src } " target="${ f . target } " />` ) . join ( '\n' )
181+ templateContent = templateContent . replace (
182+ '<% file src="additionalFiles.src" target="additionalFiles.target" / %>' ,
183+ additionalFilesContent
184+ )
185+ } else {
186+ templateContent = templateContent . replace (
187+ '<% file src="additionalFiles.src" target="additionalFiles.target" / %>' ,
188+ ''
189+ )
190+ }
191+
192+ await fs . promises . writeFile ( nuspecTemplate , templateContent )
193+ return nuspecTemplate
194+ }
195+
196+ private async getAdditionalFiles ( appOutDir : string , exeName : string ) {
197+ const files = await fs . promises . readdir ( appOutDir , { withFileTypes : true } )
198+ const appExe = `${ this . exeName } .exe`
199+
200+ const additionalFiles = files . filter ( f => {
201+ if ( f . isDirectory ( ) ) {
202+ // Filter out directories already included in template
203+ return f . name !== "resources" && f . name !== "locales"
204+ }
205+
206+ // Filter out files already included in template.nuspectemplate
207+ const fileName = f . name
208+
209+ // Files explicitly included in template
210+ if ( fileName . endsWith ( ".bin" ) ||
211+ fileName . endsWith ( ".dll" ) ||
212+ fileName . endsWith ( ".pak" ) ||
213+ fileName . endsWith ( ".exe.config" ) ||
214+ fileName . endsWith ( ".exe.sig" ) ||
215+ fileName . endsWith ( "_ExecutionStub.exe" ) ||
216+ fileName === "icudtl.dat" ||
217+ fileName === "Squirrel.exe" ||
218+ fileName === "LICENSE.electron.txt" ||
219+ fileName === "LICENSES.chromium.html" ||
220+ fileName === appExe ) {
221+ return false
222+ }
223+ return true
224+ } )
225+
226+ return additionalFiles . map ( f => {
227+ if ( f . isDirectory ( ) ) {
228+ return {
229+ src : `${ f . name } \\**` ,
230+ target : `lib\\net45\\${ f . name } ` ,
231+ }
232+ }
233+ return {
234+ src : f . name ,
235+ target : `lib\\net45\\${ f . name } ` ,
236+ }
237+ } )
176238 }
177239
240+
241+
178242 async computeEffectiveDistOptions ( appDirectory : string , outputDirectory : string , setupFile : string ) : Promise < SquirrelOptions > {
179243 const packager = this . packager
180244 let iconUrl = this . options . iconUrl
@@ -189,6 +253,8 @@ export default class SquirrelWindowsTarget extends Target {
189253 }
190254 }
191255
256+
257+ const additionalFiles = await this . getAdditionalFiles ( appDirectory , this . exeName )
192258 checkConflictingOptions ( this . options )
193259 const appInfo = packager . appInfo
194260 const options : SquirrelOptions = {
@@ -200,7 +266,7 @@ export default class SquirrelWindowsTarget extends Target {
200266 description : appInfo . description ,
201267 exe : `${ appInfo . productFilename || this . options . name || appInfo . productName } .exe` ,
202268 authors : appInfo . companyName || "" ,
203- nuspecTemplate : await this . createNuspecTemplateWithProjectUrl ( ) ,
269+ nuspecTemplate : await this . createNuspecTemplateWithProjectUrl ( additionalFiles ) ,
204270 iconUrl,
205271 copyright : appInfo . copyright ,
206272 noMsi : ! this . options . msi ,
0 commit comments