diff --git a/scripts/archive.js b/scripts/archive.js index 21b15bd8..1dadfee4 100644 --- a/scripts/archive.js +++ b/scripts/archive.js @@ -2,206 +2,203 @@ // Archive packaging script. Takes one argument, which is the path to the // repository's root. Requires 7-zip and Git to be installed, and Git to be // available on the system path. +'use strict'; +const childProcess = require('child_process'); +const path = require('path'); +const fs = require('fs-extra'); +const os = require('os'); +const helpers = require('./helpers'); -var child_process = require('child_process'); -var path = require('path'); -var fs = require('fs-extra'); -var os = require('os'); -var helpers = require('./helpers'); - -function vulcanize() { - return child_process.execFileSync('node', [ - 'scripts/vulcanize.js', - root_path - ]); +function vulcanize(rootPath) { + return childProcess.execFileSync('node', [ + 'scripts/vulcanize.js', + rootPath, + ]); } function getGitDescription() { - return String(child_process.execFileSync('git', [ - 'describe', - '--tags', - '--long' - ])).slice(0, -1); + return String(childProcess.execFileSync('git', [ + 'describe', + '--tags', + '--long', + ])).slice(0, -1); } -function compress(source_path, dest_path) { - var sevenzip_path = ''; - if (os.platform() == 'win32') { - sevenzip_path = path.join('C:\\', 'Program Files', '7-Zip', '7z.exe'); - } else { - sevenzip_path = '/usr/bin/7z'; +function compress(sourcePath, destPath) { + let sevenzipPath = ''; + if (os.platform() === 'win32') { + sevenzipPath = path.join('C:\\', 'Program Files', '7-Zip', '7z.exe'); + } else { + sevenzipPath = '/usr/bin/7z'; + } + + // First remove any existing archive. + fs.removeSync(destPath); + + // The last argument must have a leading dot for the subdirectory not to + // be present in the archive, but path.join removes it, so it's prefixed. + return childProcess.execFileSync(sevenzipPath, [ + 'a', + '-r', + destPath, + '.' + path.sep + path.join(sourcePath, '*'), + ]); +} + +function createAppArchive(rootPath, releasePath, tempPath, destPath) { + // Ensure that the output directory is empty. + fs.emptyDirSync(tempPath); + + // Copy LOOT exectuable and CEF files. + let binaries = []; + if (os.platform() === 'win32') { + binaries = [ + 'LOOT.exe', + 'd3dcompiler_47.dll', + 'libEGL.dll', + 'libGLESv2.dll', + 'libcef.dll', + 'natives_blob.bin', + 'snapshot_blob.bin', + 'cef.pak', + 'cef_100_percent.pak', + 'cef_200_percent.pak', + 'devtools_resources.pak', + 'icudtl.dat', + ]; + + if (helpers.fileExists(path.join(releasePath, 'wow_helper.exe'))) { + binaries.push('wow_helper.exe'); } + } else { + binaries = [ + 'LOOT', + 'chrome-sandbox', + 'libcef.so', + 'natives_blob.bin', + 'snapshot_blob.bin', + 'cef.pak', + 'cef_100_percent.pak', + 'cef_200_percent.pak', + 'devtools_resources.pak', + 'icudtl.dat', + ]; + } + binaries.forEach((file) => { + fs.copySync( + path.join(releasePath, file), + path.join(tempPath, file) + ); + }); - // First remove any existing archive. - fs.removeSync(dest_path); + // CEF locale file. + fs.mkdirsSync(path.join(tempPath, 'resources', 'l10n')); + fs.copySync( + path.join(releasePath, 'resources', 'l10n', 'en-US.pak'), + path.join(tempPath, 'resources', 'l10n', 'en-US.pak') + ); - // The last argument must have a leading dot for the subdirectory not to - // be present in the archive, but path.join removes it, so it's prefixed. - return child_process.execFileSync(sevenzip_path, [ - 'a', - '-r', - dest_path, - '.' + path.sep + path.join(source_path, '*') - ]); + // Translation files. + [ + 'es', 'ru', 'fr', 'zh_CN', 'pl', 'pt_BR', 'fi', 'de', 'da', 'ko', + ].forEach((lang) => { + fs.mkdirsSync(path.join(tempPath, 'resources', 'l10n', lang, 'LC_MESSAGES')); + fs.copySync( + path.join(rootPath, 'resources', 'l10n', lang, 'LC_MESSAGES', 'loot.mo'), + path.join(tempPath, 'resources', 'l10n', lang, 'LC_MESSAGES', 'loot.mo') + ); + }); + + // UI files. + fs.mkdirsSync(path.join(tempPath, 'resources', 'ui', 'css')); + fs.copySync( + path.join(releasePath, 'resources', 'ui', 'index.html'), + path.join(tempPath, 'resources', 'ui', 'index.html') + ); + fs.copySync( + path.join(rootPath, 'resources', 'ui', 'css', 'dark-theme.css'), + path.join(tempPath, 'resources', 'ui', 'css', 'dark-theme.css') + ); + fs.copySync( + path.join(rootPath, 'resources', 'ui', 'fonts'), + path.join(tempPath, 'resources', 'ui', 'fonts') + ); + + // Docs. + fs.mkdirsSync(path.join(tempPath, 'docs')); + [ + 'images', + 'licenses', + 'LOOT Metadata Syntax.html', + 'LOOT Readme.html', + ].forEach((item) => { + fs.copySync( + path.join(rootPath, 'docs', item), + path.join(tempPath, 'docs', item) + ); + }); + + // Now compress the folder to a 7-zip archive. + compress(tempPath, destPath); + + // Finally, delete the temporary folder. + fs.removeSync(tempPath); } -function createAppArchive(release_path, dest_path) { - // Ensure that the output directory is empty. - fs.emptyDirSync(temp_path); +function createApiArchive(rootPath, binaryPath, tempPath, destPath) { + // Ensure that the output directory is empty. + fs.emptyDirSync(tempPath); - // Copy LOOT exectuable and CEF files. - var binaries = []; - if (os.platform() == 'win32') { - binaries = [ - 'LOOT.exe', - 'd3dcompiler_47.dll', - 'libEGL.dll', - 'libGLESv2.dll', - 'libcef.dll', - 'natives_blob.bin', - 'snapshot_blob.bin', - 'cef.pak', - 'cef_100_percent.pak', - 'cef_200_percent.pak', - 'devtools_resources.pak', - 'icudtl.dat' - ]; + // API binary/binaries. + fs.copySync( + binaryPath, + path.join(tempPath, path.basename(binaryPath)) + ); - if (helpers.fileExists(path.join(release_path, 'wow_helper.exe'))) { - binaries.push('wow_helper.exe'); - } - } else { - binaries = [ - 'LOOT', - 'chrome-sandbox', - 'libcef.so', - 'natives_blob.bin', - 'snapshot_blob.bin', - 'cef.pak', - 'cef_100_percent.pak', - 'cef_200_percent.pak', - 'devtools_resources.pak', - 'icudtl.dat' - ]; - } - binaries.forEach(function(file){ - fs.copySync( - path.join(release_path, file), - path.join(temp_path, file) - ); - }); + // API header file. + fs.mkdirsSync(path.join(tempPath, 'include', 'loot')); + fs.copySync( + path.join(rootPath, 'include', 'loot', 'api.h'), + path.join(tempPath, 'include', 'loot', 'api.h') + ); - // CEF locale file. - fs.mkdirsSync(path.join(temp_path, 'resources', 'l10n')); - fs.copySync( - path.join(release_path, 'resources', 'l10n', 'en-US.pak'), - path.join(temp_path, 'resources', 'l10n', 'en-US.pak') - ); + // Docs. + fs.mkdirsSync(path.join(tempPath, 'docs')); + fs.copySync( + path.join(rootPath, 'docs', 'latex', 'refman.pdf'), + path.join(tempPath, 'docs', 'readme.pdf') + ); + fs.copySync( + path.join(rootPath, 'docs', 'licenses'), + path.join(tempPath, 'docs', 'licenses') + ); - // Translation files. - [ - 'es', 'ru', 'fr', 'zh_CN', 'pl', - 'pt_BR', 'fi', 'de', 'da', 'ko' - ].forEach(function(lang){ - fs.mkdirsSync(path.join(temp_path, 'resources', 'l10n', lang, 'LC_MESSAGES')); - fs.copySync( - path.join(root_path, 'resources', 'l10n', lang, 'LC_MESSAGES', 'loot.mo'), - path.join(temp_path, 'resources', 'l10n', lang, 'LC_MESSAGES', 'loot.mo') - ); - }); + // Now compress the folder to a 7-zip archive. + compress(tempPath, destPath); - // UI files. - fs.mkdirsSync(path.join(temp_path, 'resources', 'ui', 'css')); - fs.copySync( - path.join(release_path, 'resources', 'ui', 'index.html'), - path.join(temp_path, 'resources', 'ui', 'index.html') - ); - fs.copySync( - path.join(root_path, 'resources', 'ui', 'css', 'dark-theme.css'), - path.join(temp_path, 'resources', 'ui', 'css', 'dark-theme.css') - ); - fs.copySync( - path.join(root_path, 'resources', 'ui', 'fonts'), - path.join(temp_path, 'resources', 'ui', 'fonts') - ); - - // Docs. - fs.mkdirsSync(path.join(temp_path, 'docs')); - [ - 'images', - 'licenses', - 'LOOT Metadata Syntax.html', - 'LOOT Readme.html' - ].forEach(function(item){ - fs.copySync( - path.join(root_path, 'docs', item), - path.join(temp_path, 'docs', item) - ); - }); - - // Now compress the folder to a 7-zip archive. - compress(temp_path, dest_path); - - // Finally, delete the temporary folder. - fs.removeSync(temp_path); + // Finally, delete the temporary folder. + fs.removeSync(tempPath); } -function createApiArchive(binary_path, dest_path) { - // Ensure that the output directory is empty. - fs.emptyDirSync(temp_path); +let rootPath = '.'; +if (process.argv.length > 2) { + rootPath = process.argv[2]; +} +const tempPath = path.join(rootPath, 'build', 'archive.tmp'); - // API binary/binaries. - fs.copySync( - binary_path, - path.join(temp_path, path.basename(binary_path)) - ); +const gitDesc = getGitDescription(); +vulcanize(rootPath); - // API header file. - fs.mkdirsSync(path.join(temp_path, 'include', 'loot')); - fs.copySync( - path.join(root_path, 'include', 'loot', 'api.h'), - path.join(temp_path, 'include', 'loot', 'api.h') - ); - - // Docs. - fs.mkdirsSync(path.join(temp_path, 'docs')); - fs.copySync( - path.join(root_path, 'docs', 'latex', 'refman.pdf'), - path.join(temp_path, 'docs', 'readme.pdf') - ); - fs.copySync( - path.join(root_path, 'docs', 'licenses'), - path.join(temp_path, 'docs', 'licenses') - ); - - - // Now compress the folder to a 7-zip archive. - compress(temp_path, dest_path); - - // Finally, delete the temporary folder. - fs.removeSync(temp_path); +const releasePaths = helpers.getAppReleasePaths(rootPath); +for (let i = 0; i < releasePaths.length; ++i) { + if (releasePaths[i].label) { + createAppArchive(rootPath, releasePaths[i].path, tempPath, path.join(rootPath, 'build', 'LOOT ' + gitDesc + ' (' + releasePaths[i].label + ').7z')); + } else { + createAppArchive(releasePaths[i].path, path.join(rootPath, 'build', 'LOOT ' + gitDesc + '.7z')); + } } -if (process.argv.length < 3) { - var root_path = '.'; -} else { - var root_path = process.argv[2]; -} -var temp_path = path.join(root_path, 'build', 'archive.tmp'); - -var git_desc = getGitDescription(); -vulcanize(); - -var release_paths = helpers.getAppReleasePaths(root_path); -for (var i = 0; i < release_paths.length; ++i) { - if (release_paths[i].label) { - createAppArchive(release_paths[i].path, path.join(root_path, 'build', 'LOOT ' + git_desc + ' (' + release_paths[i].label + ').7z')); - } else { - createAppArchive(release_paths[i].path, path.join(root_path, 'build', 'LOOT ' + git_desc + '.7z')); - } -} - -var binary_paths = helpers.getApiBinaryPaths(root_path); -for (var i = 0; i < binary_paths.length; ++i) { - createApiArchive(binary_paths[i].path, path.join(root_path, 'build', 'LOOT API ' + git_desc + ' (' + binary_paths[i].label + ').7z')); +const binaryPaths = helpers.getApiBinaryPaths(rootPath); +for (let i = 0; i < binaryPaths.length; ++i) { + createApiArchive(rootPath, binaryPaths[i].path, tempPath, path.join(rootPath, 'build', 'LOOT API ' + gitDesc + ' (' + binaryPaths[i].label + ').7z')); } diff --git a/scripts/helpers.js b/scripts/helpers.js index 8f4a531c..45dcba71 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -1,113 +1,116 @@ // Helper functions shared across scripts. -var path = require('path'); -var fs = require('fs'); -var os = require('os'); +'use strict'; +const path = require('path'); +const fs = require('fs'); +const os = require('os'); -function fileExists(file_path) { - try { - // Query the entry - stats = fs.lstatSync(file_path); +function fileExists(filePath) { + try { + // Query the entry + const stats = fs.lstatSync(filePath); - // Is it a directory? - if (stats.isFile()) { - return true; - } - } catch (e) {} + // Is it a directory? + if (stats.isFile()) { + return true; + } + } catch (e) { + /* Don't do anything, it's not an error. */ + } - return false; + return false; } -function getAppReleasePaths(root_path) { - var paths = []; - var file = 'LOOT'; - var paths_to_try = [ - { - path: path.join(root_path, 'build'), - label: null - }, - { - path: path.join(root_path, 'build', '32'), - label: '32 bit' - }, - { - path: path.join(root_path, 'build', '64'), - label: '64 bit' - } - ]; +function getAppReleasePaths(rootPath) { + const paths = []; + const pathsToTry = [ + { + path: path.join(rootPath, 'build'), + label: null, + }, + { + path: path.join(rootPath, 'build', '32'), + label: '32 bit', + }, + { + path: path.join(rootPath, 'build', '64'), + label: '64 bit', + }, + ]; - if (os.platform() == 'win32') { - file += '.exe'; + let file = 'LOOT'; + if (os.platform() === 'win32') { + file += '.exe'; + } + + for (let i = 0; i < pathsToTry.length; ++i) { + if (os.platform() === 'win32') { + pathsToTry[i].path = path.join(pathsToTry[i].path, 'Release'); } - for (var i = 0; i < paths_to_try.length; ++i) { - if (os.platform() == 'win32') { - paths_to_try[i].path = path.join(paths_to_try[i].path, 'Release'); - } - - if (fileExists(path.join(paths_to_try[i].path, file))) { - paths.push(paths_to_try[i]); - } + if (fileExists(path.join(pathsToTry[i].path, file))) { + paths.push(pathsToTry[i]); } + } - return paths; + return paths; } -function getApiBinaryPaths(root_path) { - var paths = []; - var files = []; - var paths_to_try = [ +function getApiBinaryPaths(rootPath) { + const paths = []; + const pathsToTry = [ + { + path: path.join(rootPath, 'build'), + label: null, + }, + { + path: path.join(rootPath, 'build', '32'), + label: '32 bit', + }, + { + path: path.join(rootPath, 'build', '64'), + label: '64 bit', + }, + ]; + + for (let i = 0; i < pathsToTry.length; ++i) { + let files = []; + if (os.platform() === 'win32') { + pathsToTry[i].path = path.join(pathsToTry[i].path, 'Release'); + + files = [ { - path: path.join(root_path, 'build'), - label: null + name: 'loot32.dll', + label: '32 bit', }, { - path: path.join(root_path, 'build', '32'), - label: '32 bit' + name: 'loot64.dll', + label: '64 bit', + }, + ]; + } else { + files = [ + { + name: 'libloot32.so', + label: '32 bit', }, { - path: path.join(root_path, 'build', '64'), - label: '64 bit' - } - ]; - - for (var i = 0; i < paths_to_try.length; ++i) { - if (os.platform() == 'win32') { - paths_to_try[i].path = path.join(paths_to_try[i].path, 'Release'); - - files = [ - { - name: 'loot32.dll', - label: '32 bit' - }, - { - name: 'loot64.dll', - label: '64 bit' - } - ]; - } else { - files = [ - { - name: 'libloot32.so', - label: '32 bit' - }, - { - name: 'libloot64.so', - label: '64 bit' - } - ]; - } - - for (var j = 0; j < files.length; ++j) { - if (fileExists(path.join(paths_to_try[i].path, files[j].name))) { - paths_to_try[i].path = path.join(paths_to_try[i].path, files[j].name); - paths_to_try[i].label = files[j].label; - paths.push(paths_to_try[i]); - break; - } - } + name: 'libloot64.so', + label: '64 bit', + }, + ]; } - return paths; + for (let j = 0; j < files.length; ++j) { + if (fileExists(path.join(pathsToTry[i].path, files[j].name))) { + pathsToTry[i].path = path.join(pathsToTry[i].path, files[j].name); + pathsToTry[i].label = files[j].label; + paths.push(pathsToTry[i]); + break; + } + } + } + + return paths; } module.exports.fileExists = fileExists; diff --git a/scripts/vulcanize.js b/scripts/vulcanize.js index 4fc5a950..38caf50b 100755 --- a/scripts/vulcanize.js +++ b/scripts/vulcanize.js @@ -1,43 +1,43 @@ #!/usr/bin/env node // Build the UI's index.html file. Takes one argument, which is the path to the // repository's root. -var child_process = require('child_process'); -var path = require('path'); -var fs = require('fs'); -var os = require('os'); -var helpers = require('./helpers'); +'use strict'; +const childProcess = require('child_process'); +const path = require('path'); +const fs = require('fs'); +const os = require('os'); +const helpers = require('./helpers'); -if (process.argv.length < 3) { - var root_path = '.'; -} else { - var root_path = process.argv[2]; +let rootPath = '.'; +if (process.argv.length > 2) { + rootPath = process.argv[2]; } -var release_paths = helpers.getAppReleasePaths(root_path); +const releasePaths = helpers.getAppReleasePaths(rootPath); -for (var i = 0; i < release_paths.length; ++i) { - var output_path = path.join(release_paths[i].path, 'resources', 'ui'); +for (let i = 0; i < releasePaths.length; ++i) { + const outputPath = path.join(releasePaths[i].path, 'resources', 'ui'); - // Makes sure output directory exists first. - try { - fs.mkdirSync(output_path); - } catch (e) { - if (e.code != 'EEXIST') { - console.log(e); - } + // Makes sure output directory exists first. + try { + fs.mkdirSync(outputPath); + } catch (e) { + if (e.code !== 'EEXIST') { + console.log(e); } + } - var vulcanize = path.join(root_path, 'node_modules', '.bin', 'vulcanize'); - if (os.platform() == 'win32') { - vulcanize += '.cmd'; - } + let vulcanize = path.join(rootPath, 'node_modules', '.bin', 'vulcanize'); + if (os.platform() === 'win32') { + vulcanize += '.cmd'; + } - child_process.execFileSync(vulcanize, [ - '--inline', - '--config', - path.join(root_path, 'scripts', 'vulcanize.config.json'), - '-o', - path.join(output_path, 'index.html'), - path.join(root_path, 'src', 'gui', 'html', 'index.html') - ]); + childProcess.execFileSync(vulcanize, [ + '--inline', + '--config', + path.join(rootPath, 'scripts', 'vulcanize.config.json'), + '-o', + path.join(outputPath, 'index.html'), + path.join(rootPath, 'src', 'gui', 'html', 'index.html'), + ]); }