mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: finally directly generate markdown files (#1881)
Some checks are pending
tinymist::ci / publish-vscode (push) Blocked by required conditions
tinymist::ci / build-vsc-assets (push) Blocked by required conditions
tinymist::ci / build-vscode (push) Blocked by required conditions
tinymist::ci / build-vscode-others (push) Blocked by required conditions
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-2022) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Blocked by required conditions
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / build-binary (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run
Some checks are pending
tinymist::ci / publish-vscode (push) Blocked by required conditions
tinymist::ci / build-vsc-assets (push) Blocked by required conditions
tinymist::ci / build-vscode (push) Blocked by required conditions
tinymist::ci / build-vscode-others (push) Blocked by required conditions
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Blocked by required conditions
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-2022) (push) Blocked by required conditions
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Blocked by required conditions
tinymist::ci / prepare-build (push) Waiting to run
tinymist::ci / build-binary (push) Blocked by required conditions
tinymist::gh_pages / build-gh-pages (push) Waiting to run
* feat: finally directly generate markdown files * fix: trim * fix: await
This commit is contained in:
parent
0f748d24ba
commit
1210b54515
23 changed files with 78 additions and 100 deletions
|
@ -1,20 +1,12 @@
|
|||
import { resolve, basename, relative } from "path";
|
||||
import * as fs from "fs";
|
||||
import * as util from "util";
|
||||
import { execSync } from "child_process";
|
||||
const exec = util.promisify(execSync);
|
||||
|
||||
const root = resolve(import.meta.dirname, "..");
|
||||
const dry = process.argv.includes("--dry");
|
||||
|
||||
const bytes2utf8 = new TextDecoder();
|
||||
|
||||
/**
|
||||
* Base64 to UTF-8
|
||||
* @param encoded Base64 encoded string
|
||||
* @returns UTF-8 string
|
||||
*/
|
||||
export const base64Decode = (encoded) =>
|
||||
bytes2utf8.decode(Uint8Array.from(atob(encoded), (m) => m.charCodeAt(0)));
|
||||
|
||||
const yarn = (cmd, stdio = "inherit") => {
|
||||
const script = `yarn run ${cmd}`;
|
||||
if (dry) {
|
||||
|
@ -32,19 +24,32 @@ const typlite = (input, output) => {
|
|||
return res.toString();
|
||||
};
|
||||
|
||||
const convert = async (inp, out, opts) => {
|
||||
const isCheck = process.argv.includes("--check");
|
||||
|
||||
const convert = async ({ input: inp, output: out }) => {
|
||||
const input = resolve(root, inp);
|
||||
const output = resolve(root, out);
|
||||
const { before } = opts || {};
|
||||
|
||||
const res = typlite(input, output).trim();
|
||||
const outputContent = typlite(input, output).trim();
|
||||
if (dry) {
|
||||
console.log(res);
|
||||
console.log(outputContent);
|
||||
return;
|
||||
}
|
||||
|
||||
const outputContent = `<!-- This file is generated by scripts/link-docs.mjs from ${inp}. Do not edit manually. -->\n${before || ""}${res}\n`;
|
||||
await fs.promises.writeFile(output, outputContent);
|
||||
await fs.promises.writeFile(output, outputContent.trim() + "\n");
|
||||
|
||||
if (isCheck) {
|
||||
const gitStatus = (
|
||||
await exec(`git status --porcelain ${output}`, {
|
||||
encoding: "utf-8",
|
||||
})
|
||||
).trim();
|
||||
if (gitStatus) {
|
||||
throw new Error(
|
||||
`The file ${out} is not up to date. Please run \`node scripts/link-docs.mjs\` locally to update it.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// todo: generate me using typlite.
|
||||
|
@ -113,77 +118,45 @@ const maintainerMd = async () => {
|
|||
await fs.promises.writeFile(outPath, outputContent);
|
||||
};
|
||||
|
||||
const isCheck = process.argv.includes("--check");
|
||||
|
||||
const tasks = [
|
||||
{
|
||||
input: "docs/tinymist/introduction.typ",
|
||||
output: "README.md",
|
||||
title: "Tinymist",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/release-instruction.typ",
|
||||
output: "docs/release-instruction.md",
|
||||
title: "Release Instructions",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/crates/typlite.typ",
|
||||
output: "crates/typlite/README.md",
|
||||
title: "Typlite",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/frontend/emacs.typ",
|
||||
output: "editors/emacs/README.md",
|
||||
title: "Tinymist Emacs Support for Typst",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/frontend/helix.typ",
|
||||
output: "editors/helix/README.md",
|
||||
title: "Tinymist Helix Support for Typst",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/frontend/neovim.typ",
|
||||
output: "editors/neovim/README.md",
|
||||
title: "Tinymist Neovim Support for Typst",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/frontend/sublime-text.typ",
|
||||
output: "editors/sublime-text/README.md",
|
||||
title: "Tinymist Sublime Support for Typst",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/frontend/vscode.typ",
|
||||
output: "editors/vscode/README.md",
|
||||
title: "Tinymist Typst VS Code Extension",
|
||||
},
|
||||
{
|
||||
input: "docs/tinymist/frontend/zed.typ",
|
||||
output: "editors/zed/README.md",
|
||||
title: "Tinymist Zed Support for Typst",
|
||||
},
|
||||
];
|
||||
|
||||
const main = async () => {
|
||||
await Promise.all([
|
||||
...tasks.map((task) => convert(task.input, task.output, { before: `# ${task.title}\n\n` })),
|
||||
maintainerMd(),
|
||||
]);
|
||||
|
||||
if (isCheck) {
|
||||
// any dirty git files?
|
||||
await Promise.all(
|
||||
tasks.map(async (task) => {
|
||||
const gitStatus = execSync(`git status --porcelain ${task.output}`, {
|
||||
encoding: "utf-8",
|
||||
}).trim();
|
||||
if (gitStatus) {
|
||||
throw new Error(
|
||||
`The file ${task.output} is not up to date. Please run \`node scripts/link-docs.mjs\` to update it.`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
const main = async () => await Promise.all([...tasks.map(convert), maintainerMd()]);
|
||||
|
||||
main();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue