Files
libloot/scripts/vulcanize.js
T

93 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2015-08-27 12:07:31 +01:00
#!/usr/bin/env node
// Build the UI's index.html file. Takes one argument, which is the path to the
// repository's root.
2016-09-14 18:47:11 +01:00
/* eslint-disable no-unused-vars */
2015-12-13 18:27:43 +00:00
'use strict';
const path = require('path');
const fs = require('fs');
const helpers = require('./helpers');
2015-08-27 17:18:31 +01:00
const Vulcanize = require('vulcanize');
2016-01-31 09:29:32 +00:00
const mkdirp = require('mkdirp');
2015-12-28 20:22:19 +00:00
2016-01-31 09:29:32 +00:00
// Initialise from command line parameters.
2016-01-30 22:43:02 +00:00
let rootPath = '.';
2016-01-31 09:29:32 +00:00
let buildType = 'ui';
if (process.argv.length > 3) {
rootPath = process.argv[2];
buildType = process.argv[3];
} else if (process.argv.length > 2) {
2016-01-30 22:43:02 +00:00
rootPath = process.argv[2];
}
2015-08-27 17:18:31 +01:00
const vulcanize = new Vulcanize({
inlineScripts: true,
inlineCss: true,
2016-07-07 17:42:19 +01:00
excludes: [
'css/theme.css',
],
2015-08-27 17:18:31 +01:00
});
2016-01-30 22:43:02 +00:00
function mkdir(dir) {
try {
2016-01-31 09:29:32 +00:00
mkdirp.sync(dir);
2016-01-30 22:43:02 +00:00
} catch (e) {
if (e.code !== 'EEXIST') {
console.log(e);
}
}
}
2015-08-27 17:18:31 +01:00
function vulcanizeFile(inputPath, outputPath) {
// Make sure output directory exists first.
mkdir(path.dirname(outputPath));
vulcanize.process(inputPath, (err, inlinedHtml) => {
if (err) {
console.error(err);
process.exit(1);
}
fs.writeFileSync(outputPath, inlinedHtml);
});
2015-12-28 20:22:19 +00:00
}
2015-08-27 12:07:31 +01:00
2016-01-30 22:43:02 +00:00
function vulcanizeRelease(releasePath) {
const inputPath = path.join(rootPath, 'src', 'gui', 'html', 'index.html');
const outputPath = path.join(releasePath.path, 'resources', 'ui', 'index.html');
2015-08-27 17:18:31 +01:00
vulcanizeFile(inputPath, outputPath);
2016-01-30 22:43:02 +00:00
}
2016-01-31 09:29:32 +00:00
function vulcanizeTests(releasePath) {
const inputPath = path.join(rootPath, 'src', 'tests', 'gui', 'html', 'elements');
const outputPath = path.join(releasePath.path, 'html_tests', 'elements');
const tests = [
2015-08-28 13:11:45 +01:00
'test_editable-table.html',
2016-01-31 09:29:32 +00:00
'test_loot-custom-icons.html',
2015-08-28 11:22:37 +01:00
'test_loot-dropdown-menu.html',
2016-02-17 18:21:27 +00:00
'test_loot-menu.html',
2016-01-31 11:23:47 +00:00
'test_loot-message-dialog.html',
2015-08-30 21:01:28 +01:00
'test_loot-plugin-card.html',
2015-08-30 12:49:03 +01:00
'test_loot-plugin-editor.html',
2015-08-29 11:09:58 +01:00
'test_loot-plugin-item.html',
'test_loot-search-toolbar.html',
2016-01-31 09:29:32 +00:00
];
tests.forEach((test) => {
vulcanizeFile(path.join(inputPath, test), path.join(outputPath, test));
});
}
// Run the appropriate build(s).
const releasePaths = helpers.getAppReleasePaths(rootPath);
if (buildType === 'ui' || buildType === 'all') {
releasePaths.forEach(vulcanizeRelease);
}
if (buildType === 'tests' || buildType === 'all') {
releasePaths.forEach(vulcanizeTests);
}