Package metadata validator in archive script

Also a general tidy of the code.
This commit is contained in:
Oliver Hamlet
2016-07-22 19:39:15 +01:00
parent 2e8718e482
commit d4d54c8db3
2 changed files with 65 additions and 47 deletions
+32 -7
View File
@@ -177,9 +177,26 @@ function createApiArchive(rootPath, binaryPath, tempPath, destPath) {
fs.removeSync(tempPath);
}
function getFilenameSuffix(releasePath, gitDescription) {
if (releasePath.label) {
return `${gitDescription} (${releasePath.label}).7z`;
function createMetadataValidatorArchive(rootPath, binaryPath, tempPath, destPath) {
// Ensure that the output directory is empty.
fs.emptyDirSync(tempPath);
// Metadata validator binary.
fs.copySync(
binaryPath,
path.join(tempPath, path.basename(binaryPath))
);
// Now compress the folder to a 7-zip archive.
compress(tempPath, destPath);
// Finally, delete the temporary folder.
fs.removeSync(tempPath);
}
function getFilenameSuffix(label, gitDescription) {
if (label) {
return `${gitDescription} (${label}).7z`;
}
return `${gitDescription}.7z`;
@@ -195,17 +212,25 @@ const gitDesc = getGitDescription();
vulcanize(rootPath);
helpers.getAppReleasePaths(rootPath).forEach(releasePath => {
const filename = `LOOT ${getFilenameSuffix(releasePath, gitDesc)}`;
const filename = `LOOT ${getFilenameSuffix(releasePath.label, gitDesc)}`;
createAppArchive(rootPath,
releasePath.path,
tempPath,
path.join(rootPath, 'build', filename));
});
helpers.getApiBinaryPaths(rootPath).forEach(releasePath => {
const filename = `LOOT API ${getFilenameSuffix(releasePath, gitDesc)}`
helpers.getApiBinaryPaths(rootPath).forEach(binaryPath => {
const filename = `LOOT API ${getFilenameSuffix(binaryPath.label, gitDesc)}`;
createApiArchive(rootPath,
releasePath.path,
binaryPath.path,
tempPath,
path.join(rootPath, 'build', filename));
});
helpers.getMetadataValidatorBinaryPaths(rootPath).forEach(binaryPath => {
const filename = `Metadata Validator ${getFilenameSuffix(binaryPath.label, gitDesc)}`;
createMetadataValidatorArchive(rootPath,
binaryPath.path,
tempPath,
path.join(rootPath, 'build', filename));
});
+33 -40
View File
@@ -20,9 +20,8 @@ function fileExists(filePath) {
return false;
}
function getAppReleasePaths(rootPath) {
const paths = [];
const pathsToTry = [
function getBinaryParentPaths(rootPath) {
const paths = [
{
path: path.join(rootPath, 'build'),
label: null,
@@ -37,41 +36,36 @@ function getAppReleasePaths(rootPath) {
},
];
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');
}
if (fileExists(path.join(pathsToTry[i].path, file))) {
paths.push(pathsToTry[i]);
}
paths.forEach(parentPath => {
parentPath.path = path.join(parentPath.path, 'Release');
});
}
return paths;
}
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',
},
];
function getAppReleasePaths(rootPath) {
let file = 'LOOT';
if (os.platform() === 'win32') {
file += '.exe';
}
return getBinaryParentPaths(rootPath).filter(
parentPath => fileExists(path.join(parentPath.path, file))
);
}
function getBinaryPaths(rootPath, file) {
return getBinaryParentPaths(rootPath)
.map(parentPath => {
parentPath.path = path.join(parentPath.path, file);
return parentPath;
})
.filter(parentPath => fileExists(parentPath.path));
}
function getApiBinaryPaths(rootPath) {
let file = 'loot_api';
if (os.platform() === 'win32') {
file += '.dll';
@@ -79,20 +73,19 @@ function getApiBinaryPaths(rootPath) {
file = `lib${file}.so`;
}
for (let i = 0; i < pathsToTry.length; ++i) {
if (os.platform() === 'win32') {
pathsToTry[i].path = path.join(pathsToTry[i].path, 'Release');
}
return getBinaryPaths(rootPath, file);
}
if (fileExists(path.join(pathsToTry[i].path, file))) {
pathsToTry[i].path = path.join(pathsToTry[i].path, file);
paths.push(pathsToTry[i]);
}
function getMetadataValidatorBinaryPaths(rootPath) {
let file = 'metadata-validator';
if (os.platform() === 'win32') {
file += '.exe';
}
return paths;
return getBinaryPaths(rootPath, file);
}
module.exports.fileExists = fileExists;
module.exports.getAppReleasePaths = getAppReleasePaths;
module.exports.getApiBinaryPaths = getApiBinaryPaths;
module.exports.getMetadataValidatorBinaryPaths = getMetadataValidatorBinaryPaths;