Skip to content

Commit

Permalink
[extension-manager] the extension protocol definition and implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Oct 12, 2017
1 parent 2543b38 commit 550a38a
Show file tree
Hide file tree
Showing 31 changed files with 1,665 additions and 115 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ coverage
examples/*/src-gen
examples/*/webpack.config.js
.browser_modules
**/docs/api
**/docs/api
package-backup.json
75 changes: 55 additions & 20 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@
"protocol": "inspector",
"args": [
"--loglevel=debug",
"--hostname=localhost"
"--hostname=localhost",
"--no-cluster",
"--app-project-path=${workspaceRoot}/examples/electron",
"--no-app-auto-install"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/examples/electron/src-gen/frontend/electron-main.js",
"${workspaceRoot}/examples/electron/src-gen/backend/main.js",
"${workspaceRoot}/examples/electron/lib/**/*.js",
"${workspaceRoot}/packages/*/lib/**/*.js"
]
"${workspaceRoot}/packages/*/lib/**/*.js",
"${workspaceRoot}/dev-packages/*/lib/**/*.js"
],
"smartStep": true,
"console": "integratedTerminal"
},
{
"type": "node",
Expand All @@ -33,14 +42,23 @@
"program": "${workspaceRoot}/examples/browser/src-gen/backend/main.js",
"args": [
"--loglevel=debug",
"--port=3000"
"--port=3000",
"--no-cluster",
"--app-project-path=${workspaceRoot}/examples/browser",
"--no-app-auto-install"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/examples/browser/src-gen/backend/main.js",
"${workspaceRoot}/examples/browser/src-gen/backend/*.js",
"${workspaceRoot}/examples/browser/lib/**/*.js",
"${workspaceRoot}/packages/*/lib/**/*.js"
]
"${workspaceRoot}/packages/*/lib/**/*.js",
"${workspaceRoot}/dev-packages/*/lib/**/*.js"
],
"smartStep": true,
"console": "integratedTerminal"
},
{
"type": "node",
Expand All @@ -50,38 +68,55 @@
"args": [
"--loglevel=debug",
"--root-dir=${workspaceRoot}/../eclipse.jdt.ls/org.eclipse.jdt.ls.core",
"--port=3000"
"--port=3000",
"--no-cluster",
"--no-app-auto-install"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/examples/browser/src-gen/backend/main.js",
"${workspaceRoot}/examples/browser/src-gen/backend/*.js",
"${workspaceRoot}/examples/browser/lib/**/*.js",
"${workspaceRoot}/packages/*/lib/**/*.js"
]
"${workspaceRoot}/packages/*/lib/**/*.js",
"${workspaceRoot}/dev-packages/*/lib/**/*.js"
],
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"runtimeArgs": [
"--inspect"
],
"request": "launch",
"protocol": "inspector",
"name": "Run Mocha Test",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"${file}",
"--no-timeouts",
"--colors",
"--opts",
"${workspaceRoot}/packages/mocha.opts"
],
"env": {
"TS_NODE_PROJECT": "${workspaceRoot}/packages/tsconfig.json"
"TS_NODE_PROJECT": "${workspaceRoot}/tsconfig.json"
},
"sourceMaps": true,
"internalConsoleOptions": "openOnSessionStart",
"port": 9229
"smartStep": true,
"console": "integratedTerminal"
},
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/packages/*/lib/**/*.js",
"${workspaceRoot}/dev-packages/*/lib/**/*.js"
],
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Launch Frontend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import { ApplicationProcess } from './application-process';
export class ApplicationPackageManager {

readonly pck: ApplicationPackage;
/** application process */
readonly process: ApplicationProcess;
/** manager process */
protected readonly __process: ApplicationProcess;
protected readonly webpack: WebpackGenerator;
protected readonly backend: BackendGenerator;
protected readonly frontend: FrontendGenerator;
protected readonly appProcess: ApplicationProcess;

constructor(options: ApplicationPackageOptions) {
this.pck = new ApplicationPackage(options);
this.process = new ApplicationProcess(this.pck, options.projectPath);
this.__process = new ApplicationProcess(this.pck, `${__dirname}/..`);
this.webpack = new WebpackGenerator(this.pck);
this.backend = new BackendGenerator(this.pck);
this.frontend = new FrontendGenerator(this.pck);
this.appProcess = new ApplicationProcess(this.pck);
}

protected async remove(path: string): Promise<void> {
Expand Down Expand Up @@ -52,7 +56,7 @@ export class ApplicationPackageManager {
async build(args: string[] = []): Promise<void> {
await this.generate();
await this.copy();
return this.appProcess.run('webpack', args);
return this.__process.run('webpack', args);
}

async start(args: string[] = []): Promise<void> {
Expand All @@ -66,8 +70,8 @@ export class ApplicationPackageManager {
if (!args.some(arg => arg.startsWith('--hostname='))) {
args.push('--hostname=localhost');
}
return this.appProcess.bunyan(
this.appProcess.spawnBin('electron', [this.pck.frontend('electron-main.js'), ...args], {
return this.__process.bunyan(
this.__process.spawnBin('electron', [this.pck.frontend('electron-main.js'), ...args], {
stdio: [0, 'pipe', 'pipe', 'ipc']
})
);
Expand All @@ -77,8 +81,8 @@ export class ApplicationPackageManager {
if (!args.some(arg => arg.startsWith('--port='))) {
args.push('--port=3000');
}
return this.appProcess.bunyan(
this.appProcess.fork(this.pck.backend('main.js'), args, {
return this.__process.bunyan(
this.__process.fork(this.pck.backend('main.js'), args, {
stdio: [0, 'pipe', 'pipe', 'ipc']
})
);
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/application-package/src/application-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as fs from 'fs';
import * as paths from 'path';
import { NpmRegistry, NpmRegistryOptions, NodePackage, PublishedNodePackage } from './npm-registry';
import { NpmRegistry, NpmRegistryOptions, NodePackage, PublishedNodePackage, sortByKey } from './npm-registry';
import { Extension, ExtensionPackage, RawExtensionPackage } from './extension-package';

import writeJsonFile = require('write-json-file');
Expand Down Expand Up @@ -243,7 +243,7 @@ export class ApplicationPackage {
} else {
delete dependencies[name];
}
this.pck.dependencies = dependencies;
this.pck.dependencies = sortByKey(dependencies);
return true;
}

Expand Down
14 changes: 8 additions & 6 deletions dev-packages/application-package/src/application-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs-extra';
import * as cp from 'child_process';
import { ApplicationPackage } from './application-package';

Expand All @@ -17,7 +18,8 @@ export class ApplicationProcess {
};

constructor(
protected readonly pck: ApplicationPackage
protected readonly pck: ApplicationPackage,
protected readonly binProjectPath: string
) { }

spawn(command: string, args?: string[], options?: cp.SpawnOptions): cp.ChildProcess {
Expand All @@ -27,6 +29,9 @@ export class ApplicationProcess {
return cp.fork(modulePath, args, Object.assign({}, this.defaultOptions, options));
}

canRun(command: string): boolean {
return fs.existsSync(this.resolveBin(command));
}
run(command: string, args: string[], options?: cp.SpawnOptions): Promise<void> {
const commandProcess = this.spawnBin(command, args, options);
return this.promisify(command, commandProcess);
Expand All @@ -36,11 +41,8 @@ export class ApplicationProcess {
return this.spawn(binPath, args, options);
}
protected resolveBin(command: string): string {
const commandPath = path.resolve(__dirname, '..', 'node_modules', '.bin', command);
if (process.platform === 'win32') {
return commandPath + '.cmd';
}
return commandPath;
const commandPath = path.resolve(this.binProjectPath, 'node_modules', '.bin', command);
return process.platform === 'win32' ? commandPath + '.cmd' : commandPath;
}

bunyan(childProcess: cp.ChildProcess): Promise<void> {
Expand Down
7 changes: 7 additions & 0 deletions dev-packages/application-package/src/npm-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export interface ViewResult {
[key: string]: any
}

export function sortByKey(object: { [key: string]: any }) {
return Object.keys(object).sort().reduce((sorted, key) => {
sorted[key] = object[key];
return sorted;
}, {} as { [key: string]: any });
}

export class NpmRegistryOptions {
/**
* Default: https://registry.npmjs.org/.
Expand Down
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@theia/core": "^0.1.1",
"@theia/filesystem": "^0.1.1",
"@theia/git": "^0.1.1",
"@theia/extension-manager": "^0.1.1",
"@theia/workspace": "^0.1.1",
"@theia/preferences": "^0.1.1",
"@theia/navigator": "^0.1.1",
Expand Down
1 change: 1 addition & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@theia/core": "^0.1.1",
"@theia/filesystem": "^0.1.1",
"@theia/git": "^0.1.1",
"@theia/extension-manager": "^0.1.1",
"@theia/workspace": "^0.1.1",
"@theia/preferences": "^0.1.1",
"@theia/navigator": "^0.1.1",
Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/common/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

export const isWindows: boolean = (() => { return is('Windows', 'win32') })();
export const isOSX: boolean = (() => { return is('Mac', 'darwin') })();

function is(userAgent: string, platform: string): boolean {
if (typeof navigator !== 'undefined') {
if (navigator.userAgent && navigator.userAgent.indexOf(userAgent) >= 0) {
Expand All @@ -18,4 +15,15 @@ function is(userAgent: string, platform: string): boolean {
return (process.platform === platform);
}
return false;
}
}

export const isWindows = is('Windows', 'win32');
export const isOSX = is('Mac', 'darwin');

export type CMD = [string, string[]];
export function cmd(command: string, ...args: string[]): CMD {
return [
isWindows ? 'cmd' : command,
isWindows ? ['/c', command, ...args] : args
];
}
1 change: 1 addition & 0 deletions packages/extension-manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testproject_temp
6 changes: 6 additions & 0 deletions packages/extension-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Theia - Extension Manager

See [here](https://github.com/theia-ide/theia) for a detailed documentation.

## License
[Apache-2.0](https://github.com/theia-ide/theia/blob/master/LICENSE)
10 changes: 10 additions & 0 deletions packages/extension-manager/compile.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../base.tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}
53 changes: 53 additions & 0 deletions packages/extension-manager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@theia/extension-manager",
"version": "0.1.1",
"description": "Theia - Extension Manager",
"dependencies": {
"@theia/application-package": "^0.1.1",
"@theia/core": "^0.1.1",
"@theia/filesystem": "^0.1.1",
"@types/sanitize-html": "^1.13.31",
"@types/showdown": "^1.7.1",
"sanitize-html": "^1.14.1",
"showdown": "^1.7.4"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"theia-extension"
],
"theiaExtensions": [
{
"frontend": "lib/browser/extension-frontend-module",
"backend": "lib/node/extension-backend-module"
}
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/theia-ide/theia.git"
},
"bugs": {
"url": "https://github.com/theia-ide/theia/issues"
},
"homepage": "https://github.com/theia-ide/theia",
"files": [
"lib",
"src"
],
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "theiaext clean",
"build": "theiaext build",
"watch": "theiaext watch",
"test": "theiaext test",
"docs": "theiaext docs"
},
"devDependencies": {
"@theia/ext-scripts": "^0.1.1"
},
"nyc": {
"extends": "../nyc.json"
}
}
Loading

0 comments on commit 550a38a

Please sign in to comment.