-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgenerate-context7-docs.cjs
More file actions
281 lines (233 loc) · 8.48 KB
/
generate-context7-docs.cjs
File metadata and controls
281 lines (233 loc) · 8.48 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* eslint-env node */
const shell = require('shelljs');
const fs = require('node:fs');
const path = require('node:path');
const argv = require('yargs').argv;
const OUTPUT_DIR = 'www/markdown-docs';
const GUIDES_DIR = `${OUTPUT_DIR}/guides`;
if (argv.h !== undefined) {
shell.echo(`
usage: node generate-context7-docs.cjs
`);
shell.exit(0);
}
shell.echo('=== Generating Context7-compatible documentation ===\n');
try {
shell.echo('Building component markdown documentation...');
if (
shell.exec(
'cross-env-shell NODE_ENV=prod SASS_PATH=node_modules "npx stencil build --config stencil.config.context7.ts"'
).code !== 0
) {
shell.echo('ERROR: Stencil build failed!');
shell.exit(1);
}
shell.echo('✓ Component READMEs generated\n');
shell.echo('Creating guides directory...');
shell.mkdir('-p', GUIDES_DIR);
shell.echo('✓ Guides directory created\n');
shell.echo('Copying root-level documentation...');
const rootDocs = ['README.md', 'CONTRIBUTING.md'];
for (const doc of rootDocs) {
if (fs.existsSync(doc)) {
shell.cp(doc, OUTPUT_DIR);
shell.echo(` ✓ Copied ${doc}`);
} else {
shell.echo(` ⚠ Warning: ${doc} not found, skipping`);
}
}
shell.echo();
shell.echo('Copying guide documentation...');
const guides = ['src/contributing.md', 'src/events.md', 'src/theming.md'];
for (const guide of guides) {
if (fs.existsSync(guide)) {
const basename = path.basename(guide);
shell.cp(guide, path.join(GUIDES_DIR, basename));
shell.echo(` ✓ Copied ${guide} → guides/${basename}`);
} else {
shell.echo(` ⚠ Warning: ${guide} not found, skipping`);
}
}
shell.echo();
shell.echo('Copying design guideline markdown files...');
const guidelineSources = shell
.find('src/design-guidelines')
.filter((file) => {
return (
file.endsWith('.md') &&
!file.includes('/examples/') &&
file !== 'src/design-guidelines'
);
});
for (const guideline of guidelineSources) {
// Preserve directory structure: src/design-guidelines/foo/bar.md →
// www/markdown-docs/design-guidelines/foo/bar.md
const relativePath = guideline.replace('src/', '');
const targetPath = path.join(OUTPUT_DIR, relativePath);
const targetDir = path.dirname(targetPath);
shell.mkdir('-p', targetDir);
shell.cp(guideline, targetPath);
shell.echo(` ✓ Copied ${guideline} → ${relativePath}`);
}
shell.echo();
shell.echo('Generating INDEX.md...');
const indexContent = generateIndexFile();
fs.writeFileSync(path.join(OUTPUT_DIR, 'INDEX.md'), indexContent);
shell.echo('✓ INDEX.md created\n');
shell.echo('Generating META.json...');
const metadata = generateMetadata();
fs.writeFileSync(
path.join(OUTPUT_DIR, 'META.json'),
JSON.stringify(metadata, null, 2)
);
shell.echo('✓ META.json created\n');
shell.echo('=== Documentation generation complete! ===');
shell.echo(`Output directory: ${OUTPUT_DIR}`);
shell.echo(`Total components: ${metadata.componentCount}`);
shell.echo(`Total files: ${metadata.fileCount}`);
} catch (error) {
shell.echo('ERROR: Documentation generation failed');
shell.echo(error.message);
shell.exit(1);
}
/**
* Generate the INDEX.md file with navigation and overview
* @returns The content of the INDEX.md file
*/
function generateIndexFile() {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const version = packageJson.version;
// Get list of components
const componentsDir = path.join(OUTPUT_DIR, 'components');
const components = fs
.readdirSync(componentsDir)
.filter((item) => {
const stat = fs.statSync(path.join(componentsDir, item));
return stat.isDirectory();
})
.sort();
// Get list of design guidelines
const guidelinesDir = path.join(OUTPUT_DIR, 'design-guidelines');
const guidelines = fs.existsSync(guidelinesDir)
? fs
.readdirSync(guidelinesDir)
.filter((item) => {
const stat = fs.statSync(path.join(guidelinesDir, item));
return stat.isDirectory();
})
.sort()
: [];
let content = `# Lime Elements Documentation
**Version ${version}**
A comprehensive design system and component library built with Stencil.
## Quick Start
\`\`\`bash
npm install @limetech/lime-elements
\`\`\`
\`\`\`html
<script type="module" src="https://cdn.jsdelivr.net/npm/@limetech/lime-elements@latest/dist/lime-elements/lime-elements.esm.js"></script>
<limel-button primary label="Hello World"></limel-button>
\`\`\`
## Components (${components.length})
`;
// Add components in columns
const columns = 3;
for (let i = 0; i < components.length; i += columns) {
const row = components.slice(i, i + columns);
content +=
'| ' +
row
.map(
(c) =>
`[${formatComponentName(c)}](components/${c}/readme.md)`
)
.join(' | ') +
' |\n';
if (i === 0) {
content += '| ' + '--- | '.repeat(row.length) + '\n';
}
}
content += `
## Design Guidelines
`;
for (const guideline of guidelines) {
// Try to find the main markdown file in the guideline directory
const guidelineDir = path.join(guidelinesDir, guideline);
const mdFiles = fs
.readdirSync(guidelineDir)
.filter((f) => f.endsWith('.md') && f !== 'readme.md');
if (mdFiles.length > 0) {
content += `- [${formatComponentName(guideline)}](design-guidelines/${guideline}/${mdFiles[0]})\n`;
} else {
content += `- [${formatComponentName(guideline)}](design-guidelines/${guideline}/)\n`;
}
}
content += `
## Guides
- [Contributing](guides/contributing.md) - How to contribute to Lime Elements
- [Events](guides/events.md) - Working with component events
- [Theming](guides/theming.md) - Customizing component styles
## Resources
- [Full README](README.md)
- [Contributing Guidelines](CONTRIBUTING.md)
- [NPM Package](https://www.npmjs.com/package/@limetech/lime-elements)
- [GitHub Repository](https://github.com/Lundalogik/lime-elements)
- [Official Documentation](https://lundalogik.github.io/lime-elements/)
## About
Lime Elements is an enterprise-ready component library that provides:
- 🚀 Battle-tested components used in production
- 🎨 Comprehensive design system
- ⚡ Web standards-based (works with any framework)
- 👾 Full TypeScript support
- ♿ Accessibility built-in
- ⚙️ Extensive customization options
Built with ❤️ by [Lime Technologies](https://www.lime-technologies.com/)
`;
return content;
}
/**
* Format component name for display (kebab-case to Title Case)
* @param name - The kebab-case component name
* @returns The formatted component name in Title Case
*/
function formatComponentName(name) {
return name
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
}
/**
* Generate metadata about the documentation
* @returns Metadata object containing version, timestamp, and counts
*/
function generateMetadata() {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
// Count components
const componentsDir = path.join(OUTPUT_DIR, 'components');
const components = fs.readdirSync(componentsDir).filter((item) => {
const stat = fs.statSync(path.join(componentsDir, item));
return stat.isDirectory();
});
// Count all markdown files
let fileCount = 0;
const countFiles = (dir) => {
const items = fs.readdirSync(dir);
for (const item of items) {
const fullPath = path.join(dir, item);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
countFiles(fullPath);
} else if (item.endsWith('.md')) {
fileCount++;
}
}
};
countFiles(OUTPUT_DIR);
return {
version: packageJson.version,
generated: new Date().toISOString(),
componentCount: components.length,
fileCount: fileCount,
generator: 'generate-context7-docs.cjs',
};
}