Skip to content

Commit

Permalink
Use arguments in promise
Browse files Browse the repository at this point in the history
  • Loading branch information
PerThomasHaga committed Jul 15, 2024
1 parent c106304 commit 6877352
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/utils/uploadScreenshots.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { initializeApp, cert, getApps, getApp } from "firebase-admin/app";
import { getStorage } from "firebase-admin/storage";
import { glob } from "glob";
import { execFile } from "child_process";
import { promisify } from "util";
import dotenv from "dotenv";
import * as path from "path";
import * as util from "util";
import * as fs from "fs";

const exec = util.promisify(require("child_process").exec);
const execFilePromise = promisify(execFile);

dotenv.config();

Expand Down Expand Up @@ -74,7 +75,7 @@ async function uploadScreenshots(
async function getScreenshotsFromXcresult(
xcresultPath: string,
destinationPath: string
) {
): Promise<void> {
if (!fs.existsSync(xcresultPath)) {
throw new Error("The specified xcresultPath does not exist.");
}
Expand All @@ -83,17 +84,28 @@ async function getScreenshotsFromXcresult(
fs.mkdirSync(destinationPath, { recursive: true });
}

await exec("brew install imagemagick --quiet");
await exec("brew install chargepoint/xcparse/xcparse --quiet");
await execFilePromise("brew", ["install", "imagemagick", "--quiet"]);
await execFilePromise("brew", [
"install",
"chargepoint/xcparse/xcparse",
"--quiet",
]);

const sanitizedDestinationPath = path.resolve(destinationPath);
const sanitizedXcresultPath = path.resolve(xcresultPath);
await exec(`rm -rf ${sanitizedDestinationPath}`);
await exec(
`xcparse screenshots --test ${sanitizedXcresultPath} ${sanitizedDestinationPath}`
);

await execFilePromise("rm", ["-rf", sanitizedDestinationPath]);
await execFilePromise("xcparse", [
"screenshots",
"--test",
sanitizedXcresultPath,
sanitizedDestinationPath,
]);

const scriptPath = path.resolve(__dirname, "../../dist/scale_screenshots.sh");
await exec(`"${scriptPath}" "${destinationPath}"`, { shell: "/bin/bash" });
await execFilePromise(scriptPath, [sanitizedDestinationPath], {
shell: "/bin/bash",
});
}

async function upload(path: string, destinationPath: string): Promise<string> {
Expand Down

0 comments on commit 6877352

Please sign in to comment.