Node.js based forum software built for the modern web
fix(#8828): web install templates now compiled (#8832)
Peter Jaszkowiakde5a21f19bb9
diff --git a/.gitignore b/.gitignoreindex 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 Studiodiff --git a/install/web.js b/install/web.jsindex 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');