Skip to content

Commit

Permalink
Merge pull request #87 from electron-userland/arch-api-and-docs
Browse files Browse the repository at this point in the history
Update arch API/docs
  • Loading branch information
malept authored May 20, 2019
2 parents 1696232 + c8ba108 commit 94382c7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
### Simple: Downloading an Electron Binary ZIP

```js
import { downloadElectron } from '@electron/download';
import { download } from '@electron/download';

const zipFilePath = await downloadElectron('4.0.4');
const zipFilePath = await download('4.0.4');
```

### Advanced: Downloading a macOS Electron Symbol File


```js
import { downloadElectron } from '@electron/download';
import { downloadArtifact } from '@electron/download';

const zipFilePath = await downloadElectron({
const zipFilePath = await downloadArtifact({
version: '4.0.4',
platform: 'darwin',
assetName: 'electron',
assetSuffix: 'symbols',
artifactName: 'electron',
artifactSuffix: 'symbols',
arch: 'x64',
});
```
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifa
import { ElectronArtifactDetails, ElectronDownloadRequestOptions } from './types';
import { Cache } from './Cache';
import { getDownloaderForSystem } from './downloader-resolver';
import { withTempDirectory, normalizeVersion, getArch } from './utils';
import { withTempDirectory, normalizeVersion, getHostArch } from './utils';

export { getHostArch } from './utils';

/**
* Downloads a specific version of Electron and returns an absolute path to a
Expand All @@ -21,7 +23,7 @@ export function download(
...options,
version,
platform: process.platform,
arch: getArch(),
arch: getHostArch(),
artifactName: 'electron',
});
}
Expand Down
17 changes: 15 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,29 @@ export function normalizeVersion(version: string) {
return version;
}

/**
* Runs the `uname` command and returns the trimmed output.
*/
export function uname() {
return childProcess
.execSync('uname -m')
.toString()
.trim();
}

export function getArch() {
const arch = process.arch;
/**
* Generates an architecture name that would be used in an Electron or Node.js
* download file name, from the `process` module information.
*/
export function getHostArch() {
return getNodeArch(process.arch);
}

/**
* Generates an architecture name that would be used in an Electron or Node.js
* download file name.
*/
export function getNodeArch(arch: string) {
if (arch === 'arm') {
switch ((process.config.variables as any).arm_version) {
case '6':
Expand Down
20 changes: 8 additions & 12 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs-extra';

import { normalizeVersion, uname, withTempDirectory, getArch } from '../src/utils';
import { normalizeVersion, uname, withTempDirectory, getHostArch } from '../src/utils';

describe('utils', () => {
describe('normalizeVersion()', () => {
Expand All @@ -16,11 +16,7 @@ describe('utils', () => {
describe('uname()', () => {
if (process.platform !== 'win32') {
it('should return the correct arch for your system', () => {
if (process.platform === 'darwin') {
expect(uname()).toEqual('x86_64');
} else {
expect(uname()).toEqual('x64');
}
expect(uname()).toEqual('x86_64');
});
}
});
Expand Down Expand Up @@ -59,7 +55,7 @@ describe('utils', () => {
});
});

describe('getArch()', () => {
describe('getHostArch()', () => {
let savedArch: string;
let savedVariables: any;

Expand All @@ -79,22 +75,22 @@ describe('utils', () => {
Object.defineProperty(process, 'arch', {
value: 'x64',
});
expect(getArch()).toEqual('x64');
expect(getHostArch()).toEqual('x64');
});

it('should return process.arch on ia32', () => {
Object.defineProperty(process, 'arch', {
value: 'ia32',
});
expect(getArch()).toEqual('ia32');
expect(getHostArch()).toEqual('ia32');
});

it('should return process.arch on unknown arm', () => {
Object.defineProperty(process, 'arch', {
value: 'arm',
});
process.config.variables = {} as any;
expect(getArch()).toEqual('arm');
expect(getHostArch()).toEqual('arm');
});

it('should return uname on arm 6', () => {
Expand All @@ -103,7 +99,7 @@ describe('utils', () => {
value: 'arm',
});
process.config.variables = { arm_version: '6' } as any;
expect(getArch()).toEqual(uname());
expect(getHostArch()).toEqual(uname());
}
});

Expand All @@ -112,7 +108,7 @@ describe('utils', () => {
value: 'arm',
});
process.config.variables = { arm_version: '7' } as any;
expect(getArch()).toEqual('armv7l');
expect(getHostArch()).toEqual('armv7l');
});
});
});

0 comments on commit 94382c7

Please sign in to comment.