本文整理汇总了TypeScript中temp-file.TmpDir类的典型用法代码示例。如果您正苦于以下问题:TypeScript TmpDir类的具体用法?TypeScript TmpDir怎么用?TypeScript TmpDir使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TmpDir类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
test.ifAll.ifDevOrWinCi("web installer", async () => {
let outDirs: Array<string> = []
async function buildApp(version: string, tmpDir: TmpDir) {
await assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget(["nsis-web"], Arch.x64),
config: {
extraMetadata: {
version,
},
// package in any case compressed, customization is explicitly disabled - "do not allow to change compression level to avoid different packages"
compression: process.env.COMPRESSION as any || "store",
publish: {
provider: "s3",
bucket: "develar",
path: "test",
},
},
}, {
signedWin: true,
packed: async context => {
outDirs.push(context.outDir)
},
tmpDir,
})
}
if (process.env.__SKIP_BUILD == null) {
const tmpDir = new TmpDir("differential-updater-test")
try {
await buildApp(OLD_VERSION_NUMBER, tmpDir)
// move dist temporarily out of project dir
const oldDir = await tmpDir.getTempDir()
await move(outDirs[0], oldDir)
outDirs[0] = oldDir
await buildApp("1.0.1", tmpDir)
}
catch (e) {
await tmpDir.cleanup()
throw e
}
// move old dist to new project as oldDist - simplify development (no need to guess where old dist located in the temp fs)
const oldDir = path.join(outDirs[1], "..", "oldDist")
await move(outDirs[0], oldDir)
outDirs[0] = oldDir
await move(path.join(oldDir, "nsis-web", `TestApp-${OLD_VERSION_NUMBER}-x64.nsis.7z`), path.join(getTestUpdaterCacheDir(oldDir), testAppCacheDirName, "package.7z"))
}
else {
nsisWebDifferentialUpdateTestFakeSnapshot()
outDirs = [
path.join(process.env.TEST_APP_TMP_DIR!!, "oldDist"),
path.join(process.env.TEST_APP_TMP_DIR!!, "dist"),
]
}
await testBlockMap(outDirs[0], path.join(outDirs[1], "nsis-web"), NsisUpdater, "win-unpacked", Platform.WINDOWS)
})
示例2: 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())
}
示例3: testLinux
async function testLinux(arch: Arch) {
process.env.TEST_UPDATER_ARCH = Arch[arch]
const outDirs: Array<string> = []
const tmpDir = new TmpDir("differential-updater-test")
try {
await doBuild(outDirs, Platform.LINUX.createTarget(["appimage"], arch), tmpDir)
process.env.APPIMAGE = path.join(outDirs[0], `TestApp-1.0.0-${arch === Arch.x64 ? "x86_64" : "i386"}.AppImage`)
await testBlockMap(outDirs[0], path.join(outDirs[1]), AppImageUpdater, `__appImage-${Arch[arch]}`, Platform.LINUX)
}
finally {
await tmpDir.cleanup()
}
}
示例4: doBuild
async function doBuild(outDirs: Array<string>, targets: Map<Platform, Map<Arch, Array<string>>>, tmpDir: TmpDir, extraConfig?: Configuration | null) {
await buildApp("1.0.0", outDirs, targets, tmpDir, extraConfig)
try {
// move dist temporarily out of project dir
const oldDir = await tmpDir.getTempDir()
await move(outDirs[0], oldDir)
outDirs[0] = oldDir
await buildApp("1.0.1", outDirs, targets, tmpDir, extraConfig)
}
catch (e) {
await tmpDir.cleanup()
throw e
}
// move old dist to new project as oldDist - simplify development (no need to guess where old dist located in the temp fs)
const oldDir = path.join(outDirs[1], "..", "oldDist")
await move(outDirs[0], oldDir)
outDirs[0] = oldDir
}
示例5: transformBackgroundFileIfNeed
export async function transformBackgroundFileIfNeed(file: string, tmpDir: TmpDir): Promise<string> {
if (file.endsWith(".tiff") || file.endsWith(".TIFF")) {
return file
}
const retinaFile = file.replace(/\.([a-z]+)$/, "@2x.$1")
if (await exists(retinaFile)) {
const tiffFile = await tmpDir.getTempFile({suffix: ".tiff"})
await exec("tiffutil", ["-cathidpicheck", file, retinaFile, "-out", tiffFile])
return tiffFile
}
return file
}
示例6: downloadCertificate
export async function downloadCertificate(urlOrBase64: string, tmpDir: TmpDir, currentDir: string): Promise<string> {
urlOrBase64 = urlOrBase64.trim()
let file: string | null = null
if ((urlOrBase64.length > 3 && urlOrBase64[1] === ":") || urlOrBase64.startsWith("/") || urlOrBase64.startsWith(".")) {
file = urlOrBase64
}
else if (urlOrBase64.startsWith("file://")) {
file = urlOrBase64.substring("file://".length)
}
else if (urlOrBase64.startsWith("~/")) {
file = path.join(homedir(), urlOrBase64.substring("~/".length))
}
else {
const isUrl = urlOrBase64.startsWith("https://")
if (isUrl || urlOrBase64.length > 2048 || urlOrBase64.endsWith("=")) {
const tempFile = await tmpDir.getTempFile({suffix: ".p12"})
if (isUrl) {
await download(urlOrBase64, tempFile)
}
else {
await outputFile(tempFile, Buffer.from(urlOrBase64, "base64"))
}
return tempFile
}
else {
file = urlOrBase64
}
}
file = path.resolve(currentDir, file)
const stat = await statOrNull(file)
if (stat == null) {
throw new InvalidConfigurationError(`${file} doesn't exist`)
}
else if (!stat.isFile()) {
throw new InvalidConfigurationError(`${file} not a file`)
}
else {
return file
}
}
示例7: 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)
}
示例8: async
test.ifAll.ifDevOrWinCi("web installer", async () => {
process.env.TEST_UPDATER_PLATFORM = "win32"
let outDirs: Array<string> = []
async function buildApp(version: string) {
await assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget(["nsis-web"], Arch.x64),
config: {
extraMetadata: {
version,
},
// package in any case compressed, customization is explicitly disabled - "do not allow to change compression level to avoid different packages"
compression: process.env.COMPRESSION as any || "store",
publish: {
provider: "s3",
bucket: "develar",
path: "test",
},
},
}, {
signed: true,
packed: async context => {
outDirs.push(context.outDir)
}
})
}
if (process.env.__SKIP_BUILD == null) {
await buildApp("1.0.0")
const tmpDir = new TmpDir()
try {
// move dist temporarily out of project dir
const oldDir = await tmpDir.getTempDir()
await rename(outDirs[0], oldDir)
outDirs[0] = oldDir
await buildApp("1.0.1")
}
catch (e) {
await tmpDir.cleanup()
throw e
}
// move old dist to new project as oldDist - simplify development (no need to guess where old dist located in the temp fs)
const oldDir = path.join(outDirs[1], "..", "oldDist")
await rename(outDirs[0], oldDir)
outDirs[0] = oldDir
await rename(path.join(oldDir, "nsis-web", "TestApp-1.0.0-x64.nsis.7z"), path.join(oldDir, "win-unpacked", "package.7z"))
}
else {
// to avoid snapshot mismatch (since in this node app is not packed)
expect({
win: [
{
file: "latest.yml",
fileContent: {
files: [
{
sha512: "@sha512",
url: "Test App ßW Web Setup 1.0.0.exe",
},
],
packages: {
x64: {
blockMapSize: "@blockMapSize",
headerSize: "@headerSize",
path: "TestApp-1.0.0-x64.nsis.7z",
sha512: "@sha512",
size: "@size",
},
},
path: "Test App ßW Web Setup 1.0.0.exe",
releaseDate: "@releaseDate",
sha2: "@sha2",
sha512: "@sha512",
version: "1.0.0",
},
},
{
arch: "x64",
file: "Test App ßW Web Setup 1.0.0.exe",
safeArtifactName: "TestApp-WebSetup-1.0.0.exe",
updateInfo: {
packages: {
x64: {
blockMapSize: "@blockMapSize",
headerSize: "@headerSize",
path: "TestApp-1.0.0-x64.nsis.7z",
sha512: "@sha512",
size: "@size",
},
},
},
},
{
arch: "x64",
file: "TestApp-1.0.0-x64.nsis.7z",
//.........这里部分代码省略.........
示例9: assertThat
test.ifAll.ifDevOrLinuxCi("download to nonexistent dir", async () => {
const tempFile = await tmpDir.getTempFile()
await httpExecutor.download("https://drive.google.com/uc?export=download&id=0Bz3JwZ-jqfRONTkzTGlsMkM2TlE", tempFile)
await assertThat(tempFile).isFile()
})
示例10:
afterEach(() => tmpDir.cleanup())