Compare commits

..

6 Commits

Author SHA1 Message Date
Rich Harris
9b1b545194 -> v0.6.3 2018-02-03 16:26:53 -05:00
Rich Harris
7b01242f3e always build in prod mode 2018-02-03 16:26:47 -05:00
Rich Harris
15b1fbf8a6 ignore non-html responses when crawling, and close middleware when done 2018-02-03 16:17:28 -05:00
Rich Harris
8f1d2e0a04 -> v0.6.2 2018-02-03 13:56:38 -05:00
Rich Harris
dfb8692d78 handle unspecified type in sapper export 2018-02-03 13:56:14 -05:00
Rich Harris
09d3c4d85e add prepublish script 2018-02-03 13:49:21 -05:00
5 changed files with 35 additions and 19 deletions

View File

@@ -1,5 +1,14 @@
# sapper changelog
## 0.6.3
* Ignore non-HTML responses when crawling during `export`
* Build in prod mode for `export`
## 0.6.2
* Handle unspecified type in `sapper export`
## 0.6.1
* Fix `pkg.files` and `pkg.bin`

View File

@@ -1,6 +1,6 @@
{
"name": "sapper",
"version": "0.6.1",
"version": "0.6.3",
"description": "Military-grade apps, engineered by Svelte",
"main": "middleware.js",
"bin": {
@@ -66,7 +66,8 @@
"test": "mocha --opts mocha.opts",
"pretest": "npm run build",
"build": "rollup -c",
"dev": "rollup -cw"
"dev": "rollup -cw",
"prepublish": "npm test"
},
"repository": "https://github.com/sveltejs/sapper",
"keywords": [

View File

@@ -1,6 +1,8 @@
import { build, export as exporter } from 'sapper/core.js';
import { dest, dev, entry, src } from '../config';
process.env.NODE_ENV = 'production';
const cmd = process.argv[2];
const start = Date.now();
@@ -14,9 +16,7 @@ if (cmd === 'build') {
console.error(err ? err.details || err.stack || err.message || err : 'Unknown error');
});
} else if (cmd === 'export') {
const start = Date.now();
build({ dest, dev, entry, src })
build({ dest, dev: false, entry, src })
.then(() => exporter({ src, dest }))
.then(() => {
const elapsed = Date.now() - start;

View File

@@ -41,7 +41,7 @@ export default function exporter({ src, dest }) { // TODO dest is a terrible nam
let dest = OUTPUT_DIR + pathname;
const type = res.headers.get('Content-Type');
if (type.startsWith('text/html')) dest += '/index.html';
if (type && type.startsWith('text/html')) dest += '/index.html';
sander.writeFileSync(dest, body);
@@ -63,7 +63,8 @@ export default function exporter({ src, dest }) { // TODO dest is a terrible nam
return fetch(url, opts);
};
app.use(require('./middleware')()); // TODO this is filthy
const middleware = require('./middleware')({ dev: false }); // TODO this is filthy
app.use(middleware);
const server = app.listen(PORT);
const seen = new Set();
@@ -77,19 +78,21 @@ export default function exporter({ src, dest }) { // TODO dest is a terrible nam
return fetch(url.href)
.then(r => {
save(r);
return r.text();
})
.then(body => {
const $ = cheerio.load(body);
const hrefs = [];
$('a[href]').each((i, $a) => {
hrefs.push($a.attribs.href);
});
if (r.headers.get('Content-Type') === 'text/html') {
return r.text().then(body => {
const $ = cheerio.load(body);
const hrefs = [];
return hrefs.reduce((promise, href) => {
return promise.then(() => handle(new URL(href, url.href)));
}, Promise.resolve());
$('a[href]').each((i, $a) => {
hrefs.push($a.attribs.href);
});
return hrefs.reduce((promise, href) => {
return promise.then(() => handle(new URL(href, url.href)));
}, Promise.resolve());
});
}
})
.catch(err => {
console.error(`Error rendering ${url.pathname}: ${err.message}`);

View File

@@ -122,7 +122,10 @@ function connect_prod() {
return middleware;
}
export default dev ? connect_dev : connect_prod;
export default function connect({ dev: _dev = dev } = {}) {
console.log({ dev, _dev });
return _dev ? connect_dev() : connect_prod();
}
function set_req_pathname(req, res, next) {
req.pathname = req.url.replace(/\?.*/, '');