Skip to content

Commit

Permalink
feat: allow bare version placeholder to be replaced in customDir (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Feb 25, 2020
1 parent 330898b commit b7c50a5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ const nightlyZipFilePath = await download('8.0.0-nightly.20190901', {
// Will download from https://nightly.example.com/nightlies/nightly-linux.zip
```

`customDir` can have the placeholder `{{ version }}`, which will be replaced by the version
specified (without the leading `v`). For example:

```javascript
const zipFilePath = await download('4.0.4', {
mirrorOptions: {
mirror: 'https://mirror.example.com/electron/',
customDir: 'version-{{ version }}',
platform: 'linux',
arch: 'x64'
}
});
// Will download from https://mirror.example.com/electron/version-4.0.4/electron-v4.0.4-linux-x64.zip
```

## How It Works

This module downloads Electron to a known place on your system and caches it
Expand Down
5 changes: 4 additions & 1 deletion src/artifact-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export function getArtifactRemoteURL(details: ElectronArtifactDetails): string {
if (details.version.includes('nightly')) {
base = mirrorVar('nightly_mirror', opts, NIGHTLY_BASE_URL);
}
const path = mirrorVar('customDir', opts, details.version);
const path = mirrorVar('customDir', opts, details.version).replace(
'{{ version }}',
details.version.replace(/^v/, ''),
);
const file = mirrorVar('customFilename', opts, getArtifactFileName(details));

return `${base}${path}/${file}`;
Expand Down
16 changes: 16 additions & 0 deletions test/artifact-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ describe('artifact-utils', () => {
);
});

it('should replace {{ version }} when mirrorOptions.customDir is set', () => {
expect(
getArtifactRemoteURL({
arch: 'x64',
artifactName: 'electron',
mirrorOptions: {
customDir: 'foo{{ version }}bar',
},
platform: 'linux',
version: 'v1.2.3',
}),
).toMatchInlineSnapshot(
`"https://github.com/electron/electron/releases/download/foo1.2.3bar/electron-v1.2.3-linux-x64.zip"`,
);
});

it('should replace the filename when mirrorOptions.customFilename is set', () => {
expect(
getArtifactRemoteURL({
Expand Down

0 comments on commit b7c50a5

Please sign in to comment.