-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Development dependencies are never copied in any case
You don't need to ignore it explicitly anymore
- Loading branch information
Showing
9 changed files
with
160 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { spawn, debug, debug7zArgs } from "../util" | ||
import { CompressionLevel } from "../metadata" | ||
import * as path from "path" | ||
import { unlink } from "fs-extra-p" | ||
import { path7za } from "7zip-bin" | ||
|
||
//noinspection JSUnusedLocalSymbols | ||
const __awaiter = require("../awaiter") | ||
|
||
class CompressionDescriptor { | ||
constructor(public flag: string, public env: string, public minLevel: string, public maxLevel: string = "-9") { | ||
} | ||
} | ||
|
||
const extToCompressionDescriptor: { [key: string]: CompressionDescriptor; } = { | ||
"tar.xz": new CompressionDescriptor("--xz", "XZ_OPT", "-0", "-9e"), | ||
"tar.lz": new CompressionDescriptor("--lzip", "LZOP", "-0"), | ||
"tar.gz": new CompressionDescriptor("--gz", "GZIP", "-1"), | ||
"tar.bz2": new CompressionDescriptor("--bzip2", "BZIP2", "-1"), | ||
} | ||
|
||
export async function archiveApp(compression: CompressionLevel | n, format: string, outFile: string, dirToArchive: string): Promise<any> { | ||
const storeOnly = compression === "store" | ||
|
||
if (format.startsWith("tar.")) { | ||
// we don't use 7z here - develar: I spent a lot of time making pipe working - but it works on OS X and often hangs on Linux (even if use pipe-io lib) | ||
// and in any case it is better to use system tools (in the light of docker - it is not problem for user because we provide complete docker image). | ||
const info = extToCompressionDescriptor[format] | ||
let tarEnv = process.env | ||
if (compression != null && compression !== "normal") { | ||
tarEnv = Object.assign({}, process.env) | ||
tarEnv[info.env] = storeOnly ? info.minLevel : info.maxLevel | ||
} | ||
|
||
await spawn(process.platform === "darwin" || process.platform === "freebsd" ? "gtar" : "tar", [info.flag, "--transform", `s,^\.,${path.basename(outFile, "." + format)},`, "-cf", outFile, "."], { | ||
cwd: dirToArchive, | ||
stdio: ["ignore", debug.enabled ? "inherit" : "ignore", "inherit"], | ||
env: tarEnv | ||
}) | ||
return | ||
} | ||
|
||
const args = debug7zArgs("a") | ||
if (compression === "maximum") { | ||
if (format === "7z" || format.endsWith(".7z")) { | ||
args.push("-mx=9", "-mfb=64", "-md=32m", "-ms=on") | ||
} | ||
else if (format === "zip") { | ||
// http://superuser.com/a/742034 | ||
//noinspection SpellCheckingInspection | ||
args.push("-mfb=258", "-mpass=15") | ||
} | ||
else { | ||
args.push("-mx=9") | ||
} | ||
} | ||
else if (storeOnly) { | ||
if (format !== "zip") { | ||
args.push("-mx=1") | ||
} | ||
} | ||
|
||
// remove file before - 7z doesn't overwrite file, but update | ||
try { | ||
await unlink(outFile) | ||
} | ||
catch (e) { | ||
// ignore | ||
} | ||
|
||
if (format === "zip" || storeOnly) { | ||
args.push("-mm=" + (storeOnly ? "Copy" : "Deflate")) | ||
} | ||
|
||
args.push(outFile, dirToArchive) | ||
|
||
await spawn(path7za, args, { | ||
cwd: path.dirname(dirToArchive), | ||
stdio: ["ignore", debug.enabled ? "inherit" : "ignore", "inherit"], | ||
}) | ||
} |
Oops, something went wrong.