Skip to content
Merged
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
3 changes: 2 additions & 1 deletion code/build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const extensionsPath = path.join(path.dirname(__dirname), 'extensions');
// });
const compilations = [
'authentication-proxy/tsconfig.json',
'che-api/tsconfig.json',
'che-port/tsconfig.json',
'configuration-editing/build/tsconfig.json',
'configuration-editing/tsconfig.json',
'css-language-features/client/tsconfig.json',
Expand Down Expand Up @@ -149,7 +151,6 @@ const tasks = compilations.map(function (tsconfigFile) {
}

const cleanTask = task.define(`clean-extension-${name}`, util.rimraf(out));

const compileTask = task.define(`compile-extension:${name}`, task.series(cleanTask, () => {
const pipeline = createPipeline(false, true);
const nonts = gulp.src(src, srcOpts).pipe(filter(['**', '!**/*.ts']));
Expand Down
2 changes: 2 additions & 0 deletions code/build/npm/dirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ exports.dirs = [
'build',
'build/lib/watch',
'extensions',
'extensions/che-api',
'extensions/che-port',
'extensions/configuration-editing',
'extensions/css-language-features',
'extensions/css-language-features/server',
Expand Down
8 changes: 8 additions & 0 deletions code/extensions/che-api/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/**
src/**
tests/**
coverage/**
out/**
tsconfig.json
extension.webpack.config.js
yarn.lock
7 changes: 7 additions & 0 deletions code/extensions/che-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Eclipse Che API for Visual Studio Code

**Notice:** This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled.

## Features

This extension provides helpers to interact with DevWorkspaces/Che
47 changes: 47 additions & 0 deletions code/extensions/che-api/__mocks__/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**********************************************************************
* 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 */

const axios: any = jest.createMockFromModule('axios');

// map between URL and content
const myContent: Map<string, any> = new Map();
const myErrors: Map<string, any> = new Map();

function __setContent(url: string, content: string): void {
myContent.set(url, content);
}

function __setError(url: string, error: any): void {
myErrors.set(url, error);
}

async function get(url: string): Promise<any> {
if (myErrors.has(url)) {
const storedError = myErrors.get(url);
throw storedError;
}

return { data: myContent.get(url) };
}
function __clearMock(): void {
myContent.clear();
myErrors.clear();
}

axios.get = jest.fn(get);
axios.__setContent = __setContent;
axios.__setError = __setError;
axios.__clearMock = __clearMock;
module.exports = axios;


axios.create = jest.fn();
axios.create.mockResolvedValue(axios);
35 changes: 35 additions & 0 deletions code/extensions/che-api/extension.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**********************************************************************
* Copyright (c) 2022 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 header/header */

//@ts-check

'use strict';

const withDefaults = require('../shared.webpack.config');
const webpack = require('webpack');

module.exports = withDefaults({
context: __dirname,
resolve: {
mainFields: ['module', 'main']
},
entry: {
extension: './src/extension.ts',
},
externals: {
'bufferutil': 'commonjs bufferutil', // ignored
'utf-8-validate': 'commonjs utf-8-validate', // ignored
},
plugins: [
new webpack.ContextReplacementPlugin(/keyv/), // needs to exclude the package to ignore warnings https://github.com/jaredwray/keyv/issues/45
],
});
Binary file added code/extensions/che-api/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions code/extensions/che-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "api",
"displayName": "%displayName%",
"description": "%description%",
"publisher": "eclipse-che",
"license": "EPL-2.0",
"version": "0.0.1",
"engines": {
"vscode": "^1.63.0"
},
"icon": "images/icon.png",
"categories": [
"Other"
],
"activationEvents": [
"*"
],
"capabilities": {
"virtualWorkspaces": true,
"untrustedWorkspaces": {
"supported": true
}
},
"main": "./out/extension.js",
"scripts": {
"compile": "gulp compile-extension:che-api",
"watch": "gulp watch-extension:che-api",
"vscode:prepublish": "npm run compile",
"test": "jest"
},
"dependencies": {
"@devfile/api": "^2.2.0-alpha-1641413790",
"@kubernetes/client-node": "^0.16.1",
"fs-extra": "^10.0.0",
"inversify": "^6.0.1",
"js-yaml": "^4.1.0",
"reflect-metadata": "^0.1.13",
"vscode-nls": "^5.0.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.4.0",
"@types/js-yaml": "^4.0.5",
"@types/node": "14.x",
"jest": "^27.4.7",
"ts-jest": "^27.1.2",
"webpack-node-externals": "^3.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/che-incubator/che-code.git"
},
"jest": {
"testEnvironment": "node",
"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"
]
}
}
4 changes: 4 additions & 0 deletions code/extensions/che-api/package.nls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"displayName": "Eclipse Che API",
"description": "Eclipse Che API"
}
8 changes: 8 additions & 0 deletions code/extensions/che-api/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


import { DevfileService } from './devfile-service';


export interface Api {
getDevfileService(): DevfileService;
}
28 changes: 28 additions & 0 deletions code/extensions/che-api/src/api/devfile-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

/**********************************************************************
* Copyright (c) 2022 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 header/header */

import {
V1alpha2DevWorkspaceSpecTemplate
} from '@devfile/api';

export const DevfileService = Symbol('DevfileService');

export interface DevfileService {
// Provides raw content of the devfile as a string
getRaw(): Promise<string>;
// Get structured object of the devfile
get(): Promise<V1alpha2DevWorkspaceSpecTemplate>;

// Update the devfile based on the given content
updateDevfile(devfile: V1alpha2DevWorkspaceSpecTemplate): Promise<void>;
}
23 changes: 23 additions & 0 deletions code/extensions/che-api/src/api/k8s-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable header/header */
/**********************************************************************
* Copyright (c) 2022 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
***********************************************************************/

export interface K8SRawResponse {
statusCode: number;
data: string;
error: string;
}

export const K8SService = Symbol('K8SService');

export interface K8SService {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sendRawQuery(requestURL: string, opts: any): Promise<K8SRawResponse>;
}
42 changes: 42 additions & 0 deletions code/extensions/che-api/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**********************************************************************
* Copyright (c) 2022 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 header/header */
import 'reflect-metadata';

import { Container } from 'inversify';
import * as vscode from 'vscode';
import { Api } from './api/api';
import { DevfileService } from './api/devfile-service';
import { K8SService } from './api/k8s-service';
import { K8sDevfileServiceImpl } from './impl/k8s-devfile-service-impl';
import { K8SServiceImpl } from './impl/k8s-service-impl';
import { K8sDevWorkspaceEnvVariables } from './impl/k8s-devworkspace-env-variables';


export async function activate(_extensionContext: vscode.ExtensionContext): Promise<Api> {

const container = new Container();
container.bind(K8sDevfileServiceImpl).toSelf().inSingletonScope();
container.bind(DevfileService).to(K8sDevfileServiceImpl).inSingletonScope();
container.bind(K8SServiceImpl).toSelf().inSingletonScope();
container.bind(K8SService).to(K8SServiceImpl).inSingletonScope();
container.bind(K8sDevWorkspaceEnvVariables).toSelf().inSingletonScope();

const devfileService = container.get(DevfileService) as DevfileService;
const api = {
getDevfileService(): DevfileService {
return devfileService;
}
};

return api;
}
Loading