Skip to content

Commit

Permalink
Push cli actions
Browse files Browse the repository at this point in the history
  • Loading branch information
YassineOuhadi committed Jan 4, 2024
1 parent c1c657d commit fd1a853
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 99 deletions.
74 changes: 29 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@ Jgen, the DSL, is constructed on the Spring Boot REST API Ecore metamodel, devel

The VS Code extension for the Jgen DSL allows the implementation of code validations, code completion, syntax highlighting, and a server protocol language. It features a tree view that synchronizes with the Jgen editor.

- Clone the repository to your local machine:

`git clone https://github.com/YassineOuhadi/Jgen.git`

## Features

1. Domain specific language using Langium.
2. Semantic validators for our DSL based on TypeScript code.
3. CLI for our DSL.
3. Customizing the Jgen CLI.
4. Parser for Jgen DSL that outputs JSON format.
5. Transformation M2M between Ecore model and Jgen DSL.
6. Generate Java RESTful APIs from Jgen DSL.
7. Building an Extension.
- Open Jgen file.
- Initialize Jgen file.
- Tree view for Extension
9. Generation in the Web.
10. Graphical model for Jgen DSL.
- Import Ecore / JSON file.
8. Tree view for Extension.
9. Monaco Editor.
10. Generation in the Web.

## Jgen Metamodel

![jgen metamodel ecore](https://github.com/YassineOuhadi/Jgen/assets/109771302/c842fce7-2ec1-4261-87d1-e60505a524e6)


## DSL for Generating Spring Boot REST APIs using Langium

Expand Down Expand Up @@ -184,18 +194,9 @@ project Demo
relationship OneToMany from User to Tweet
repository userRepository for User
query findBYName
type SELECT
parameter username is fullname
query getUserByEmail
type SELECT
parameter email is email
query modifyUsername
type UPDATE
parameter id is id
parameter username is username
service userService for User
repository userRepository
Expand All @@ -205,39 +206,10 @@ project Demo
controller userController for User
path /user
service userService
route addUser
path /add
operation POST
requestBody
parameter fullname is fullname
parameter email is email
route getUser
path /get
operation GET
requestParameter userId is id required
route getUserByEmail
path /get
operation GET
requestParameter userEmail is email required
route getAllUsers
path /all
operation GET
route updateUser
path /update
operation PUT
requestBody
parameter fullname is fullname
parameter email is email
route updateUser
path /update
operation PUT
requestParameter fullname is email required
requestParameter email is email required
configuration
metadata
Expand All @@ -264,9 +236,16 @@ project Demo
```


## Visual Studio Code extension

![mde drawio](https://github.com/YassineOuhadi/Jgen/assets/109771302/f3fc8b8f-aa45-4135-803f-72bfcc039156)
![mde jgen arch diagram](https://github.com/YassineOuhadi/Jgen/assets/109771302/d15ade27-b16d-4826-8939-9de2125c089b)

## Language Server Protocol (LSP)

![mde jgen lsp](https://github.com/YassineOuhadi/Jgen/assets/109771302/8f611814-65f6-459c-8c3a-9fe655979985)



## Get started

Expand All @@ -280,6 +259,10 @@ project Demo
* To generate REST code for a given DSL file with a specified destination, use the following command:
- `./bin/cli generateRESTfulAPI --help` to see options and help for the `generateRESTfulAPI` command.
- `./bin/cli generateRESTfulAPI -d <destination-path> -p <file>` for file path or `./bin/cli generateRESTfulAPI -d <destination-path> -c "<jgen-content>"` for direct content. Replace `<destination-path>` with the desired directory path where you want to store the generated code.
* To validate Grammar for a given DSL instance use the following command:
- `./bin/cli validateGrammar <file>`.
* To generate Ecore code / JSON format for a given DSL file with a specified destination, use the following command:
- `./bin/cli generateEcore / generateJson -d <destination-path> <file>`.

## Get started with the Docker image

Expand All @@ -305,7 +288,7 @@ project Demo
```bash
docker run -p 3000:3000 yassineouhadi/jgen:web
```

## Overview

## Perspectives
Expand All @@ -316,6 +299,7 @@ project Demo
1. Documentation about the Langium framework is available at [https://langium.org/docs/](https://langium.org/docs/)
2. Vs Code Extension Guidelines is available at [https://code.visualstudio.com/api/ux-guidelines/overview](https://code.visualstudio.com/api/ux-guidelines/overview)
3. MDE course available at [https://portail.fil.univ-lille.fr/portail/index.php?dipl=MInfo&sem=GL&ue=IDM&label=Cours](https://portail.fil.univ-lille.fr/portail/index.php?dipl=MInfo&sem=GL&ue=IDM&label=Cours)
## Members
Expand All @@ -324,4 +308,4 @@ project Demo
3. [CHARIF Mehdi](https://github.com/mehdicharife)
4. [ALAMI IBN JAMAA Hamza](https://github.com/Schrodingdong)
## License
## License
24 changes: 0 additions & 24 deletions example/hh.jgen

This file was deleted.

11 changes: 0 additions & 11 deletions example/test.jgen
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@ project Demo

relationship OneToMany from User to Tweet

relationship ManyToOne from Tweet to User

repository userRepository for User
query findBYName
type SELECT
parameter username is fullname
query getUserByEmail
type SELECT
parameter email is email
query modifyUsername
type UPDATE
parameter id is id
parameter username is fullname

service userService for User
repository userRepository
Expand All @@ -56,13 +47,11 @@ project Demo
package com.example.demo
packaging Jar
javaVersion 17

datasource
type MySQL
host localhost
port 3306
database jgen

server
host localhost
port 9090
Binary file added jgen-report-fr.pdf
Binary file not shown.
56 changes: 38 additions & 18 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,36 @@ import { JgenLanguageMetaData } from '../language-server/generated/module';
import { createJgenServices } from '../language-server/jgen-module';
import { extractAstNode } from './cli-util';
import { generateEcore } from '../generators/EcoreGenerator';
import { generateJson } from '../generators/JsonGenerator';
import { generateJgen } from '../generators/JgenGenerator';
import { NodeFileSystem } from 'langium/node';
import { generateRestfulAPI } from '../generators/RestfulAPIGenerator';
import fs from 'fs';
import path from 'path';

export const generateAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
export const generateEcoreAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
const services = createJgenServices(NodeFileSystem).Jgen;
const model = await extractAstNode<Project>(fileName, services);
const generatedFilePath = generateEcore(model, fileName, opts.destination);
console.log(chalk.green(`Ecore code generated successfully: ${generatedFilePath}`));
};

export const generateJsonAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
const services = createJgenServices(NodeFileSystem).Jgen;
const model = await extractAstNode<Project>(fileName, services);
const generatedFilePath = generateJson(model, fileName, opts.destination);
console.log(chalk.green(`Json code generated successfully: ${generatedFilePath}`));
};

export const generateJgenAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
const services = createJgenServices(NodeFileSystem).Jgen;
const generatedFilePath = generateJgen(fileName, opts.destination);
console.log(chalk.green(`Json code generated successfully: ${generatedFilePath}`));
};

// export const generateRestfulAPIAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
// const services = createJgenServices(NodeFileSystem).Jgen;
// const model = await extractAstNode<Project>(fileName, services);
// const generatedFilePath = generateRestfulAPI(model, fileName, opts.destination);
// console.log(chalk.green(`Restful api code generated successfully: ${generatedFilePath}`));
// };
export const validateGrammarAction = async (fileName: string): Promise<void> => {
//
};

export const generateRestfulAPIAction = async (opts: GenerateOptions): Promise<void> => {
const services = createJgenServices(NodeFileSystem).Jgen;
Expand Down Expand Up @@ -70,20 +81,31 @@ export default function (): void {
.command('generateEcore')
.argument('<file>', `source file (possible file extensions: ${fileExtensions})`)
.option('-d, --destination <dir>', 'destination directory of generating')
.description('generates Ecore from jgen file')
.action(generateAction);
// program
// .command('generateRESTfulAPI')
// .argument('<file>', `source file (possible file extensions: ${fileExtensions})`)
// .option('-d, --destination <dir>', 'destination directory of generating')
// .description('generates Restful API from jgen file')
// .action(generateRestfulAPIAction);
.description('generates Ecore from Jgen code')
.action(generateEcoreAction);
program
.command('generateJson')
.argument('<file>', `source file (possible file extensions: ${fileExtensions})`)
.option('-d, --destination <dir>', 'destination directory of generating')
.description('generates Json from Jgen code')
.action(generateJsonAction);
program
.command('generateJgen')
.argument('<file>', `source file (possible file Json or Ecore)`)
.option('-d, --destination <dir>', 'destination directory of generating')
.description('generates Jgen from Json/Ecore code')
.action(generateJgenAction);
program
.command('validateGrammar')
.argument('<file>', `source file (possible file extensions: ${fileExtensions})`)
.description('validate grammar for a given Jgen code')
.action(validateGrammarAction);
program
.command('generateRESTfulAPI')
.option('-d, --destination <dir>', 'destination directory of generating')
.option('-c, --content <content>', 'jgen content directly')
.option('-p, --path <file>', 'source file (possible file extensions: ${fileExtensions})')
.description('generates Restful API from jgen file or content')
.description('generates Restful API from Jgen code')
.action(generateRestfulAPIAction)
.on('--help', () => {
console.log('');
Expand All @@ -98,8 +120,6 @@ export default function (): void {
console.log('Replace <destination-path> with the desired directory path where you want to store the generated code.');
});



program.parse(process.argv);
}

Expand Down
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ export async function activate(context: vscode.ExtensionContext) {
});
}));

// create new file button
context.subscriptions.push(vscode.commands.registerCommand("myImportEcoreButtonCommand", () => {
//
}));

// create new file button
context.subscriptions.push(vscode.commands.registerCommand("myImportJsonButtonCommand", () => {
//
}));

// ..
}

Expand Down
3 changes: 3 additions & 0 deletions src/generators/JgenGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function generateJgen(filePath: string, destination: string | undefined): string {
return '';
}
5 changes: 5 additions & 0 deletions src/generators/JsonGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Project } from '../language-server/generated/ast';

export function generateJson(project: Project, filePath: string, destination: string | undefined): string {
return '';
}
3 changes: 2 additions & 1 deletion src/models/selectFileButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class MyMenuButtonsProvider implements vscode.TreeDataProvider<MyMenuButt
return [
new MyMenuButtons("Open Jgen file", vscode.TreeItemCollapsibleState.None, "mySelectFileButtonCommand"),
new MyMenuButtons("Create new Jgen file", vscode.TreeItemCollapsibleState.None, "myCreateFileButtonCommand"),
// new MyMenuButtons("Import Ecore File", vscode.TreeItemCollapsibleState.None, "myImportEcoreButtonCommand")
new MyMenuButtons("Import Ecore File", vscode.TreeItemCollapsibleState.None, "myImportEcoreButtonCommand"),
new MyMenuButtons("Import Json File", vscode.TreeItemCollapsibleState.None, "myImportJsonButtonCommand")
];
}
return undefined;
Expand Down

0 comments on commit fd1a853

Please sign in to comment.