diff --git a/lib/index.js b/lib/index.js
index 93cee47..720d114 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -149,7 +149,7 @@ function get_route_handler(fn) {
});
return templates.stream(res, 200, {
- main: client.main_file,
+ scripts: ``,
html: promise.then(rendered => rendered.html),
head: promise.then(({ head }) => `${head}`),
styles: promise.then(({ css }) => (css && css.code ? `` : ''))
@@ -158,7 +158,7 @@ function get_route_handler(fn) {
const { html, head, css } = mod.render(data);
const page = templates.render(200, {
- main: client.main_file,
+ scripts: ``,
html,
head: `${head}`,
styles: (css && css.code ? `` : '')
@@ -221,7 +221,7 @@ function get_not_found_handler(fn) {
title: 'Not found',
status: 404,
method: req.method,
- main: asset_cache.client.main_file,
+ scripts: ``,
url: req.url
}));
};
diff --git a/lib/templates.js b/lib/templates.js
index 8260aa8..058325c 100644
--- a/lib/templates.js
+++ b/lib/templates.js
@@ -1,10 +1,22 @@
const fs = require('fs');
const glob = require('glob');
+const chalk = require('chalk');
const chokidar = require('chokidar');
+const framer = require('code-frame');
+const { locate } = require('locate-character');
const { dev } = require('./config.js');
let templates;
+function error(e) {
+ if (e.title) console.error(chalk.bold.red(e.title));
+ if (e.body) console.error(chalk.red(e.body));
+ if (e.url) console.error(chalk.cyan(e.url));
+ if (e.frame) console.error(chalk.grey(e.frame));
+
+ process.exit(1);
+}
+
function create_templates() {
templates = glob.sync('*.html', { cwd: 'templates' })
.map(file => {
@@ -12,7 +24,24 @@ function create_templates() {
const status = file.replace('.html', '').toLowerCase();
if (!/^[0-9x]{3}$/.test(status)) {
- throw new Error(`Bad template — should be a valid status code like 404.html, or a wildcard like 2xx.html`);
+ error({
+ title: `templates/${file}`,
+ body: `Bad template — should be a valid status code like 404.html, or a wildcard like 2xx.html`
+ });
+ }
+
+ const index = template.indexOf('%sapper.main%');
+ if (index !== -1) {
+ // TODO remove this in a future version
+ const { line, column } = locate(template, index, { offsetLine: 1 });
+ const frame = framer(template, line, column);
+
+ error({
+ title: `templates/${file}`,
+ body: `
+ %sapper.scripts%