本文整理汇总了TypeScript中builder-util/out/fs.unlinkIfExists函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unlinkIfExists函数的具体用法?TypeScript unlinkIfExists怎么用?TypeScript unlinkIfExists使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unlinkIfExists函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: prepareWine
async prepareWine(wineDir: string) {
await emptyDir(wineDir)
//noinspection SpellCheckingInspection
const env = Object.assign({}, process.env, {
WINEDLLOVERRIDES: "winemenubuilder.exe=d",
WINEPREFIX: wineDir
})
await exec("wineboot", ["--init"], {env: env})
// regedit often doesn't modify correctly
let systemReg = await readFile(path.join(wineDir, "system.reg"), "utf8")
systemReg = systemReg.replace('"CSDVersion"="Service Pack 3"', '"CSDVersion"=" "')
systemReg = systemReg.replace('"CurrentBuildNumber"="2600"', '"CurrentBuildNumber"="10240"')
systemReg = systemReg.replace('"CurrentVersion"="5.1"', '"CurrentVersion"="10.0"')
systemReg = systemReg.replace('"ProductName"="Microsoft Windows XP"', '"ProductName"="Microsoft Windows 10"')
systemReg = systemReg.replace('"CSDVersion"=dword:00000300', '"CSDVersion"=dword:00000000')
await writeFile(path.join(wineDir, "system.reg"), systemReg)
// remove links to host OS
const desktopDir = path.join(this.userDir, "Desktop")
await BluebirdPromise.all([
unlinkIfExists(desktopDir),
unlinkIfExists(path.join(this.userDir, "My Documents")),
unlinkIfExists(path.join(this.userDir, "My Music")),
unlinkIfExists(path.join(this.userDir, "My Pictures")),
unlinkIfExists(path.join(this.userDir, "My Videos")),
])
await ensureDir(desktopDir)
return env
}
示例2: archive
export async function archive(format: string, outFile: string, dirToArchive: string, options: ArchiveOptions = {}): Promise<string> {
const args = compute7zCompressArgs(format, options)
// remove file before - 7z doesn't overwrite file, but update
await unlinkIfExists(outFile)
args.push(outFile, options.withoutDir ? "." : path.basename(dirToArchive))
if (options.excluded != null) {
for (const mask of options.excluded) {
args.push(`-xr!${mask}`)
}
}
try {
await exec(path7za, args, {
cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive),
}, debug7z.enabled)
}
catch (e) {
if (e.code === "ENOENT" && !(await exists(dirToArchive))) {
throw new Error(`Cannot create archive: "${dirToArchive}" doesn't exist`)
}
else {
throw e
}
}
return outFile
}
示例3: createSelfSignedCert
export async function createSelfSignedCert(publisher: string) {
const tmpDir = new TmpDir()
const targetDir = process.cwd()
const tempPrefix = path.join(await tmpDir.getTempDir({prefix: "self-signed-cert-creator"}), sanitizeFileName(publisher))
const cer = `${tempPrefix}.cer`
const pvk = `${tempPrefix}.pvk`
log.info(chalk.bold('When asked to enter a password ("Create Private Key Password"), please select "None".'))
try {
await ensureDir(path.dirname(tempPrefix))
const vendorPath = path.join(await getSignVendorPath(), "windows-10", process.arch)
await exec(path.join(vendorPath, "makecert.exe"),
["-r", "-h", "0", "-n", `CN=${quoteString(publisher)}`, "-eku", "1.3.6.1.5.5.7.3.3", "-pe", "-sv", pvk, cer])
const pfx = path.join(targetDir, `${sanitizeFileName(publisher)}.pfx`)
await unlinkIfExists(pfx)
await exec(path.join(vendorPath, "pvk2pfx.exe"), ["-pvk", pvk, "-spc", cer, "-pfx", pfx])
log.info({file: pfx}, `created. Please see https://electron.build/code-signing how to use it to sign.`)
const certLocation = "Cert:\\LocalMachine\\TrustedPeople"
log.info({file: pfx, certLocation}, `importing. Operation will be succeed only if runned from root. Otherwise import file manually.`)
await spawn("powershell.exe", ["Import-PfxCertificate", "-FilePath", `"${pfx}"`, "-CertStoreLocation", ""])
}
finally {
await tmpDir.cleanup()
}
}
示例4: removeKeychain
async function removeKeychain(keychainFile: string) {
try {
await exec("security", ["delete-keychain", keychainFile])
}
catch (e) {
console.warn(`Cannot delete keychain ${keychainFile}: ${e.stack || e}`)
await unlinkIfExists(keychainFile)
}
}
示例5: tar
export async function tar(compression: CompressionLevel | any | any, format: string, outFile: string, dirToArchive: string, isMacApp: boolean, tempDirManager: TmpDir): Promise<void> {
const tarFile = await tempDirManager.getTempFile({suffix: ".tar"})
const tarArgs = debug7zArgs("a")
tarArgs.push(tarFile)
tarArgs.push(path.basename(dirToArchive))
await Promise.all([
exec(path7za, tarArgs, {cwd: path.dirname(dirToArchive)}),
// remove file before - 7z doesn't overwrite file, but update
unlinkIfExists(outFile),
])
if (!isMacApp) {
await exec(path7za, ["rn", tarFile, path.basename(dirToArchive), path.basename(outFile, `.${format}`)])
}
if (format === "tar.lz") {
// noinspection SpellCheckingInspection
let lzipPath = "lzip"
if (process.platform === "darwin") {
lzipPath = path.join(await getLinuxToolsPath(), "bin", lzipPath)
}
await exec(lzipPath, [compression === "store" ? "-1" : "-9", "--keep" /* keep (don't delete) input files */, tarFile])
// bloody lzip creates file in the same dir where input file with postfix `.lz`, option --output doesn't work
await move(`${tarFile}.lz`, outFile)
return
}
const args = compute7zCompressArgs(format === "tar.xz" ? "xz" : (format === "tar.bz2" ? "bzip2" : "gzip"), {
isRegularFile: true,
method: "DEFAULT",
compression,
})
args.push(outFile, tarFile)
await exec(path7za, args, {
cwd: path.dirname(dirToArchive),
}, debug7z.enabled)
}
示例6: createMacApp
//.........这里部分代码省略.........
const oldIcon = appPlist.CFBundleIconFile
if (icon != null) {
appPlist.CFBundleIconFile = `${appFilename}.icns`
}
appPlist.CFBundleDisplayName = appInfo.productName
appPlist.CFBundleIdentifier = appBundleIdentifier
appPlist.CFBundleName = appInfo.productName
// https://github.com/electron-userland/electron-builder/issues/1278
appPlist.CFBundleExecutable = !appFilename.endsWith(" Helper") ? appFilename : appFilename.substring(0, appFilename.length - " Helper".length)
helperPlist.CFBundleExecutable = `${appFilename} Helper`
helperEHPlist.CFBundleExecutable = `${appFilename} Helper EH`
helperNPPlist.CFBundleExecutable = `${appFilename} Helper NP`
helperPlist.CFBundleDisplayName = `${appInfo.productName} Helper`
helperEHPlist.CFBundleDisplayName = `${appInfo.productName} Helper EH`
helperNPPlist.CFBundleDisplayName = `${appInfo.productName} Helper NP`
helperPlist.CFBundleIdentifier = helperBundleIdentifier
helperEHPlist.CFBundleIdentifier = `${helperBundleIdentifier}.EH`
helperNPPlist.CFBundleIdentifier = `${helperBundleIdentifier}.NP`
appPlist.CFBundleShortVersionString = macOptions.bundleShortVersion || appInfo.version
appPlist.CFBundleVersion = appInfo.buildVersion
const protocols = asArray(buildMetadata.protocols).concat(asArray(packager.platformSpecificBuildOptions.protocols))
if (protocols.length > 0) {
appPlist.CFBundleURLTypes = protocols.map(protocol => {
const schemes = asArray(protocol.schemes)
if (schemes.length === 0) {
throw new Error(`Protocol "${protocol.name}": must be at least one scheme specified`)
}
return {
CFBundleURLName: protocol.name,
CFBundleTypeRole: protocol.role || "Editor",
CFBundleURLSchemes: schemes.slice()
}
})
}
const resourcesPath = path.join(contentsPath, "Resources")
const fileAssociations = packager.fileAssociations
if (fileAssociations.length > 0) {
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const extensions = asArray(fileAssociation.ext).map(normalizeExt)
const customIcon = await packager.getResource(getPlatformIconFileName(fileAssociation.icon, true), `${extensions[0]}.icns`)
let iconFile = appPlist.CFBundleIconFile
if (customIcon != null) {
iconFile = path.basename(customIcon)
await copyOrLinkFile(customIcon, path.join(resourcesPath, iconFile))
}
const result = {
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name || extensions[0],
CFBundleTypeRole: fileAssociation.role || "Editor",
CFBundleTypeIconFile: iconFile
} as any
if (fileAssociation.isPackage) {
result.LSTypeIsPackage = true
}
return result
})
}
use(packager.platformSpecificBuildOptions.category || (buildMetadata as any).category, it => appPlist.LSApplicationCategoryType = it)
appPlist.NSHumanReadableCopyright = appInfo.copyright
if (asarIntegrity != null) {
appPlist.AsarIntegrity = JSON.stringify(asarIntegrity)
}
const promises: Array<Promise<any | null | undefined>> = [
writeFile(appPlistFilename, buildPlist(appPlist)),
writeFile(helperPlistFilename, buildPlist(helperPlist)),
writeFile(helperEHPlistFilename, buildPlist(helperEHPlist)),
writeFile(helperNPPlistFilename, buildPlist(helperNPPlist)),
doRename(path.join(contentsPath, "MacOS"), packager.electronDistMacOsExecutableName, appPlist.CFBundleExecutable),
unlinkIfExists(path.join(appOutDir, "LICENSE")),
unlinkIfExists(path.join(appOutDir, "LICENSES.chromium.html")),
]
if (icon != null) {
promises.push(unlinkIfExists(path.join(resourcesPath, oldIcon)))
promises.push(copyFile(icon, path.join(resourcesPath, appPlist.CFBundleIconFile)))
}
await BluebirdPromise.all(promises)
await moveHelpers(frameworksPath, appFilename, packager.electronDistMacOsExecutableName)
const appPath = path.join(appOutDir, `${appFilename}.app`)
await rename(path.dirname(contentsPath), appPath)
// https://github.com/electron-userland/electron-builder/issues/840
const now = Date.now() / 1000
await utimes(appPath, now, now)
}
示例7: createMacApp
//.........这里部分代码省略.........
configureLocalhostAts(appPlist)
}
helperPlist.CFBundleExecutable = `${appFilename} Helper`
helperPlist.CFBundleDisplayName = `${appInfo.productName} Helper`
helperPlist.CFBundleIdentifier = helperBundleIdentifier
helperPlist.CFBundleVersion = appPlist.CFBundleVersion
function configureHelper(helper: any, postfix: string) {
helper.CFBundleExecutable = `${appFilename} Helper ${postfix}`
helper.CFBundleDisplayName = `${appInfo.productName} Helper ${postfix}`
helper.CFBundleIdentifier = `${helperBundleIdentifier}.${postfix}`
helper.CFBundleVersion = appPlist.CFBundleVersion
}
if (helperEHPlist != null) {
configureHelper(helperEHPlist, "EH")
}
if (helperNPPlist != null) {
configureHelper(helperNPPlist, "NP")
}
if (helperLoginPlist != null) {
helperLoginPlist.CFBundleExecutable = `${appFilename} Login Helper`
helperLoginPlist.CFBundleDisplayName = `${appInfo.productName} Login Helper`
// noinspection SpellCheckingInspection
helperLoginPlist.CFBundleIdentifier = `${appInfo.macBundleIdentifier}.loginhelper`
helperLoginPlist.CFBundleVersion = appPlist.CFBundleVersion
}
const protocols = asArray(buildMetadata.protocols).concat(asArray(packager.platformSpecificBuildOptions.protocols))
if (protocols.length > 0) {
appPlist.CFBundleURLTypes = protocols.map(protocol => {
const schemes = asArray(protocol.schemes)
if (schemes.length === 0) {
throw new InvalidConfigurationError(`Protocol "${protocol.name}": must be at least one scheme specified`)
}
return {
CFBundleURLName: protocol.name,
CFBundleTypeRole: protocol.role || "Editor",
CFBundleURLSchemes: schemes.slice()
}
})
}
const fileAssociations = packager.fileAssociations
if (fileAssociations.length > 0) {
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const extensions = asArray(fileAssociation.ext).map(normalizeExt)
const customIcon = await packager.getResource(getPlatformIconFileName(fileAssociation.icon, true), `${extensions[0]}.icns`)
let iconFile = appPlist.CFBundleIconFile
if (customIcon != null) {
iconFile = path.basename(customIcon)
await copyOrLinkFile(customIcon, path.join(path.join(contentsPath, "Resources"), iconFile))
}
const result = {
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name || extensions[0],
CFBundleTypeRole: fileAssociation.role || "Editor",
CFBundleTypeIconFile: iconFile
} as any
if (fileAssociation.isPackage) {
result.LSTypeIsPackage = true
}
return result
})
}
if (asarIntegrity != null) {
appPlist.AsarIntegrity = JSON.stringify(asarIntegrity)
}
await Promise.all([
writeFile(appPlistFilename, buildPlist(appPlist)),
writeFile(helperPlistFilename, buildPlist(helperPlist)),
helperEHPlist == null ? Promise.resolve() : writeFile(helperEHPlistFilename, buildPlist(helperEHPlist)),
helperNPPlist == null ? Promise.resolve() : writeFile(helperNPPlistFilename, buildPlist(helperNPPlist)),
helperLoginPlist == null ? Promise.resolve() : writeFile(helperLoginPlistFilename, buildPlist(helperLoginPlist)),
doRename(path.join(contentsPath, "MacOS"), packager.electronDistMacOsExecutableName, appPlist.CFBundleExecutable),
unlinkIfExists(path.join(appOutDir, "LICENSE")),
unlinkIfExists(path.join(appOutDir, "LICENSES.chromium.html")),
])
await moveHelpers(getAvailableHelperSuffixes(helperEHPlist, helperNPPlist), frameworksPath, appFilename, packager.electronDistMacOsExecutableName)
if (helperLoginPlist != null) {
const prefix = packager.electronDistMacOsExecutableName
const suffix = " Login Helper"
const executableBasePath = path.join(loginItemPath, `${prefix}${suffix}.app`, "Contents", "MacOS")
await doRename(executableBasePath, `${prefix}${suffix}`, appFilename + suffix)
.then(() => doRename(loginItemPath, `${prefix}${suffix}.app`, `${appFilename}${suffix}.app`))
}
const appPath = path.join(appOutDir, `${appFilename}.app`)
await rename(path.dirname(contentsPath), appPath)
// https://github.com/electron-userland/electron-builder/issues/840
const now = Date.now() / 1000
await utimes(appPath, now, now)
}