Skip to content

Commit

Permalink
Merge branch 'master' into GH-115
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Helming <jhelming@eclipsesource.com>
  • Loading branch information
JonasHelming committed Sep 27, 2021
2 parents d797988 + 2b0ad9e commit 9467b65
Show file tree
Hide file tree
Showing 39 changed files with 219 additions and 79 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
pull_request:
branches:
- master
schedule:
- cron: '0 23 * * *'

jobs:
build:
Expand Down Expand Up @@ -35,3 +37,7 @@ jobs:
- name: Test
shell: bash
run: yarn test

- name: Generate and Build Templates
shell: bash
run: ./.github/workflows/generate-and-build-all-templates.sh
14 changes: 14 additions & 0 deletions .github/workflows/generate-and-build-all-templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
npm install -g yo
npm link
mkdir tmp
cd tmp
exit_code=0
for d in ../templates/*/ ; do
extension=$(basename $d)
mkdir $extension
cd $extension
yo theia-extension $extension -y $extension || exit_code=$?
cd ..
done
cd ..
exit $exit_code
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
<br />
<img src='https://raw.githubusercontent.com/theia-ide/generator-theia-extension/master/logo/theia.svg?sanitize=true' alt='theia logo' width='125'>

<h2>THEIA - EXTENSION GENERATOR</h2>
<h2>ECLIPSE THEIA - EXTENSION GENERATOR</h2>



[![Build](https://github.com/theia-ide/generator-theia-extension/workflows/Build/badge.svg?branch=master)](https://github.com/theia-ide/generator-theia-extension/actions?query=branch%3Amaster)
![npm](https://img.shields.io/npm/v/generator-theia-extension?color=blue)

<br />

A [yeoman](https://yeoman.io/) generator that scaffolds a project structure for developing [Eclipse Theia](https://github.com/eclipse-theia/theia) extensions.

A [Yeoman](yeoman.io) generator that scaffolds a project structure for developing extensions to the [Theia IDE](https://github.com/theia-ide/theia).

<br />

Expand All @@ -28,18 +34,25 @@ mkdir my-extension && cd my-extension
yo theia-extension
```

Extension options
1. `hello-world`: creates a simple extension which provides a command and menu item which displays a message.
2. `widget`: creates the basis for a simple widget including a toggle command, alert message and button displaying a message.
3. `labelprovider`: create a simple extension which adds a custom label (with icon) for `.my` files.
4. `tree-editor`: create a tree editor extension.

For configuration options, see
For configuration options, see:

```
yo theia-extension --help
```

## Extension Options


| Template Option | Description | Documentation |
|:---|:---|:---|
| `hello-world` | Creates a simple extension which provides a command and menu item which displays a message | [readme](https://github.com/eclipse-theia/generator-theia-extension/blob/master/templates/hello-world/README.md) |
| `widget` | Creates the basis for a simple widget including a toggle command, alert message and button displaying a message. The template also contains an example unit test. | [readme](https://github.com/eclipse-theia/generator-theia-extension/blob/master/templates/widget/README.md) |
| `labelprovider` | Creates a simple extension which adds a custom label (with icon) for .my files | [readme](https://github.com/eclipse-theia/generator-theia-extension/blob/master/templates/labelprovider/README.md) |
| `tree-editor` | Creates a tree editor extension | [readme](https://github.com/eclipse-theia/generator-theia-extension/blob/master/templates/tree-editor/README.md) |
| `empty` | Creates a simple, minimal extension | [readme](https://github.com/eclipse-theia/generator-theia-extension/blob/master/templates/empty/README.md) |
| `backend` | Creates a backend communication extension | [readme](https://github.com/eclipse-theia/generator-theia-extension/blob/master/templates/backend/README.md) |



## Publishing

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-theia-extension",
"version": "0.1.21",
"version": "0.1.25",
"description": "Helps to setup the project structure for developing extensions to the Theia IDE",
"repository": {
"type": "git",
Expand Down
40 changes: 35 additions & 5 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module.exports = class TheiaExtension extends Base {
skipInstall: boolean
standalone: boolean
dependencies: string
browserDevDependencies: string
devdependencies: string
scripts: string
rootscripts: string
containsTests: boolean
};

constructor(args: string | string[], options: any) {
Expand Down Expand Up @@ -147,7 +152,7 @@ module.exports = class TheiaExtension extends Base {
message: "The extension's type",
choices: [
{ value: ExtensionType.HelloWorld, name: 'Hello World' },
{ value: ExtensionType.Widget, name: 'Widget' },
{ value: ExtensionType.Widget, name: 'Widget (with unit tests)' },
{ value: ExtensionType.LabelProvider, name: 'LabelProvider' },
{ value: ExtensionType.TreeEditor, name: 'TreeEditor' },
{ value: ExtensionType.Backend, name: 'Backend Communication' },
Expand Down Expand Up @@ -192,10 +197,17 @@ module.exports = class TheiaExtension extends Base {
lernaVersion: options["lerna-version"],
backend: options["extensionType"] === ExtensionType.Backend
}
this.params.dependencies = '';
this.params.browserDevDependencies = '';
if (this.params.extensionType === ExtensionType.TreeEditor) {
this.params.dependencies = `,\n "@theia/editor": "${this.params.theiaVersion}",\n "@theia/filesystem": "${this.params.theiaVersion}",\n "@theia/workspace": "${this.params.theiaVersion}",\n "@eclipse-emfcloud/theia-tree-editor": "latest",\n "uuid": "^3.3.2"`;
} else {
this.params.dependencies = '';
this.params.browserDevDependencies = `,\n "node-polyfill-webpack-plugin": "latest"`;
}
if (this.params.extensionType === ExtensionType.Widget) {
this.params.devdependencies = `,\n "@testing-library/react": "^11.2.7",\n "@types/jest": "^26.0.20",\n "jest": "^26.6.3",\n "ts-node": "^9.1.1",\n "ts-jest": "^26.5.6"`;
this.params.scripts = `,\n "test": "jest --config configs/jest.config.ts"`;
this.params.rootscripts =`,\n "test": "cd ${this.params.extensionPath} && yarn test"`;
this.params.containsTests = true;
}
options.params = this.params
if (!options.standalone) {
Expand Down Expand Up @@ -317,7 +329,17 @@ module.exports = class TheiaExtension extends Base {
this.extensionPath('README.md'),
{ params: this.params }
);
}
this.fs.copyTpl(
this.templatePath('widget/widget.test.ts'),
this.extensionPath(`src/browser/${this.params.extensionPath}-widget.test.ts`),
{ params: this.params }
);
this.fs.copyTpl(
this.templatePath('widget/configs/jest.config.ts'),
this.extensionPath(`configs/jest.config.ts`),
{ params: this.params }
);
}

/** backend */
if (this.params.extensionType === ExtensionType.Backend) {
Expand Down Expand Up @@ -409,11 +431,19 @@ module.exports = class TheiaExtension extends Base {

install() {
if (!(this.options as any).skipInstall) {
this.spawnCommand('yarn', []);
var command = this.spawnCommand('yarn', []);

command.on('close', function(code: number){
if (code !== 0 ) {
process.exit(code);
}
})
}
}

private _capitalize(name: string): string {
return name.substring(0, 1).toUpperCase() + name.substring(1)
}
}

module.exports.ExtensionType = ExtensionType;
10 changes: 9 additions & 1 deletion src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ module.exports = class TheiaBrowser extends Base {
}

writing() {
const params = (this.options as any).params
this.fs.copyTpl(
this.templatePath('app-browser-package.json'),
this.destinationPath('browser-app/package.json'),
{
appMode: 'browser',
params: (this.options as any).params
params
}
);
if (params.extensionType === 'tree-editor') {
this.fs.copyTpl(
this.templatePath('app-browser-webpack-config.js'),
this.destinationPath('browser-app/webpack.config.js'),
{}
);
}
}
}
12 changes: 12 additions & 0 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ Open http://localhost:3000 in the browser.
yarn start

*or:* launch `Start Electron Backend` configuration from VS code.

<%if(params.containsTests){%>
## Running the tests

yarn test

*or* run the tests of a specific package with

cd <%= params.extensionPath %>
yarn test

<%}%>
## Developing with the browser example

Start watching all packages, including `browser-app`, of your application with
Expand Down
2 changes: 1 addition & 1 deletion templates/app-browser-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"<%= params.extensionName %>": "<%= params.version %>"
},
"devDependencies": {
"@theia/cli": "<%= params.theiaVersion %>"
"@theia/cli": "<%= params.theiaVersion %>"<% if (params.browserDevDependencies) { %><%- params.browserDevDependencies %><% } %>
},
"scripts": {
"prepare": "theia build --mode development",
Expand Down
21 changes: 21 additions & 0 deletions templates/app-browser-webpack-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This file can be edited to customize webpack configuration.
* To reset delete this file and rerun theia build again.
*/
// @ts-check
const config = require('./gen-webpack.config.js');

/**
* Expose bundled modules on window.theia.moduleName namespace, e.g.
* window['theia']['@theia/core/lib/common/uri'].
* Such syntax can be used by external code, for instance, for testing.
config.module.rules.push({
test: /\.js$/,
loader: require.resolve('@theia/application-manager/lib/expose-loader')
}); */

// Load node polyfills as they are no longer automatically included with webpack 5.
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
config.plugins.push(new NodePolyfillPlugin());

module.exports = config;
10 changes: 5 additions & 5 deletions templates/backend/backend-module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConnectionHandler, JsonRpcConnectionHandler } from "@theia/core";
import { ContainerModule } from "inversify";
import { BackendClient, HelloBackendWithClientService, HelloBackendService, HELLO_BACKEND_PATH, HELLO_BACKEND_WITH_CLIENT_PATH } from "../common/protocol";
import { HelloBackendWithClientServiceImpl } from "./hello-backend-with-client-service";
import { HelloBackendServiceImpl } from "./hello-backend-service";
import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core';
import { ContainerModule } from '@theia/core/shared/inversify';
import { BackendClient, HelloBackendWithClientService, HelloBackendService, HELLO_BACKEND_PATH, HELLO_BACKEND_WITH_CLIENT_PATH } from '../common/protocol';
import { HelloBackendWithClientServiceImpl } from './hello-backend-with-client-service';
import { HelloBackendServiceImpl } from './hello-backend-service';

export default new ContainerModule(bind => {
bind(HelloBackendService).to(HelloBackendServiceImpl).inSingletonScope()
Expand Down
2 changes: 1 addition & 1 deletion templates/backend/contribution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command, CommandContribution, CommandRegistry} from '@theia/core/lib/common';
import { inject, injectable } from 'inversify';
import { inject, injectable } from '@theia/core/shared/inversify';
import { HelloBackendWithClientService, HelloBackendService } from '../common/protocol';

const SayHelloViaBackendCommandWithCallBack: Command = {
Expand Down
4 changes: 2 additions & 2 deletions templates/backend/frontend-module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandContribution} from '@theia/core';
import { WebSocketConnectionProvider } from "@theia/core/lib/browser";
import { ContainerModule, injectable } from "inversify";
import { WebSocketConnectionProvider } from '@theia/core/lib/browser';
import { ContainerModule, injectable } from '@theia/core/shared/inversify';
import { BackendClient, HelloBackendWithClientService, HelloBackendService, HELLO_BACKEND_PATH, HELLO_BACKEND_WITH_CLIENT_PATH } from '../common/protocol';
import { <%= params.extensionPrefix %>CommandContribution} from './<%= params.extensionPath %>-contribution';

Expand Down
4 changes: 2 additions & 2 deletions templates/backend/hello-backend-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { injectable } from "inversify";
import { HelloBackendService } from "../common/protocol";
import { injectable } from '@theia/core/shared/inversify';
import { HelloBackendService } from '../common/protocol';

@injectable()
export class HelloBackendServiceImpl implements HelloBackendService {
Expand Down
4 changes: 2 additions & 2 deletions templates/backend/hello-backend-with-client-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { injectable } from "inversify";
import { BackendClient, HelloBackendWithClientService } from "../common/protocol";
import { injectable } from '@theia/core/shared/inversify';
import { BackendClient, HelloBackendWithClientService } from '../common/protocol';

@injectable()
export class HelloBackendWithClientServiceImpl implements HelloBackendWithClientService {
Expand Down
2 changes: 1 addition & 1 deletion templates/empty/contribution.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { injectable } from 'inversify';
import { injectable } from '@theia/core/shared/inversify';

@injectable()
// Add contribution interface to be implemented, e.g. "<%= params.extensionPrefix %>Contribution implements CommandContribution"
Expand Down
2 changes: 1 addition & 1 deletion templates/empty/frontend-module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Generated using theia-extension-generator
*/
import { ContainerModule } from 'inversify';
import { ContainerModule } from '@theia/core/shared/inversify';
import { <%= params.extensionPrefix %>Contribution } from './<%= params.extensionPath %>-contribution';


Expand Down
4 changes: 2 additions & 2 deletions templates/extension-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
},
"devDependencies": {
"rimraf": "latest",
"typescript": "latest"
"typescript": "latest"<% if (params.devdependencies) { %><%- params.devdependencies %><% } %>
},
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib",
"build": "tsc",
"watch": "tsc -w"
"watch": "tsc -w"<% if (params.scripts) { %><%- params.scripts %><% } %>
},
"theiaExtensions": [
{
Expand Down
4 changes: 2 additions & 2 deletions templates/hello-world/contribution.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { injectable, inject } from "inversify";
import { injectable, inject } from '@theia/core/shared/inversify';
import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, MessageService } from "@theia/core/lib/common";
import { CommonMenus } from "@theia/core/lib/browser";

export const <%= params.extensionPrefix %>Command: Command = {
id: '<%= params.extensionPrefix %>.command',
label: "Say Hello"
label: 'Say Hello'
};

@injectable()
Expand Down
7 changes: 2 additions & 5 deletions templates/hello-world/frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
* Generated using theia-extension-generator
*/
import { <%= params.extensionPrefix %>CommandContribution, <%= params.extensionPrefix %>MenuContribution } from './<%= params.extensionPath %>-contribution';
import {
CommandContribution,
MenuContribution
} from "@theia/core/lib/common";
import { ContainerModule } from "inversify";
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
import { ContainerModule } from '@theia/core/shared/inversify';

export default new ContainerModule(bind => {
// add your contribution bindings here
Expand Down
6 changes: 3 additions & 3 deletions templates/labelprovider/contribution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FileStatNode } from "@theia/filesystem/lib/browser/file-tree/file-tree";
import { FileTreeLabelProvider } from "@theia/filesystem/lib/browser/file-tree/file-tree-label-provider";
import { injectable, } from "inversify";
import { FileStatNode } from '@theia/filesystem/lib/browser/file-tree/file-tree';
import { FileTreeLabelProvider } from '@theia/filesystem/lib/browser/file-tree/file-tree-label-provider';
import { injectable } from '@theia/core/shared/inversify';

@injectable()
export class <%= params.extensionPrefix %>LabelProviderContribution extends FileTreeLabelProvider {
Expand Down
2 changes: 1 addition & 1 deletion templates/labelprovider/frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated using theia-extension-generator
*/
import { LabelProviderContribution } from "@theia/core/lib/browser";
import { ContainerModule } from "inversify";
import { ContainerModule } from "@theia/core/shared/inversify";
import { <%= params.extensionPrefix %>LabelProviderContribution } from './<%= params.extensionPath %>-contribution';
import '../../src/browser/style/example.css';

Expand Down
4 changes: 2 additions & 2 deletions templates/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/node_modules/@theia/*/lib/**/*.js",
"${workspaceRoot}/browser-app/lib/**/*.js",
"${workspaceRoot}/*/lib/**/*.js",
"${workspaceRoot}/browser-app/src-gen/**/*.js"
],
"smartStep": true,
Expand Down Expand Up @@ -49,7 +49,7 @@
"outFiles": [
"${workspaceRoot}/electron-app/src-gen/frontend/electron-main.js",
"${workspaceRoot}/electron-app/src-gen/backend/main.js",
"${workspaceRoot}/electron-app/lib/**/*.js",
"${workspaceRoot}/*/lib/**/*.js",
"${workspaceRoot}/node_modules/@theia/*/lib/**/*.js"
],
"smartStep": true,
Expand Down
2 changes: 1 addition & 1 deletion templates/root-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rebuild:electron": "theia rebuild:electron",
"start:browser": "yarn rebuild:browser && yarn --cwd browser-app start",
"start:electron": "yarn rebuild:electron && yarn --cwd electron-app start",
"watch": "lerna run --parallel watch"
"watch": "lerna run --parallel watch"<% if (params.rootscripts) { %><%- params.rootscripts %><% } %>
},
"devDependencies": {
"lerna": "<%= params.lernaVersion %>"
Expand Down
Loading

0 comments on commit 9467b65

Please sign in to comment.