本文整理匯總了TypeScript中fs-extra-p.unlink函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript unlink函數的具體用法?TypeScript unlink怎麽用?TypeScript unlink使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了unlink函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: deleteOldElectronVersion
async function deleteOldElectronVersion(): Promise<any> {
if (!process.env.CI) {
return
}
const cacheDir = path.join(require("os").homedir(), ".electron")
try {
const deletePromises: Array<Promise<any>> = []
for (let file of (await readdir(cacheDir))) {
if (file.endsWith(".zip") && !file.includes(electronVersion)) {
console.log("Remove old electron " + file)
deletePromises.push(unlink(path.join(cacheDir, file)))
}
}
return BluebirdPromise.all(deletePromises)
}
catch (e) {
if (e.code === "ENOENT") {
return []
}
else {
throw e
}
}
}
示例2: deleteOldElectronVersion
async function deleteOldElectronVersion(): Promise<any> {
if (!isCi) {
return
}
const cacheDir = require("env-paths")("electron", {suffix: ""}).cache
try {
const deletePromises: Array<Promise<any>> = []
for (const file of (await readdir(cacheDir))) {
if (file.endsWith(".zip") && !file.includes(ELECTRON_VERSION)) {
console.log(`Remove old electron ${file}`)
deletePromises.push(unlink(path.join(cacheDir, file)))
}
}
return await BluebirdPromise.all(deletePromises)
}
catch (e) {
if (e.code === "ENOENT") {
return []
}
else {
throw e
}
}
}
示例3: unlink
return BluebirdPromise.map(readdir(cacheDir), (file): any => {
if (file.endsWith(".zip") && !file.includes(ELECTRON_VERSION)) {
console.log(`Remove old electron ${file}`)
return unlink(path.join(cacheDir, file))
}
return null
})
示例4: modifyPackageJson
export async function modifyPackageJson(projectDir: string, task: (data: any) => void, isApp = false): Promise<any> {
const file = isApp ? path.join(projectDir, "app", "package.json") : path.join(projectDir, "package.json")
const data = await readJson(file)
task(data)
// because copied as hard link
await unlink(file)
return await writeJson(file, data)
}
示例5:
.then(it => {
const deletePromises: Array<Promise<any>> = []
for (let file of it) {
if (file.endsWith(".zip") && !file.includes(electronVersion)) {
console.log("Remove old electron " + file)
deletePromises.push(fs.unlink(path.join(cacheDir, file)))
}
}
return BluebirdPromise.all(deletePromises)
})
示例6: msi
async function msi(options: SquirrelOptions, nupkgPath: string, setupPath: string, outputDirectory: string, outFile: string) {
const args = [
"--createMsi", nupkgPath,
"--bootstrapperExe", setupPath
]
await exec(process.platform === "win32" ? path.join(options.vendorPath, "Update.com") : "mono", prepareArgs(args, path.join(options.vendorPath, "Update-Mono.exe")))
//noinspection SpellCheckingInspection
await exec(path.join(options.vendorPath, "candle.exe"), ["-nologo", "-ext", "WixNetFxExtension", "-out", "Setup.wixobj", "Setup.wxs"], {
cwd: outputDirectory,
})
//noinspection SpellCheckingInspection
await exec(path.join(options.vendorPath, "light.exe"), ["-ext", "WixNetFxExtension", "-sval", "-out", outFile, "Setup.wixobj"], {
cwd: outputDirectory,
})
//noinspection SpellCheckingInspection
await BluebirdPromise.all([
unlink(path.join(outputDirectory, "Setup.wxs")),
unlink(path.join(outputDirectory, "Setup.wixobj")),
unlink(path.join(outputDirectory, outFile.replace(".msi", ".wixpdb"))).catch(e => debug(e.toString())),
])
}
示例7: copyFile
projectDirCreated: async projectDir => {
const resourceDir = path.join(projectDir, "build")
await copyFile(path.join(getDmgTemplatePath(), "background.tiff"), path.join(resourceDir, "background.tiff"))
async function extractPng(index: number, suffix: string) {
await exec("tiffutil", ["-extract", index.toString(), path.join(getDmgTemplatePath(), "background.tiff")], {
cwd: projectDir
})
await exec("sips", ["-s", "format", "png", "out.tiff", "--out", `background${suffix}.png`], {
cwd: projectDir
})
}
await extractPng(0, "")
await extractPng(1, "@2x")
await unlink(path.join(resourceDir, "background.tiff"))
},
示例8: async
task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {
const packageInfo = fileInfo.packageInfo
const isWebInstaller = packageInfo != null && packageFile != null
if (isWebInstaller || await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider)) {
await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)
}
const signatureVerificationStatus = await this.verifySignature(destinationFile)
if (signatureVerificationStatus != null) {
await removeTempDirIfAny()
// noinspection ThrowInsideFinallyBlockJS
throw newError(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, "ERR_UPDATER_INVALID_SIGNATURE")
}
if (isWebInstaller) {
if (await this.differentialDownloadWebPackage(packageInfo!!, packageFile!!, provider)) {
try {
await this.httpExecutor.download(new URL(packageInfo!!.path), packageFile!!, {
headers: downloadUpdateOptions.requestHeaders,
cancellationToken: downloadUpdateOptions.cancellationToken,
sha512: packageInfo!!.sha512,
})
}
catch (e) {
try {
await unlink(packageFile!!)
}
catch (ignored) {
// ignore
}
throw e
}
}
}
},
示例9: unlink
projectDirCreated: projectDir => Promise.all([
unlink(path.join(projectDir, "build", "icon.ico")),
remove(path.join(projectDir, "build", "icons")),
]),
示例10: unlink
projectDirCreated: projectDir => Promise.all([
unlink(path.join(projectDir, "build", "icon.icns")),
unlink(path.join(projectDir, "build", "icon.ico")),
copy(path.join(projectDir, "build", "icons", "512x512.png"), path.join(projectDir, "build", "icon.png"))
.then(() => remove(path.join(projectDir, "build", "icons")))
]),
示例11: unlinkIfExists
export function unlinkIfExists(file: string) {
return unlink(file)
.catch(() => {/* ignore */})
}
示例12: doGetBin
// we cache in the global location - in the home dir, not in the node_modules/.cache (https://www.npmjs.com/package/find-cache-dir) because
// * don't need to find node_modules
// * don't pollute user project dir (important in case of 1-package.json project structure)
// * simplify/speed-up tests (don't download fpm for each test project)
async function doGetBin(name: string, dirName: string, url: string, checksum: string): Promise<string> {
const cachePath = path.join(getCacheDirectory(), name)
const dirPath = path.join(cachePath, dirName)
const logFlags = {path: dirPath}
const dirStat = await statOrNull(dirPath)
if (dirStat != null && dirStat.isDirectory()) {
log.debug(logFlags, "found existing")
return dirPath
}
log.info({...logFlags, url}, "downloading")
// 7z cannot be extracted from the input stream, temp file is required
const tempUnpackDir = path.join(cachePath, getTempName())
const archiveName = `${tempUnpackDir}.7z`
// 7z doesn't create out dir, so, we don't create dir in parallel to download - dir creation will create parent dirs for archive file also
await emptyDir(tempUnpackDir)
const options: DownloadOptions = {
skipDirCreation: true,
cancellationToken: new CancellationToken(),
}
if (checksum.length === 64 && !checksum.includes("+") && !checksum.includes("Z") && !checksum.includes("=")) {
(options as any).sha2 = checksum
}
else {
(options as any).sha512 = checksum
}
for (let attemptNumber = 1; attemptNumber < 4; attemptNumber++) {
try {
await httpExecutor.download(url, archiveName, options)
}
catch (e) {
if (attemptNumber >= 3) {
throw e
}
log.warn({...logFlags, attempt: attemptNumber}, `cannot download: ${e}`)
await new BluebirdPromise((resolve, reject) => {
setTimeout(() =>
httpExecutor
.download(url, archiveName, options)
.then(resolve).catch(reject), 1000 * attemptNumber)
})
}
}
await spawn(path7za, debug7zArgs("x").concat(archiveName, `-o${tempUnpackDir}`), {
cwd: cachePath,
})
await BluebirdPromise.all([
rename(tempUnpackDir, dirPath)
.catch(e => log.debug({...logFlags, tempUnpackDir, e}, `cannot move downloaded into final location (another process downloaded faster?)`)),
unlink(archiveName),
])
log.debug(logFlags, `downloaded`)
return dirPath
}