Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Allow to use VS Code builtin extensions in che-theia #572

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $ node /projects/theia/production/src-gen/backend/main.js /tmp/theiadev_projects
You can then access to your modified Che-theia from the Container view `theia-dev` endpoint
![Che-Theia-dev-endpoint](https://raw.githubusercontent.com/eclipse/che-theia/assets/theia-dev-endpoint.png)

### Step 7bis: Run che-theia + plugin in dev mode
### Step 7: Run che-theia + plugin in dev mode
In this section we show how to run the che-theia assembly but in `dev mode`: keeping all the information for debugging.

You can use the che command `run ... DEV yarn start ... che-theia + factory-plugin` or
Expand All @@ -144,6 +144,9 @@ If you do not have any changes on Theia or Che-theia extension, you could just b
and run these plugins with the existing che-theia app:
`run ... HOSTED che-theia + container-plugin` or `run ... HOSTED che-theia + factory-plugin`

### How to run Che Theia with VS Code builtin extensions

First of all it is needed to download extensions: `download builtin extensions ... DEV che-theia`. Then start che-theia: `run ... HOSTED che-theia + builtin extensions`.

## How to develop Che Theia remote plugin mechanism

Expand All @@ -161,7 +164,7 @@ When workspace is ready:
Or a user may generate one using `Generate Hello World plugin package` command.
- Run dev Che Theia and Remote plugins endpoint in `theia-dev` and `theia-remote-runtime-dev` containers correspondingly.
One may use predefined commands to start them.
- Open `theia-dev` route from `My Workspace` panel and test chenges.
- Open `theia-dev` route from `My Workspace` panel and test changes.

Also it is possible to run watchers for remote plugin mechanism.
In `theia-dev` container run `npx run watch @eclipse-che/theia-remote` from `/projects/theia` folder to recompile the extension on changes made.
Expand Down
31 changes: 31 additions & 0 deletions devfiles/che-theia-all.devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ commands:
echo -e "\e[32mDone.\e[0m che:theia init"
workdir: /projects/theia

- name: download builtin extensions ... DEV che-theia
actions:
- type: exec
component: che-dev
command: >
che:theia builtin-extensions --plugins builtin-extensions &&
echo -e "\e[32mDone.\e[0m che:theia extensions"
workdir: /projects

- name: clean ... DEV che-theia
actions:
- type: exec
Expand Down Expand Up @@ -134,6 +143,17 @@ commands:
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /projects/theia/production

- name: run ... DEV che-theia + builtin extensions
actions:
- type: exec
component: theia-editor
command: >
kill `cat /tmp/node_theiadev.pid`;
mkdir -p /tmp/theiadev_projects &&
export CHE_PROJECTS_ROOT=/tmp/theiadev_projects &&
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 --plugins=local-dir:/projects/builtin-extensions & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /projects/theia/production

- name: run ... HOSTED che-theia + factory-plugin
actions:
- type: exec
Expand All @@ -160,6 +180,17 @@ commands:
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /home/theia

- name: run ... HOSTED che-theia + builtin extensions
actions:
- type: exec
component: theia-editor
command: >
kill `cat /tmp/node_theiadev.pid`;
mkdir -p /tmp/theiadev_projects &&
export CHE_PROJECTS_ROOT=/tmp/theiadev_projects &&
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 --plugins=local-dir:/projects/builtin-extensions & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /home/theia

- name: run ... DEV yarn start ... che-theia + factory-plugin
actions:
- type: exec
Expand Down
7 changes: 5 additions & 2 deletions dockerfiles/theia/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ RUN if [ -z $GITHUB_TOKEN ]; then unset GITHUB_TOKEN; fi && \
#{INCLUDE:docker/${BUILD_IMAGE_TARGET}/builder-before-production.dockerfile}
RUN che:theia production

# run che:theia builtin-extensions to download vscode builtin extensions
RUN che:theia builtin-extensions --plugins builtin-extensions

# Compile plugins
RUN if [ -z $GITHUB_TOKEN ]; then unset GITHUB_TOKEN; fi && \
cd plugins && ./foreach_yarn
Expand Down Expand Up @@ -115,13 +118,13 @@ ENV USE_LOCAL_GIT=true \
EXPOSE 3100 3130

COPY --from=builder /home/theia-dev/theia-source-code/production/plugins /default-theia-plugins

COPY --from=builder /home/theia-dev/theia-source-code/builtin-extensions /default-theia-plugins
#{INCLUDE:docker/${BUILD_IMAGE_TARGET}/runtime-install-dependencies.dockerfile}

# setup yarn (if missing)
#{INCLUDE:docker/${BUILD_IMAGE_TARGET}/runtime-setup-yarn.dockerfile}

RUN \
RUN \
#{INCLUDE:docker/${BUILD_IMAGE_TARGET}/runtime-adduser.sh}
&& echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
# Create /projects for Che
Expand Down
14 changes: 12 additions & 2 deletions generator/src/__mocks__/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ export class Command {
* Map between the name of the exec command and the output.
*/
private static readonly execMap: Map<string, string> = new Map();
private static readonly execRegExpMap: Map<RegExp, string> = new Map();

// mock any exec command by providing the output
public static __setExecCommandOutput(command: string, output: string): void {
Command.execMap.set(command, output);
public static __setExecCommandOutput(command: string | RegExp, output: string): void {
if (typeof command === 'string') {
Command.execMap.set(command, output);
} else {
Command.execRegExpMap.set(command, output);
}
}

constructor() {
Expand All @@ -34,6 +39,11 @@ export class Command {
if (result) {
return Promise.resolve(result);
} else {
for (const entry of Command.execRegExpMap) {
if (entry[0].test(command)) {
return entry[1];
}
}
return Promise.resolve('');
}
}
Expand Down
69 changes: 69 additions & 0 deletions generator/src/builtin-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import * as axios from 'axios';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as yargs from 'yargs';
import { Logger } from './logger';

/**
* Downloads builtin extensions.
* @author Anatolii Bazko
*/
export class BuiltinExtensions {
static argBuilder = (theYargs: yargs.Argv) => {
return theYargs.option('plugins', {
description: 'Plugins folder to download VS Code builtin extension into.',
alias: 'p',
}).option('extensions', {
description: 'List of VS Code builtin extensions to download.',
alias: 'e',
});
}

constructor(
protected readonly pluginsFolder: string, protected readonly extensions?: string) {
}

async download(): Promise<string[]> {
const downloaded = [];

await fs.ensureDir(this.pluginsFolder);
const srcDir = path.resolve(__dirname, '../src');
const confDir = path.join(srcDir, 'conf');
const extensions = this.extensions || await fs.readFile(path.join(confDir, 'builtin-extensions'));

Logger.info(`Downloading extensions into '${this.pluginsFolder}' started`);

for (const extension of extensions.toString().split('\n')) {
if (!extension.trim() || extension.startsWith('//')) {
continue;
}

Logger.info(`Downloading '${extension}'`);
try {
await this.downloadExtension(extension);
downloaded.push(extension);
} catch (error) {
Logger.error(error);
}
}

Logger.info('Downloading extensions completed.');
return downloaded;
}

protected async downloadExtension(extension: string): Promise<void> {
const response = await axios.default.get(extension);
const filename = extension.substring(extension.lastIndexOf('/') + 1);

fs.writeFileSync(path.resolve(this.pluginsFolder, filename), response.data);
}
}
47 changes: 47 additions & 0 deletions generator/src/conf/builtin-extensions
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/bat-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/clojure-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/coffeescript-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/configuration-editing-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/cpp-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/csharp-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/debug-auto-launch-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/docker-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/fsharp-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/go-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/groovy-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/grunt-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/gulp-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/handlebars-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/hlsl-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/html-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/ini-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/jake-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/java-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/javascript-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/json-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/less-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/log-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/lua-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/make-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/markdown-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/merge-conflict-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/npm-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/objective-c-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/perl-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/powershell-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/pug-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/python-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/r-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/razor-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/ruby-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/rust-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/scss-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/shaderlab-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/shellscript-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/sql-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/swift-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/typescript-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/vb-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/xml-1.39.1-prel.vsix
https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/yaml-1.39.1-prel.vsix
3 changes: 0 additions & 3 deletions generator/src/templates/assembly-package.mst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@theia/keymaps": "^{{ version }}",
"@theia/languages": "^{{ version }}",
"@theia/markers": "^{{ version }}",
"@theia/merge-conflicts": "^{{ version }}",
"@theia/messages": "^{{ version }}",
"@theia/metrics": "^{{ version }}",
"@theia/mini-browser": "^{{ version }}",
Expand All @@ -38,11 +37,9 @@
"@theia/plugin-ext": "^{{ version }}",
"@theia/plugin-ext-vscode": "^{{ version }}",
"@theia/preferences": "^{{ version }}",
"@theia/preview": "^{{ version }}",
"@theia/process": "^{{ version }}",
"@theia/search-in-workspace": "^{{ version }}",
"@theia/task": "^{{ version }}",
"@theia/textmate-grammars": "^{{ version }}",
"@theia/tslint": "^{{ version }}",
"@theia/userstorage": "^{{ version }}",
"@theia/variable-resolver": "^{{ version }}",
Expand Down
27 changes: 21 additions & 6 deletions generator/src/yargs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import * as yargs from 'yargs';
import { Logger } from './logger';
import * as path from 'path';
import * as yargs from 'yargs';
import { BuiltinExtensions } from './builtin-extensions';
import { Cdn } from './cdn';
import { Clean } from './clean';
import { CliError } from './cli-error';
import { Production } from './production';
import { Init } from './init';
import { Cdn } from './cdn';
import { InitSources } from './init-sources';
import { Clean } from './clean';
import { Logger } from './logger';
import { Production } from './production';

const ASSSEMBLY_PATH = 'examples/assembly';

Expand All @@ -28,7 +29,7 @@ const commandArgs = yargs
.usage('$0 <cmd> [args]')
.command({
command: 'init',
describe: 'Initialize current theia to beahve like a Che/Theia',
describe: 'Initialize current theia to behave like a Che/Theia',
builder: InitSources.argBuilder,
handler: async (args) => {
try {
Expand Down Expand Up @@ -91,6 +92,20 @@ const commandArgs = yargs
}
}
})
.command({
command: 'builtin-extensions',
describe: 'Download builtin extensions',
builder: BuiltinExtensions.argBuilder,
handler: async (args) => {
try {
const pluginsFolder = args.plugins ? path.resolve(args.plugins) : path.resolve(process.cwd(), 'plugins');
const builtinExtensions = new BuiltinExtensions(pluginsFolder, args.extensions);
await builtinExtensions.download();
} catch (err) {
handleError(err);
}
}
})
.help()
.strict()
.demandCommand()
Expand Down
Loading