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:
Myriad-Dreamin 2024-07-30 17:12:20 +08:00 committed by GitHub
parent bc3bd9f762
commit acd22b71a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 221 additions and 21 deletions

48
scripts/link-docs.mjs Normal file
View 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);