Skip to content

Commit

Permalink
[cli] Update download function to cache builds
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Jan 30, 2024
1 parent d69ac56 commit 309cee3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/eas-shared/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,21 @@ async function maybeCacheAppAsync(appPath: string, cachedAppPath?: string): Prom
return appPath;
}

export async function downloadAndMaybeExtractAppAsync(
url: string,
cachedAppPath?: string
): Promise<string> {
const outputDir = path.join(getTmpDirectory(), uuidv4());
function _downloadsCacheDirectory() {
const dir = path.join(getTmpDirectory(), 'downloads-cache');
fs.mkdirpSync(dir);
return dir;
}

export async function downloadAndMaybeExtractAppAsync(url: string): Promise<string> {
const name = encodeURIComponent(url.replace(/^[^:]+:\/\//, ''));

const outputDir = path.join(_downloadsCacheDirectory(), `${name}`);
if (await fs.pathExists(outputDir)) {
const appPath = await getAppPathAsync(outputDir, '(apk|app|ipa)');
return appPath;
}

await fs.promises.mkdir(outputDir, { recursive: true });

if (url.endsWith('apk')) {
Expand All @@ -139,7 +149,7 @@ export async function downloadAndMaybeExtractAppAsync(
(ratio, total) => `Downloading app (${formatBytes(total * ratio)} / ${formatBytes(total)})`,
'Successfully downloaded app'
);
return maybeCacheAppAsync(apkFilePath, cachedAppPath);
return maybeCacheAppAsync(apkFilePath, outputDir);
} else {
const tmpArchivePathDir = path.join(getTmpDirectory(), uuidv4());
await fs.mkdir(tmpArchivePathDir, { recursive: true });
Expand All @@ -157,7 +167,7 @@ export async function downloadAndMaybeExtractAppAsync(

const appPath = await getAppPathAsync(outputDir, '(apk|app|ipa)');

return maybeCacheAppAsync(appPath, cachedAppPath);
return appPath;
}
}

Expand Down

0 comments on commit 309cee3

Please sign in to comment.