@beforesemicolon/builder 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -0
- package/dist/build-browser.d.ts +1 -0
- package/dist/build-browser.js +32 -0
- package/dist/build-browser.js.map +1 -0
- package/dist/build-modules.d.ts +1 -0
- package/{src/build-modules.ts → dist/build-modules.js} +19 -26
- package/dist/build-modules.js.map +1 -0
- package/dist/docs/renderer/code.d.ts +2 -0
- package/{src/docs/renderer/code.ts → dist/docs/renderer/code.js} +3 -4
- package/dist/docs/renderer/code.js.map +1 -0
- package/dist/docs/renderer/heading.d.ts +2 -0
- package/dist/docs/renderer/heading.js +10 -0
- package/dist/docs/renderer/heading.js.map +1 -0
- package/dist/docs/renderer/index.d.ts +3 -0
- package/dist/docs/renderer/index.js +9 -0
- package/dist/docs/renderer/index.js.map +1 -0
- package/dist/docs/renderer/link.d.ts +2 -0
- package/dist/docs/renderer/link.js +6 -0
- package/dist/docs/renderer/link.js.map +1 -0
- package/dist/docs/run.d.ts +1 -0
- package/dist/docs/run.js +158 -0
- package/dist/docs/run.js.map +1 -0
- package/dist/docs/templates/default.d.ts +3 -0
- package/{src/docs/templates/default.ts → dist/docs/templates/default.js} +3 -4
- package/dist/docs/templates/default.js.map +1 -0
- package/dist/docs/types.d.ts +17 -0
- package/dist/docs/types.js +2 -0
- package/dist/docs/types.js.map +1 -0
- package/package.json +1 -1
- package/.eslintignore +0 -1
- package/.eslintrc.cjs +0 -13
- package/.prettierignore +0 -2
- package/.prettierrc +0 -6
- package/src/build-browser.ts +0 -35
- package/src/docs/renderer/heading.ts +0 -13
- package/src/docs/renderer/index.ts +0 -10
- package/src/docs/renderer/link.ts +0 -7
- package/src/docs/run.ts +0 -212
- package/src/docs/types.ts +0 -16
- package/tsconfig.json +0 -24
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import esbuild from 'esbuild';
|
2
|
+
const emptyParserDoc = {
|
3
|
+
name: 'empty-parser-Doc-plugin',
|
4
|
+
setup(build) {
|
5
|
+
build.onResolve({ filter: /Doc$/ }, (args) => {
|
6
|
+
if (args.importer.includes('@beforesemicolon/html-parser')) {
|
7
|
+
return {
|
8
|
+
path: args.path,
|
9
|
+
namespace: 'empty-Doc',
|
10
|
+
};
|
11
|
+
}
|
12
|
+
});
|
13
|
+
build.onLoad({ filter: /.*/, namespace: 'empty-Doc' }, () => {
|
14
|
+
return {
|
15
|
+
contents: '',
|
16
|
+
};
|
17
|
+
});
|
18
|
+
},
|
19
|
+
};
|
20
|
+
esbuild
|
21
|
+
.build({
|
22
|
+
entryPoints: ['src/client.ts'],
|
23
|
+
outfile: 'dist/client.js',
|
24
|
+
bundle: true,
|
25
|
+
keepNames: true,
|
26
|
+
sourcemap: true,
|
27
|
+
target: 'esnext',
|
28
|
+
minify: true,
|
29
|
+
plugins: [emptyParserDoc],
|
30
|
+
})
|
31
|
+
.catch(console.error);
|
32
|
+
//# sourceMappingURL=build-browser.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"build-browser.js","sourceRoot":"","sources":["../src/build-browser.ts"],"names":[],"mappings":"AAAA,OAAO,OAAmB,MAAM,SAAS,CAAA;AAIzC,MAAM,cAAc,GAAG;IACnB,IAAI,EAAE,yBAAyB;IAC/B,KAAK,CAAC,KAAK;QACP,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;YACzC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,8BAA8B,CAAC,EAAE,CAAC;gBACzD,OAAO;oBACH,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,SAAS,EAAE,WAAW;iBACzB,CAAA;YACL,CAAC;QACL,CAAC,CAAC,CAAA;QACF,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;YACxD,OAAO;gBACH,QAAQ,EAAE,EAAE;aACf,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACM,CAAA;AAEX,OAAO;KACF,KAAK,CAAC;IACH,WAAW,EAAE,CAAC,eAAe,CAAC;IAC9B,OAAO,EAAE,gBAAgB;IACzB,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,CAAC,cAAc,CAAC;CAC5B,CAAC;KACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -1,34 +1,26 @@
|
|
1
|
-
import esbuild from 'esbuild'
|
2
|
-
import path from 'path'
|
3
|
-
import fs from 'fs'
|
4
|
-
import { transformExtPlugin } from '@gjsify/esbuild-plugin-transform-ext'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
function readDirectory(currentPath: string) {
|
10
|
-
const entries = fs.readdirSync(currentPath, { withFileTypes: true })
|
11
|
-
|
1
|
+
import esbuild from 'esbuild';
|
2
|
+
import path from 'path';
|
3
|
+
import fs from 'fs';
|
4
|
+
import { transformExtPlugin } from '@gjsify/esbuild-plugin-transform-ext';
|
5
|
+
function readFilesRecursively(directoryPath) {
|
6
|
+
const files = [];
|
7
|
+
function readDirectory(currentPath) {
|
8
|
+
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
|
12
9
|
for (const entry of entries) {
|
13
|
-
const fullPath = path.join(currentPath, entry.name)
|
14
|
-
|
10
|
+
const fullPath = path.join(currentPath, entry.name);
|
15
11
|
if (entry.isDirectory()) {
|
16
|
-
readDirectory(fullPath)
|
17
|
-
}
|
18
|
-
|
12
|
+
readDirectory(fullPath);
|
13
|
+
}
|
14
|
+
else {
|
15
|
+
files.push(fullPath);
|
19
16
|
}
|
20
17
|
}
|
21
18
|
}
|
22
|
-
|
23
|
-
|
24
|
-
return files
|
19
|
+
readDirectory(directoryPath);
|
20
|
+
return files;
|
25
21
|
}
|
26
|
-
|
27
|
-
const
|
28
|
-
const allFiles = readFilesRecursively(directoryPath).filter(
|
29
|
-
(file) => !file.endsWith('.spec.ts') && !file.endsWith('/client.ts')
|
30
|
-
)
|
31
|
-
|
22
|
+
const directoryPath = path.join(process.cwd(), 'src');
|
23
|
+
const allFiles = readFilesRecursively(directoryPath).filter((file) => !file.endsWith('.spec.ts') && !file.endsWith('/client.ts'));
|
32
24
|
Promise.all([
|
33
25
|
esbuild.build({
|
34
26
|
entryPoints: allFiles,
|
@@ -50,4 +42,5 @@ Promise.all([
|
|
50
42
|
keepNames: true,
|
51
43
|
plugins: [transformExtPlugin({ outExtension: { '.ts': '.js' } })],
|
52
44
|
}),
|
53
|
-
]).catch(console.error)
|
45
|
+
]).catch(console.error);
|
46
|
+
//# sourceMappingURL=build-modules.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"build-modules.js","sourceRoot":"","sources":["../src/build-modules.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAEzE,SAAS,oBAAoB,CAAC,aAAqB;IAC/C,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,SAAS,aAAa,CAAC,WAAmB;QACtC,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;QAEpE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;YAEnD,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACtB,aAAa,CA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,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
export default function code({ lang, text }: Tokens.Code) {
|
1
|
+
export default function code({ lang, text }) {
|
4
2
|
return `<div class="code-snippet">
|
5
3
|
${lang ? `<div class="label ${lang.toLowerCase()}">${lang}</div>` : ''}
|
6
4
|
<div class="content">
|
@@ -11,5 +9,6 @@ export default function code({ lang, text }: Tokens.Code) {
|
|
11
9
|
<button type="button" class="code-copy-btn" style="visibility: hidden">
|
12
10
|
copy
|
13
11
|
</button>
|
14
|
-
</div
|
12
|
+
</div>`;
|
15
13
|
}
|
14
|
+
//# sourceMappingURL=code.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../../src/docs/renderer/code.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAe;IACpD,OAAO;UACD,IAAI,CAAC,CAAC,CAAC,qBAAqB,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE;;;yDAGrB,IAAI;;;;;;WAMlD,CAAA;AACX,CAAC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export default function heading({ tokens, depth }) {
|
2
|
+
const text = this.parser.parseInline(tokens);
|
3
|
+
const escapedText = text
|
4
|
+
.toLowerCase()
|
5
|
+
.replace(/[^\w]+/g, ' ')
|
6
|
+
.trim()
|
7
|
+
.replace(/\s/g, '-');
|
8
|
+
return `<h${depth} id="${escapedText}"><a href="#${escapedText}">${text}</a></h${depth}>`;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=heading.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"heading.js","sourceRoot":"","sources":["../../../src/docs/renderer/heading.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAkB;IAE7D,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAC5C,MAAM,WAAW,GAAG,IAAI;SACnB,WAAW,EAAE;SACb,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,IAAI,EAAE;SACN,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAExB,OAAO,KAAK,KAAK,QAAQ,WAAW,eAAe,WAAW,KAAK,IAAI,UAAU,KAAK,GAAG,CAAA;AAC7F,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/docs/renderer/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,eAAe;IACX,OAAO;IACP,IAAI;IACJ,IAAI;CACsB,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../../src/docs/renderer/link.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAe;IACpD,OAAO,YAAY,IAAI;SAClB,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;SACxB,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,KAAK,IAAI,MAAM,CAAA;AAClD,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/docs/run.js
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
11
|
+
var t = {};
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
13
|
+
t[p] = s[p];
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
17
|
+
t[p[i]] = s[p[i]];
|
18
|
+
}
|
19
|
+
return t;
|
20
|
+
};
|
21
|
+
import { Marked } from 'marked';
|
22
|
+
import { cp, mkdir, readdir, readFile, writeFile } from 'fs/promises';
|
23
|
+
import path from 'path';
|
24
|
+
import fm from 'front-matter';
|
25
|
+
import DOMPurify from 'isomorphic-dompurify';
|
26
|
+
import { markedHighlight } from 'marked-highlight';
|
27
|
+
import hljs from 'highlight.js';
|
28
|
+
import defaultTemp from './templates/default.js';
|
29
|
+
import renderer from './renderer/index.js';
|
30
|
+
const layouts = new Map();
|
31
|
+
layouts.set('default', defaultTemp);
|
32
|
+
let currentFileMeta;
|
33
|
+
const marked = new Marked(markedHighlight({
|
34
|
+
langPrefix: 'hljs language-',
|
35
|
+
highlight(code, lang) {
|
36
|
+
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
37
|
+
return hljs.highlight(code, { language }).value;
|
38
|
+
},
|
39
|
+
}));
|
40
|
+
marked.use({ renderer });
|
41
|
+
const docsDir = path.resolve(process.cwd(), 'docs');
|
42
|
+
const docsSiteDir = path.resolve(process.cwd(), 'website');
|
43
|
+
const docsLayoutsDir = path.resolve(process.cwd(), 'docs/_layouts');
|
44
|
+
const docsAssetsDir = path.resolve(process.cwd(), 'docs/assets');
|
45
|
+
const docsStylesheetsDir = path.resolve(process.cwd(), 'docs/stylesheets');
|
46
|
+
const docsScriptsDir = path.resolve(process.cwd(), 'docs/scripts');
|
47
|
+
const traverseDirectory = (dir) => __awaiter(void 0, void 0, void 0, function* () {
|
48
|
+
const items = yield readdir(dir);
|
49
|
+
const files = [];
|
50
|
+
for (const item of items) {
|
51
|
+
const ext = path.extname(item);
|
52
|
+
if (/^[._]/.test(item))
|
53
|
+
continue;
|
54
|
+
if (ext) {
|
55
|
+
files.push(path.join(dir, item));
|
56
|
+
}
|
57
|
+
else if (!/(stylesheets|assets|scripts)/.test(item)) {
|
58
|
+
files.push(...(yield traverseDirectory(path.join(dir, item))));
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return files;
|
62
|
+
});
|
63
|
+
marked.use({
|
64
|
+
hooks: {
|
65
|
+
postprocess(html) {
|
66
|
+
var _a;
|
67
|
+
const _b = currentFileMeta.attributes, { layout = 'default' } = _b, options = __rest(_b, ["layout"]);
|
68
|
+
html = DOMPurify.sanitize(html);
|
69
|
+
const tableOfContent = [
|
70
|
+
...html.matchAll(/<h([0-6])\sid="[^"]+".*?>.*?<a\s+href="([^"]+)".*?>([^<]+)<\/a>/gm),
|
71
|
+
].map((m) => ({ path: m[2], label: m[3], level: m[1] }));
|
72
|
+
return (((_a = layouts.get(layout)) === null || _a === void 0 ? void 0 : _a(Object.assign(Object.assign({}, options), { content: html, siteMap: currentFileMeta.siteMap, tableOfContent }))) || html);
|
73
|
+
},
|
74
|
+
},
|
75
|
+
});
|
76
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
77
|
+
yield mkdir(docsSiteDir, { recursive: true });
|
78
|
+
try {
|
79
|
+
yield cp(docsAssetsDir, docsAssetsDir.replace(docsDir, docsSiteDir), {
|
80
|
+
recursive: true,
|
81
|
+
});
|
82
|
+
}
|
83
|
+
catch (e) {
|
84
|
+
}
|
85
|
+
try {
|
86
|
+
yield cp(docsStylesheetsDir, docsStylesheetsDir.replace(docsDir, docsSiteDir), { recursive: true });
|
87
|
+
}
|
88
|
+
catch (e) {
|
89
|
+
}
|
90
|
+
try {
|
91
|
+
yield cp(docsScriptsDir, docsScriptsDir.replace(docsDir, docsSiteDir), {
|
92
|
+
recursive: true,
|
93
|
+
});
|
94
|
+
}
|
95
|
+
catch (e) {
|
96
|
+
}
|
97
|
+
try {
|
98
|
+
const layoutPaths = yield traverseDirectory(docsLayoutsDir);
|
99
|
+
for (const layoutPath of layoutPaths) {
|
100
|
+
if (/\.(j|t)s$/.test(layoutPath)) {
|
101
|
+
const fileName = path
|
102
|
+
.basename(layoutPath)
|
103
|
+
.replace(path.extname(layoutPath), '');
|
104
|
+
const handler = yield import(layoutPath);
|
105
|
+
layouts.set(fileName, handler.default);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
catch (e) {
|
110
|
+
}
|
111
|
+
const filePaths = yield traverseDirectory(docsDir);
|
112
|
+
const siteMap = new Map();
|
113
|
+
(yield Promise.all(filePaths
|
114
|
+
.filter((filePath) => filePath.endsWith('.md'))
|
115
|
+
.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
116
|
+
const content = yield readFile(filePath, 'utf-8');
|
117
|
+
return Object.assign({ filePath }, fm(content));
|
118
|
+
}))))
|
119
|
+
.sort((a, b) => a.attributes.order - b.attributes.order)
|
120
|
+
.map(({ attributes, body, filePath }) => {
|
121
|
+
const pathname = filePath
|
122
|
+
.replace(docsDir, '')
|
123
|
+
.replace(/\.md/, '.html');
|
124
|
+
const fileWebsitePath = filePath
|
125
|
+
.replace(docsDir, docsSiteDir)
|
126
|
+
.replace('.md', '.html');
|
127
|
+
const fileDirWebsitePath = fileWebsitePath.replace(path.basename(fileWebsitePath), '');
|
128
|
+
const fileName = path.basename(pathname) || '/';
|
129
|
+
const dir = pathname.replace(fileName, '').replace(/\/$/, '');
|
130
|
+
let currentDir = siteMap;
|
131
|
+
dir.split('/')
|
132
|
+
.filter(Boolean)
|
133
|
+
.forEach((d) => {
|
134
|
+
if (!currentDir.has(d)) {
|
135
|
+
currentDir.set(d, new Map());
|
136
|
+
}
|
137
|
+
currentDir = currentDir.get(d);
|
138
|
+
});
|
139
|
+
const attrs = Object.assign(Object.assign({}, attributes), { path: pathname });
|
140
|
+
if (!currentDir.has(fileName)) {
|
141
|
+
currentDir.set(fileName, attrs);
|
142
|
+
}
|
143
|
+
return {
|
144
|
+
attributes: attrs,
|
145
|
+
fileWebsitePath,
|
146
|
+
fileDirWebsitePath,
|
147
|
+
body,
|
148
|
+
siteMap,
|
149
|
+
};
|
150
|
+
})
|
151
|
+
.forEach((_a) => __awaiter(void 0, [_a], void 0, function* ({ attributes, body, fileDirWebsitePath, fileWebsitePath, siteMap, }) {
|
152
|
+
currentFileMeta = { attributes, siteMap };
|
153
|
+
const contentMd = yield marked.parse(body);
|
154
|
+
yield mkdir(fileDirWebsitePath, { recursive: true });
|
155
|
+
yield writeFile(fileWebsitePath, contentMd);
|
156
|
+
}));
|
157
|
+
}))();
|
158
|
+
//# sourceMappingURL=run.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/docs/run.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACrE,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,cAAc,CAAA;AAC7B,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,IAAI,MAAM,cAAc,CAAA;AAC/B,OAAO,WAAW,MAAM,wBAAwB,CAAA;AAEhD,OAAO,QAAQ,MAAM,qBAAqB,CAAA;AAE1C,MAAM,OAAO,GAA8C,IAAI,GAAG,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CAAA;AACT,CAAC,CAAA,CAAC,EAAE,CAAA"}
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
export default ({ title, description, content }: PageProps) => `
|
1
|
+
export default ({ title, description, content }) => `
|
4
2
|
<!doctype html>
|
5
3
|
<html lang="en">
|
6
4
|
<head>
|
@@ -16,4 +14,5 @@ export default ({ title, description, content }: PageProps) => `
|
|
16
14
|
${content}
|
17
15
|
</body>
|
18
16
|
</html>
|
19
|
-
|
17
|
+
`;
|
18
|
+
//# sourceMappingURL=default.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../../src/docs/templates/default.ts"],"names":[],"mappings":"AAEA,eAAe,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAa,EAAE,EAAE,CAAC;;;;;;;;;4CASnB,WAAW;iBACtC,KAAK;;;UAGZ,OAAO;;;CAGhB,CAAA"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export interface PageProps {
|
2
|
+
name: string;
|
3
|
+
path: string;
|
4
|
+
order: number;
|
5
|
+
title: string;
|
6
|
+
description: string;
|
7
|
+
content: string;
|
8
|
+
siteMap: SiteMap;
|
9
|
+
tableOfContent: {
|
10
|
+
path: string;
|
11
|
+
label: string;
|
12
|
+
}[];
|
13
|
+
}
|
14
|
+
export interface CustomOptions extends Omit<PageProps, 'content'> {
|
15
|
+
layout: string;
|
16
|
+
}
|
17
|
+
export type SiteMap = Map<string, CustomOptions | SiteMap>;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/docs/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/.eslintignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
src/**/*.spec.ts
|
package/.eslintrc.cjs
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module.exports = {
|
2
|
-
extends: [
|
3
|
-
'eslint:recommended',
|
4
|
-
'plugin:@typescript-eslint/recommended',
|
5
|
-
'prettier',
|
6
|
-
],
|
7
|
-
parser: '@typescript-eslint/parser',
|
8
|
-
plugins: ['@typescript-eslint'],
|
9
|
-
root: true,
|
10
|
-
rules: {
|
11
|
-
'no-prototype-builtins': ['off'],
|
12
|
-
},
|
13
|
-
}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/src/build-browser.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import esbuild, { Plugin } from 'esbuild'
|
2
|
-
|
3
|
-
// the Doc exported with @beforesemicolon/html-parser is not used so no need
|
4
|
-
// to include it in the final package
|
5
|
-
const emptyParserDoc = {
|
6
|
-
name: 'empty-parser-Doc-plugin',
|
7
|
-
setup(build) {
|
8
|
-
build.onResolve({ filter: /Doc$/ }, (args) => {
|
9
|
-
if (args.importer.includes('@beforesemicolon/html-parser')) {
|
10
|
-
return {
|
11
|
-
path: args.path,
|
12
|
-
namespace: 'empty-Doc',
|
13
|
-
}
|
14
|
-
}
|
15
|
-
})
|
16
|
-
build.onLoad({ filter: /.*/, namespace: 'empty-Doc' }, () => {
|
17
|
-
return {
|
18
|
-
contents: '',
|
19
|
-
}
|
20
|
-
})
|
21
|
-
},
|
22
|
-
} as Plugin
|
23
|
-
|
24
|
-
esbuild
|
25
|
-
.build({
|
26
|
-
entryPoints: ['src/client.ts'],
|
27
|
-
outfile: 'dist/client.js',
|
28
|
-
bundle: true,
|
29
|
-
keepNames: true,
|
30
|
-
sourcemap: true,
|
31
|
-
target: 'esnext',
|
32
|
-
minify: true,
|
33
|
-
plugins: [emptyParserDoc],
|
34
|
-
})
|
35
|
-
.catch(console.error)
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Tokens } from 'marked'
|
2
|
-
|
3
|
-
export default function heading({ tokens, depth }: Tokens.Heading) {
|
4
|
-
// @ts-expect-error this
|
5
|
-
const text = this.parser.parseInline(tokens)
|
6
|
-
const escapedText = text
|
7
|
-
.toLowerCase()
|
8
|
-
.replace(/[^\w]+/g, ' ')
|
9
|
-
.trim()
|
10
|
-
.replace(/\s/g, '-')
|
11
|
-
|
12
|
-
return `<h${depth} id="${escapedText}"><a href="#${escapedText}">${text}</a></h${depth}>`
|
13
|
-
}
|
package/src/docs/run.ts
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
import { Marked } from 'marked'
|
2
|
-
import { cp, mkdir, readdir, readFile, writeFile } from 'fs/promises'
|
3
|
-
import path from 'path'
|
4
|
-
import fm from 'front-matter'
|
5
|
-
import DOMPurify from 'isomorphic-dompurify'
|
6
|
-
import { markedHighlight } from 'marked-highlight'
|
7
|
-
import hljs from 'highlight.js'
|
8
|
-
import defaultTemp from './templates/default.js'
|
9
|
-
import { CustomOptions, PageProps, SiteMap } from './types.js'
|
10
|
-
import renderer from './renderer/index.js'
|
11
|
-
|
12
|
-
const layouts: Map<string, (props: PageProps) => string> = new Map()
|
13
|
-
|
14
|
-
layouts.set('default', defaultTemp)
|
15
|
-
|
16
|
-
let currentFileMeta: {
|
17
|
-
attributes: CustomOptions
|
18
|
-
siteMap: SiteMap
|
19
|
-
}
|
20
|
-
|
21
|
-
const marked = new Marked(
|
22
|
-
markedHighlight({
|
23
|
-
langPrefix: 'hljs language-',
|
24
|
-
highlight(code, lang) {
|
25
|
-
const language = hljs.getLanguage(lang) ? lang : 'plaintext'
|
26
|
-
return hljs.highlight(code, { language }).value
|
27
|
-
},
|
28
|
-
})
|
29
|
-
)
|
30
|
-
|
31
|
-
marked.use({ renderer })
|
32
|
-
|
33
|
-
const docsDir = path.resolve(process.cwd(), 'docs')
|
34
|
-
const docsSiteDir = path.resolve(process.cwd(), 'website')
|
35
|
-
const docsLayoutsDir = path.resolve(process.cwd(), 'docs/_layouts')
|
36
|
-
const docsAssetsDir = path.resolve(process.cwd(), 'docs/assets')
|
37
|
-
const docsStylesheetsDir = path.resolve(process.cwd(), 'docs/stylesheets')
|
38
|
-
const docsScriptsDir = path.resolve(process.cwd(), 'docs/scripts')
|
39
|
-
|
40
|
-
const traverseDirectory = async (dir: string) => {
|
41
|
-
const items = await readdir(dir)
|
42
|
-
const files: string[] = []
|
43
|
-
|
44
|
-
for (const item of items) {
|
45
|
-
const ext = path.extname(item)
|
46
|
-
|
47
|
-
if (/^[._]/.test(item)) continue
|
48
|
-
|
49
|
-
if (ext) {
|
50
|
-
files.push(path.join(dir, item))
|
51
|
-
} else if (!/(stylesheets|assets|scripts)/.test(item)) {
|
52
|
-
files.push(...(await traverseDirectory(path.join(dir, item))))
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
return files
|
57
|
-
}
|
58
|
-
|
59
|
-
marked.use({
|
60
|
-
hooks: {
|
61
|
-
postprocess(html: string) {
|
62
|
-
const { layout = 'default', ...options } =
|
63
|
-
currentFileMeta.attributes
|
64
|
-
|
65
|
-
html = DOMPurify.sanitize(html)
|
66
|
-
|
67
|
-
const tableOfContent = [
|
68
|
-
...html.matchAll(
|
69
|
-
/<h([0-6])\sid="[^"]+".*?>.*?<a\s+href="([^"]+)".*?>([^<]+)<\/a>/gm
|
70
|
-
),
|
71
|
-
].map((m) => ({ path: m[2], label: m[3], level: m[1] }))
|
72
|
-
|
73
|
-
return (
|
74
|
-
layouts.get(layout)?.({
|
75
|
-
...options,
|
76
|
-
content: html,
|
77
|
-
siteMap: currentFileMeta.siteMap,
|
78
|
-
tableOfContent,
|
79
|
-
}) || html
|
80
|
-
)
|
81
|
-
},
|
82
|
-
},
|
83
|
-
})
|
84
|
-
;(async () => {
|
85
|
-
// create website dir
|
86
|
-
await mkdir(docsSiteDir, { recursive: true })
|
87
|
-
|
88
|
-
try {
|
89
|
-
await cp(docsAssetsDir, docsAssetsDir.replace(docsDir, docsSiteDir), {
|
90
|
-
recursive: true,
|
91
|
-
})
|
92
|
-
} catch (e) {
|
93
|
-
// ignore
|
94
|
-
}
|
95
|
-
|
96
|
-
try {
|
97
|
-
await cp(
|
98
|
-
docsStylesheetsDir,
|
99
|
-
docsStylesheetsDir.replace(docsDir, docsSiteDir),
|
100
|
-
{ recursive: true }
|
101
|
-
)
|
102
|
-
} catch (e) {
|
103
|
-
// ignore
|
104
|
-
}
|
105
|
-
|
106
|
-
try {
|
107
|
-
await cp(docsScriptsDir, docsScriptsDir.replace(docsDir, docsSiteDir), {
|
108
|
-
recursive: true,
|
109
|
-
})
|
110
|
-
} catch (e) {
|
111
|
-
// ignore
|
112
|
-
}
|
113
|
-
|
114
|
-
try {
|
115
|
-
// import the layouts first
|
116
|
-
const layoutPaths = await traverseDirectory(docsLayoutsDir)
|
117
|
-
|
118
|
-
for (const layoutPath of layoutPaths) {
|
119
|
-
if (/\.(j|t)s$/.test(layoutPath)) {
|
120
|
-
const fileName = path
|
121
|
-
.basename(layoutPath)
|
122
|
-
.replace(path.extname(layoutPath), '')
|
123
|
-
const handler = await import(layoutPath)
|
124
|
-
|
125
|
-
layouts.set(fileName, handler.default)
|
126
|
-
}
|
127
|
-
}
|
128
|
-
} catch (e) {
|
129
|
-
// ignore
|
130
|
-
}
|
131
|
-
|
132
|
-
const filePaths = await traverseDirectory(docsDir)
|
133
|
-
|
134
|
-
const siteMap: SiteMap = new Map()
|
135
|
-
|
136
|
-
;(
|
137
|
-
await Promise.all(
|
138
|
-
filePaths
|
139
|
-
.filter((filePath) => filePath.endsWith('.md'))
|
140
|
-
.map(async (filePath) => {
|
141
|
-
const content = await readFile(filePath, 'utf-8')
|
142
|
-
return {
|
143
|
-
filePath,
|
144
|
-
// @ts-expect-error call unknown
|
145
|
-
...(fm(content) as {
|
146
|
-
attributes: CustomOptions
|
147
|
-
body: string
|
148
|
-
}),
|
149
|
-
}
|
150
|
-
})
|
151
|
-
)
|
152
|
-
)
|
153
|
-
.sort((a, b) => a.attributes.order - b.attributes.order)
|
154
|
-
.map(({ attributes, body, filePath }) => {
|
155
|
-
const pathname = filePath
|
156
|
-
.replace(docsDir, '')
|
157
|
-
.replace(/\.md/, '.html')
|
158
|
-
const fileWebsitePath = filePath
|
159
|
-
.replace(docsDir, docsSiteDir)
|
160
|
-
.replace('.md', '.html')
|
161
|
-
const fileDirWebsitePath = fileWebsitePath.replace(
|
162
|
-
path.basename(fileWebsitePath),
|
163
|
-
''
|
164
|
-
)
|
165
|
-
|
166
|
-
const fileName = path.basename(pathname) || '/'
|
167
|
-
const dir = pathname.replace(fileName, '').replace(/\/$/, '')
|
168
|
-
|
169
|
-
let currentDir = siteMap
|
170
|
-
|
171
|
-
dir.split('/')
|
172
|
-
.filter(Boolean)
|
173
|
-
.forEach((d) => {
|
174
|
-
if (!currentDir.has(d)) {
|
175
|
-
currentDir.set(d, new Map())
|
176
|
-
}
|
177
|
-
|
178
|
-
currentDir = currentDir.get(d) as SiteMap
|
179
|
-
})
|
180
|
-
|
181
|
-
const attrs = {
|
182
|
-
...attributes,
|
183
|
-
path: pathname,
|
184
|
-
} as CustomOptions
|
185
|
-
|
186
|
-
if (!currentDir.has(fileName)) {
|
187
|
-
currentDir.set(fileName, attrs)
|
188
|
-
}
|
189
|
-
|
190
|
-
return {
|
191
|
-
attributes: attrs,
|
192
|
-
fileWebsitePath,
|
193
|
-
fileDirWebsitePath,
|
194
|
-
body,
|
195
|
-
siteMap,
|
196
|
-
}
|
197
|
-
})
|
198
|
-
.forEach(
|
199
|
-
async ({
|
200
|
-
attributes,
|
201
|
-
body,
|
202
|
-
fileDirWebsitePath,
|
203
|
-
fileWebsitePath,
|
204
|
-
siteMap,
|
205
|
-
}) => {
|
206
|
-
currentFileMeta = { attributes, siteMap }
|
207
|
-
const contentMd = await marked.parse(body)
|
208
|
-
await mkdir(fileDirWebsitePath, { recursive: true })
|
209
|
-
await writeFile(fileWebsitePath, contentMd)
|
210
|
-
}
|
211
|
-
)
|
212
|
-
})()
|
package/src/docs/types.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
export interface PageProps {
|
2
|
-
name: string
|
3
|
-
path: string
|
4
|
-
order: number
|
5
|
-
title: string
|
6
|
-
description: string
|
7
|
-
content: string
|
8
|
-
siteMap: SiteMap
|
9
|
-
tableOfContent: { path: string; label: string }[]
|
10
|
-
}
|
11
|
-
|
12
|
-
export interface CustomOptions extends Omit<PageProps, 'content'> {
|
13
|
-
layout: string
|
14
|
-
}
|
15
|
-
|
16
|
-
export type SiteMap = Map<string, CustomOptions | SiteMap>
|
package/tsconfig.json
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "es2015",
|
4
|
-
"types": ["node"],
|
5
|
-
"moduleResolution": "nodenext",
|
6
|
-
"lib": ["decorators", "es5", "scripthost", "es2015.promise"],
|
7
|
-
"outDir": "./dist",
|
8
|
-
"module": "nodenext",
|
9
|
-
"declaration": true,
|
10
|
-
"declarationMap": false,
|
11
|
-
"sourceMap": true,
|
12
|
-
"removeComments": true,
|
13
|
-
"downlevelIteration": true,
|
14
|
-
"strict": true,
|
15
|
-
"alwaysStrict": true,
|
16
|
-
"resolveJsonModule": true,
|
17
|
-
"allowSyntheticDefaultImports": true,
|
18
|
-
"esModuleInterop": true,
|
19
|
-
"skipLibCheck": true,
|
20
|
-
"forceConsistentCasingInFileNames": true,
|
21
|
-
"allowJs": true
|
22
|
-
},
|
23
|
-
"include": ["./src/**/*"]
|
24
|
-
}
|