forked from open-wc/open-wc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-start.js
68 lines (61 loc) · 1.77 KB
/
cli-start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable */
const { createConfig, startServer } = require('es-dev-server');
const Eleventy = require('@11ty/eleventy');
const elev = new Eleventy('./docs', './__site');
elev.setConfigPathOverride('./docs/.eleventy.js');
elev.setDryRun(true); // do not write to file system
async function run() {
await elev.init();
const config = {
nodeResolve: true,
watch: true,
open: './docs/README.md',
middlewares: [
async (ctx, next) => {
if (ctx.path.endsWith('index.html')) {
ctx.path = ctx.path.replace('index.html', 'README.md');
} else if (ctx.path.endsWith('.html')) {
ctx.path = ctx.path.replace('.html', '.md');
} else if (ctx.path.endsWith('/')) {
ctx.path += 'README.md';
}
return next();
},
],
plugins: [
{
async transform(context) {
if (context.path.endsWith('md')) {
const serverPath = context.path;
let { body } = 'File not found';
elev.config.filters['hook-for-rocket'] = (content, outputPath, inputPath) => {
if (inputPath === `.${serverPath}`) {
body = content;
}
return content;
};
await elev.write();
return {
body: body.replace(/href="\//g, 'href="/docs/').replace(/src="\//g, 'src="/docs/'),
};
}
return undefined;
},
resolveMimeType(context) {
if (context.path.endsWith('md')) {
return 'text/html';
}
return undefined;
},
},
],
};
startServer(createConfig(config));
['exit', 'SIGINT'].forEach(event => {
// @ts-ignore
process.on(event, () => {
process.exit(0);
});
});
}
run();