@mgks/docmd 0.3.3 โ 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -100
- package/bin/docmd.js +55 -93
- package/docmd.config.js +175 -0
- package/package.json +16 -15
- package/scripts/build-live.js +157 -0
- package/scripts/test-live.js +54 -0
- package/src/assets/css/docmd-highlight-dark.css +1 -0
- package/src/assets/css/docmd-highlight-light.css +1 -0
- package/src/assets/css/docmd-main.css +1627 -0
- package/src/assets/css/docmd-theme-retro.css +868 -0
- package/src/assets/css/docmd-theme-ruby.css +629 -0
- package/src/assets/css/docmd-theme-sky.css +618 -0
- package/src/assets/favicon.ico +0 -0
- package/src/assets/images/docmd-logo-dark.png +0 -0
- package/src/assets/images/docmd-logo-light.png +0 -0
- package/src/assets/images/docmd-logo.png +0 -0
- package/src/assets/js/docmd-image-lightbox.js +74 -0
- package/src/assets/js/docmd-main.js +214 -0
- package/src/assets/js/docmd-mermaid.js +205 -0
- package/src/assets/js/docmd-search.js +218 -0
- package/src/commands/build.js +11 -6
- package/src/commands/dev.js +100 -189
- package/src/commands/init.js +8 -8
- package/src/core/config-loader.js +23 -3
- package/src/core/file-processor.js +8 -2
- package/src/core/html-generator.js +107 -102
- package/src/live/core.js +63 -0
- package/src/live/index.html +201 -0
- package/src/live/live.css +167 -0
- package/src/live/shims.js +1 -0
- package/src/live/templates.js +9 -0
- package/src/templates/layout.ejs +11 -11
- package/src/templates/navigation.ejs +69 -7
- package/config.js +0 -175
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mgks/docmd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Generate beautiful, lightweight static documentation sites directly from your Markdown files. Zero clutter, just content.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"start": "node ./bin/docmd.js dev",
|
|
17
17
|
"build": "node ./bin/docmd.js build",
|
|
18
|
+
"live": "node scripts/build-live.js && npx serve dist",
|
|
18
19
|
"postinstall": "node ./bin/postinstall.js",
|
|
19
20
|
"lint": "eslint .",
|
|
20
21
|
"format": "prettier --write .",
|
|
@@ -22,32 +23,32 @@
|
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"chalk": "^4.1.2",
|
|
25
|
-
"chokidar": "^
|
|
26
|
+
"chokidar": "^5.0.0",
|
|
26
27
|
"clean-css": "^5.3.3",
|
|
27
|
-
"commander": "^14.0.
|
|
28
|
-
"ejs": "^3.1.
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"fs-extra": "^11.2.0",
|
|
28
|
+
"commander": "^14.0.2",
|
|
29
|
+
"ejs": "^3.1.10",
|
|
30
|
+
"express": "^5.2.1",
|
|
31
|
+
"fs-extra": "^11.3.3",
|
|
32
32
|
"gray-matter": "^4.0.3",
|
|
33
33
|
"highlight.js": "^11.11.1",
|
|
34
|
-
"lucide-static": "^0.
|
|
34
|
+
"lucide-static": "^0.562.0",
|
|
35
|
+
"markdown-it": "^14.1.0",
|
|
35
36
|
"markdown-it-abbr": "^2.0.0",
|
|
36
37
|
"markdown-it-attrs": "^4.3.1",
|
|
37
38
|
"markdown-it-container": "^4.0.0",
|
|
38
39
|
"markdown-it-deflist": "^3.0.0",
|
|
39
40
|
"markdown-it-footnote": "^4.0.0",
|
|
40
41
|
"markdown-it-task-lists": "^2.1.1",
|
|
41
|
-
"mermaid": "^11.12.
|
|
42
|
+
"mermaid": "^11.12.2",
|
|
42
43
|
"minisearch": "^7.2.0",
|
|
43
44
|
"striptags": "^3.2.0",
|
|
44
|
-
"ws": "^8.
|
|
45
|
+
"ws": "^8.18.3"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"eslint
|
|
50
|
-
"prettier": "^3.
|
|
48
|
+
"buffer": "^6.0.3",
|
|
49
|
+
"esbuild": "^0.27.2",
|
|
50
|
+
"eslint": "^9.39.2",
|
|
51
|
+
"prettier": "^3.7.4"
|
|
51
52
|
},
|
|
52
53
|
"directories": {
|
|
53
54
|
"doc": "docs"
|
|
@@ -77,4 +78,4 @@
|
|
|
77
78
|
"homepage": "https://github.com/mgks/docmd#readme",
|
|
78
79
|
"funding": "https://github.com/sponsors/mgks",
|
|
79
80
|
"license": "MIT"
|
|
80
|
-
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const esbuild = require('esbuild');
|
|
4
|
+
|
|
5
|
+
async function build() {
|
|
6
|
+
console.log('๐ฆ Building @docmd/live core...');
|
|
7
|
+
|
|
8
|
+
const SRC_DIR = path.join(__dirname, '../src');
|
|
9
|
+
const LIVE_SRC_DIR = path.join(SRC_DIR, 'live');
|
|
10
|
+
const DIST_DIR = path.join(__dirname, '../dist');
|
|
11
|
+
|
|
12
|
+
// Ensure dist exists and is empty
|
|
13
|
+
fs.emptyDirSync(DIST_DIR);
|
|
14
|
+
|
|
15
|
+
// 1. Read Templates
|
|
16
|
+
const templatesDir = path.join(SRC_DIR, 'templates');
|
|
17
|
+
const files = fs.readdirSync(templatesDir);
|
|
18
|
+
const templates = {};
|
|
19
|
+
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
if (file.endsWith('.ejs')) {
|
|
22
|
+
templates[file] = fs.readFileSync(path.join(templatesDir, file), 'utf8');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 2. Generate templates.js
|
|
27
|
+
const templatesJsPath = path.join(LIVE_SRC_DIR, 'templates.js');
|
|
28
|
+
const templatesContent = `
|
|
29
|
+
const templates = ${JSON.stringify(templates, null, 2)};
|
|
30
|
+
if (typeof globalThis !== 'undefined') globalThis.__DOCMD_TEMPLATES__ = templates;
|
|
31
|
+
module.exports = templates;
|
|
32
|
+
`;
|
|
33
|
+
fs.writeFileSync(templatesJsPath, templatesContent);
|
|
34
|
+
|
|
35
|
+
// 3. Generate Shim for Buffer
|
|
36
|
+
const shimPath = path.join(LIVE_SRC_DIR, 'shims.js');
|
|
37
|
+
fs.writeFileSync(shimPath, `import { Buffer } from 'buffer'; globalThis.Buffer = Buffer;`);
|
|
38
|
+
|
|
39
|
+
// 4. Bundle JS
|
|
40
|
+
try {
|
|
41
|
+
await esbuild.build({
|
|
42
|
+
entryPoints: [path.join(LIVE_SRC_DIR, 'core.js')],
|
|
43
|
+
bundle: true,
|
|
44
|
+
outfile: path.join(DIST_DIR, 'docmd-live.js'),
|
|
45
|
+
platform: 'browser',
|
|
46
|
+
format: 'iife',
|
|
47
|
+
globalName: 'docmd',
|
|
48
|
+
minify: true,
|
|
49
|
+
define: { 'process.env.NODE_ENV': '"production"' },
|
|
50
|
+
inject: [shimPath],
|
|
51
|
+
plugins: [
|
|
52
|
+
{
|
|
53
|
+
name: 'node-deps-shim',
|
|
54
|
+
setup(build) {
|
|
55
|
+
build.onResolve({ filter: /^path$/ }, args => ({ path: args.path, namespace: 'path-shim' }));
|
|
56
|
+
build.onLoad({ filter: /.*/, namespace: 'path-shim' }, () => ({
|
|
57
|
+
contents: `
|
|
58
|
+
module.exports = {
|
|
59
|
+
join: (...args) => args.filter(Boolean).join('/'),
|
|
60
|
+
resolve: (...args) => '/' + args.filter(Boolean).join('/'),
|
|
61
|
+
basename: (p) => p ? p.split(/[\\\\/]/).pop() : '',
|
|
62
|
+
dirname: (p) => p ? p.split(/[\\\\/]/).slice(0, -1).join('/') || '.' : '.',
|
|
63
|
+
extname: (p) => {
|
|
64
|
+
if (!p) return '';
|
|
65
|
+
const parts = p.split('.');
|
|
66
|
+
return parts.length > 1 ? '.' + parts.pop() : '';
|
|
67
|
+
},
|
|
68
|
+
isAbsolute: (p) => p.startsWith('/'),
|
|
69
|
+
normalize: (p) => p,
|
|
70
|
+
sep: '/'
|
|
71
|
+
};
|
|
72
|
+
`,
|
|
73
|
+
loader: 'js'
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
build.onResolve({ filter: /^(fs|fs-extra)$/ }, args => ({ path: args.path, namespace: 'fs-shim' }));
|
|
77
|
+
build.onLoad({ filter: /.*/, namespace: 'fs-shim' }, () => ({
|
|
78
|
+
contents: `
|
|
79
|
+
module.exports = {
|
|
80
|
+
existsSync: (p) => {
|
|
81
|
+
if (!globalThis.__DOCMD_TEMPLATES__) return false;
|
|
82
|
+
let name = p.split(/[\\\\/]/).pop();
|
|
83
|
+
if (globalThis.__DOCMD_TEMPLATES__[name]) return true;
|
|
84
|
+
if (!name.endsWith('.ejs') && globalThis.__DOCMD_TEMPLATES__[name + '.ejs']) return true;
|
|
85
|
+
return false;
|
|
86
|
+
},
|
|
87
|
+
readFileSync: (p) => {
|
|
88
|
+
if (!globalThis.__DOCMD_TEMPLATES__) return '';
|
|
89
|
+
let name = p.split(/[\\\\/]/).pop();
|
|
90
|
+
if (globalThis.__DOCMD_TEMPLATES__[name]) return globalThis.__DOCMD_TEMPLATES__[name];
|
|
91
|
+
if (!name.endsWith('.ejs')) name += '.ejs';
|
|
92
|
+
return globalThis.__DOCMD_TEMPLATES__[name] || '';
|
|
93
|
+
},
|
|
94
|
+
statSync: () => ({ isFile: () => true, isDirectory: () => false }),
|
|
95
|
+
constants: { F_OK: 0, R_OK: 4 }
|
|
96
|
+
};
|
|
97
|
+
`,
|
|
98
|
+
loader: 'js'
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
console.log('โ
Bundled JS to dist/docmd-live.js');
|
|
105
|
+
|
|
106
|
+
// 5. Copy Assets
|
|
107
|
+
console.log('๐ Copying assets...');
|
|
108
|
+
await fs.copy(path.join(SRC_DIR, 'assets'), path.join(DIST_DIR, 'assets'));
|
|
109
|
+
|
|
110
|
+
// 5.5 Bundle Third-Party Libraries (The FIX)
|
|
111
|
+
// We need to manually copy these from node_modules because they aren't in src/assets
|
|
112
|
+
const copyLibrary = async (packageName, fileToBundle, destFileName) => {
|
|
113
|
+
try {
|
|
114
|
+
// Try to resolve the package path
|
|
115
|
+
let srcPath;
|
|
116
|
+
try {
|
|
117
|
+
srcPath = require.resolve(`${packageName}/${fileToBundle}`);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
// Fallback search if require.resolve fails
|
|
120
|
+
const mainPath = require.resolve(packageName);
|
|
121
|
+
let currentDir = path.dirname(mainPath);
|
|
122
|
+
for (let i = 0; i < 5; i++) {
|
|
123
|
+
if (fs.existsSync(path.join(currentDir, 'package.json'))) break;
|
|
124
|
+
currentDir = path.dirname(currentDir);
|
|
125
|
+
}
|
|
126
|
+
srcPath = path.join(currentDir, fileToBundle);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (srcPath && fs.existsSync(srcPath)) {
|
|
130
|
+
const destPath = path.join(DIST_DIR, 'assets/js', destFileName);
|
|
131
|
+
await fs.ensureDir(path.dirname(destPath));
|
|
132
|
+
await fs.copy(srcPath, destPath);
|
|
133
|
+
console.log(` โโ Copied ${packageName} -> assets/js/${destFileName}`);
|
|
134
|
+
} else {
|
|
135
|
+
console.warn(`โ ๏ธ Could not locate ${fileToBundle} in ${packageName}`);
|
|
136
|
+
}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.warn(`โ ๏ธ Failed to bundle ${packageName}: ${e.message}`);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
await copyLibrary('minisearch', 'dist/umd/index.js', 'minisearch.js');
|
|
143
|
+
await copyLibrary('mermaid', 'dist/mermaid.min.js', 'mermaid.min.js');
|
|
144
|
+
console.log('โ
Assets & Libraries copied.');
|
|
145
|
+
|
|
146
|
+
// 6. Copy Demo HTML
|
|
147
|
+
await fs.copy(path.join(LIVE_SRC_DIR, 'index.html'), path.join(DIST_DIR, 'index.html'));
|
|
148
|
+
await fs.copy(path.join(LIVE_SRC_DIR, 'live.css'), path.join(DIST_DIR, 'live.css'));
|
|
149
|
+
console.log('โ
Demo HTML copied.');
|
|
150
|
+
|
|
151
|
+
} catch (e) {
|
|
152
|
+
console.error('โ Build failed:', e);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
build();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const vm = require('vm');
|
|
4
|
+
|
|
5
|
+
const bundlePath = path.join(__dirname, '../dist/docmd-live.js');
|
|
6
|
+
|
|
7
|
+
if (!fs.existsSync(bundlePath)) {
|
|
8
|
+
console.error('โ Bundle not found. Run "npm run live" or "node scripts/build-live.js" first.');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const bundleCode = fs.readFileSync(bundlePath, 'utf8');
|
|
13
|
+
|
|
14
|
+
const sandbox = {
|
|
15
|
+
console: console,
|
|
16
|
+
setTimeout: setTimeout,
|
|
17
|
+
clearTimeout: clearTimeout,
|
|
18
|
+
window: {},
|
|
19
|
+
self: {},
|
|
20
|
+
globalThis: {}
|
|
21
|
+
};
|
|
22
|
+
sandbox.window = sandbox;
|
|
23
|
+
sandbox.self = sandbox;
|
|
24
|
+
sandbox.globalThis = sandbox;
|
|
25
|
+
|
|
26
|
+
vm.createContext(sandbox);
|
|
27
|
+
|
|
28
|
+
console.log('๐งช Testing Live Bundle...');
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
vm.runInContext(bundleCode, sandbox);
|
|
32
|
+
|
|
33
|
+
if (!sandbox.docmd) {
|
|
34
|
+
throw new Error('docmd global not found in bundle');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const markdown = '# Hello Live\nThis is a test.';
|
|
38
|
+
const config = { siteTitle: 'Live Test' };
|
|
39
|
+
|
|
40
|
+
console.log('Compiling markdown...');
|
|
41
|
+
const result = sandbox.docmd.compile(markdown, config);
|
|
42
|
+
|
|
43
|
+
if (result.includes('<h1>Hello Live</h1>') && result.includes('Live Test')) {
|
|
44
|
+
console.log('โ
Bundle works! Output contains expected HTML.');
|
|
45
|
+
} else {
|
|
46
|
+
console.error('โ Bundle produced unexpected output.');
|
|
47
|
+
console.log('Output snippet:', result.substring(0, 200));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error('โ Test failed:', e);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#abb2bf;background:#282c34}.hljs-comment,.hljs-quote{color:#5c6370;font-style:italic}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#c678dd}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e06c75}.hljs-literal{color:#56b6c2}.hljs-addition,.hljs-attribute,.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#98c379}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#d19a66}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#61aeee}.hljs-built_in,.hljs-class .hljs-title,.hljs-title.class_{color:#e6c07b}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-link{text-decoration:underline}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#383a42;background:#fafafa}.hljs-comment,.hljs-quote{color:#a0a1a7;font-style:italic}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#a626a4}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e45649}.hljs-literal{color:#0184bb}.hljs-addition,.hljs-attribute,.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#50a14f}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#986801}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#4078f2}.hljs-built_in,.hljs-class .hljs-title,.hljs-title.class_{color:#c18401}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-link{text-decoration:underline}
|