Skip to content

Commit 577388d

Browse files
authored
Merge pull request #127 from webdoc-labs/feature/out-source-files
Feature: Support for publishing source files
2 parents 2567fc5 + b799598 commit 577388d

File tree

19 files changed

+303
-37
lines changed

19 files changed

+303
-37
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 16 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"build-pixi-api": "cd ../../pixi-api && webdoc --verbose && cd ../webdoc/example",
2929
"build-pixi-api-prod": "cd ../../pixi-api && webdoc --site-root pixi-api && cd ../webdoc/example",
3030
"build-pixi-api-gcp": "cd ../../pixi-api && webdoc --tutorials ./projects/guides --verbose && cd ../webdoc/example",
31+
"build-pixi-api-gcp-inspect": "cd ../../pixi-api && node --inspect-brk --trace-warnings ../webdoc/example/node_modules/@webdoc/cli/cli.js --tutorials ./projects/guides --verbose && cd ../webdoc/example",
3132
"build-pixi-guides": "cd ../../guides && webdoc --tutorials docs && cd ../webdoc/example",
3233
"build-mongodb": "cd ../../node-mongodb-native && webdoc --verbose && cd ../webdoc/example"
3334
},

packages/webdoc-cli/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ The `template` object is used by the site template.
138138
item defines a name and URI.
139139
* `template.routes`: This can be used to override specific routes generated by the template. For example, you can move the
140140
`tutorials` to be outputted at "/faq" instead of "/tutorials", if desired.
141+
* `template.sources`: (enabled by default) This will output the source code of the project as well and link symbols to their
142+
locations in the code.
141143
* `template.title`: This is the title shown in the browser tabs (defaults to `template.applicationName`). You should use this
142144
if you have HTML in the application name.
143145
* `template.meta`: (optional) This can be used to define the `<meta>` key-value tags. The `{{url}}` variable can be used

packages/webdoc-cli/src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type ConfigSchema = {
4848
routes: {
4949
tutorials: string,
5050
},
51+
sources: boolean,
5152
stylesheets: Array<string>,
5253
siteDomain?: string,
5354
siteRoot: string,
@@ -104,6 +105,7 @@ const defaultConfig: ConfigSchema = {
104105
tutorials: "tutorials",
105106
},
106107
siteRoot: "",
108+
sources: true,
107109
stylesheets: [],
108110
mainPage: {
109111
title: "Main Page",

packages/webdoc-cli/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ async function main(argv: yargs.Argv) {
141141
docDatabase: db,
142142
opts: config.opts,
143143
tutorials,
144+
source: sourceFiles,
144145
verbose: !!argv.verbose,
146+
cmdLine: {
147+
mainThread: argv.mainThread,
148+
},
145149
};
146150

147151
if (template.publish && typeof template.publish === "function") {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @flow
2+
3+
const fs = require("fs");
4+
const hljs = require("highlight.js");
5+
// $FlowFixMe
6+
const {isMainThread, parentPort} = require("worker_threads");
7+
8+
function onMessage(data /*: { id: number, file: string } */) {
9+
const {id, file} = data;
10+
11+
fs.readFile(file, "utf8", function onFileRead(err, raw) {
12+
if (err) {
13+
return parentPort.postMessage({
14+
id,
15+
file,
16+
error: true,
17+
result: null,
18+
});
19+
}
20+
21+
const languageSubset = file.endsWith(".js") ? ["javascript"] : undefined;
22+
const result = hljs.highlightAuto(raw, languageSubset).value;
23+
24+
parentPort.postMessage({
25+
id,
26+
file,
27+
error: false,
28+
result,
29+
});
30+
});
31+
}
32+
33+
if (!isMainThread) {
34+
parentPort.on("message", onMessage);
35+
}

packages/webdoc-default-template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"code-prettify": "^0.1.0",
4848
"fs-extra": "^9.0.1",
4949
"markdown-it": "^11.0.0",
50-
"markdown-it-highlightjs": "^3.1.0"
50+
"markdown-it-highlightjs": "^3.1.0",
51+
"highlight.js": "~10.7.2"
5152
},
5253
"devDependencies": {
5354
"@babel/cli": "^7.8.4",

0 commit comments

Comments
 (0)