Moving HTML builder into webpack

- Allows handling of template variables
- Retaining test_mode switch for hot-swap JS bundle
This commit is contained in:
James Barnsley
2022-11-12 08:52:38 +13:00
parent 074b97ce7d
commit 154e72234e
3 changed files with 41 additions and 30 deletions

View File

@ -8,15 +8,15 @@
* To run, execute npm run dev|build|prod|release
**/
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');
var copydir = require('copy-dir');
var copyfile = require('fs-copy-file');
var version = fs.readFileSync("IRIS_VERSION", "utf8");
const process = require( 'process' );
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const copydir = require('copy-dir');
const copyfile = require('fs-copy-file');
let version = fs.readFileSync("IRIS_VERSION", "utf8");
version = version.replace(/\r?\n?/g, '').trim();
var build = Math.floor(Date.now() / 1000);
console.log('Building version '+version+' ('+build+')');
console.log('Building version '+version+'');
if (fs.existsSync('mopidy_iris/static/')){
rimraf.sync('mopidy_iris/static/');
@ -53,12 +53,12 @@ copydir('src/assets', 'mopidy_iris/static/assets', { filter: assetsFilter }, fun
console.log('Copied assets');
var html_file = "mopidy_iris/static/index.html";
var html_file_content = fs.readFileSync("src/index.html", "utf8");
html_file_content = html_file_content.replace("VERSION_HERE", version);
html_file_content = html_file_content.replace("BUILD_HERE", build);
fs.writeFileSync(html_file, html_file_content, 'utf8');
console.log('Setting version in HTML');
// var html_file = "mopidy_iris/static/index.html";
// var html_file_content = fs.readFileSync("src/index.html", "utf8");
// html_file_content = html_file_content.replace("VERSION_HERE", version);
// html_file_content = html_file_content.replace("BUILD_HERE", build);
// fs.writeFileSync(html_file, html_file_content, 'utf8');
// console.log('Setting version in HTML');
console.log('Setting version in manifest.json');
var manifest_file = "mopidy_iris/static/manifest.json";
@ -83,9 +83,7 @@ copydir('src/assets', 'mopidy_iris/static/assets', { filter: assetsFilter }, fun
var package_file_content = fs.readFileSync(package_file, "utf8");
package_file_content = package_file_content.replace(/(?:\"version\"\:\ \")(?:.*)"/, '"version": "'+version+'"');
fs.writeFileSync(package_file, package_file_content, 'utf8');
console.log('Done!');
return true;
});
return false;