Resolved eslint issues.

This commit is contained in:
chris062689 2017-10-10 22:36:47 -04:00
parent 1ed3279538
commit 9db3e8547d

270
app.js
View file

@ -1,9 +1,9 @@
const xml = require('xml'); const xml = require('xml');
const fs = require('fs-extra'); const fs = require('fs-extra');
const exec = require('execa'); const exec = require('execa');
const sha1 = require('sha1-file'); const sha1 = require('sha1-file');
const req = require('request-promise'); const req = require('request-promise');
const zip_bin = require('7zip-bin').path7za; const zipBin = require('7zip-bin').path7za;
const logger = require('winston'); const logger = require('winston');
logger.exitOnError = false; logger.exitOnError = false;
@ -12,167 +12,171 @@ logger.add(logger.transports.File, { filename: '/var/log/citra-qt-installer/citr
const tempDir = './temp'; const tempDir = './temp';
const distDir = '/citra/nginx/repo'; const distDir = '/citra/nginx/repo';
async function getReleases(repo) { async function getReleases (repo) {
const result = await req({ const result = await req({
uri: `https://api.github.com/repos/${repo}/releases`, uri: `https://api.github.com/repos/${repo}/releases`,
headers: { headers: {
"Accept": "application/vnd.github.v3+json", 'Accept': 'application/vnd.github.v3+json',
"User-Agent": "Citra Installer - Repo (j-selby)" 'User-Agent': 'Citra Installer - Repo (j-selby)'
} }
}); });
return JSON.parse(result); return JSON.parse(result);
} }
function getTopResultFor(jsonData, platform) { function getTopResultFor (jsonData, platform) {
for (let releaseKey in jsonData) { for (let releaseKey in jsonData) {
const release = jsonData[releaseKey]; const release = jsonData[releaseKey];
for (let assetKey in release.assets) { for (let assetKey in release.assets) {
const asset = release.assets[assetKey]; const asset = release.assets[assetKey];
if (asset.name.indexOf(platform) !== -1 && asset.name.endsWith(".7z")) { if (asset.name.indexOf(platform) !== -1 && asset.name.endsWith('.7z')) {
return { return {
"release_id": release.tag_name.split("-")[1], 'release_id': release.tag_name.split('-')[1],
"published_at": release.published_at.substr(0, 10), 'published_at': release.published_at.substr(0, 10),
"name": asset.name, 'name': asset.name,
"size": asset.size, 'size': asset.size,
"hash": release.tag_name 'hash': release.tag_name
} };
} }
}
} }
}
return {"notFound": true}; return {'notFound': true};
} }
// The Qt Installer Framework is a pain to build or download. // The Qt Installer Framework is a pain to build or download.
// Because all we need are a few 7-zipped + xml files, we might as well generate them for ourselves. // Because all we need are a few 7-zipped + xml files, we might as well generate them for ourselves.
let targets = [ let targets = [
{ {
"Name": "org.citra.nightly.%platform%", 'Name': 'org.citra.nightly.%platform%',
"DisplayName": "Citra Nightly", 'DisplayName': 'Citra Nightly',
"Description": "The nightly builds of Citra are official, tested versions of Citra that are known to work.\n" + 'Description': 'The nightly builds of Citra are official, tested versions of Citra that are known to work.\n' +
"(%platform%, commit: %commithash%, release date: %releasedate%)", '(%platform%, commit: %commithash%, release date: %releasedate%)',
"Repo": "citra-emu/citra-nightly", 'Repo': 'citra-emu/citra-nightly',
"ScriptName": "nightly", 'ScriptName': 'nightly',
"Default": "script", 'Default': 'script',
"Licenses": [ 'Licenses': [
{"License": [{ _attr: { file: 'license.txt', name: "GNU General Public License v2.0" }}]} {'License': [{_attr: { file: 'license.txt', name: 'GNU General Public License v2.0' }}]}
], ]
}, },
{ {
"Name": "org.citra.canary.%platform%", 'Name': 'org.citra.canary.%platform%',
"DisplayName": "Citra Canary", 'DisplayName': 'Citra Canary',
"Description": "An in-development version of Citra that uses changes that are relatively untested.\n" + 'Description': 'An in-development version of Citra that uses changes that are relatively untested.\n' +
"(%platform%, commit: %commithash%, release date: %releasedate%)", '(%platform%, commit: %commithash%, release date: %releasedate%)',
"Repo": "citra-emu/citra-canary", 'Repo': 'citra-emu/citra-canary',
"ScriptName": "canary", 'ScriptName': 'canary',
"Default": "script", 'Default': 'script',
"Licenses": [ 'Licenses': [
{"License": [{ _attr: { file: 'license.txt', name: "GNU General Public License v2.0" }}]} {'License': [{_attr: { file: 'license.txt', name: 'GNU General Public License v2.0' }}]}
], ]
} }
]; ];
async function execute() { async function execute () {
// Clean up any temporary directories. // Clean up any temporary directories.
fs.emptyDirSync(tempDir); fs.emptyDirSync(tempDir);
// Get Git information // Get Git information
logger.debug("Getting release info..."); logger.debug('Getting release info...');
for (result_key in targets) { for (var resultKey in targets) {
const target = targets[result_key]; const target = targets[resultKey];
target.Repo = await getReleases(target.Repo); target.Repo = await getReleases(target.Repo);
} }
logger.debug("Building metadata..."); logger.debug('Building metadata...');
// If updates available is still false at the end of the foreach loop // If updates available is still false at the end of the foreach loop
// then that means no releases have been made -- nothing to do. // then that means no releases have been made -- nothing to do.
var updatesAvailable = false; var updatesAvailable = false;
// Updates.xml // Updates.xml
let updates = [ let updates = [
{"ApplicationName": "{AnyApplication}"}, {'ApplicationName': '{AnyApplication}'},
{"ApplicationVersion": "1.0.0"}, // Separate from nightly / canary versions {'ApplicationVersion': '1.0.0'}, // Separate from nightly / canary versions
{"Checksum": false} // As they are pulled straight from Github {'Checksum': false} // As they are pulled straight from Github
]; ];
["msvc", "osx", "linux"].forEach((platform) => { ['msvc', 'osx', 'linux'].forEach((platform) => {
targets.forEach((target_source) => { targets.forEach((targetSource) => {
// Get Git metadata // Get Git metadata
const release_data = getTopResultFor(target_source.Repo, platform); const releaseData = getTopResultFor(targetSource.Repo, platform);
const name = target_source.Name.replace("%platform%", platform); const name = targetSource.Name.replace('%platform%', platform);
if (release_data.notFound === true) { if (releaseData.notFound === true) {
logger.error(`Release information not found for ${name}!`); logger.error(`Release information not found for ${name}!`);
return; return;
} }
const scriptName = platform + "-" + target_source.ScriptName; const scriptName = platform + '-' + targetSource.ScriptName;
const version = release_data.release_id; const version = releaseData.release_id;
const targetMetadataFilePath = `${distDir}/${name}/${version}meta.7z`; const targetMetadataFilePath = `${distDir}/${name}/${version}meta.7z`;
if (fs.existsSync(targetMetadataFilePath)) { if (fs.existsSync(targetMetadataFilePath)) {
logger.debug(`Metadata information already exists for ${name} ${version}, skipping.`); logger.debug(`Metadata information already exists for ${name} ${version}, skipping.`);
} else { } else {
logger.info(`Building release information for ${name} ${version}.`); logger.info(`Building release information for ${name} ${version}.`);
updatesAvailable = true; updatesAvailable = true;
// Create the temporary working directory. // Create the temporary working directory.
const workingDirectoryPath = `${tempDir}/${name}`; const workingDirectoryPath = `${tempDir}/${name}`;
fs.ensureDirSync(workingDirectoryPath); fs.ensureDirSync(workingDirectoryPath);
// Copy license // Copy license
fs.copySync("license.txt", `${workingDirectoryPath}/license.txt`); fs.copySync('license.txt', `${workingDirectoryPath}/license.txt`);
fs.copySync(`scripts/${scriptName}.qs`, `${workingDirectoryPath}/installscript.qs`); fs.copySync(`scripts/${scriptName}.qs`, `${workingDirectoryPath}/installscript.qs`);
// Create 7zip archive // Create 7zip archive
exec.sync(zip_bin, ["a", "meta.7z", name], {"cwd": tempDir}); exec.sync(zipBin, ['a', 'meta.7z', name], {'cwd': tempDir});
// Copy the metadata file into the target path. // Copy the metadata file into the target path.
logger.debug(`Creating target metadata for ${name} at ${targetMetadataFilePath}`); logger.debug(`Creating target metadata for ${name} at ${targetMetadataFilePath}`);
fs.moveSync(`${tempDir}/meta.7z`, targetMetadataFilePath); fs.moveSync(`${tempDir}/meta.7z`, targetMetadataFilePath);
// Cleanup temporary working directory. // Cleanup temporary working directory.
fs.removeSync(workingDirectoryPath); fs.removeSync(workingDirectoryPath);
} }
// Create metadata for the Update.xml // Create metadata for the Update.xml
var metaHash = sha1(targetMetadataFilePath); var metaHash = sha1(targetMetadataFilePath);
let target = []; let target = [];
target.push({"Name": name}); target.push({'Name': name});
target.push({"DisplayName": target_source.DisplayName.replace("%platform%", platform)}); target.push({'DisplayName': targetSource.DisplayName.replace('%platform%', platform)});
target.push({"Version": version}); target.push({'Version': version});
target.push({"DownloadableArchives": release_data.name}); target.push({'DownloadableArchives': releaseData.name});
// Because we cannot compute the uncompressed size ourselves, just give a generous estimate // Because we cannot compute the uncompressed size ourselves, just give a generous estimate
// (to make sure they have enough disk space). // (to make sure they have enough disk space).
// OS flag is useless - i.e the installer stubs it :P // OS flag is useless - i.e the installer stubs it :P
target.push({"UpdateFile": [{_attr: {UncompressedSize: release_data.size * 2, target.push({'UpdateFile': [{_attr: {
CompressedSize: release_data.size, OS: "Any"}}]}); UncompressedSize: releaseData.size * 2,
CompressedSize: releaseData.size,
OS: 'Any'}
}]});
target.push({"ReleaseDate": release_data.published_at}); target.push({'ReleaseDate': releaseData.published_at});
target.push({"Description": target_source.Description.replace("%platform%", platform) target.push({'Description': targetSource.Description
.replace("%commithash%", release_data.hash) .replace('%platform%', platform)
.replace("%releasedate%", release_data.published_at)}); .replace('%commithash%', releaseData.hash)
target.push({"Default": target_source.Default}); .replace('%releasedate%', releaseData.published_at)});
target.push({"Licenses": target_source.Licenses}); target.push({'Default': targetSource.Default});
target.push({"Script": "installscript.qs"}); target.push({'Licenses': targetSource.Licenses});
target.push({"SHA": metaHash}); target.push({'Script': 'installscript.qs'});
target.push({'SHA': metaHash});
updates.push({"PackageUpdate": target}); updates.push({'PackageUpdate': target});
});
}); });
});
if (updatesAvailable) { if (updatesAvailable) {
const updatesXml = xml({"Updates": updates}, {indent: " "}); const updatesXml = xml({'Updates': updates}, {indent: ' '});
// Save Updates.xml // Save Updates.xml
fs.writeFileSync(`${distDir}/Updates.xml`, updatesXml); fs.writeFileSync(`${distDir}/Updates.xml`, updatesXml);
logger.info('Wrote a new Updates.xml file -- updates are available.'); logger.info('Wrote a new Updates.xml file -- updates are available.');
} else { } else {
logger.info('No Citra binary release updates are available for the Updates.xml -- nothing to do.'); logger.info('No Citra binary release updates are available for the Updates.xml -- nothing to do.');
} }
} }
execute().catch((err) => { execute().catch((err) => {