Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit ad14320

Browse files
authored
Merge pull request #195 from sveltejs/export-logs
show which files are being exported
2 parents 02d558b + 43563bd commit ad14320

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"mkdirp": "^0.5.1",
2828
"node-fetch": "^1.7.3",
2929
"polka": "^0.3.4",
30-
"port-authority": "^1.0.0",
30+
"port-authority": "^1.0.2",
31+
"pretty-bytes": "^4.0.2",
3132
"pretty-ms": "^3.1.0",
3233
"require-relative": "^0.8.7",
3334
"rimraf": "^2.6.2",

src/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ prog.command('export [dest]')
5858
try {
5959
const { build } = await import('./cli/build');
6060
await build();
61-
console.error(`\n> Built in ${elapsed(start)}. Exporting...`);
61+
console.error(`\n> Built in ${elapsed(start)}. Crawling site...`);
6262

6363
const { exporter } = await import('./cli/export');
6464
await exporter(dest);

src/cli/export.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as child_process from 'child_process';
22
import * as path from 'path';
33
import * as sander from 'sander';
4+
import * as clorox from 'clorox';
45
import cheerio from 'cheerio';
56
import URL from 'url-parse';
67
import fetch from 'node-fetch';
78
import * as ports from 'port-authority';
9+
import prettyBytes from 'pretty-bytes';
810
import { minify_html } from './utils/minify_html';
911
import { locations } from '../config';
1012

@@ -41,18 +43,22 @@ export async function exporter(export_dir: string) {
4143
proc.on('message', message => {
4244
if (!message.__sapper__) return;
4345

44-
const url = new URL(message.url, origin);
46+
let file = new URL(message.url, origin).pathname.slice(1);
47+
let { body } = message;
4548

46-
if (saved.has(url.pathname)) return;
47-
saved.add(url.pathname);
49+
if (saved.has(file)) return;
50+
saved.add(file);
4851

49-
if (message.type === 'text/html') {
50-
const file = `${export_dir}/${url.pathname}/index.html`;
51-
sander.writeFileSync(file, minify_html(message.body));
52-
} else {
53-
const file = `${export_dir}/${url.pathname}`;
54-
sander.writeFileSync(file, message.body);
52+
const is_html = message.type === 'text/html';
53+
54+
if (is_html) {
55+
file = file === '' ? 'index.html' : `${file}/index.html`;
56+
body = minify_html(body);
5557
}
58+
59+
console.log(`${clorox.bold.cyan(file)} ${clorox.gray(`(${prettyBytes(body.length)})`)}`);
60+
61+
sander.writeFileSync(`${export_dir}/${file}`, body);
5662
});
5763

5864
function handle(url: URL) {
@@ -79,7 +85,7 @@ export async function exporter(export_dir: string) {
7985
}
8086
})
8187
.catch((err: Error) => {
82-
console.error(`Error rendering ${url.pathname}: ${err.message}`);
88+
console.log(clorox.red(`> Error rendering ${url.pathname}: ${err.message}`));
8389
});
8490
}
8591

0 commit comments

Comments
 (0)