mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-24 21:19:37 +00:00
fix: build script for editor tools (#2099)
This commit is contained in:
parent
ce447185d1
commit
985c0c16b8
1 changed files with 24 additions and 18 deletions
|
|
@ -3,13 +3,19 @@ import { genVscodeExt } from "./build-l10n.mjs";
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { rimraf } from "rimraf";
|
import copyDirSync from "cpr";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
generate as generateTextmate,
|
generate as generateTextmate,
|
||||||
install as installTextmate,
|
install as installTextmate,
|
||||||
} from "../syntaxes/textmate/main.ts";
|
} from "../syntaxes/textmate/main.ts";
|
||||||
|
|
||||||
|
/// The default working directory is the root of the project
|
||||||
|
const cwd = path.resolve(import.meta.dirname, "..");
|
||||||
|
const vscodeDir = path.resolve(cwd, "editors/vscode");
|
||||||
|
const previewDir = path.resolve(cwd, "tools/typst-preview-frontend");
|
||||||
|
const editorToolsDir = path.resolve(cwd, "tools/editor-tools");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spawns a command and return a promise that resolves to the code. The id is used to identify the command in the output and prepended to each line.
|
* Spawns a command and return a promise that resolves to the code. The id is used to identify the command in the output and prepended to each line.
|
||||||
* The line will be buffered and printed to avoid line crossing.
|
* The line will be buffered and printed to avoid line crossing.
|
||||||
|
|
@ -50,9 +56,11 @@ export function spawnAsync(id, cmd, options = { cwd }) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const cwd = path.resolve(import.meta.dirname, "..");
|
const _copyDirOpts = { deleteFirst: true, overwrite: true, confirm: true };
|
||||||
const vscodeDir = path.resolve(cwd, "editors/vscode");
|
const copyDir = (fr, to) =>
|
||||||
const editorToolsDir = path.resolve(cwd, "editors/editor-tools");
|
new Promise((resolve, reject) =>
|
||||||
|
copyDirSync(fr, to, _copyDirOpts, (err) => (err ? reject(err) : resolve())),
|
||||||
|
);
|
||||||
|
|
||||||
export async function extractL10nTs() {
|
export async function extractL10nTs() {
|
||||||
await spawnAsync(
|
await spawnAsync(
|
||||||
|
|
@ -83,30 +91,28 @@ export async function buildSyntax() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildPreview() {
|
export async function buildPreview() {
|
||||||
await Promise.all([
|
const run = (id, cmd) => spawnAsync(`build:preview:${id}`, cmd, { cwd: previewDir });
|
||||||
spawnAsync("build:preview:tsc", "cd tools/typst-preview-frontend && npx tsc"),
|
|
||||||
spawnAsync("build:preview:vite", "cd tools/typst-preview-frontend && npx vite build"),
|
await Promise.all([run("tsc", "npx tsc"), run("vite", "npx vite build")]);
|
||||||
]);
|
|
||||||
|
|
||||||
await fs.copyFile(
|
await fs.copyFile(
|
||||||
path.resolve(cwd, "tools/typst-preview-frontend/dist/index.html"),
|
path.resolve(previewDir, "dist/index.html"),
|
||||||
path.resolve(cwd, "crates/tinymist-assets/src/typst-preview.html"),
|
path.resolve(cwd, "crates/tinymist-assets/src/typst-preview.html"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildEditorTools() {
|
export async function buildEditorTools() {
|
||||||
await spawnAsync("build:editor-tools:tsc", "cd tools/editor-tools && npx tsc");
|
const run = (id, cmd) => spawnAsync(`build:editor-tools:${id}`, cmd, { cwd: editorToolsDir });
|
||||||
await spawnAsync(
|
|
||||||
"build:editor-tools:vite",
|
await run("tsc", "npx tsc");
|
||||||
"cd tools/editor-tools && npx vite build -- --component=symbol-view",
|
await run("vite", "npx vite build -- --component=symbol-view");
|
||||||
);
|
await run("vite", "npx vite build");
|
||||||
await spawnAsync("build:editor-tools:vite", "cd tools/editor-tools && npx vite build");
|
|
||||||
|
await installEditorTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installEditorTools() {
|
export async function installEditorTools() {
|
||||||
await rimraf(path.join(vscodeDir, "out/editor-tools/"));
|
await copyDir(path.join(editorToolsDir, "dist"), path.join(vscodeDir, "out/editor-tools/"));
|
||||||
await fs.mkdir(path.join(vscodeDir, "out/editor-tools/"), { recursive: true });
|
|
||||||
await fs.copyFile(path.join(editorToolsDir, "dist"), path.join(vscodeDir, "out/editor-tools/"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkVersion() {
|
export async function checkVersion() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue