Skip to content

Commit c5bf3bb

Browse files
committed
chore(release): include Markdown docs in package
1 parent 31c54dc commit c5bf3bb

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ jobs:
8181
- name: Build
8282
run: node --run build
8383

84+
- name: Prepare release
85+
run: node --run release:prepare
86+
8487
- name: Publish to npm
8588
run: |
8689
pnpm --filter './packages/*' -r stage publish --tag ${{ github.event.inputs.npm_tag }} --no-git-checks

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"format": "rs fmt && heading-case --write",
1414
"lint": "rs lint --type-check",
1515
"prepare": "node scripts/rs.js setup",
16+
"release:prepare": "node scripts/prepare-release.js",
1617
"test": "pnpm --filter './packages/**' test"
1718
},
1819
"devDependencies": {

scripts/prepare-release.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env node
2+
import { spawn } from 'node:child_process';
3+
import { copyFile, mkdir, readdir, rm } from 'node:fs/promises';
4+
import path from 'node:path';
5+
6+
const rootDir = path.resolve(import.meta.dirname, '..');
7+
const websiteDir = path.join(rootDir, 'website');
8+
const websiteDistDir = path.join(websiteDir, 'doc_build');
9+
const packageDocsDir = path.join(rootDir, 'packages/rstack/dist/docs');
10+
11+
const run = (command, args) =>
12+
new Promise((resolve, reject) => {
13+
const child = spawn(command, args, {
14+
cwd: rootDir,
15+
env: {
16+
...process.env,
17+
RSPRESS_INJECT_LLMS_HINT: 'false',
18+
},
19+
stdio: 'inherit',
20+
});
21+
22+
child.on('error', reject);
23+
child.on('exit', (code, signal) => {
24+
if (code === 0) {
25+
resolve();
26+
return;
27+
}
28+
29+
const reason = signal ? `signal ${signal}` : `exit code ${code}`;
30+
reject(new Error(`${command} ${args.join(' ')} failed with ${reason}.`));
31+
});
32+
});
33+
34+
const collectMarkdownFiles = async (directory, relativeDir = '') => {
35+
const entries = await readdir(directory, { withFileTypes: true });
36+
const files = [];
37+
38+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
39+
if (entry.isDirectory() && entry.name === 'zh') {
40+
continue;
41+
}
42+
43+
const relativePath = path.join(relativeDir, entry.name);
44+
const absolutePath = path.join(directory, entry.name);
45+
46+
if (entry.isDirectory()) {
47+
files.push(...(await collectMarkdownFiles(absolutePath, relativePath)));
48+
} else if (entry.isFile() && path.extname(entry.name) === '.md') {
49+
files.push(relativePath);
50+
}
51+
}
52+
53+
return files;
54+
};
55+
56+
const pnpmCommand = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';
57+
58+
console.log('Building the website...');
59+
await run(pnpmCommand, ['--dir', websiteDir, 'build']);
60+
61+
const markdownFiles = await collectMarkdownFiles(websiteDistDir);
62+
if (markdownFiles.length === 0) {
63+
throw new Error(`No English Markdown files found in ${websiteDistDir}.`);
64+
}
65+
66+
await rm(packageDocsDir, { recursive: true, force: true });
67+
68+
for (const relativePath of markdownFiles) {
69+
const destination = path.join(packageDocsDir, relativePath);
70+
await mkdir(path.dirname(destination), { recursive: true });
71+
await copyFile(path.join(websiteDistDir, relativePath), destination);
72+
}
73+
74+
console.log(`Copied ${markdownFiles.length} English Markdown files to ${packageDocsDir}.`);

website/rstack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const title = 'Rstack CLI';
66
const description =
77
'Rstack CLI brings the Rstack toolchain together with one CLI, one configuration, and one consistent workflow.';
88
const descriptionZh = 'Rstack CLI 通过统一的命令行、配置和工作流整合 Rstack 工具链。';
9+
const injectLlmsHint = process.env.RSPRESS_INJECT_LLMS_HINT !== 'false';
910

1011
define.doc(async () => {
1112
const { pluginSass } = await import('@rsbuild/plugin-sass');
@@ -57,6 +58,9 @@ define.doc(async () => {
5758
pluginSitemap({ siteUrl }),
5859
],
5960
themeConfig: {
61+
llmsUI: {
62+
injectLlmsHint,
63+
},
6064
socialLinks: [
6165
{
6266
icon: 'github',

0 commit comments

Comments
 (0)