本文整理汇总了TypeScript中fs-extra-p.emptyDir函数的典型用法代码示例。如果您正苦于以下问题:TypeScript emptyDir函数的具体用法?TypeScript emptyDir怎么用?TypeScript emptyDir使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了emptyDir函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: pack
async pack(outDir: string, arch: string, postAsyncTasks: Array<Promise<any>>): Promise<any> {
if (arch === "ia32") {
warn("For windows consider only distributing 64-bit, see https://github.com/electron-userland/electron-builder/issues/359#issuecomment-214851130")
}
// we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
await this.iconPath
let appOutDir = this.computeAppOutDir(outDir, arch)
const packOptions = this.computePackOptions(outDir, arch)
if (!this.options.dist) {
await this.doPack(packOptions, outDir, appOutDir, arch, this.customBuildOptions)
return
}
const unpackedDir = path.join(outDir, `win${arch === "x64" ? "" : `-${arch}`}-unpacked`)
const finalAppOut = path.join(unpackedDir, "lib", "net45")
const installerOut = computeDistOut(outDir, arch)
log("Removing %s and %s", path.relative(this.projectDir, installerOut), path.relative(this.projectDir, unpackedDir))
await BluebirdPromise.all([
this.packApp(packOptions, appOutDir),
emptyDir(installerOut),
emptyDir(unpackedDir)
])
await move(appOutDir, finalAppOut)
appOutDir = finalAppOut
await this.copyExtraResources(appOutDir, arch, this.customBuildOptions)
if (this.options.dist) {
postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, arch, packOptions))
}
}
示例2: unpack
async function unpack(packager: PlatformPackager<any>, out: string, platform: string, options: any) {
const dist = packager.config.electronDist
if (dist == null) {
const zipPath = (await BluebirdPromise.all<any>([
downloadElectron(options),
emptyDir(out)
]))[0]
await spawn(path7za, debug7zArgs("x").concat(zipPath, `-o${out}`))
}
else {
const source = packager.getElectronSrcDir(dist)
const destination = packager.getElectronDestDir(out)
log(`Copying Electron from "${source}" to "${destination}"`)
await emptyDir(out)
await copyDir(source, destination)
}
if (platform === "linux") {
// https://github.com/electron-userland/electron-builder/issues/786
// fix dir permissions â opposite to extract-zip, 7za creates dir with no-access for other users, but dir must be readable for non-root users
await BluebirdPromise.all([
chmod(path.join(out, "locales"), "0755"),
chmod(path.join(out, "resources"), "0755")
])
}
}
示例3: build
async build(arch: Arch, appOutDir: string) {
if (arch === Arch.ia32) {
warn("For windows consider only distributing 64-bit, see https://github.com/electron-userland/electron-builder/issues/359#issuecomment-214851130")
}
const appInfo = this.packager.appInfo
const version = appInfo.version
const archSuffix = getArchSuffix(arch)
const setupFileName = `${appInfo.productName} Setup ${version}${archSuffix}.exe`
const installerOutDir = path.join(appOutDir, "..", `win${getArchSuffix(arch)}`)
await emptyDir(installerOutDir)
const distOptions = await this.computeEffectiveDistOptions(appOutDir, installerOutDir, setupFileName)
await createWindowsInstaller(distOptions)
this.packager.dispatchArtifactCreated(path.join(installerOutDir, setupFileName), `${appInfo.name}-Setup-${version}${archSuffix}.exe`)
const packagePrefix = `${appInfo.name}-${convertVersion(version)}-`
this.packager.dispatchArtifactCreated(path.join(installerOutDir, `${packagePrefix}full.nupkg`))
if (distOptions.remoteReleases != null) {
this.packager.dispatchArtifactCreated(path.join(installerOutDir, `${packagePrefix}delta.nupkg`))
}
this.packager.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))
}
示例4: 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
}
示例5: pack
async pack(outDir: string, appOutDir: string, arch: string): Promise<any> {
// we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
await this.iconPath
if (!this.options.dist) {
return super.pack(outDir, appOutDir, arch)
}
const installerOut = computeDistOut(outDir, arch)
log("Removing %s", installerOut)
await
BluebirdPromise.all([
this.doPack(outDir, appOutDir, arch),
emptyDir(installerOut)
])
const extraResources = await this.copyExtraResources(appOutDir, arch)
if (extraResources.length > 0) {
this.extraNuGetFileSources = BluebirdPromise.map(extraResources, file => {
return stat(file)
.then(it => {
const relativePath = path.relative(appOutDir, file)
const src = it.isDirectory() ? `${relativePath}${path.sep}**` : relativePath
return `<file src="${src}" target="lib\\net45\\${relativePath.replace(/\//g, "\\")}"/>`
})
})
}
}
示例6: pack
async pack(outDir: string, arch: string, postAsyncTasks: Array<Promise<any>>): Promise<any> {
if (arch === "ia32") {
warn("For windows consider only distributing 64-bit, see https://github.com/electron-userland/electron-builder/issues/359#issuecomment-214851130")
}
// we must check icon before pack because electron-packager uses icon and it leads to cryptic error message "spawn wine ENOENT"
await this.iconPath
const appOutDir = this.computeAppOutDir(outDir, arch)
const packOptions = this.computePackOptions(outDir, appOutDir, arch)
if (!this.options.dist) {
await this.doPack(packOptions, outDir, appOutDir, arch, this.customBuildOptions)
return
}
const installerOut = this.options.dist ? computeDistOut(outDir, arch) : null
await BluebirdPromise.all([
this.packApp(packOptions, appOutDir),
installerOut == null ? BluebirdPromise.resolve() : emptyDir(installerOut)
])
await this.copyExtraResources(appOutDir, arch, this.customBuildOptions)
if (this.options.dist) {
postAsyncTasks.push(this.packageInDistributableFormat(outDir, appOutDir, installerOut!, arch, packOptions))
}
}
示例7: assertPack
export async function assertPack(fixtureName: string, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions = {}): Promise<void> {
if (checkOptions.signed) {
packagerOptions = signed(packagerOptions)
}
if (checkOptions.signedWin) {
packagerOptions.cscLink = WIN_CSC_LINK
packagerOptions.cscKeyPassword = ""
}
else if (packagerOptions.cscLink == null) {
packagerOptions = deepAssign({}, packagerOptions, {config: {mac: {identity: null}}})
}
const projectDirCreated = checkOptions.projectDirCreated
let projectDir = path.join(__dirname, "..", "..", "fixtures", fixtureName)
// const isDoNotUseTempDir = platform === "darwin"
const customTmpDir = process.env.TEST_APP_TMP_DIR
const tmpDir = new TmpDir()
// non-macOS test uses the same dir as macOS test, but we cannot share node_modules (because tests executed in parallel)
const dir = customTmpDir == null ? await tmpDir.createTempDir() : path.resolve(customTmpDir)
if (customTmpDir != null) {
await emptyDir(dir)
log(`Custom temp dir used: ${customTmpDir}`)
}
await copyDir(projectDir, dir, it => {
const basename = path.basename(it)
return basename !== OUT_DIR_NAME && basename !== "node_modules" && !basename.startsWith(".")
}, null, it => path.basename(it) !== "package.json")
projectDir = dir
await executeFinally((async () => {
if (projectDirCreated != null) {
await projectDirCreated(projectDir, tmpDir)
if (checkOptions.installDepsBefore) {
// bin links required (e.g. for node-pre-gyp - if package refers to it in the install script)
await spawn(process.platform === "win32" ? "yarn.cmd" : "yarn", ["install", "--production", "--no-lockfile"], {
cwd: projectDir,
})
}
}
const {packager, outDir} = await packAndCheck({projectDir, ...packagerOptions}, checkOptions)
if (checkOptions.packed != null) {
function base(platform: Platform, arch?: Arch): string {
return path.join(outDir, `${platform.buildConfigurationKey}${getArchSuffix(arch == null ? Arch.x64 : arch)}${platform === Platform.MAC ? "" : "-unpacked"}`)
}
await checkOptions.packed({
projectDir,
outDir,
getResources: (platform, arch) => path.join(base(platform, arch), "resources"),
getContent: platform => base(platform),
packager,
tmpDir,
})
}
})(), () => tmpDir.cleanup())
}
示例8: pack
export async function pack(opts: ElectronPackagerOptions, out: string, platform: string, arch: string, electronVersion: string, initializeApp: () => Promise<any>) {
const zipPath = (await BluebirdPromise.all<any>([
downloadElectron(createDownloadOpts(opts, platform, arch, electronVersion)),
emptyDir(out)
]))[0]
await extract(zipPath, {dir: out})
await require(supportedPlatforms[platform]).createApp(opts, out, initializeApp)
}
示例9: unpack
async function unpack(packager: PlatformPackager<any>, out: string, platform: string, options: InternalElectronDownloadOptions) {
let dist: string | null | undefined = packager.config.electronDist
if (dist != null) {
const zipFile = `electron-v${options.version}-${platform}-${options.arch}.zip`
const resolvedDist = path.resolve(packager.projectDir, dist)
if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) {
options.cache = resolvedDist
dist = null
}
}
if (dist == null) {
const zipPath = (await BluebirdPromise.all<any>([
packager.info.electronDownloader(options),
emptyDir(out)
]))[0]
if (process.platform === "darwin" || isEnvTrue(process.env.USE_UNZIP)) {
// on mac unzip faster than 7za (1.1 sec vs 1.6 see)
await exec("unzip", ["-oqq", "-d", out, zipPath])
}
else {
await spawn(path7za, debug7zArgs("x").concat(zipPath, "-aoa", `-o${out}`))
if (platform === "linux") {
// https://github.com/electron-userland/electron-builder/issues/786
// fix dir permissions â opposite to extract-zip, 7za creates dir with no-access for other users, but dir must be readable for non-root users
await BluebirdPromise.all([
chmod(path.join(out, "locales"), "0755"),
chmod(path.join(out, "resources"), "0755")
])
}
}
}
else {
const source = packager.getElectronSrcDir(dist)
const destination = packager.getElectronDestinationDir(out)
log.info({source, destination}, "copying Electron")
await emptyDir(out)
await copyDir(source, destination, {
isUseHardLink: DO_NOT_USE_HARD_LINKS,
})
}
}
示例10: assertPack
export async function assertPack(fixtureName: string, packagerOptions: PackagerOptions, checkOptions?: AssertPackOptions): Promise<void> {
const tempDirCreated = checkOptions == null ? null : checkOptions.tempDirCreated
const useTempDir = tempDirCreated != null || packagerOptions.devMetadata != null
let projectDir = path.join(__dirname, "..", "..", "fixtures", fixtureName)
// const isDoNotUseTempDir = platform === "darwin"
const customTmpDir = process.env.TEST_APP_TMP_DIR
if (useTempDir) {
// non-osx test uses the same dir as osx test, but we cannot share node_modules (because tests executed in parallel)
const dir = customTmpDir == null ? path.join(tmpdir(), `${tmpDirPrefix}${fixtureName}-${tmpDirCounter++}}`) : path.resolve(customTmpDir)
if (customTmpDir != null) {
console.log("Custom temp dir used: %s", customTmpDir)
}
await emptyDir(dir)
await copy(projectDir, dir, {
filter: it => {
const basename = path.basename(it)
return basename !== outDirName && basename !== "node_modules" && basename[0] !== "."
}
})
projectDir = dir
}
try {
if (tempDirCreated != null) {
await tempDirCreated(projectDir)
}
await packAndCheck(projectDir, Object.assign({
projectDir: projectDir,
cscLink: CSC_LINK,
cscKeyPassword: CSC_KEY_PASSWORD,
cscInstallerLink: CSC_INSTALLER_LINK,
cscInstallerKeyPassword: CSC_INSTALLER_KEY_PASSWORD,
dist: true,
}, packagerOptions), checkOptions)
if (checkOptions != null && checkOptions.packed != null) {
await checkOptions.packed(projectDir)
}
}
finally {
if (useTempDir && customTmpDir == null) {
try {
await remove(projectDir)
}
catch (e) {
console.warn("Cannot delete temporary directory " + projectDir + ": " + (e.stack || e))
}
}
}
}