package.install.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of conveyor Show documentation
Show all versions of conveyor Show documentation
Conveyor makes distributing desktop and command line apps as easy as shipping a web app.
The newest version!
const axios = require('axios');
const extract = require('extract-zip');
const fs = require('fs');
const path = require('path');
const pjson = require('./package.json');
const process = require('process');
const tar = require('tar');
const {rimraf} = require('rimraf');
const binDir = path.join(__dirname, 'bin');
const destDir = path.join(binDir, 'install');
async function install(url, script, ext='') {
// If there is a previous installation, just leave it alone.
if (fs.existsSync(destDir)) {
return;
}
const tmpDir = path.join(binDir, '.tmp-install')
fs.mkdirSync(tmpDir, {recursive: true});
const response = await axios.get(url, {
responseType: 'arraybuffer'
});
const archivePath = path.join(binDir, '.temp');
fs.writeFileSync(archivePath, response.data);
try {
if (url.endsWith('.zip')) {
await extract(archivePath, { dir: tmpDir });
} else {
await tar.extract({
file: archivePath,
cwd: tmpDir,
strip: 1
});
}
// Remove stub that only exists so npm creates a link to the executable.
await rimraf(path.join(binDir, 'conveyor'));
const bin = path.join(binDir, 'conveyor' + ext);
fs.copyFileSync(path.join(binDir, script), bin);
// Rename atomically as the last step, so we know that if the installation path exists, it is complete and consistent.
fs.renameSync(tmpDir, destDir);
} finally {
rimraf(archivePath);
// In case something went wrong, clean up the temporary dir.
rimraf(tmpDir);
}
}
function parse_version() {
const parts = pjson.version.split('.');
// Only include revision number if it is larger than zero.
if (parseInt(parts[2], 10) != 0) {
return `${parts[0]}.${parts[1]}-${parts[2]}`;
}
return `${parts[0]}.${parts[1]}`;
}
const version = parse_version();
const prefix = `https://downloads.hydraulic.dev/conveyor/conveyor-${version}`;
if (process.platform == 'darwin') {
if (process.arch == 'arm64') {
install(`${prefix}-mac-aarch64.zip`, 'conveyor.mac');
} else {
install(`${prefix}-mac-amd64.zip`, 'conveyor.mac');
}
} else if (process.platform == 'win32') {
install(`${prefix}-windows-amd64.zip`, 'conveyor.win', '.bat');
} else if (process.platform == 'linux') {
install(`${prefix}-linux-amd64.tar.gz`, 'conveyor.linux');
} else {
throw new Error(`Platform ${process.platform} currently not supported`);
}