diff --git a/README.md b/README.md index 68cfd07..9eb346b 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,30 @@ Please visit the [Visual Studio Code Marketplace](https://marketplace.visualstud ### Commands +- Compile your ``model.cto `` file to a target + +![Code Gen GIF](./assets/Code%20Gen.gif) + + +- Draft clause after passing relevent input into the form. + +![Draft Clause GIF](./assets/Draft%20Clause.gif) + + - Work offline by downloading Concerto model dependencies (context-click on a `*.cto` file) -- Package templates into Cicero Template Archive (cta) files (context-click on root folder) - Export PlantUML class diagram (context-click on a `*.cto` file) + +![Downdload Models and Export Class Diagrsms GIF](./assets/Downloads%20Models%20and%20Export%20Class%20Diagrsm.gif) + +- Parse Clause after entering relevent information into the input form. +- Export the template directory as a ``.cta`` archive. + + ![Parse Clause and Export as archive GIF](./assets/Parse%20Clause%20And%20Export%20As%20Archive.gif) + - Trigger a template, parsing data from sample.md and passing in `request.json` and `state.json` (context-click on root folder) +![Trigger Clause GIF](./assets/Trigger%20Clause.gif) + ### Views - HTML preview for template text (open `grammar.tem.md` and then press the _Open Preview_ icon in the editor or context menu) - HTML preview for Concerto models (open `*.cto` and then press the _Open Preview_ icon in the editor or context menu) diff --git a/assets/Code Gen.gif b/assets/Code Gen.gif new file mode 100644 index 0000000..3635d6a Binary files /dev/null and b/assets/Code Gen.gif differ diff --git a/assets/Downloads Models and Export Class Diagrsm.gif b/assets/Downloads Models and Export Class Diagrsm.gif new file mode 100644 index 0000000..4e5fa30 Binary files /dev/null and b/assets/Downloads Models and Export Class Diagrsm.gif differ diff --git a/assets/Draft Clause.gif b/assets/Draft Clause.gif new file mode 100644 index 0000000..3c56941 Binary files /dev/null and b/assets/Draft Clause.gif differ diff --git a/assets/Parse Clause And Export As Archive.gif b/assets/Parse Clause And Export As Archive.gif new file mode 100644 index 0000000..d817a9b Binary files /dev/null and b/assets/Parse Clause And Export As Archive.gif differ diff --git a/assets/Trigger Clause.gif b/assets/Trigger Clause.gif new file mode 100644 index 0000000..efd0c16 Binary files /dev/null and b/assets/Trigger Clause.gif differ diff --git a/babel.config.json b/babel.config.json index 1cdfa65..37c4c07 100644 --- a/babel.config.json +++ b/babel.config.json @@ -3,5 +3,8 @@ "@babel/preset-env", "@babel/preset-typescript" ], - "plugins": ["@babel/plugin-transform-typescript"] + "plugins": ["@babel/plugin-transform-typescript",["@babel/plugin-transform-runtime", + { + "regenerator": true + }]] } \ No newline at end of file diff --git a/client/package-lock.json b/client/package-lock.json index c64ec4f..9b81efa 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -11,8 +11,8 @@ "dependencies": { "@accordproject/cicero-core": "^0.22.0", "@accordproject/cicero-engine": "^0.22.0", - "@accordproject/concerto-core": "^1.0.0", - "@accordproject/concerto-tools": "^1.0.0", + "@accordproject/concerto-core": "^1.2.1", + "@accordproject/concerto-tools": "^1.2.1", "@accordproject/markdown-it-cicero": "^0.13.0", "@accordproject/markdown-it-template": "^0.13.0", "mermaid": "^8.13.8", diff --git a/client/package.json b/client/package.json index c628051..ebd3f3f 100644 --- a/client/package.json +++ b/client/package.json @@ -21,8 +21,8 @@ "dependencies": { "@accordproject/cicero-core": "^0.22.0", "@accordproject/cicero-engine": "^0.22.0", - "@accordproject/concerto-core": "^1.0.0", - "@accordproject/concerto-tools": "^1.0.0", + "@accordproject/concerto-core": "^1.2.1", + "@accordproject/concerto-tools": "^1.2.1", "@accordproject/markdown-it-cicero": "^0.13.0", "@accordproject/markdown-it-template": "^0.13.0", "mermaid": "^8.13.8", diff --git a/client/src/extension.ts b/client/src/extension.ts index 17e5d97..0d5ef1c 100755 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -36,6 +36,8 @@ import { getPreviewWebviewContent, parseClause, setOutputChannelForCommonCommands, + draftClause, + compileToTarget, } from './webCommandHandlers'; let client: LanguageClient; @@ -123,7 +125,11 @@ export function activate(context: vscode.ExtensionContext) { .registerCommand('cicero-vscode-extension.parseClause', parseClause)); context.subscriptions.push(vscode.commands .registerCommand('cicero-vscode-extension.verifyTemplateSignature', verifyTemplateSignature)); - + context.subscriptions.push(vscode.commands + .registerCommand('cicero-vscode-extension.draftClause', draftClause)); + context.subscriptions.push(vscode.commands + .registerCommand('cicero-vscode-extension.compileToTarget', compileToTarget)); + let currentPanel: vscode.WebviewPanel | undefined = undefined; context.subscriptions.push( diff --git a/client/src/utils.ts b/client/src/utils.ts index 9189886..47ae897 100644 --- a/client/src/utils.ts +++ b/client/src/utils.ts @@ -69,7 +69,8 @@ async function loadFileBuffer(path, fileName, required=false) { const filePath = Utils.resolvePath(path, fileName); try{ - return await vscode.workspace.fs.readFile(filePath); + const contents = Buffer.from(await vscode.workspace.fs.readFile(filePath)); + return contents; } catch(e) { if(required){ @@ -117,8 +118,7 @@ export async function fromDirectory(Template, path, options = {offline:false}) { const readmeContents = await loadFileContents(path, 'README.md'); // grab the logo.png - const logo = Buffer.from(await loadFileBuffer(path, 'logo.png')); - + const logo = await loadFileBuffer(path, 'logo.png'); // grab the request.json const requestJsonObject = await loadFileContents(path, 'request.json', true ); diff --git a/client/src/webClientMain.ts b/client/src/webClientMain.ts index ec130d0..4094546 100644 --- a/client/src/webClientMain.ts +++ b/client/src/webClientMain.ts @@ -24,7 +24,9 @@ import { downloadModels, exportClassDiagram, parseClause, - exportArchive + exportArchive, + compileToTarget, + draftClause } from './webCommandHandlers'; async function onDocumentChange(event) { @@ -55,6 +57,10 @@ export async function activate(context: vscode.ExtensionContext) { .registerCommand('cicero-vscode-extension.downloadModels', downloadModels)); context.subscriptions.push(vscode.commands .registerCommand('cicero-vscode-extension.exportClassDiagram', exportClassDiagram)); + context.subscriptions.push(vscode.commands + .registerCommand('cicero-vscode-extension.compileToTarget', compileToTarget)); + context.subscriptions.push(vscode.commands + .registerCommand('cicero-vscode-extension.draftClause', draftClause)); let currentPanel: vscode.WebviewPanel | undefined = undefined; diff --git a/client/src/webCommandHandlers.ts b/client/src/webCommandHandlers.ts index 95069f4..c894607 100644 --- a/client/src/webCommandHandlers.ts +++ b/client/src/webCommandHandlers.ts @@ -101,6 +101,112 @@ async function getModelManager(ctoFile: vscode.Uri) { return null; } +export async function draftClause(file: vscode.Uri) { + try { + const templateDirectory = Utils.resolvePath(file,".."); + await vscode.workspace.saveAll(); + + var panel = vscode.window.createWebviewPanel( + 'draftInput', + 'Draft Input', + vscode.ViewColumn.Beside, + { + // Enable scripts in the webview + enableScripts: true + } + ); + + panel.webview.html = await getDraftWebviewContent(path.relative(templateDirectory.path,file.path)); + + panel.webview.onDidReceiveMessage( + async (message) => { + const {dataPath,outputPath,utcOffset,currentTime} = message; + outputChannel.show(); + const template = await fromDirectory(Template,templateDirectory); + const clause = new Clause(template); + + const clauseData = JSON.parse(Buffer.from(await vscode.workspace.fs.readFile(Utils.resolvePath(templateDirectory,dataPath.slice(1)))).toString()); + clause.setData(clauseData); + + const drafted = clause.draft(null, currentTime, utcOffset); + + outputChannel.show(); + + outputChannel.appendLine(`${dataPath} parse result`); + outputChannel.appendLine('======================'); + outputChannel.appendLine(drafted); + outputChannel.appendLine(''); + + await vscode.workspace.fs.writeFile( Utils.resolvePath(templateDirectory,outputPath), Buffer.from(drafted,'utf-8')); + outputChannel.appendLine(`Output written to ${outputPath}`); + outputChannel.appendLine(''); + }, + null + ) + + return true; + } catch (error) { + vscode.window.showErrorMessage( `Failed to draft clause ${error}`); + } + + return false; +} + +export async function compileToTarget(file: vscode.Uri) { + try{ + const modelManager = await getModelManager(file); + + const targets = await vscode.window.showQuickPick(['Go', 'PlantUML', 'JSONSchema', 'Typescript', 'Java', 'XMLSchema', 'GraphQL', 'CSharp'],{canPickMany:true}) + + for(const target of targets){ + let visitor = null; + const outputPath = Utils.resolvePath(Utils.dirname(file),target); + + switch(target) { + case 'Go': + visitor = new CodeGen.GoLangVisitor(); + break; + case 'PlantUML': + visitor = new CodeGen.PlantUMLVisitor(); + break; + case 'Typescript': + visitor = new CodeGen.TypescriptVisitor(); + break; + case 'Java': + visitor = new CodeGen.JavaVisitor(); + break; + case 'JSONSchema': + visitor = new CodeGen.JSONSchemaVisitor(); + break; + case 'XMLSchema': + visitor = new CodeGen.XmlSchemaVisitor(); + break; + case 'GraphQL': + visitor = new CodeGen.GraphQLVisitor(); + break; + case 'CSharp': + visitor = new CodeGen.CSharpVisitor(); + break; + case 'OData': + visitor = new CodeGen.ODataVisitor(); + break; + } + + if(visitor) { + let parameters = {} as any; + parameters.fileWriter = new FileWriter(outputPath); + modelManager.accept(visitor, parameters); + vscode.window.showInformationMessage(`Compiled to ${target} in '${outputPath.path}'.`); + } else { + vscode.window.showErrorMessage('Unrecognized target: ' + target); + } + } + + }catch(e) { + vscode.window.showErrorMessage("Compilation error: "+e); + } +} + export async function downloadModels(file: vscode.Uri) { try { const outputPath = Utils.dirname(file); @@ -154,7 +260,7 @@ export async function exportClassDiagram(file: vscode.Uri) { } -function getParseWebviewHtml(defaultSamplePath,defaultOutPath){ +function getDraftWebviewHtml(defaultSamplePath,defaultOutPath, defaultDataPath){ return `