Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80537 views
1
require('../server');
2
3
import { exec } from 'mz/child_process';
4
import { rename } from 'mz/fs';
5
import _mkdirp from 'mkdirp';
6
import readdirp from 'readdirp';
7
import { map } from 'event-stream';
8
import path from 'path';
9
10
const outputRoot = path.resolve(process.cwd(), 'dist');
11
12
async () => {
13
await exec('wget -p -P dist/ -m -nH -erobots=off --reject index.html --html-extension http://localhost:3000/flummox');
14
await exec('cp -a public/flummox/data dist/flummox/data');
15
16
const docStream = readdirp({ root: outputRoot, fileFilter: '*.html' })
17
.pipe(map((entry, cb) => {
18
const { path: relativePath } = entry;
19
const { name } = path.parse(relativePath);
20
const originalPath = path.resolve(outputRoot, relativePath);
21
const dir = path.resolve(originalPath, `../${name}`);
22
const newPath = path.resolve(dir, 'index.html');
23
24
async () => {
25
await mkdirp(dir);
26
await rename(originalPath, newPath);
27
cb(null);
28
}().catch(error => cb(error));
29
}))
30
.on('error', error => console.log(error))
31
.on('end', () => {
32
process.exit(0);
33
});
34
}();
35
36
function mkdirp(dir) {
37
return new Promise((resolve, reject) => _mkdirp(dir, (err) => {
38
if (err) reject(err);
39
resolve();
40
}));
41
}
42
43