refactor: Use platform helper instead of os api in desktop

This commit is contained in:
Susmitha Girumala committed 2021-05-24 10:41:09 -04:00
1 parent d572d5157d
commit 89891a401a
5 files changed
+893 -1106

No files matched your search

+20 -15
View File
@@ -1,34 +1,39 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const https = require('https');
const decompress = require('decompress');
const os = require('os');
const { isMac, isWindows } = require('../src/helpers/platform.js');
const artifactVersion = '0.2.2';
const artifactDestination = path.resolve(__dirname, '..', 'cli');
const platform = {
name: 'darwin',
arch: 'amd64',
};
if(os.type().match(/(windows)/i)) {
platform.name = 'windows';
arch = 'amd64';
}
const downloadArtifact = (version) => {
const archivePlatform = {};
// TODO: Support all available build machines
if (isMac) {
archivePlatform.name = 'darwin';
archivePlatform.arch = 'amd64';
}
const downloadArtifact = version => {
const url = `https://releases.hashicorp.com/boundary/${version}/boundary_${version}_${platform.name}_${platform.arch}.zip`;
if (isWindows) {
archivePlatform.name = 'windows';
archivePlatform.arch = 'amd64';
}
const archiveName = `boundary_${version}_${archivePlatform.name}_${archivePlatform.arch}.zip`;
const url = `https://releases.hashicorp.com/boundary/${version}/${archiveName}`;
return new Promise((resolve, reject) => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'boundary-artifact-'));
console.log('Create tmp artifact directory: ', tmpDir);
const artifactFileName = url.split('/').pop();
if(!artifactFileName) reject('Could not find artifact filename in: ', url);
if (!artifactFileName) reject('Could not find artifact filename in: ', url);
const artifactPath = path.resolve(tmpDir, artifactFileName);
console.log('Download artifact url: ', url);
https.get(url, (response) => {
const stream = response.pipe(fs.createWriteStream(artifactPath))
const stream = response.pipe(fs.createWriteStream(artifactPath));
stream.on('close', () => resolve(artifactPath));
stream.on('error', reject);
});
@@ -43,7 +48,7 @@ const extract = (artifactPath, destination) => {
module.exports = {
setup: async () => {
const artifactPath = await downloadArtifact(artifactVersion);
await extract(artifactPath, artifactDestination);
const artifactPath = await downloadArtifact(artifactVersion);
await extract(artifactPath, artifactDestination);
}
}
+5 -5
View File
@@ -1,6 +1,6 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const { isMac, isWindows } = require('../src/helpers/platform.js');
const DEFAULT_CONFIG = {
packagerConfig: {
@@ -31,9 +31,9 @@ const createConfig = () => {
// Version
if (config.RELEASE_VERSION)
config.packagerConfig.version = config.RELEASE_VERSION;
config.packagerConfig.version = config.RELEASE_VERSION;
if (os.platform().match(/(darwin)/i)) {
if (isMac) {
config.packagerConfig.icon = './config/macos/icon.icns';
config.packagerConfig.osxSign = {
'hardened-runtime': true,
@@ -64,10 +64,10 @@ const createConfig = () => {
});
}
if (os.platform().match(/(win32)/i)) {
if (isWindows) {
// Generate EXE file
config.makers.push({
name: '@electron-forge/maker-squirrel'
name: '@electron-forge/maker-squirrel',
});
}
+5 -5
View File
@@ -1,12 +1,12 @@
const path = require('path');
const os = require('os');
const { isWindows } = require('../helpers/platform.js');
const { spawnSync } = require('../helpers/spawn-promise.js');
const cliPath = async () => {
let cli = 'boundary';
if(os.type().match(/(windows)/i)) cli = 'boundary.exe';
return path.resolve(__dirname, '..', 'cli', cli);
}
let name = 'boundary';
if (isWindows) name = 'boundary.exe';
return path.resolve(__dirname, '..', 'cli', name);
};
module.exports = {
// Check boundary cli existence
@@ -1,9 +1,6 @@
const os = require('os');
const isMac = () => Boolean(os.type().match(/darwin/i));
const isWindows = () => Boolean(os.type().match(/(windows)/i));
module.exports = {
isMac: isMac,
isWindows: isWindows,
}
isMac: () => Boolean(os.type().match(/darwin/i)),
isWindows: () => Boolean(os.type().match(/(windows)/i)),
};
+860 -1075
View File
File diff suppressed because it is too large. Load diff