Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,76 @@ export default class SquirrelWindowsTarget extends Target {
fs.copyFileSync(path.join(vendorDirectory, `7z-${resolvedArch}.dll`), path.join(vendorDirectory, "7z.dll"))
}

private async createNuspecTemplateWithProjectUrl() {
private async createNuspecTemplateWithProjectUrl(additionalFiles: { src: string; target: string }[]) {
const templatePath = path.resolve(__dirname, "..", "template.nuspectemplate")
const projectUrl = await this.packager.appInfo.computePackageUrl()

// Always create a customized template to include additionalFiles
const nuspecTemplate = await this.packager.info.tempDirManager.getTempFile({ prefix: "template", suffix: ".nuspectemplate" })
let templateContent = await fs.promises.readFile(templatePath, "utf8")

// Add project URL if available
if (projectUrl != null) {
const nuspecTemplate = await this.packager.info.tempDirManager.getTempFile({ prefix: "template", suffix: ".nuspectemplate" })
let templateContent = await fs.promises.readFile(templatePath, "utf8")
const searchString = "<copyright><%- copyright %></copyright>"
templateContent = templateContent.replace(searchString, `${searchString}\n <projectUrl>${projectUrl}</projectUrl>`)
await fs.promises.writeFile(nuspecTemplate, templateContent)
return nuspecTemplate
}
return templatePath

// Replace the additionalFiles loop with the actual files
if (additionalFiles.length > 0) {
const additionalFilesContent = additionalFiles.map(f => ` <file src="${f.src}" target="${f.target}" />`).join("\n")
templateContent = templateContent.replace('<% file src="additionalFiles.src" target="additionalFiles.target" / %>', additionalFilesContent)
} else {
templateContent = templateContent.replace('<% file src="additionalFiles.src" target="additionalFiles.target" / %>', "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach!

Can you create a const for this? (similar to searchString on line 170)

const additionalFilesReplaceKey = '<% file src="additionalFiles.src" target="additionalFiles.target" / %>'

}

await fs.promises.writeFile(nuspecTemplate, templateContent)
return nuspecTemplate
}

private async getAdditionalFiles(appOutDir: string) {
const files = await fs.promises.readdir(appOutDir, { withFileTypes: true })
const appExe = `${this.exeName}.exe`

const additionalFiles = files.filter(f => {
if (f.isDirectory()) {
// Filter out directories already included in template
return f.name !== "resources" && f.name !== "locales"
}

// Filter out files already included in template.nuspectemplate
const fileName = f.name

// Files explicitly included in template
if (
fileName.endsWith(".bin") ||
fileName.endsWith(".dll") ||
fileName.endsWith(".pak") ||
fileName.endsWith(".exe.config") ||
fileName.endsWith(".exe.sig") ||
fileName.endsWith("_ExecutionStub.exe") ||
fileName === "icudtl.dat" ||
fileName === "Squirrel.exe" ||
fileName === "LICENSE.electron.txt" ||
fileName === "LICENSES.chromium.html" ||
fileName === appExe
) {
return false
}
return true
})

return additionalFiles.map(f => {
if (f.isDirectory()) {
return {
src: `${f.name}\\**`,
target: `lib\\net45\\${f.name}`,
}
}
return {
src: f.name,
target: `lib\\net45\\${f.name}`,
}
})
}

async computeEffectiveDistOptions(appDirectory: string, outputDirectory: string, setupFile: string): Promise<SquirrelOptions> {
Expand All @@ -189,6 +247,7 @@ export default class SquirrelWindowsTarget extends Target {
}
}

const additionalFiles = await this.getAdditionalFiles(appDirectory)
checkConflictingOptions(this.options)
const appInfo = packager.appInfo
const options: SquirrelOptions = {
Expand All @@ -200,7 +259,7 @@ export default class SquirrelWindowsTarget extends Target {
description: appInfo.description,
exe: `${appInfo.productFilename || this.options.name || appInfo.productName}.exe`,
authors: appInfo.companyName || "",
nuspecTemplate: await this.createNuspecTemplateWithProjectUrl(),
nuspecTemplate: await this.createNuspecTemplateWithProjectUrl(additionalFiles),
iconUrl,
copyright: appInfo.copyright,
noMsi: !this.options.msi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
<file src="LICENSE.electron.txt" target="lib\net45\LICENSE.electron.txt" />
<file src="LICENSES.chromium.html" target="lib\net45\LICENSES.chromium.html" />
<file src="<%- exe %>" target="lib\net45\<%- exe %>" />
<% additionalFiles.forEach(function(f) { %>
<file src="<%- f.src %>" target="<%- f.target %>" />
<% }); %>
<% file src="additionalFiles.src" target="additionalFiles.target" / %>
</files>
</package>
1 change: 1 addition & 0 deletions test/snapshots/windows/squirrelWindowsTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ exports[`squirrel.windows > squirrel window x64 msi 2`] = `
"lib/net45/d3dcompiler_47.dll",
"lib/net45/ffmpeg.dll",
"lib/net45/icudtl.dat",
"lib/net45/index.html",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected behavior? If we're testing just extraFiles, then I'd rather it not be the index.html since it may get misconstrued as part of the normal bundle when comparing manually comparing snapshot diffs.

Maybe create a temp file in the unit test?

"lib/net45/libEGL.dll",
"lib/net45/libGLESv2.dll",
"lib/net45/LICENSE.electron.txt",
Expand Down
1 change: 1 addition & 0 deletions test/src/windows/squirrelWindowsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("squirrel.windows", { sequential: true }, () => {
squirrelWindows: {
msi: true,
},
extraFiles: ["index.html"],
},
},
{ signedWin: true }
Expand Down
Loading