Skip to content

Commit

Permalink
Fix generator-langium cli for esm (#1201)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich authored Sep 27, 2023
1 parent 2187f83 commit 03e0cbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/generator-langium/templates/cli/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node

import '../out/cli/main';
import main from '../out/cli/main.js';
main();
11 changes: 8 additions & 3 deletions packages/generator-langium/templates/cli/src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { create<%= LanguageName %>Services } from '../language/<%= language-id %
import { extractAstNode } from './cli-util.js';
import { generateJavaScript } from './generator.js';
import { NodeFileSystem } from 'langium/node';
import * as url from 'node:url';
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const packagePath = path.resolve(__dirname, '..', '..', 'package.json');
const packageContent = await fs.readFile(packagePath, 'utf-8');

export const generateAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
const services = create<%= LanguageName %>Services(NodeFileSystem).<%= LanguageName %>;
Expand All @@ -21,9 +28,7 @@ export type GenerateOptions = {
export default function(): void {
const program = new Command();

program
// eslint-disable-next-line @typescript-eslint/no-var-requires
.version(require('../../package.json').version);
program.version(JSON.parse(packageContent).version);

const fileExtensions = <%= LanguageName %>LanguageMetaData.fileExtensions.join(', ');
program
Expand Down

0 comments on commit 03e0cbf

Please sign in to comment.