From de5a21f19bb92ffad249e584b96bf91895b98eab Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Thu, 5 Nov 2020 10:05:31 -0700
Subject: [PATCH] fix(#8828): web install templates now compiled (#8832)
---
.gitignore | 1 +
install/web.js | 24 +++++++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 596c863e83..515b93ce4a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,7 @@ pidfile
/public/acp.min.js.map
/public/installer.css
/public/installer.min.js
+/public/bootstrap.min.css
/public/logo.png
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
diff --git a/install/web.js b/install/web.js
index 0efe68e05d..715b90a766 100644
--- a/install/web.js
+++ b/install/web.js
@@ -15,6 +15,7 @@ const uglify = require('uglify-es');
const nconf = require('nconf');
const Benchpress = require('benchpressjs');
+const mkdirp = require('mkdirp');
const { paths } = require('../src/constants');
const app = express();
@@ -63,6 +64,8 @@ let success = false;
let error = false;
let launchUrl;
+const viewsDir = path.join(paths.baseDir, 'build/public/templates');
+
web.install = async function (port) {
port = port || 4567;
winston.info('Launching web installer on port ' + port);
@@ -74,13 +77,13 @@ web.install = async function (port) {
Benchpress.__express(filepath, options, callback);
});
app.set('view engine', 'tpl');
- const viewsDir = path.join(paths.baseDir, 'build/public/templates');
app.set('views', viewsDir);
app.use(bodyParser.urlencoded({
extended: true,
}));
try {
await Promise.all([
+ compileTemplate(),
compileLess(),
compileJS(),
copyCSS(),
@@ -228,6 +231,25 @@ async function launch(req, res) {
}
}
+// this is necessary because otherwise the compiled templates won't be available on a clean install
+async function compileTemplate() {
+ const sourceFile = path.join(__dirname, '../src/views/install/index.tpl');
+ const destTpl = path.join(viewsDir, 'install/index.tpl');
+ const destJs = path.join(viewsDir, 'install/index.js');
+
+ const source = await fs.promises.readFile(sourceFile, 'utf8');
+
+ const [compiled] = await Promise.all([
+ Benchpress.precompile(source),
+ mkdirp(path.dirname(destJs)),
+ ]);
+
+ await Promise.all([
+ fs.promises.writeFile(destJs, compiled),
+ fs.promises.writeFile(destTpl, source),
+ ]);
+}
+
async function compileLess() {
try {
const installSrc = path.join(__dirname, '../public/less/install.less');