Merge branch 'compile-json-output' into 'dev'

Added JSON output to compile command

See merge request ligolang/ligo!417
This commit is contained in:
Jev Björsell 2020-02-15 02:19:31 +00:00
commit b4ef2ed76f
10 changed files with 98 additions and 25 deletions

View File

@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="The LIGO Playground for learning LIGO" />
<link rel="apple-touch-icon" href="logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/

View File

@ -3,16 +3,25 @@ import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeEntrypointAction, CompileState } from '../redux/compile';
import { Group, Input, Label } from './inputs';
import { ChangeEntrypointAction, ChangeMichelsonFormatAction, CompileState, MichelsonFormat } from '../redux/compile';
import { CheckboxComponent } from './checkbox';
import { Group, HGroup, Input, Label } from './inputs';
const Container = styled.div``;
const Checkbox = styled(CheckboxComponent)`
margin-right: 0.3em;
`;
export const CompilePaneComponent = () => {
const dispatch = useDispatch();
const entrypoint = useSelector<AppState, CompileState['entrypoint']>(
state => state.compile.entrypoint
);
const michelsonFormat = useSelector<
AppState,
CompileState['michelsonFormat']
>(state => state.compile.michelsonFormat);
return (
<Container>
@ -26,6 +35,19 @@ export const CompilePaneComponent = () => {
}
></Input>
</Group>
<HGroup>
<Checkbox
checked={michelsonFormat === MichelsonFormat.Json}
onChanged={value =>
dispatch({
...new ChangeMichelsonFormatAction(
value ? MichelsonFormat.Json : MichelsonFormat.Text
)
})
}
></Checkbox>
<Label htmlFor="michelsonFormat">Output michelson in JSON format</Label>
</HGroup>
</Container>
);
};

View File

@ -16,7 +16,8 @@ export class CompileAction extends CancellableAction {
const michelsonCode = await compileContract(
editor.language,
editor.code,
compileState.entrypoint
compileState.entrypoint,
compileState.michelsonFormat
);
if (this.isCancelled()) {

View File

@ -6,11 +6,13 @@ export enum MichelsonFormat {
}
export enum ActionType {
ChangeEntrypoint = 'compile-change-entrypoint'
ChangeEntrypoint = 'compile-change-entrypoint',
ChangeMichelsonFormat = 'compile-change-michelson-format'
}
export interface CompileState {
entrypoint: string;
michelsonFormat: MichelsonFormat;
}
export class ChangeEntrypointAction {
@ -18,10 +20,19 @@ export class ChangeEntrypointAction {
constructor(public payload: CompileState['entrypoint']) {}
}
type Action = ChangeEntrypointAction | ChangeSelectedExampleAction;
export class ChangeMichelsonFormatAction {
public readonly type = ActionType.ChangeMichelsonFormat;
constructor(public payload: CompileState['michelsonFormat']) {}
}
type Action =
| ChangeEntrypointAction
| ChangeMichelsonFormatAction
| ChangeSelectedExampleAction;
const DEFAULT_STATE: CompileState = {
entrypoint: ''
entrypoint: '',
michelsonFormat: MichelsonFormat.Text
};
export default (state = DEFAULT_STATE, action: Action): CompileState => {
@ -36,6 +47,12 @@ export default (state = DEFAULT_STATE, action: Action): CompileState => {
...state,
entrypoint: action.payload
};
case ActionType.ChangeMichelsonFormat:
return {
...state,
michelsonFormat: action.payload
};
default:
return state;
}
return state;
};

View File

@ -1,4 +1,8 @@
import { ActionType as CompileActionType, ChangeEntrypointAction as ChangeCompileEntrypointAction } from './compile';
import {
ActionType as CompileActionType,
ChangeEntrypointAction as ChangeCompileEntrypointAction,
ChangeMichelsonFormatAction,
} from './compile';
import {
ActionType as DeployActionType,
ChangeEntrypointAction as ChangeDeployEntrypointAction,
@ -40,6 +44,7 @@ type Action =
| ChangeCodeAction
| ChangeLanguageAction
| ChangeCompileEntrypointAction
| ChangeMichelsonFormatAction
| ChangeDeployEntrypointAction
| ChangeDeployStorageAction
| UseTezBridgeAction
@ -61,7 +66,6 @@ export default (state = DEFAULT_STATE, action: Action): ShareState => {
case CompileActionType.ChangeEntrypoint:
case DeployActionType.ChangeEntrypoint:
case DeployActionType.ChangeStorage:
case DeployActionType.UseTezBridge:
case DryRunActionType.ChangeEntrypoint:
case DryRunActionType.ChangeParameters:
case DryRunActionType.ChangeStorage:

View File

@ -30,7 +30,7 @@ export async function compileExpression(
) {
const response = await axios.post('/api/compile-expression', {
syntax,
expression,
expression: `${expression}`,
format
});
return response.data;
@ -64,14 +64,24 @@ export async function share({
evaluateValue,
evaluateFunction
}: Partial<AppState>) {
const response = await axios.post('/api/share', {
const params = {
editor,
compile,
dryRun,
deploy,
evaluateValue,
evaluateFunction
});
};
// We don't want to store the following configuration
if (params.compile) {
delete params.compile.michelsonFormat;
}
if (params.deploy) {
delete params.deploy.useTezBridge;
}
const response = await axios.post('/api/share', params);
return response.data;
}

View File

@ -1,12 +1,12 @@
import { Request, Response } from 'express';
import { loadDefaultState } from '../load-state';
import { logger } from '../logger';
import latestSchema from '../schemas/share-latest';
import { storage } from '../storage';
import { FileNotFoundError } from '../storage/interface';
import { logger } from '../logger';
export function createSharedLinkHandler(
export function sharedLinkHandler(
appBundleDirectory: string,
template: (state: string) => string
) {

View File

@ -9,9 +9,9 @@ import { dryRunHandler } from './handlers/dry-run';
import { evaluateValueHandler } from './handlers/evaluate-value';
import { runFunctionHandler } from './handlers/run-function';
import { shareHandler } from './handlers/share';
import { createSharedLinkHandler } from './handlers/shared-link';
import { sharedLinkHandler } from './handlers/shared-link';
import { loadDefaultState } from './load-state';
import { loggerMiddleware, errorLoggerMiddleware } from './logger';
import { errorLoggerMiddleware, loggerMiddleware } from './logger';
var bodyParser = require('body-parser');
var escape = require('escape-html');
@ -47,7 +47,7 @@ app.use('^/$', async (_, res) =>
app.use(express.static(appBundleDirectory));
app.get(
`/p/:hash([0-9a-zA-Z\-\_]+)`,
createSharedLinkHandler(appBundleDirectory, template)
sharedLinkHandler(appBundleDirectory, template)
);
app.post('/api/compile-contract', compileContractHandler);
app.post('/api/compile-expression', compileExpressionHandler);

View File

@ -37,12 +37,30 @@ export async function loadDefaultState(appBundleDirectory: string) {
);
const defaultExample = JSON.parse(example);
defaultState.compile = defaultExample.compile;
defaultState.dryRun = defaultExample.dryRun;
defaultState.deploy = defaultExample.deploy;
defaultState.evaluateValue = defaultExample.evaluateValue;
defaultState.evaluateFunction = defaultExample.evaluateFunction;
defaultState.editor = defaultExample.editor;
defaultState.compile = {
...defaultState.compile,
...defaultExample.compile
};
defaultState.dryRun = {
...defaultState.dryRun,
...defaultExample.dryRun
};
defaultState.deploy = {
...defaultState.deploy,
...defaultExample.deploy
};
defaultState.evaluateValue = {
...defaultState.evaluateValue,
...defaultExample.evaluateValue
};
defaultState.evaluateFunction = {
...defaultState.evaluateFunction,
...defaultExample.evaluateFunction
};
defaultState.editor = {
...defaultState.editor,
...defaultExample.editor
};
defaultState.examples.selected = defaultExample;
}

View File

@ -18,7 +18,9 @@ export abstract class Migration {
}
throw new Error(
`Unable to migrate ${data}. Reached the end of the migration chain.`
`Unable to migrate ${JSON.stringify(
data
)}. Reached the end of the migration chain.`
);
}
return value;