-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Summary of Changes The CLI should now start properly when running `node ./bin/cli` in the project root. This PR also adds a test to ensure this in the future. --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
7998eb1
commit 4bde898
Showing
11 changed files
with
97 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
.vscode/ | ||
|
||
# Compilation/build outputs | ||
bin/ | ||
build/ | ||
coverage/ | ||
dist/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env node | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import '../out/cli/main.cjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,25 @@ | ||
import chalk from 'chalk'; | ||
import { Command } from 'commander'; | ||
import { SdsModule } from '../language/generated/ast.js'; | ||
import { SafeDsLanguageMetaData } from '../language/generated/module.js'; | ||
import { createSafeDsServices } from '../language/safe-ds-module.js'; | ||
import { extractAstNode } from './cli-util.js'; | ||
import { generatePython } from './generator.js'; | ||
import { NodeFileSystem } from 'langium/node'; | ||
import { generateAction } from './generator.js'; | ||
import * as path from 'node:path'; | ||
|
||
export const generateAction = async (fileName: string, opts: GenerateOptions): Promise<void> => { | ||
const services = createSafeDsServices(NodeFileSystem).SafeDs; | ||
const module = await extractAstNode<SdsModule>(fileName, services); | ||
const generatedFilePath = generatePython(module, fileName, opts.destination); | ||
// eslint-disable-next-line no-console | ||
console.log(chalk.green(`JavaScript code generated successfully: ${generatedFilePath}`)); | ||
}; | ||
const packagePath = path.resolve(__dirname, '..', '..', 'package.json'); | ||
|
||
export type GenerateOptions = { | ||
destination?: string; | ||
}; | ||
const fileExtensions = SafeDsLanguageMetaData.fileExtensions.join(', '); | ||
|
||
// eslint-disable-next-line import/no-default-export, func-names | ||
export default function (): void { | ||
const program = new Command(); | ||
const program = new Command(); | ||
|
||
program | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
.version(require('../../package.json').version); | ||
program | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
.version(require(packagePath).version); | ||
|
||
const fileExtensions = SafeDsLanguageMetaData.fileExtensions.join(', '); | ||
program | ||
.command('generate') | ||
.argument('<file>', `source file (possible file extensions: ${fileExtensions})`) | ||
.option('-d, --destination <dir>', 'destination directory of generating') | ||
.description('generates JavaScript code that prints "Hello, {name}!" for each greeting in a source file') | ||
.action(generateAction); | ||
program | ||
.command('generate') | ||
.argument('<file>', `possible file extensions: ${fileExtensions}`) | ||
.option('-d, --destination <dir>', 'destination directory of generation') | ||
.option('-r, --root <dir>', 'source root folder') | ||
.option('-q, --quiet', 'whether the program should print something', false) | ||
.description('generate Python code') | ||
.action(generateAction); | ||
|
||
program.parse(process.argv); | ||
} | ||
program.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { beforeAll, describe, expect, it } from 'vitest'; | ||
import path from 'node:path'; | ||
import { spawnSync, execSync } from 'node:child_process'; | ||
import url from 'node:url'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
const projectRoot = path.resolve(__dirname, '..', '..'); | ||
|
||
describe('program', () => { | ||
beforeAll(() => { | ||
execSync('npm run build', { cwd: projectRoot }); | ||
}); | ||
|
||
it('should show usage if no arguments are passed', () => { | ||
const process = spawnSync('node', ['./bin/cli'], { cwd: projectRoot }); | ||
expect(process.stderr.toString()).toContain('Usage: cli [options] [command]'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2017", | ||
"module": "Node16", | ||
"lib": ["ESNext", "DOM", "WebWorker"], | ||
"sourceMap": true, | ||
"outDir": "out", | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noImplicitReturns": true, | ||
"noImplicitOverride": true, | ||
"moduleResolution": "Node16", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
"target": "ES2017", | ||
"module": "Node16", | ||
"lib": ["ESNext", "DOM", "WebWorker"], | ||
"sourceMap": true, | ||
"outDir": "out", | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noImplicitReturns": true, | ||
"noImplicitOverride": true, | ||
"moduleResolution": "Node16", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"out", | ||
"node_modules" | ||
] | ||
} | ||
|
||
"include": ["src/**/*.ts"], | ||
"exclude": ["out", "node_modules"] | ||
} |