-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f028255
commit abc592b
Showing
1 changed file
with
58 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,79 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const execa = require('execa'); | ||
const { join } = require('path'); | ||
const fetch = require('node-fetch'); | ||
const { copyFileSync, chmodSync, existsSync, mkdirSync } = require('fs'); | ||
const Installer = require('../installer'); | ||
const assert = require('assert');'' | ||
const execa = require('execa');'' | ||
const { platform } = require('../common'); | ||
const { copyFileSync, chmodSync, existsSync, mkdirSync } = require('fs'); | ||
const { join } = require('path'); | ||
|
||
function getFilename() { | ||
switch (platform) { | ||
case 'darwin-x64': | ||
return 'boa-macos-amd64'; | ||
case 'linux-x64': | ||
return 'boa-linux-amd64'; | ||
case 'win32-x64': | ||
return 'boa-windows-amd64'; | ||
default: | ||
throw new Error(`No Boa builds available for ${platform}`); | ||
} | ||
switch (platform) { | ||
case 'darwin-x64': | ||
return 'boa-macos-amd64'; | ||
case 'linux-x64': | ||
return 'boa-linux-amd64'; | ||
case 'win32-x64': | ||
return 'boa-windows-amd64'; | ||
default: | ||
throw new Error(`No Boa builds available for ${platform}`); | ||
} | ||
} | ||
|
||
class BoaInstaller extends Installer { | ||
constructor(...args) { | ||
super(...args); | ||
this.binPath = undefined; | ||
} | ||
constructor(...args) { | ||
super(...args); | ||
this.binPath = undefined; | ||
} | ||
|
||
static resolveVersion(version) { | ||
if (version === 'latest') { | ||
return fetch('https://api.github.com/repos/boa-dev/boa/releases/latest') | ||
.then((r) => r.json()) | ||
.then((r) => r.tag_name); | ||
} | ||
return version; | ||
static resolveVersion(version) { | ||
if (version === 'latest') { | ||
return fetch('https://api.github.com/repos/boa-dev/boa/releases/latest') | ||
.then((r) => r.json()) | ||
.then((r) => r.tag_name); | ||
} | ||
return version; | ||
} | ||
|
||
getDownloadURL(version) { | ||
return `https://github.com/boa-dev/boa/releases/download/${version}/${getFilename()}`; | ||
} | ||
getDownloadURL(version) { | ||
return `https://github.com/boa-dev/boa/releases/download/${version}/${getFilename()}`; | ||
} | ||
|
||
async extract() { | ||
// The file is not zipped so we don't need to do any extraction here, instead just moving it to the extractedPath | ||
// The file doesn't seem to be executable so we need to set it manually | ||
chmodSync(this.downloadPath, '755'); | ||
// Windows will fail if the extractedPath doesn't exist | ||
if (!existsSync(this.extractedPath)){ | ||
mkdirSync(this.extractedPath); | ||
} | ||
return copyFileSync(this.downloadPath, join(this.extractedPath, 'boa')); | ||
async extract() { | ||
// The file is not zipped so we don't need to do any extraction here | ||
// The file doesn't seem to be executable so we need to set it manually | ||
chmodSync(this.downloadPath, '755'); | ||
// Windows will fail if the extractedPath doesn't exist | ||
if (!existsSync(this.extractedPath)) { | ||
mkdirSync(this.extractedPath); | ||
} | ||
return copyFileSync(this.downloadPath, join(this.extractedPath, 'boa')); | ||
} | ||
|
||
async install() { | ||
this.binPath = await this.registerBinary('boa'); | ||
} | ||
async install() { | ||
this.binPath = await this.registerBinary('boa'); | ||
} | ||
|
||
async test() { | ||
const program = 'console.log("42");'; | ||
const output = '42\nundefined'; | ||
async test() { | ||
const program = 'console.log("42");'; | ||
const output = '42\nundefined'; | ||
|
||
assert.strictEqual( | ||
(await execa(this.binPath, [], { input: program })).stdout, | ||
output, | ||
); | ||
} | ||
assert.strictEqual( | ||
(await execa(this.binPath, [], { input: program })).stdout, | ||
output, | ||
); | ||
} | ||
} | ||
|
||
BoaInstaller.config = { | ||
name: 'Boa', | ||
id: 'boa', | ||
supported: [ | ||
'linux-x64', | ||
'win32-x64', | ||
'darwin-x64', | ||
] | ||
name: 'Boa', | ||
id: 'boa', | ||
supported: [ | ||
'linux-x64', | ||
'win32-x64', | ||
'darwin-x64', | ||
], | ||
}; | ||
|
||
|
||
module.exports = BoaInstaller; |