Skip to content

Commit e2cde34

Browse files
radaretrufae
authored andcommitted
Add --tempdir and -T flags
1 parent 2226eb3 commit e2cde34

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

index.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ class Applesign {
9595
}
9696
await this._pullMobileProvision();
9797
this.emit("message", "File: " + this.config.file);
98-
this.emit("message", "Outdir: " + this.config.outdir);
98+
this.emit("message", "Tempdir: " + this.config.tempdir);
9999
if (tools.isDirectory(this.config.file as string)) {
100100
throw new Error("This is a directory");
101101
}
102102
try {
103-
await this.unzipIPA(this.config.file, this.config.outdir);
104-
const appDirectory = path.join(this.config.outdir, "/Payload");
103+
if (!this.config.tempdir) {
104+
throw new Error("No tempdir specified");
105+
}
106+
await this.unzipIPA(this.config.file, this.config.tempdir);
107+
const appDirectory = path.join(this.config.tempdir, "/Payload");
105108
this.config.appdir = getAppDirectory(appDirectory);
106109
if (this.config.debug) {
107110
this.debugObject = {};
@@ -337,7 +340,7 @@ class Applesign {
337340
if (!val) {
338341
return;
339342
}
340-
const f = path.replace(this.config.outdir + "/", "");
343+
const f = path.replace(this.config.tempdir + "/", "");
341344
if (!this.debugObject) {
342345
this.debugObject = {};
343346
}
@@ -829,10 +832,9 @@ class Applesign {
829832
if (this.config.noclean) {
830833
return;
831834
}
832-
const outdir = this.config.outdir;
833-
this.emit("message", "Cleaning up " + outdir);
834-
// await tools.asyncRimraf(this.config.outfile);
835-
return tools.asyncRimraf(outdir);
835+
const tempdir = this.config.tempdir;
836+
this.emit("message", "Cleaning up " + tempdir);
837+
return tools.asyncRimraf(tempdir);
836838
}
837839

838840
async cleanupTmp() {
@@ -847,15 +849,18 @@ class Applesign {
847849
return;
848850
}
849851
const ipaIn = this.config.file as string;
850-
const ipaOut = getOutputPath(this.config.outdir, this.config.outfile!);
852+
if (!this.config.tempdir) {
853+
throw new Error("No tempdir specified");
854+
}
855+
const ipaOut = getOutputPath(this.config.tempdir, this.config.outfile!);
851856
try {
852857
fs.unlinkSync(ipaOut); // await for it
853858
} catch (e) {
854859
/* do nothing */
855860
}
856861
this.events.emit("message", "Zipifying into " + ipaOut + " ...");
857862
const rootFolder = this.config.payloadOnly ? "Payload" : ".";
858-
await tools.zip(this.config.outdir, ipaOut, rootFolder);
863+
await tools.zip(this.config.tempdir, ipaOut, rootFolder);
859864
if (this.config.replaceipa) {
860865
this.events.emit("message", "mv into " + ipaIn);
861866
fs.rename(ipaOut, ipaIn);
@@ -865,23 +870,23 @@ class Applesign {
865870
setFile(name: any) {
866871
fchk(arguments, ["string"]);
867872
this.config.file = path.resolve(name);
868-
this.config.outdir = this.config.file + "." + uuid.v4();
873+
this.config.tempdir ??= this.config.file + "." + uuid.v4();
869874
if (!this.config.outfile) {
870875
this.config.outfile = getResignedFilename(this.config.file);
871876
}
872877
}
873878

874-
async unzipIPA(file: any, outdir: any): Promise<any> {
879+
async unzipIPA(file: any, workdir: any): Promise<any> {
875880
fchk(arguments, ["string", "string"]);
876-
if (!file || !outdir) {
881+
if (!file || !workdir) {
877882
throw new Error("No output specified");
878883
}
879-
if (!outdir) {
884+
if (!workdir) {
880885
throw new Error("Invalid output directory");
881886
}
882887
await this.cleanup();
883888
this.events.emit("message", "Unzipping " + file);
884-
return tools.unzip(file, outdir);
889+
return tools.unzip(file, workdir);
885890
}
886891

887892
/* Event Wrapper API with cb support */
@@ -994,7 +999,7 @@ function runScriptSync(script: string, session: any) {
994999
process.env.APPLESIGN_DIRECTORY = session.config.appdir;
9951000
process.env.APPLESIGN_MAINBIN = session.config.appbin;
9961001
process.env.APPLESIGN_OUTFILE = session.config.outfile;
997-
process.env.APPLESIGN_OUTDIR = session.config.outdir;
1002+
process.env.APPLESIGN_TEMPDIR = session.config.tempdir || "";
9981003
process.env.APPLESIGN_FILE = session.config.file;
9991004
try {
10001005
const res = execSync(script);
@@ -1020,7 +1025,7 @@ function nestedApp(file: string) {
10201025

10211026
function getAppDirectory(this: any, ipadir: string) {
10221027
if (!ipadir) {
1023-
ipadir = path.join(this.config.outdir, "Payload");
1028+
ipadir = path.join(this.config.tempdir, "Payload");
10241029
}
10251030
if (!tools.isDirectory(ipadir)) {
10261031
throw new Error("Not a directory " + ipadir);

lib/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const shortHelpMessage = `Usage:
2020
-m, --mobileprovision [FILE] Specify the mobileprovision file to use
2121
-o, --output [APP.IPA] Path to the output IPA filename
2222
-O, --osversion 9.0 Force specific OSVersion if any in Info.plist
23+
-T, --tempdir [DIR] Path to the output directory for temporary files
2324
-p, --without-plugins Remove plugins (excluding XCTests) from the resigned IPA
2425
-w, --without-watchapp Remove the WatchApp from the IPA before resigning
2526
-x, --without-xctests Remove the XCTests from the resigned IPA
@@ -42,6 +43,7 @@ const helpMessage = `Usage:
4243
-o, --output [APP.IPA] Path to the output IPA filename
4344
-P, --parallel Run layered signing dependencies in parallel (EXPERIMENTAL)
4445
-r, --replace Replace the input IPA file with the resigned one
46+
-T, --tempdir [DIR] Path to the output directory for temporary files
4547
-u, --unfair Resign encrypted applications
4648
-z, --ignore-zip-errors Ignore unzip/7z uncompressing errors
4749
@@ -149,7 +151,7 @@ export interface ConfigOptions {
149151
payloadOnly: boolean;
150152
noclean: boolean;
151153
osversion: any; // opt.osversion || undefined,
152-
outdir: any;
154+
tempdir: string | undefined;
153155
outfile: string | null;
154156
parallel: boolean;
155157
pseudoSign: boolean;
@@ -229,7 +231,7 @@ const fromOptions = function (opt: any): ConfigOptions {
229231
osversion: opt.osversion || undefined,
230232
appbin: undefined,
231233
appdir: undefined,
232-
outdir: undefined,
234+
tempdir: opt.tempdir ? path.resolve(opt.tempdir) : undefined,
233235
payloadOnly: false,
234236
outfile: opt.outfile,
235237
parallel: opt.parallel || false,
@@ -267,6 +269,8 @@ function parse(argv: any) {
267269
"osversion",
268270
"R",
269271
"run",
272+
"T",
273+
"tempdir",
270274
],
271275
boolean: [
272276
"7",
@@ -357,6 +361,7 @@ function compile(conf: any) {
357361
conf.noEntitlementsFile,
358362
noclean: conf.n || conf.noclean,
359363
osversion: conf.osversion || conf.O,
364+
tempdir: conf.tempdir ? path.resolve(conf.tempdir) : undefined,
360365
outfile: (conf.output || conf.o) ? path.resolve(conf.output || conf.o) : "",
361366
parallel: conf.parallel || conf.P,
362367
pseudoSign: conf.Z || conf["pseudo-sign"],

0 commit comments

Comments
 (0)