Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix - support trigger with missing state.json file
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Selman <[email protected]>
  • Loading branch information
dselman committed Aug 5, 2020
1 parent ec61d0f commit a9015db
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change Log

### 0.21.8

- Support triggering templates without a `state.json` file

### 0.21.7

- Added trigger command
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Accord Project extension for Visual Studio Code, providing tools for template development.",
"author": "Accord Project",
"license": "Apache-2.0",
"version": "0.21.7",
"version": "0.21.8",
"publisher": "accordproject",
"repository": {
"type": "git",
Expand Down
19 changes: 10 additions & 9 deletions client/src/commandHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ export async function triggerClause(file: vscode.Uri) {
return false;
}

const statePath = path.join(file.path, 'state.json');

if(!fs.existsSync(statePath)) {
vscode.window.showErrorMessage('Cannot trigger: /state.json file was not found.');
return false;
}

const sampleText = fs.readFileSync( samplePath, 'utf8');
clause.parse(sampleText);
const parseResult = clause.getData();
Expand All @@ -144,14 +137,22 @@ export async function triggerClause(file: vscode.Uri) {
outputChannel.appendLine( JSON.stringify(request, null, 2) );
outputChannel.appendLine( '' );

const state = JSON.parse(fs.readFileSync( requestPath, 'utf8'));
const statePath = path.join(file.path, 'state.json');
const engine = new Engine();
let state = null;

if(!fs.existsSync(statePath)) {
const initResult = await engine.init(clause, null);
state = initResult.state;
} else {
state = JSON.parse(fs.readFileSync( statePath, 'utf8'));
}

outputChannel.appendLine( 'state.json' );
outputChannel.appendLine( '==========' );
outputChannel.appendLine( JSON.stringify(state, null, 2) );
outputChannel.appendLine( '' );

const engine = new Engine();
const result = await engine.trigger(clause, request, state, null );

outputChannel.appendLine( 'response' );
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Accord Project extension for Visual Studio Code, providing tools for template development.",
"author": "Accord Project",
"license": "Apache-2.0",
"version": "0.21.7",
"version": "0.21.8",
"icon": "icon.png",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cicero-vscode-extension-server",
"description": "A language server for Accord Project templates",
"version": "0.21.7",
"version": "0.21.8",
"license": "Apache-2.0",
"engines": {
"node": "*"
Expand Down

0 comments on commit a9015db

Please sign in to comment.