Skip to content

Commit

Permalink
feat: make platform and arch optional in downloadArtifact (#109)
Browse files Browse the repository at this point in the history
Fixes #107
  • Loading branch information
MarshallOfSound authored Jul 24, 2019
1 parent 52d9c0e commit 7b1b9c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import debug from 'debug';
import * as path from 'path';

import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifact-utils';
import { ElectronArtifactDetails, ElectronDownloadRequestOptions } from './types';
import {
ElectronArtifactDetails,
ElectronDownloadRequestOptions,
ElectronPlatformArtifactDetailsWithDefaults,
} from './types';
import { Cache } from './Cache';
import { getDownloaderForSystem } from './downloader-resolver';
import {
Expand Down Expand Up @@ -44,10 +48,18 @@ export function download(
*
* @param artifactDetails - The information required to download the artifact
*/
export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails): Promise<string> {
const artifactDetails: ElectronArtifactDetails = {
..._artifactDetails,
};
export async function downloadArtifact(
_artifactDetails: ElectronPlatformArtifactDetailsWithDefaults,
): Promise<string> {
const artifactDetails: ElectronArtifactDetails = _artifactDetails.isGeneric
? {
..._artifactDetails,
}
: {
platform: process.platform,
arch: getHostArch(),
..._artifactDetails,
};
ensureIsTruthyString(artifactDetails, 'version');
artifactDetails.version = normalizeVersion(artifactDetails.version);

Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ export type ElectronArtifactDetails =
| ElectronPlatformArtifactDetails
| ElectronGenericArtifactDetails;

export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

export type ElectronPlatformArtifactDetailsWithDefaults =
| (Omit<ElectronPlatformArtifactDetails, 'platform' | 'arch'> & {
platform?: string;
arch?: string;
})
| ElectronGenericArtifactDetails;

export type DownloadOptions = any;
7 changes: 7 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ describe('Public API', () => {
expect(await fs.readFile(dtsPath, 'utf8')).toContain('declare namespace Electron');
});

it('should work default platform/arch', async () => {
await downloadArtifact({
version: '2.0.3',
artifactName: 'electron',
});
});

it('should work for chromedriver', async () => {
const driverPath = await downloadArtifact({
cacheRoot,
Expand Down

0 comments on commit 7b1b9c1

Please sign in to comment.