show which files are being exported

This commit is contained in:
Rich Harris
2018-03-11 15:44:53 -04:00
parent 02d558b97c
commit 43563bd8e5
3 changed files with 19 additions and 12 deletions

View File

@@ -27,7 +27,8 @@
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"node-fetch": "^1.7.3", "node-fetch": "^1.7.3",
"polka": "^0.3.4", "polka": "^0.3.4",
"port-authority": "^1.0.0", "port-authority": "^1.0.2",
"pretty-bytes": "^4.0.2",
"pretty-ms": "^3.1.0", "pretty-ms": "^3.1.0",
"require-relative": "^0.8.7", "require-relative": "^0.8.7",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",

View File

@@ -58,7 +58,7 @@ prog.command('export [dest]')
try { try {
const { build } = await import('./cli/build'); const { build } = await import('./cli/build');
await build(); await build();
console.error(`\n> Built in ${elapsed(start)}. Exporting...`); console.error(`\n> Built in ${elapsed(start)}. Crawling site...`);
const { exporter } = await import('./cli/export'); const { exporter } = await import('./cli/export');
await exporter(dest); await exporter(dest);

View File

@@ -1,10 +1,12 @@
import * as child_process from 'child_process'; import * as child_process from 'child_process';
import * as path from 'path'; import * as path from 'path';
import * as sander from 'sander'; import * as sander from 'sander';
import * as clorox from 'clorox';
import cheerio from 'cheerio'; import cheerio from 'cheerio';
import URL from 'url-parse'; import URL from 'url-parse';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import * as ports from 'port-authority'; import * as ports from 'port-authority';
import prettyBytes from 'pretty-bytes';
import { minify_html } from './utils/minify_html'; import { minify_html } from './utils/minify_html';
import { locations } from '../config'; import { locations } from '../config';
@@ -41,18 +43,22 @@ export async function exporter(export_dir: string) {
proc.on('message', message => { proc.on('message', message => {
if (!message.__sapper__) return; if (!message.__sapper__) return;
const url = new URL(message.url, origin); let file = new URL(message.url, origin).pathname.slice(1);
let { body } = message;
if (saved.has(url.pathname)) return; if (saved.has(file)) return;
saved.add(url.pathname); saved.add(file);
if (message.type === 'text/html') { const is_html = message.type === 'text/html';
const file = `${export_dir}/${url.pathname}/index.html`;
sander.writeFileSync(file, minify_html(message.body)); if (is_html) {
} else { file = file === '' ? 'index.html' : `${file}/index.html`;
const file = `${export_dir}/${url.pathname}`; body = minify_html(body);
sander.writeFileSync(file, message.body);
} }
console.log(`${clorox.bold.cyan(file)} ${clorox.gray(`(${prettyBytes(body.length)})`)}`);
sander.writeFileSync(`${export_dir}/${file}`, body);
}); });
function handle(url: URL) { function handle(url: URL) {
@@ -79,7 +85,7 @@ export async function exporter(export_dir: string) {
} }
}) })
.catch((err: Error) => { .catch((err: Error) => {
console.error(`Error rendering ${url.pathname}: ${err.message}`); console.log(clorox.red(`> Error rendering ${url.pathname}: ${err.message}`));
}); });
} }