build: build `.langium` file using `generate` from `langium-cli`

This commit is contained in:
Reda Al Sulais 2023-08-22 13:38:23 +03:00
parent fc96ebefd4
commit 8d0ca2c876
7 changed files with 20 additions and 13 deletions

View File

@ -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` });
}

9
.build/langium-cli.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
declare module 'langium-cli' {
export interface GenerateOptions {
file?: string;
mode?: 'development' | 'production';
watch?: boolean;
}
export function generate(options: GenerateOptions): Promise<boolean>;
}

View File

@ -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

View File

@ -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();

View File

@ -114,7 +114,7 @@ const main = async () => {
}
};
generateLangium();
await generateLangium();
if (watch) {
await build(getBuildConfig({ minify: false, watch, core: false, entryName: 'parser' }));

View File

@ -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",

View File

@ -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