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="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta name="description" content="The LIGO Playground for learning LIGO" /> <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 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/ 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 styled from 'styled-components';
import { AppState } from '../redux/app'; import { AppState } from '../redux/app';
import { ChangeEntrypointAction, CompileState } from '../redux/compile'; import { ChangeEntrypointAction, ChangeMichelsonFormatAction, CompileState, MichelsonFormat } from '../redux/compile';
import { Group, Input, Label } from './inputs'; import { CheckboxComponent } from './checkbox';
import { Group, HGroup, Input, Label } from './inputs';
const Container = styled.div``; const Container = styled.div``;
const Checkbox = styled(CheckboxComponent)`
margin-right: 0.3em;
`;
export const CompilePaneComponent = () => { export const CompilePaneComponent = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const entrypoint = useSelector<AppState, CompileState['entrypoint']>( const entrypoint = useSelector<AppState, CompileState['entrypoint']>(
state => state.compile.entrypoint state => state.compile.entrypoint
); );
const michelsonFormat = useSelector<
AppState,
CompileState['michelsonFormat']
>(state => state.compile.michelsonFormat);
return ( return (
<Container> <Container>
@ -26,6 +35,19 @@ export const CompilePaneComponent = () => {
} }
></Input> ></Input>
</Group> </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> </Container>
); );
}; };

View File

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

View File

@ -6,11 +6,13 @@ export enum MichelsonFormat {
} }
export enum ActionType { export enum ActionType {
ChangeEntrypoint = 'compile-change-entrypoint' ChangeEntrypoint = 'compile-change-entrypoint',
ChangeMichelsonFormat = 'compile-change-michelson-format'
} }
export interface CompileState { export interface CompileState {
entrypoint: string; entrypoint: string;
michelsonFormat: MichelsonFormat;
} }
export class ChangeEntrypointAction { export class ChangeEntrypointAction {
@ -18,10 +20,19 @@ export class ChangeEntrypointAction {
constructor(public payload: CompileState['entrypoint']) {} 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 = { const DEFAULT_STATE: CompileState = {
entrypoint: '' entrypoint: '',
michelsonFormat: MichelsonFormat.Text
}; };
export default (state = DEFAULT_STATE, action: Action): CompileState => { export default (state = DEFAULT_STATE, action: Action): CompileState => {
@ -36,6 +47,12 @@ export default (state = DEFAULT_STATE, action: Action): CompileState => {
...state, ...state,
entrypoint: action.payload entrypoint: action.payload
}; };
} case ActionType.ChangeMichelsonFormat:
return state; return {
...state,
michelsonFormat: action.payload
};
default:
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 { import {
ActionType as DeployActionType, ActionType as DeployActionType,
ChangeEntrypointAction as ChangeDeployEntrypointAction, ChangeEntrypointAction as ChangeDeployEntrypointAction,
@ -40,6 +44,7 @@ type Action =
| ChangeCodeAction | ChangeCodeAction
| ChangeLanguageAction | ChangeLanguageAction
| ChangeCompileEntrypointAction | ChangeCompileEntrypointAction
| ChangeMichelsonFormatAction
| ChangeDeployEntrypointAction | ChangeDeployEntrypointAction
| ChangeDeployStorageAction | ChangeDeployStorageAction
| UseTezBridgeAction | UseTezBridgeAction
@ -61,7 +66,6 @@ export default (state = DEFAULT_STATE, action: Action): ShareState => {
case CompileActionType.ChangeEntrypoint: case CompileActionType.ChangeEntrypoint:
case DeployActionType.ChangeEntrypoint: case DeployActionType.ChangeEntrypoint:
case DeployActionType.ChangeStorage: case DeployActionType.ChangeStorage:
case DeployActionType.UseTezBridge:
case DryRunActionType.ChangeEntrypoint: case DryRunActionType.ChangeEntrypoint:
case DryRunActionType.ChangeParameters: case DryRunActionType.ChangeParameters:
case DryRunActionType.ChangeStorage: case DryRunActionType.ChangeStorage:

View File

@ -30,7 +30,7 @@ export async function compileExpression(
) { ) {
const response = await axios.post('/api/compile-expression', { const response = await axios.post('/api/compile-expression', {
syntax, syntax,
expression, expression: `${expression}`,
format format
}); });
return response.data; return response.data;
@ -64,14 +64,24 @@ export async function share({
evaluateValue, evaluateValue,
evaluateFunction evaluateFunction
}: Partial<AppState>) { }: Partial<AppState>) {
const response = await axios.post('/api/share', { const params = {
editor, editor,
compile, compile,
dryRun, dryRun,
deploy, deploy,
evaluateValue, evaluateValue,
evaluateFunction 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; return response.data;
} }

View File

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

View File

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

View File

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

View File

@ -18,7 +18,9 @@ export abstract class Migration {
} }
throw new Error( 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; return value;