Previous: Use Theia-- build your own IDE
Creating Theia Expansion Pack
In this example, we will add a menu item "Say hello" to display a notice "Hello world!". This article will guide you through all the necessary steps.
Theia architecture
Theia application of so-called extended package ( Extensions configuration). An extension package provides a set of specific functions of widgets, and the command processing program. Theia packet itself provides some extensions, such as editors, terminal, like the project view. Each expansion of their respective packages npm package.
Requirements
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash nvm install 10
And yarn:
npm install -g yarn
Also you need to make sure python 2.x has been installed by python --version to check.
Project structure
npm install -g yo generator-theia-extension mkdir theia-hello-world-extension cd theia-hello-world-extension yo theia-extension hello-world-extension
We look at the generated code. Root directory package.json file defines the workspaces, dependencies lerna and some scripts to the browser or local electron component package.
{ "private": true, "scripts": { "prepare": "lerna run prepare", "rebuild:browser": "theia rebuild:browser", "rebuild:electron": "theia rebuild:electron" }, "devDependencies": { "lerna": "2.4.0" }, "workspaces": [ "hello-world-extension", "browser-app", "electron-app" ] }
Also generated lerna.json file used to configure Lerna :
{ "lerna": "2.4.0", "version": "0.1.0", "useWorkspaces": true, "npmClient": "yarn", "command": { "run": { "stream": true } } }
Achieve expansion pack
{ "name": "hello-world-extension", "keywords": [ "theia-extension" ], "version": "0.1.0", "files": [ "lib", "src" ], "dependencies": { "@theia/core": "latest" }, "devDependencies": { "rimraf": "latest", "typescript": "latest" }, "scripts": { "prepare": "yarn run clean && yarn run build", "clean": "rimraf lib", "build": "tsc", "watch": "tsc -w" }, "theiaExtensions": [ { "frontend": "lib/browser/hello-world-frontend-module" } ] }
export default new ContainerModule(bind => { // add your contribution bindings here bind(CommandContribution).to(HelloWorldCommandContribution); bind(MenuContribution).to(HelloWorldMenuContribution); });
Command is defined as a simple data structure, which contains the id and label. id included in the command handlers registered contribution that implement the function command. Code generator has added a command and a processing program for displaying a "Hello World!" Message.
export const HelloWorldCommand = { id: 'HelloWorld.command', label: "Shows a message" }; @injectable() export class HelloWorldCommandContribution implements CommandContribution { constructor( @inject(MessageService) private readonly messageService: MessageService, ) { } registerCommands(registry: CommandRegistry): void { registry.registerCommand(HelloWorldCommand, { execute: () => this.messageService.info('Hello World!') }); } } ...
... @injectable() export class HelloWorldMenuContribution implements MenuContribution { registerMenus(menus: MenuModelRegistry): void { menus.registerMenuAction(CommonMenus.EDIT_FIND, { commandId: HelloWorldCommand.id, label: 'Say Hello' }); } }
In the browser run Expansion Pack
Now take a look at how our expansion pack works. To this end, the generator in the browser-app create a directory in a package.json file, which defines Theia browser application that contains several expansion pack, which contains our the Hello-world-Extension . Other files in the directory are the remaining yarn by the build process theia-cli tool automatically generates, as defined in section scripts.
{ "name": "browser-app", "version": "0.1.0", "dependencies": { "@theia/core": "latest", "@theia/filesystem": "latest", "@theia/workspace": "latest", "@theia/preferences": "latest", "@theia/navigator": "latest", "@theia/process": "latest", "@theia/terminal": "latest", "@theia/editor": "latest", "@theia/languages": "latest", "@theia/markers": "latest", "@theia/monaco": "latest", "@theia/typescript": "latest", "@theia/messages": "latest", "hello-world-extension": "0.1.0" }, "devDependencies": { "@theia/cli": "latest" }, "scripts": { "prepare": "theia build", "start": "theia start", "watch": "theia build --watch" }, "theia": { "target": "browser" } }
Now part of the need to build and run all the applications are ready to run it, enter the following command:
cd browser-app
yarn start <path to workspace>
Then enter in the browser HTTP: // localhost: 3000 , choose Edit> Say Hello in your application that opens, you will see "Hello World!" Message pops up.
In Electron run Expansion Pack
{ "name": "electron-app", ... "theia": { "target": "electron" } }
Before you run electron application, you need to rebuild some of the local modules:
yarn rebuild:electron cd electron-app yarn start <path to workspace>
Deployment Expansion Pack
If you want to open your expansion pack, we recommend that you publish it to npm. You can call the directory extension package in the yarn publish to complete, of course, the premise is that you need a valid account.
Original Address: https://theia-ide.org/docs/authoring_extensions