Skip to content

Commit 302ceac

Browse files
committed
Extract temp dir function
1 parent 014f2aa commit 302ceac

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./cmd";
22
export * from "./gpg";
33
export * from "./os";
44
export * from "./compare-versions";
5+
export * from "./temp-dir";

src/core/temp-dir.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { mkdtempSync } from "fs";
2+
import { tmpdir } from "os";
3+
import { join } from "path";
4+
5+
/**
6+
* Crates a new temporary directory
7+
* @param suffix Suffix to use for the temporary directory
8+
* @returns Temporary directory
9+
*/
10+
export function tempDir(suffix: string = "swiftly-") {
11+
return mkdtempSync(join(tmpdir(), suffix));
12+
}

src/swiftly/swiftly.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { addPath, debug, exportVariable, info } from "@actions/core";
2-
import { cmd } from "../core";
3-
import { existsSync, mkdtempSync } from "fs";
2+
import { cmd, tempDir } from "../core";
3+
import { existsSync } from "fs";
44
import { join } from "path";
5-
import { tmpdir } from "os";
65

76
async function swiftly(...args: string[]) {
87
return await cmd("swiftly", ...args);
98
}
109

1110
function setupPaths() {
12-
const tmpPath = mkdtempSync(join(tmpdir(), "swiftly-"));
11+
const tmpPath = tempDir();
1312

1413
const homeDir = process.env.SWIFTLY_HOME_DIR || join(tmpPath, "home");
1514
const binDir = process.env.SWIFTLY_BIN_DIR || join(tmpPath, "bin");

0 commit comments

Comments
 (0)