From 8d0ca2c87604fd8cdae97799d72c6f3dba9ecf5e Mon Sep 17 00:00:00 2001 From: Reda Al Sulais Date: Tue, 22 Aug 2023 13:38:23 +0300 Subject: [PATCH] build: build `.langium` file using `generate` from `langium-cli` --- .build/generateLangium.ts | 12 +++--------- .build/langium-cli.d.ts | 9 +++++++++ .esbuild/build.ts | 2 +- .esbuild/server.ts | 4 ++-- .vite/build.ts | 2 +- package.json | 1 + pnpm-lock.yaml | 3 +++ 7 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 .build/langium-cli.d.ts diff --git a/.build/generateLangium.ts b/.build/generateLangium.ts index 7c171a11c..e37e085a5 100644 --- a/.build/generateLangium.ts +++ b/.build/generateLangium.ts @@ -1,11 +1,5 @@ -import { execFileSync } from 'child_process'; +import { generate } from 'langium-cli'; -export function generateLangium() { - execFileSync('pnpm', [ - '--prefix', - `${process.cwd()}/packages/parser`, - 'exec', - 'langium', - 'generate', - ]); +export async function generateLangium() { + await generate({ file: `./packages/parser/langium-config.json` }); } diff --git a/.build/langium-cli.d.ts b/.build/langium-cli.d.ts new file mode 100644 index 000000000..a1cfe25f8 --- /dev/null +++ b/.build/langium-cli.d.ts @@ -0,0 +1,9 @@ +declare module 'langium-cli' { + export interface GenerateOptions { + file?: string; + mode?: 'development' | 'production'; + watch?: boolean; + } + + export function generate(options: GenerateOptions): Promise; +} diff --git a/.esbuild/build.ts b/.esbuild/build.ts index 28b841341..3e829d719 100644 --- a/.esbuild/build.ts +++ b/.esbuild/build.ts @@ -53,7 +53,7 @@ const handler = (e) => { }; const main = async () => { - generateLangium(); + await generateLangium(); await mkdir('stats').catch(() => {}); const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[]; // it should build `parser` before `mermaid` because it's a dependecy diff --git a/.esbuild/server.ts b/.esbuild/server.ts index c522cadf8..63d981b99 100644 --- a/.esbuild/server.ts +++ b/.esbuild/server.ts @@ -79,7 +79,7 @@ function sendEventsToAll() { } async function createServer() { - generateLangium(); + await generateLangium(); handleFileChange(); const app = express(); chokidar @@ -93,7 +93,7 @@ async function createServer() { return; } if (/\.langium$/.test(path)) { - generateLangium(); + await generateLangium(); } console.log(`${path} changed. Rebuilding...`); handleFileChange(); diff --git a/.vite/build.ts b/.vite/build.ts index a97b2b5a3..9cb128eb1 100644 --- a/.vite/build.ts +++ b/.vite/build.ts @@ -114,7 +114,7 @@ const main = async () => { } }; -generateLangium(); +await generateLangium(); if (watch) { await build(getBuildConfig({ minify: false, watch, core: false, entryName: 'parser' })); diff --git a/package.json b/package.json index 0dfc09919..9e24b2aa6 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "jison": "^0.4.18", "js-yaml": "^4.1.0", "jsdom": "^22.0.0", + "langium-cli": "2.0.1", "lint-staged": "^13.2.1", "nyc": "^15.1.0", "path-browserify": "^1.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 947812fdb..83b4f841d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -149,6 +149,9 @@ importers: jsdom: specifier: ^22.0.0 version: 22.0.0 + langium-cli: + specifier: 2.0.1 + version: 2.0.1 lint-staged: specifier: ^13.2.1 version: 13.2.1