-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Weminal-labs/develop
Release v0.2.0
- Loading branch information
Showing
12 changed files
with
656 additions
and
195 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as vscode from "vscode"; | ||
import { build, executeCommand, publish } from "./suiCommand"; | ||
import { join } from "path"; | ||
|
||
export class SidebarProvider implements vscode.WebviewViewProvider { | ||
constructor(private readonly _extensionContext: vscode.ExtensionContext) { } | ||
|
||
public resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, token: vscode.CancellationToken) { | ||
|
||
webviewView.webview.options = { | ||
// Allow scripts in the webview | ||
enableScripts: true, | ||
|
||
localResourceRoots: [this._extensionContext.extensionUri], | ||
}; | ||
|
||
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); | ||
|
||
webviewView.webview.onDidReceiveMessage((message) => { | ||
const { command, requestId, payload } = message; | ||
|
||
switch (command) { | ||
case "SUI_TERMINAL": | ||
executeCommand(payload.command, payload.suiPath); | ||
break; | ||
|
||
case "BUILD": | ||
build(payload.packagePath, payload.suiPath); | ||
break; | ||
|
||
case "PUBLISH": | ||
publish(payload.packagePath, payload.suiPath); | ||
break; | ||
|
||
case "SAVE_ALIASES": | ||
this._extensionContext.workspaceState.update(payload.address, { | ||
aliases: payload.aliases | ||
}).then(() => { | ||
vscode.window.showInformationMessage("Aliases saved successfully!"); | ||
}); | ||
|
||
// use value as undefined to remove the key | ||
// context.workspaceState.update("", undefined); | ||
|
||
default: | ||
vscode.window.showInformationMessage(`Unknown command: ${command}`); | ||
} | ||
}); | ||
} | ||
|
||
private _getHtmlForWebview(webview: vscode.Webview) { | ||
const jsFile = "webview.js"; | ||
const localServerUrl = "http://localhost:9999"; | ||
|
||
let scriptUrl = null; | ||
let cssUrl = null; | ||
|
||
const isProduction = this._extensionContext.extensionMode === vscode.ExtensionMode.Production; | ||
if (isProduction) { | ||
scriptUrl = webview.asWebviewUri(vscode.Uri.file(join(this._extensionContext.extensionPath, 'dist', jsFile))).toString(); | ||
} else { | ||
scriptUrl = `${localServerUrl}/${jsFile}`; | ||
} | ||
|
||
return `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
${isProduction ? `<link href="${cssUrl}" rel="stylesheet">` : ''} | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script src="${scriptUrl}"></script> | ||
</body> | ||
</html>`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export enum MoveCallStatus { | ||
BEGIN, | ||
FINISH, | ||
ERROR, | ||
}; | ||
|
||
export enum MoveCallActionType { | ||
SET_MNEMONICS = "SET_MNEMONICS", | ||
SET_PACKAGE_ID = "SET_PACKAGE_ID", | ||
SET_MODULES = "SET_MODULES", | ||
SET_ERROR = "SET_ERROR", | ||
SET_CURRENT_MODULE = "SET_CURRENT_MODULE", | ||
SET_FUNCTIONS = "SET_FUNCTIONS", | ||
SET_CURRENT_FUNCTION = "SET_CURRENT_FUNCTION", | ||
RESET_ARGS = "RESET_ARGS", | ||
RESET_ARGS_USER_INPUT = "RESET_ARGS_USER_INPUT", | ||
ADD_ARG = "ADD_ARG", | ||
SET_VALUE_TO_ARG = "SET_VALUE_TO_ARG", | ||
SET_RESPONSE = "SET_RESPONSE", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export const build = (path: string) => { | ||
const handleSuiPathEmpty = (suiPath: string) => { | ||
if (!suiPath) { | ||
return "sui"; | ||
} | ||
return suiPath; | ||
} | ||
|
||
export const build = (path: string, suiPath: string) => { | ||
suiPath = handleSuiPathEmpty(suiPath); | ||
const terminal = vscode.window.createTerminal("Sui Simulator"); | ||
terminal.sendText(`sui move build -p ${path}`); | ||
terminal.sendText(`${suiPath} move build -p ${path}`); | ||
terminal.show(); | ||
}; | ||
|
||
export const publish = (path: string) => { | ||
export const publish = (path: string, suiPath: string) => { | ||
suiPath = handleSuiPathEmpty(suiPath); | ||
const terminal = vscode.window.createTerminal("Sui Simulator"); | ||
terminal.sendText(`sui client publish --gas-budget 100000000 ${path}`); | ||
terminal.sendText(`${suiPath} client publish --gas-budget 100000000 ${path}`); | ||
terminal.show(); | ||
}; | ||
|
||
export const executeCommand = (command: string) => { | ||
export const executeCommand = (command: string, suiPath: string) => { | ||
suiPath = handleSuiPathEmpty(suiPath); | ||
const terminal = vscode.window.createTerminal("Sui Simulator"); | ||
terminal.sendText(command); | ||
terminal.sendText(`${suiPath} ${command}`); | ||
terminal.show(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { SuiMoveNormalizedFunction } from "@mysten/sui.js/client"; | ||
import { MoveCallStatus } from "../enums"; | ||
|
||
export interface ActionType { | ||
type: string, | ||
payload: any | ||
}; | ||
|
||
export interface MoveCallState { | ||
mnemonics: string, | ||
status: MoveCallStatus, | ||
packageId: string, | ||
modules: string[], | ||
currentModule: string, | ||
functions: { | ||
[key: string]: SuiMoveNormalizedFunction; | ||
}, | ||
currentFunction: string; | ||
args: string[], | ||
argsUserInput: string[], | ||
error: string, | ||
response: string, | ||
} |
Oops, something went wrong.