mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 11:35:28 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b1b545194 | ||
|
|
7b01242f3e | ||
|
|
15b1fbf8a6 | ||
|
|
8f1d2e0a04 | ||
|
|
dfb8692d78 | ||
|
|
09d3c4d85e |
@@ -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`
|
||||
|
||||
@@ -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": [
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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(/\?.*/, '');
|
||||
|
||||
Reference in New Issue
Block a user