Files
SpacetimeDB/docs/scripts/generate-cli-docs.mjs
T
Jason Larabie e9d2b117cc Refactor /docs into Concepts (#3877)
# Description of Changes

Refactoring all sections to match a concept based approach to the docs.

Closes: #3840 

Currently:
- Modules - Closes: #3841 
- Databases - Closes: #3842 
- Tables - Closes: #3843 
- Reducers - Closes: #3844 
- Procedures - Closes: #3845
- Views - Closes: #3846 

# API and ABI breaking changes

N/A

# Expected complexity level and risk

1

# Testing

- [x] Walking through all code references before pushing

---------

Signed-off-by: Jason Larabie <jason@clockworklabs.io>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2025-12-17 23:13:56 +00:00

63 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
import { createWriteStream, promises as fs } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { spawn } from 'node:child_process';
function getRepoRoot() {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
return path.resolve(__dirname, '../..');
}
function runCargoAndAppend({ cwd, outFilePath }) {
return new Promise((resolve, reject) => {
const outStream = createWriteStream(outFilePath, { flags: 'a' });
const child = spawn(
'cargo',
['run', '--features', 'markdown-docs', '-p', 'spacetimedb-cli'],
{
cwd,
stdio: ['ignore', 'pipe', 'inherit'],
},
);
child.on('error', err => {
outStream.end();
reject(err);
});
child.stdout.pipe(outStream);
child.on('close', code => {
outStream.end();
if (code === 0) resolve();
else reject(new Error(`cargo exited with code ${code ?? 'unknown'}`));
});
});
}
async function main() {
const repoRoot = getRepoRoot();
const outFile = path.join(
repoRoot,
'docs',
'docs',
'09000-reference',
'00100-cli-reference',
'00100-cli-reference.md',
);
const header = `---\ntitle: CLI Reference\nslug: /cli-reference\n---\n\n`;
await fs.writeFile(outFile, header, 'utf8');
await runCargoAndAppend({ cwd: repoRoot, outFilePath: outFile });
}
main().catch(err => {
console.error(err?.stack ?? String(err));
process.exit(1);
});