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() { export async function generateLangium() {
execFileSync('pnpm', [ await generate({ file: `./packages/parser/langium-config.json` });
'--prefix',
`${process.cwd()}/packages/parser`,
'exec',
'langium',
'generate',
]);
} }

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 () => { const main = async () => {
generateLangium(); await generateLangium();
await mkdir('stats').catch(() => {}); await mkdir('stats').catch(() => {});
const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[]; const packageNames = Object.keys(packageOptions) as (keyof typeof packageOptions)[];
// it should build `parser` before `mermaid` because it's a dependecy // it should build `parser` before `mermaid` because it's a dependecy

View File

@@ -79,7 +79,7 @@ function sendEventsToAll() {
} }
async function createServer() { async function createServer() {
generateLangium(); await generateLangium();
handleFileChange(); handleFileChange();
const app = express(); const app = express();
chokidar chokidar
@@ -93,7 +93,7 @@ async function createServer() {
return; return;
} }
if (/\.langium$/.test(path)) { if (/\.langium$/.test(path)) {
generateLangium(); await generateLangium();
} }
console.log(`${path} changed. Rebuilding...`); console.log(`${path} changed. Rebuilding...`);
handleFileChange(); handleFileChange();

View File

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

View File

@@ -107,6 +107,7 @@
"jison": "^0.4.18", "jison": "^0.4.18",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"jsdom": "^22.0.0", "jsdom": "^22.0.0",
"langium-cli": "2.0.1",
"lint-staged": "^13.2.1", "lint-staged": "^13.2.1",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"path-browserify": "^1.0.1", "path-browserify": "^1.0.1",

3
pnpm-lock.yaml generated
View File

@@ -149,6 +149,9 @@ importers:
jsdom: jsdom:
specifier: ^22.0.0 specifier: ^22.0.0
version: 22.0.0 version: 22.0.0
langium-cli:
specifier: 2.0.1
version: 2.0.1
lint-staged: lint-staged:
specifier: ^13.2.1 specifier: ^13.2.1
version: 13.2.1 version: 13.2.1