
When this is merged https://gitlab.com/ligolang/ligo-web-ide/ will be marked as deprecated. This MR does not hook up the webide build to the main CI. The CI integration will come in a subsequent MR for the sake of making review easier.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import fs from 'fs';
|
|
import { join } from 'path';
|
|
|
|
function readFile(path: string): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
fs.readFile(path, 'utf8', (error, content) => {
|
|
if (error) {
|
|
reject(error);
|
|
} else {
|
|
resolve(content);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function loadDefaultState(appBundleDirectory: string) {
|
|
const examples = await readFile(
|
|
join(appBundleDirectory, 'static', 'examples', 'list')
|
|
);
|
|
const examplesList = JSON.parse(examples);
|
|
const defaultState = {
|
|
compile: {},
|
|
dryRun: {},
|
|
deploy: {},
|
|
evaluateValue: {},
|
|
evaluateFunction: {},
|
|
editor: {},
|
|
examples: {
|
|
selected: null,
|
|
list: examplesList
|
|
}
|
|
};
|
|
|
|
if (examplesList[0]) {
|
|
const example = await readFile(
|
|
join(appBundleDirectory, 'static', 'examples', examplesList[0].id)
|
|
);
|
|
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.examples.selected = defaultExample;
|
|
}
|
|
|
|
return defaultState;
|
|
}
|