Skip to content

Commit f127d72

Browse files
committed
User browser-sync for preview
1 parent 4571a8d commit f127d72

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "node tools/prepare-gh-pages.js",
7-
"start": "node tools/dev-server.js",
8-
"watch": "concurrently \"node tools/dev-server.js\" \"browser-sync start --proxy 'http://localhost:1337' --files '**/*'\""
7+
"start": "node tools/dev-server.js"
98
},
109
"devDependencies": {
1110
"@highlightjs/cdn-assets": "^11.11.1",
@@ -19,7 +18,6 @@
1918
"gh-pages": "^6.3.0",
2019
"github-markdown-css": "^5.8.1",
2120
"handlebars": "^4.7.8",
22-
"open": "^10.1.0",
2321
"showdown": "^2.1.0",
2422
"showdown-footnotes": "^2.1.2",
2523
"showdown-highlight": "^3.1.0"

tools/dev-server.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const showdown = require('showdown');
77
const footnotes = require('showdown-footnotes');
88
const highlight = require("showdown-highlight");
99

10+
const browserSync = require("browser-sync");
11+
1012
const express = require('express');
1113
const app = express();
1214
const port = 1337;
@@ -36,11 +38,6 @@ async function getTemplate() {
3638
return templateFn;
3739
}
3840

39-
async function renderStep(step) {
40-
const html = await renderFile(`steps/${step}/README.md`, step);
41-
return html;
42-
}
43-
4441
async function renderFile(file, step) {
4542
const md = readFileSync(file, { encoding: "utf-8" });
4643
const bodyContent = await convertMarkdown(md);
@@ -49,45 +46,6 @@ async function renderFile(file, step) {
4946
return html;
5047
}
5148

52-
53-
/*
54-
55-
app.get('/', async (req, res) => {
56-
res.redirect(`/README.md`);
57-
});
58-
59-
app.get('/README.md', async (req, res) => {
60-
try {
61-
const md = readFileSync(`README.md`, { encoding: "utf-8" });
62-
const bodyContent = await convertMarkdown(md);
63-
const templateFn = await getTemplate();
64-
const html = templateFn({ title: `Walkthrough`, bodyContent });
65-
res.send(html);
66-
} catch (error) {
67-
res.status(500).send(error.message);
68-
}
69-
});
70-
71-
app.get('/steps/:step', async (req, res) => {
72-
res.redirect(`/steps/${req.params.step}/README.md`);
73-
});
74-
75-
app.get('/steps/:step/README.md', async (req, res) => {
76-
try {
77-
let html;
78-
if (req.params.step === "00") {
79-
html = await renderFile(join(__dirname, "dev-server", "README_AUTHORS.md"), "00");
80-
} else {
81-
html = await renderStep(req.params.step);
82-
}
83-
res.send(html);
84-
} catch (error) {
85-
res.status(500).send(error.message);
86-
}
87-
});
88-
*/
89-
90-
9149
app.use("/assets", express.static(join(__dirname, "..", "assets")));
9250

9351
app.use("/assets/anchor-js", express.static(join(__dirname, "..", "node_modules", "anchor-js")));
@@ -124,7 +82,8 @@ app.use(async (req, res, next) => {
12482
});
12583

12684
app.listen(port, async () => {
127-
console.log(`Example app listening on port ${port}`);
128-
const open = (await import("open")).default;
129-
await open(`http://localhost:${port}`);
85+
browserSync.init({
86+
proxy: `http://localhost:${port}`,
87+
files: ["**/*"],
88+
});
13089
});

0 commit comments

Comments
 (0)