mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 02:08:17 +00:00
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
|
|
import {resolve} from 'path';
|
|
import {fileURLToPath} from 'url';
|
|
import * as fs from 'fs';
|
|
import {execSync} from 'child_process';
|
|
|
|
const filename = fileURLToPath(import.meta.url);
|
|
const root = resolve(filename, '../..');
|
|
const dry = process.argv.includes('--dry');
|
|
|
|
const yarn = (cmd, stdio = 'inherit') => {
|
|
const script = `yarn run ${cmd}`;
|
|
if (dry) {
|
|
return script;
|
|
}
|
|
return execSync(script, {stdio});
|
|
};
|
|
const typlite = (input, output = "-") => {
|
|
if (output === "-") {
|
|
// return stdout
|
|
const res = yarn(`--silent typlite ${input} -`, 'pipe');
|
|
return res.toString();
|
|
}
|
|
|
|
return yarn(`typlite ${input} ${output}`);
|
|
};
|
|
|
|
const convert = async (inp, out, opts) => {
|
|
const input = resolve(root, inp);
|
|
const output = resolve(root, out);
|
|
const { before } = opts || {};
|
|
|
|
const res = typlite(input).trim();
|
|
if (dry) {
|
|
console.log(res);
|
|
return;
|
|
}
|
|
|
|
await fs.promises.writeFile(output, `<!-- This file is generated by scripts/link-docs.mjs from ${inp}. Do not edit manually. -->\n${before || ''}${res}\n`);
|
|
};
|
|
|
|
const main = async () => {
|
|
await Promise.all([
|
|
convert('docs/tinymist/introduction.typ', 'README.md', { before: "# Tinymist\n\n" }),
|
|
convert('docs/tinymist/frontend/neovim.typ', 'editors/neovim/README.md', { before: "# Tinymist Neovim Support for Typst\n\n" }),
|
|
convert('docs/tinymist/frontend/helix.typ', 'editors/helix/README.md', { before: "# Tinymist Helix Support for Typst\n\n" }),
|
|
convert('docs/tinymist/frontend/sublime-text.typ', 'editors/sublime-text/README.md', { before: "# Tinymist Sublime Support for Typst\n\n" }),
|
|
convert('docs/tinymist/frontend/vscode.typ', 'editors/vscode/README.md', { before: "# Tinymist Typst VS Code Extension\n\n" }),
|
|
convert('docs/tinymist/frontend/zed.typ', 'editors/zed/README.md', { before: "# Tinymist Zed Support for Typst\n\n" }),
|
|
])
|
|
};
|
|
|
|
main().catch(console.error);
|