-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathArchiveTarget.ts
More file actions
112 lines (102 loc) · 3.99 KB
/
ArchiveTarget.ts
File metadata and controls
112 lines (102 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { Arch, defaultArchFromString } from "builder-util"
import * as path from "path"
import { Platform, Target, TargetSpecificOptions } from "../core"
import { copyFiles, getFileMatchers } from "../fileMatcher"
import { ZipOptions } from "../options/macOptions"
import { PlatformPackager } from "../platformPackager"
import { archive, tar } from "./archive"
import { appendBlockmap, createBlockmap } from "./differentialUpdateInfoBuilder"
export class ArchiveTarget extends Target {
readonly options: TargetSpecificOptions = (this.packager.config as any)[this.name] ?? {}
constructor(
name: string,
readonly outDir: string,
private readonly packager: PlatformPackager<any>,
private readonly isWriteUpdateInfo: boolean | null = null
) {
super(name)
}
private shouldWriteUpdateInfo(): boolean {
// Constructor parameter takes precedence (for backward compatibility)
if (this.isWriteUpdateInfo !== null) {
return this.isWriteUpdateInfo
}
// Otherwise read from options, default to true
return (this.options as ZipOptions).writeUpdateInfo !== false
}
async build(appOutDir: string, arch: Arch): Promise<any> {
const packager = this.packager
const isMac = packager.platform === Platform.MAC
const format = this.name
let defaultPattern: string
const defaultArch: Arch = defaultArchFromString(packager.platformSpecificBuildOptions.defaultArch)
if (packager.platform === Platform.LINUX) {
// tslint:disable-next-line:no-invalid-template-strings
defaultPattern = "${name}-${version}" + (arch === defaultArch ? "" : "-${arch}") + ".${ext}"
} else {
// tslint:disable-next-line:no-invalid-template-strings
defaultPattern = "${productName}-${version}" + (arch === defaultArch ? "" : "-${arch}") + "-${os}.${ext}"
}
this.buildQueueManager.add(async () => {
const artifactName = packager.expandArtifactNamePattern(this.options, format, arch, defaultPattern, false)
const artifactPath = path.join(this.outDir, artifactName)
await packager.info.emitArtifactBuildStarted({
targetPresentableName: `${isMac ? "macOS " : ""}${format}`,
file: artifactPath,
arch,
})
let updateInfo: any = null
if (format.startsWith("tar.")) {
await tar(packager.compression, format, artifactPath, appOutDir, isMac, packager.info.tempDirManager)
} else {
let withoutDir = !isMac
let dirToArchive = appOutDir
if (isMac) {
dirToArchive = path.dirname(appOutDir)
const fileMatchers = getFileMatchers(
packager.config,
"extraDistFiles",
dirToArchive,
packager.createGetFileMatchersOptions(this.outDir, arch, packager.platformSpecificBuildOptions)
)
if (fileMatchers == null) {
dirToArchive = appOutDir
} else {
await copyFiles(fileMatchers, null, true)
withoutDir = true
}
}
const archiveOptions = {
compression: packager.compression,
withoutDir,
}
await archive(format, artifactPath, dirToArchive, archiveOptions)
if (this.shouldWriteUpdateInfo() && format === "zip") {
if (isMac) {
updateInfo = await createBlockmap(artifactPath, this, packager, artifactName)
} else {
updateInfo = await appendBlockmap(artifactPath)
}
}
}
await packager.info.emitArtifactBuildCompleted({
updateInfo,
file: artifactPath,
// tslint:disable-next-line:no-invalid-template-strings
safeArtifactName: packager.computeSafeArtifactName(
artifactName,
format,
arch,
false,
packager.platformSpecificBuildOptions.defaultArch,
defaultPattern.replace("${productName}", "${name}")
),
target: this,
arch,
packager,
isWriteUpdateInfo: this.shouldWriteUpdateInfo(),
})
})
return Promise.resolve()
}
}