Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
OC-2372: added download script
  • Loading branch information
wenjunche committed Feb 3, 2023
commit a4efc0c8f742c364eb269bbae094b885770ca7a4
3 changes: 2 additions & 1 deletion self-hosting-example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
package-lock.json

public/**
7 changes: 7 additions & 0 deletions self-hosting-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"build-clean": "rimraf ./public/rvm ./public/runtime ./public/runtimeVersions",
"build": "node ./scripts/download-assets.js",
"launch": "start http://localhost:5555/launch"
},
"keywords": [],
Expand All @@ -12,6 +14,11 @@
"dependencies": {
"express": "^4.16.2"
},
"devDependencies": {
"node-fetch": "2.6.7",
"rimraf": "4.1.2",
"yargs": "^17.6.2"
},
"repository": {
"type": "git",
"url": "https://github.com/built-on-openfin/deployment.git"
Expand Down
Binary file removed self-hosting-example/public/runtime/14.78.48.15
Binary file not shown.
Binary file removed self-hosting-example/public/runtime/14.78.48.16
Binary file not shown.
3 changes: 0 additions & 3 deletions self-hosting-example/public/runtimeVersions

This file was deleted.

Binary file removed self-hosting-example/public/rvm/latest
Binary file not shown.
1 change: 0 additions & 1 deletion self-hosting-example/public/rvm/latestVersion

This file was deleted.

88 changes: 88 additions & 0 deletions self-hosting-example/scripts/download-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const path = require('path');
const fs = require('fs');
const fetch = require('node-fetch');
const yargs = require('yargs/yargs');

const RVM_BASE_URL = 'https://cdn.openfin.co/release/rvm';
const RUNTIME_BASE_URL = 'https://cdn.openfin.co/release/runtime';

const downloadRVM = async() => {
const rvmFolder = path.join( __dirname, '..', 'public', 'rvm');
fs.mkdirSync(rvmFolder, { recursive: true });

const response = await fetch(`${RVM_BASE_URL}/latestVersion`);
if (response.ok) {
const latestVersion = await response.text();
console.log(`latest version of RVM: ${latestVersion}`);
const rvmLatestPath = path.join(rvmFolder, 'latestVersion');
fs.writeFileSync(rvmLatestPath, latestVersion);

console.log('downloading latest version of RVM');
const rvmPath = path.join(rvmFolder, 'latest');
const rvmResponse = await fetch(`${RVM_BASE_URL}/latest`);
if (rvmResponse.ok) {
const rvmBuffer = await rvmResponse.buffer();
fs.writeFileSync(rvmPath, rvmBuffer);
} else {
console.error(`error downloading latest of RVM`);
}
} else {
console.error(`error downloading latestVersion of RVM`);
}
}

const isRuntimeVersion = (value) => {
return /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(value);
}

const downloadRuntime = async(versions) => {
const runtimeFolder = path.join( __dirname, '..', 'public', 'runtime');
fs.mkdirSync(runtimeFolder, { recursive: true });

for (let version of versions) {
let numericVersion;
if (!isRuntimeVersion(version)) { // must be a release channel
const response = await fetch(`${RUNTIME_BASE_URL}/${version}`);
if (response.ok) {
const mappedVersion = await response.text();
if (isRuntimeVersion(mappedVersion)) {
numericVersion = mappedVersion;
console.log(`release channel ${version} of Runtime: ${numericVersion}`);
const channelPath = path.join(runtimeFolder, version);
fs.writeFileSync(channelPath, numericVersion);
}
} else {
console.error(`error downloading release channel ${version}`)
}
} else {
numericVersion = version;
}

if (numericVersion) {
console.log(`downloading version ${numericVersion} of Runtime`);
const runtimePath = path.join(runtimeFolder, numericVersion);
const runtimeResponse = await fetch(`${RUNTIME_BASE_URL}/${numericVersion}`);
if (runtimeResponse.ok) {
const runtimeBuffer = await runtimeResponse.buffer();
fs.writeFileSync(runtimePath, runtimeBuffer);
const versionListPath = path.join('./public', 'runtimeVersions');
fs.writeFileSync(versionListPath, numericVersion, { flag: 'a+' } );
fs.writeFileSync(versionListPath, '\n', { flag: 'a+' } );
} else {
console.error(`error downloading ${numericVersion}`)
}
}
}
}

const download = async() => {
const argv = yargs(process.argv).argv;
downloadRVM();
if (argv.runtimes) {
downloadRuntime(argv.runtimes.split(','));
} else {
downloadRuntime(['stable']);
}
}

download();