-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add os agnostic build system #34
Conversation
Can I test this without having windows somehow? Any idea? :) |
Gave up on it, I built a Windows PC 😄 |
You may want to try Windows in a VirtualBox, that's what I do. |
const { existsSync, writeFileSync } = require('fs') | ||
const { copySync } = require('fs-extra') | ||
const { join } = require('path') | ||
const { platform } = require('os') | ||
const { default: fetch } = require('node-fetch') | ||
const { execSync } = require('child_process') | ||
|
||
const binaries = { | ||
darwin: ['https://github.com/ethersphere/bee/releases/download/v1.5.1/bee-darwin-amd64', 'bee'], | ||
linux: ['https://github.com/ethersphere/bee/releases/download/v1.5.1/bee-linux-amd64', 'bee'], | ||
win32: ['https://github.com/ethersphere/bee/releases/download/v1.5.1/bee-windows-amd64.exe', 'bee.exe'], | ||
} | ||
|
||
module.exports = { | ||
generateAssets: async () => { | ||
const target = binaries[platform()] | ||
if (!existsSync(target[1])) { | ||
await downloadFile(target[0], target[1]) | ||
try { | ||
execSync(`chmod +x ${target[1]}`) | ||
} catch {} | ||
} | ||
}, | ||
postPackage: (_, options) => { | ||
if (existsSync('bee')) { | ||
copySync('bee', join(options.outputPaths[0], 'bee')) | ||
} | ||
if (existsSync('bee.exe')) { | ||
copySync('bee.exe', join(options.outputPaths[0], 'bee.exe')) | ||
} | ||
copySync('tray.png', join(options.outputPaths[0], 'tray.png')) | ||
copySync('tray@2x.png', join(options.outputPaths[0], 'tray@2x.png')) | ||
copySync('icon.png', join(options.outputPaths[0], 'icon.png')) | ||
copySync('static', join(options.outputPaths[0], 'static')) | ||
}, | ||
} | ||
|
||
function downloadFile(url, target) { | ||
return fetch(url) | ||
.then(x => x.arrayBuffer()) | ||
.then(x => writeFileSync(target, Buffer.from(x))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is POC but can these be in typescript? Happy to help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine, it is not very obvious since this script is specified in package.json as a property of forge but I'll check 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and seems to work on mac
const { existsSync, writeFileSync } = require('fs') | ||
const { copySync } = require('fs-extra') | ||
const { join } = require('path') | ||
const { platform } = require('os') | ||
const { default: fetch } = require('node-fetch') | ||
const { execSync } = require('child_process') | ||
|
||
const binaries = { | ||
darwin: ['https://github.com/ethersphere/bee/releases/download/v1.5.1/bee-darwin-amd64', 'bee'], | ||
linux: ['https://github.com/ethersphere/bee/releases/download/v1.5.1/bee-linux-amd64', 'bee'], | ||
win32: ['https://github.com/ethersphere/bee/releases/download/v1.5.1/bee-windows-amd64.exe', 'bee.exe'], | ||
} | ||
|
||
module.exports = { | ||
generateAssets: async () => { | ||
const target = binaries[platform()] | ||
if (!existsSync(target[1])) { | ||
await downloadFile(target[0], target[1]) | ||
try { | ||
execSync(`chmod +x ${target[1]}`) | ||
} catch {} | ||
} | ||
}, | ||
postPackage: (_, options) => { | ||
if (existsSync('bee')) { | ||
copySync('bee', join(options.outputPaths[0], 'bee')) | ||
} | ||
if (existsSync('bee.exe')) { | ||
copySync('bee.exe', join(options.outputPaths[0], 'bee.exe')) | ||
} | ||
copySync('tray.png', join(options.outputPaths[0], 'tray.png')) | ||
copySync('tray@2x.png', join(options.outputPaths[0], 'tray@2x.png')) | ||
copySync('icon.png', join(options.outputPaths[0], 'icon.png')) | ||
copySync('static', join(options.outputPaths[0], 'static')) | ||
}, | ||
} | ||
|
||
function downloadFile(url, target) { | ||
return fetch(url) | ||
.then(x => x.arrayBuffer()) | ||
.then(x => writeFileSync(target, Buffer.from(x))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check? :)
No description provided.