fix(#8828): web install templates now compiled (#8832)

v1.18.x
Peter Jaszkowiak 4 years ago committed by GitHub
parent 40eb658bc1
commit de5a21f19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -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

@ -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');

Loading…
Cancel
Save