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

Commit

Permalink
feat(namespace): Export @eclipse-che/plugin namespace using VS Code e…
Browse files Browse the repository at this point in the history
…xtension mechanism

Change-Id: I4d8d6c49b6797bd98b76486127ec3e38f243e120
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Feb 17, 2021
1 parent af8b33d commit 1c5d5f7
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 0 deletions.
1 change: 1 addition & 0 deletions che-theia-init-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sources:
- extensions/eclipse-che-theia-remote-impl-che-server
plugins:
- plugins/containers-plugin
- plugins/ext-plugin
- plugins/workspace-plugin
- plugins/resource-monitor-plugin
- plugins/ports-plugin
Expand Down
4 changes: 4 additions & 0 deletions plugins/ext-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
node_modules/
*.theia
coverage
15 changes: 15 additions & 0 deletions plugins/ext-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ext Plug-in
This plug-in is exposing some Eclipse Che API to be consumed by other VS Code extensions using the VS Code extension mechanism.

## Example

```typescript
const eclipseCheExtPlugin = vscode.extensions.getExtension('@eclipse-che.ext-plugin');
if (eclipseCheExtPlugin) {
// grab user
const user = yield eclipseCheExtPlugin.exports.user.getCurrentUser();
vscode.window.showInformationMessage(`Eclipse Che user information: id ${user.id} with name ${user.name}`);
}
```

Exported code is coming from https://github.com/eclipse/che-theia/blob/master/extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts
28 changes: 28 additions & 0 deletions plugins/ext-plugin/__mocks__/@eclipse-che/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**********************************************************************
* Copyright (c) 2021 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
***********************************************************************/

/**
* Mock of @eclipse-che/plugin module
* @author Florent Benoit
*/
const che: any = {};
let currentWorkspace: any = undefined;

che.setWorkspaceOutput = (input: any) => {
currentWorkspace = input;
};

che.workspace = {};

che.workspace.getCurrentWorkspace = () => {
return currentWorkspace;
};

module.exports = che;
62 changes: 62 additions & 0 deletions plugins/ext-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "ext-plugin",
"publisher": "@eclipse-che",
"version": "0.0.1",
"keywords": [
"theia-plugin"
],
"description": "Exports @eclipse-che/plugin namespace",
"license": "EPL-2.0",
"files": [
"src"
],
"activationEvents": [
"*"
],
"dependencies": {},
"devDependencies": {
"@eclipse-che/plugin": "latest",
"@theia/plugin": "next",
"@theia/plugin-packager": "latest"
},
"scripts": {
"prepare": "yarn clean && yarn build && yarn lint:fix && yarn test",
"clean": "rimraf lib",
"format": "if-env SKIP_FORMAT=true && echo 'skip format check' || prettier --check '{src,tests}/**/*.ts' package.json",
"format:fix": "prettier --write '{src,tests}/**/*.ts' package.json",
"lint": "if-env SKIP_LINT=true && echo 'skip lint check' || eslint --cache=true --no-error-on-unmatched-pattern=true '{src,tests}/**/*.ts'",
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/**/*.{ts,tsx}\"",
"compile": "tsc",
"build": "concurrently -n \"format,lint,compile\" -c \"red,green,blue\" \"yarn format\" \"yarn lint\" \"yarn compile\" && theia-plugin pack",
"watch": "tsc -w",
"test": "if-env SKIP_TEST=true && echo 'skip test' || jest --forceExit",
"test-watch": "jest --watchAll"
},
"engines": {
"theiaPlugin": "next"
},
"theiaPlugin": {
"backend": "lib/ext-plugin.js"
},
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.ts"
],
"coverageDirectory": "./coverage",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"modulePathIgnorePatterns": [
"<rootDir>/dist"
],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
}
}
18 changes: 18 additions & 0 deletions plugins/ext-plugin/src/ext-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**********************************************************************
* Copyright (c) 2021 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 che from '@eclipse-che/plugin';
/**
* Export @eclipse-che/plugin namespace as extensions.getExtension('@eclipse-che/ext-plugin') value
*/
export async function start(): Promise<unknown> {
const apiObject = che;
return apiObject;
}
25 changes: 25 additions & 0 deletions plugins/ext-plugin/tests/ext-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**********************************************************************
* Copyright (c) 2021 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
***********************************************************************/

/* eslint-disable @typescript-eslint/no-explicit-any */

import * as che from '@eclipse-che/plugin';
import * as extPlugin from '../src/ext-plugin';

describe('Test ExtPlugin', () => {
test('start', async () => {
(che as any).setWorkspaceOutput({ id: '1234' });

const api: any = await extPlugin.start();
expect(api).toBeDefined();
const workspace = await api.workspace.getCurrentWorkspace();
expect(workspace.id).toBe('1234');
});
});
19 changes: 19 additions & 0 deletions plugins/ext-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"target": "es5",
"lib": [
"es6",
"webworker"
],
"sourceMap": true,
"rootDir": "src",
"outDir": "lib",
"types": [
"node", "jest"
]
},
"include": [
"src"
]
}
3 changes: 3 additions & 0 deletions plugins/workspace-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"@theia/plugin": "next",
"@theia/plugin-packager": "latest"
},
"extensionDependencies": [
"@eclipse-che.ext-plugin"
],
"scripts": {
"prepare": "yarn clean && yarn build && yarn lint:fix && yarn test",
"clean": "rimraf lib",
Expand Down

0 comments on commit 1c5d5f7

Please sign in to comment.