提交 4c515795 编写于 作者: J Joao Moreno

driver as a standalone module

上级 7bcf857c
......@@ -67,6 +67,7 @@ const vscodeEntryPoints = _.flatten([
const vscodeResources = [
'out-build/main.js',
'out-build/cli.js',
'out-build/driver.js',
'out-build/bootstrap.js',
'out-build/bootstrap-amd.js',
'out-build/paths.js',
......
......@@ -18,8 +18,8 @@ function uriFromPath(_path) {
}
function readFile(file) {
return new Promise(function(resolve, reject) {
fs.readFile(file, 'utf8', function(err, data) {
return new Promise(function (resolve, reject) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
reject(err);
return;
......@@ -35,7 +35,7 @@ var nlsConfig = rawNlsConfig ? JSON.parse(rawNlsConfig) : { availableLanguages:
// We have a special location of the nls files. They come from a language pack
if (nlsConfig._resolvedLanguagePackCoreLocation) {
let bundles = Object.create(null);
nlsConfig.loadBundle = function(bundle, language, cb) {
nlsConfig.loadBundle = function (bundle, language, cb) {
let result = bundles[bundle];
if (result) {
cb(undefined, result);
......@@ -47,7 +47,7 @@ if (nlsConfig._resolvedLanguagePackCoreLocation) {
bundles[bundle] = json;
cb(undefined, json);
})
.catch(cb);
.catch(cb);
};
}
......@@ -66,10 +66,13 @@ if (nlsConfig.pseudo) {
});
}
exports.bootstrap = function (entrypoint) {
exports.bootstrap = function (entrypoint, onLoad, onError) {
if (!entrypoint) {
return;
}
loader([entrypoint], function () { }, function (err) { console.error(err); });
onLoad = onLoad || function () { };
onError = onError || function (err) { console.error(err); };
loader([entrypoint], onLoad, onError);
};
......@@ -3,8 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const { bootstrap } = require('./bootstrap-amd');
import { foo } from '../../src/vs/code/node/driverClient';
foo();
bootstrap('vs/code/node/driver', ({ connect }) => {
console.log(connect);
});
\ No newline at end of file
......@@ -12,7 +12,7 @@ function createModuleDescription(name, exclude) {
excludes = excludes.concat(exclude);
}
result.exclude= excludes;
return result;
}
......@@ -22,6 +22,7 @@ exports.collectModules= function() {
createModuleDescription('vs/code/node/cli', []),
createModuleDescription('vs/code/node/cliProcessMain', ['vs/code/node/cli']),
createModuleDescription('vs/code/electron-browser/sharedProcess/sharedProcessMain', []),
createModuleDescription('vs/code/electron-browser/issue/issueReporterMain', [])
createModuleDescription('vs/code/electron-browser/issue/issueReporterMain', []),
createModuleDescription('vs/code/node/driver', [])
];
};
\ No newline at end of file
......@@ -7,15 +7,46 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
export const ID = 'driverService';
export const IDriverService = createDecorator<IDriverService>(ID);
export const IDriver = createDecorator<IDriver>(ID);
export interface IWindow {
id: string;
}
export interface IDriverService {
export interface IDriver {
_serviceBrand: any;
getWindows(): TPromise<IWindow[]>;
}
export interface IDriverChannel extends IChannel {
call(command: 'getWindows'): TPromise<IWindow[]>;
call(command: string, arg: any): TPromise<any>;
}
export class DriverChannel implements IDriverChannel {
constructor(private service: IDriver) { }
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'getWindows': return this.service.getWindows();
}
return undefined;
}
}
export class DriverChannelClient implements IDriver {
_serviceBrand: any;
constructor(private channel: IDriverChannel) { }
getWindows(): TPromise<IWindow[]> {
return this.channel.call('getWindows');
}
}
......@@ -6,34 +6,27 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IWindow, IDriverService } from './driver';
import { IDriver, IWindow, DriverChannel } from 'vs/code/common/driver';
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { serve } from 'vs/base/parts/ipc/node/ipc.net';
export interface IDriverChannel extends IChannel {
call(command: 'getWindows'): TPromise<IWindow[]>;
call(command: string, arg: any): TPromise<any>;
}
export class DriverChannel implements IDriverChannel {
constructor(private service: IDriverService) { }
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'getWindows': return this.service.getWindows();
}
return undefined;
}
}
export class DriverChannelClient implements IDriverService {
class Driver implements IDriver {
_serviceBrand: any;
constructor(private channel: IDriverChannel) { }
constructor(
@IWindowsMainService protected windowsService: IWindowsMainService
) { }
getWindows(): TPromise<IWindow[]> {
return this.channel.call('getWindows');
getWindows(): TPromise<IWindow[], any> {
return TPromise.as(this.windowsService.getWindows().map(w => ({ id: `${w.id}` })));
}
}
export async function startDriver(handle: string, instantiationService: IInstantiationService): TPromise<void> {
const server = await serve(handle);
const driver = instantiationService.createInstance(Driver);
const channel = new DriverChannel(driver);
server.registerChannel('driver', channel);
}
\ No newline at end of file
......@@ -6,8 +6,11 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IDriver, DriverChannelClient } from 'vs/code/common/driver';
import { connect as connectNet } from 'vs/base/parts/ipc/node/ipc.net';
export function foo() {
return 1;
}
\ No newline at end of file
export async function connect(handle: string): TPromise<IDriver> {
const client = await connectNet(handle, 'driverClient');
const channel = client.getChannel('driver');
return new DriverChannelClient(channel);
}
out
\ No newline at end of file
{
"name": "driver",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^9.6.1",
"typescript": "^2.8.1"
}
}
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "classic",
"target": "es6",
"rootDirs": [
".",
"../../src"
],
"outDir": "out"
},
"exclude": [
"node_modules"
]
}
\ No newline at end of file
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/node@^9.6.1":
version "9.6.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.1.tgz#e2d374ef15b315b48e7efc308fa1a7cd51faa06c"
typescript@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册