Cloud Studio Editor SDK

Cloud Stuido 前端编辑器 SDK,让基于 IFrame 方式集成 Cloud Studio 方式,可以方便访问编辑器内部的能力。如执行一个编辑器内部命令等等操作。
安装
$ yarn add @cloudstudio/editor-sdk
示例
import { createClient, RPC_CONTEXT } from '@cloudstudio/editor-sdk';
const rpc = createClient(editorWindow);
const commandService = rpc.getProxy(RPC_CONTEXT.CommandService);
await commandService.executeCommand('vscode.open', 'https://cloudstudio.net');
const url = await commandService.executeCommand<string>('cloudstudio.getBrowserUrl');
await commandService.executeCommand<string>('cloudstudio.settings.updateValue', 'workbench.activityBar.visible', false);
const url = await commandService.executeCommand<string>('deploykit.deploy', { notice: true });
await commandService.executeCommand('deploykit.deploy', {
notice: true,
deployConfig: {
runtime: 'default',
mode: [ 'scf', 'event', 'qq-guild-bot' ],
cloud: {
disableProjectId: true,
region: 'ap-guangzhou',
namespace: {
name: 'default'
},
'function': {
name: 'foo',
sync: 'onlyUpdateCode',
timeout: 15,
handler: 'index.handler'
}
}
}
});
await commandService!.executeCommand('cloudstudio.insertTextForCursorPosition', 'text1');
await commandService!.executeCommand('saveAll');
const { schema, path } = await commandService!.executeCommand('cloudstudio.getActiveCodeEditorUri');
const fileService = rpc.getProxy(RPC_CONTEXT.FileService);
await fileService.createFile('vscode-remote:///Users/kevin/code/test/foo.txt', 'text1');
const { value } = await fileService.readFile('vscode-remote:///Users/kevin/code/test/foo.txt');
fileService.writeFile('vscode-remote:///Users/kevin/code/test/foo.txt', 'text1');
await fileService.del('vscode-remote:///Users/kevin/code/test/foo.txt', { recursive: true });
const isExists = await fileService.exists('vscode-remote:///Users/kevin/code/test/foo.txt');
await fileService.copy('vscode-remote:///Users/kevin/code/test/foo.txt', 'vscode-remote:///Users/kevin/code/test/bar.txt');
await fileService.createFolder('vscode-remote:///Users/kevin/code/test/foo');
const editorService = rpc.getLocal(RPC_CONTEXT.EditorService);
editorService.onDidActiveEditorChange({ uri, editorType } => {
});
const remoteAgentConnection = rpc.getLocal(RPC_CONTEXT.RemoteAgentConnection);
remoteAgentConnection.onDidStateChange(event => {
});