mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 02:08:17 +00:00
feat: convert introduction.typ to README.md (#479)
* dev: supports some functions for README * feat: convert introduction.typ to README.md
This commit is contained in:
parent
bc3bd9f762
commit
acd22b71a5
8 changed files with 221 additions and 21 deletions
48
scripts/link-docs.mjs
Normal file
48
scripts/link-docs.mjs
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
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" }),
|
||||
])
|
||||
};
|
||||
|
||||
main().catch(console.error);
|
Loading…
Add table
Add a link
Reference in a new issue