Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some follow ups after restructuring and issues around generator-theia #310

Merged
merged 10 commits into from
Jul 20, 2017
22 changes: 16 additions & 6 deletions doc/Developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This command does a few things:

## Run the browser-based example application

We can start the application with:
We can start the application from examples/browser directory with:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest saying "from the".


npm start

Expand All @@ -50,7 +50,16 @@ tab with the frontend.

## Run the electron-based example application

It can also be started with:
From the root directory run:

npm run rebuild:electron

This command rebuilds native node packages against the version of node used by electron.
To rollback changes run:

npm run rebuild:web

It can also be started with from examples/electron directory:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change it to

It can also be started from the examples/electron directory with:

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why someone would want to rollback however ?
Is this more confusing then helping?

Maybe move this to the web basec example section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After rebuilding for electron, web won't work, but by default web is working. I can put in the web section that if you run npm run rebuild:electron don't forget to run npm run rebuild:web fisrt.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK yes I was curious about that so this means that since with hoisting we have only 1 node-modules we can only have 1 example at the time without rebuilding :(
But yes sounds better to me in the web section thx

Copy link
Member Author

@akosyakov akosyakov Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be that we can have a setup where we exclude node-pty from hoisting and don't need to run rebuild, but I've spent half a day and failed to come up with such. I think mostly we work with one or another example anyway and later with more experience maybe can overcome it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good


npm start

Expand Down Expand Up @@ -116,16 +125,17 @@ To build and run the browser example:

git clone https://github.com/theia-ide/theia \
&& cd theia \
&& npm install --unsafe-perm\
&& cd ../../examples/browser \
&& npm install --unsafe-perm \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW we discussed this a bit and --unsafe-perm looks really weird.
I Suggest we move it out of the TL;DR and add it to the troubleshooting section
but that can be in another PR

Copy link
Member Author

@akosyakov akosyakov Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you open an issue for it? or PR :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #311

&& cd examples/browser \
&& npm run start

To build and run the electron example:

git clone https://github.com/theia-ide/theia \
&& cd theia \
&& npm install --unsafe-perm\
&& cd ../../examples/electron \
&& npm install --unsafe-perm \
&& npm run rebuild:electron \
&& cd examples/electron \
&& npm run start

## Code coverage
Expand Down
14 changes: 0 additions & 14 deletions doc/Internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,6 @@ And it returns the loggerServer as the object that will be exposed over JSON-RPC

This connects the factory to the connection.

So now all is set for backend/frontend communication.

The only point left is that if you're using the webpack dev server which
you probably are you need to add something like this:

``` javascript
'/logger/*': {
target: 'ws://localhost:3000',
ws: true
},
```

To webpack.config.js so that the requests are proxied to the backend properly.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update it to say that now the endpoints with /services/* are served by the webpack dev server

## Connecting to a service

So now that we have a backend service let's see how to connect to it from
Expand Down
11 changes: 8 additions & 3 deletions generator-theia/src/common/abstract-backend-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ function start() {
application.use(express.static(path.join(__dirname, '../../lib'), {
index: 'index.html'
}));
application.start();
return application.start(${this.ifWeb(`${this.model.config.port}, '${this.model.config.host}'`)})
}

Promise.resolve()${this.compileBackendModuleImports(backendModules)}
.then(start);`;
module.exports = Promise.resolve()${this.compileBackendModuleImports(backendModules)}
.then(start).catch(reason => {
console.error('Failed to start the backend application.');
if (reason) {
console.error(reason);
}
});`;
}

}
9 changes: 7 additions & 2 deletions generator-theia/src/common/abstract-frontend-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ function start() {
application.start();
}

Promise.resolve()${this.compileFrontendModuleImports(frontendModules)}
.then(start);`;
module.exports = Promise.resolve()${this.compileFrontendModuleImports(frontendModules)}
.then(start).catch(reason => {
console.error('Failed to start the frontend application.');
if (reason) {
console.error(reason);
}
});`;
}

}
18 changes: 17 additions & 1 deletion generator-theia/src/common/abstract-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export abstract class AbstractGenerator {
return `Promise.resolve(${invocation})`;
}
return invocation;
}).map(statement => `.then(function () { return ${statement}.then(load) })`);
}).map(statement => ` .then(function () { return ${statement}.then(load) })`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to fix indentation in the generated source files: src-gen/frontend/main.js and src-gen/backend/main.js

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thx for that! I had run into trouble with it

return os.EOL + lines.join(os.EOL);
}

Expand All @@ -60,4 +60,20 @@ export abstract class AbstractGenerator {
return copyright ? copyright + os.EOL : '';
}

protected isWeb(): boolean {
return this.model.target === 'web';
}

protected isElectron(): boolean {
return this.model.target === 'electron';
}

protected ifWeb(value: string, defaultValue: string = '') {
return this.isWeb() ? value : defaultValue;
}

protected ifElectron(value: string, defaultValue: string = '') {
return this.isElectron() ? value : defaultValue;
}

}
2 changes: 1 addition & 1 deletion generator-theia/src/common/generator-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Model {
for (const extension of extensions) {
const modulePath = extension[primary] || (secondary && extension[secondary]);
if (typeof modulePath === 'string') {
const extensionPath = path.join(extensionPackage.name, modulePath);
const extensionPath = path.join(extensionPackage.name, modulePath).split(path.sep).join('/')
result.set(`${primary}_${moduleIndex}`, extensionPath);
moduleIndex = moduleIndex + 1;
}
Expand Down
13 changes: 6 additions & 7 deletions generator-theia/src/electron/electron-frontend-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ process.env.LC_NUMERIC = 'C';
const electron = require('electron');
const path = require('path');

let mainWindow = undefined;

electron.app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
electron.app.quit();
}
});

electron.app.on('ready', function () {
require("../backend/main");
mainWindow = new electron.BrowserWindow({ width: 1024, height: 728 });
mainWindow.webContents.openDevTools();
mainWindow.loadURL(\`file://\${path.join(__dirname, '../../lib/index.html')}\`);
const mainWindow = new electron.BrowserWindow({ width: 1024, height: 728 });
require("../backend/main").then(server => {
mainWindow.loadURL(\`file://\${path.join(__dirname, '../../lib/index.html')}?port=\${server.address().port}\`);
mainWindow.webContents.openDevTools();
});
mainWindow.on('closed', function () {
mainWindow = undefined;
electron.app.exit(0);
});
});`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import URI from "./uri";
import URI from "../common/uri";

/**
* An endpoint provides URLs for http and ws, based on configuration ansd defaults.
Expand All @@ -24,7 +24,27 @@ export class Endpoint {
}

protected get host() {
return location.host || "127.0.0.1:3000"
if (location.host) {
return location.host;
}
return 'localhost:' + this.port;
}

protected get port(): string {
return this.getSearchParam('port', '3000');
}

protected getSearchParam(name: string, defaultValue: string): string {
const search = location.search;
if (!search) {
return defaultValue;
}
return search.substr(1).split('&')
.filter(value => value.startsWith(name + '='))
.map(value => {
const encoded = value.substr(name.length + 1);
return decodeURIComponent(encoded)
})[0] || defaultValue;
}

protected get wsScheme() {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export * from './context-menu-renderer';
export * from './widgets';
export * from './dialogs';
export * from './tree';
export * from './messaging';
export * from './messaging';
export * from './endpoint';
3 changes: 2 additions & 1 deletion packages/core/src/browser/messaging/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import { injectable, interfaces } from "inversify";
import { listen as doListen, Logger, ConsoleLogger } from "vscode-ws-jsonrpc";
import { ConnectionHandler, JsonRpcProxyFactory, JsonRpcProxy, Endpoint } from "../../common";
import { ConnectionHandler, JsonRpcProxyFactory, JsonRpcProxy } from "../../common";
import { Endpoint } from "../endpoint";
const ReconnectingWebSocket = require('reconnecting-websocket');

export interface WebSocketOptions {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export * from './selection-service';
export * from './os';
export * from './resource';
export * from './contribution-provider';
export * from './endpoint';
export * from './path';
export * from './logger';
export * from './messaging';
10 changes: 5 additions & 5 deletions packages/core/src/node/backend-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export class BackendApplication {
this.app.use(...handlers);
}

start(port: number = 3000): Promise<void> {
return new Promise<void>(resolve => {
const server = this.app.listen(port, () => {
this.logger.info(`Theia app listening on port ${port}.`);
resolve();
start(port: number = 0, hostname: string = 'localhost'): Promise<http.Server> {
return new Promise(resolve => {
const server = this.app.listen(port, hostname, () => {
this.logger.info(`Theia app listening on port ${server.address().port}.`);
resolve(server);
});
for (const contrib of this.contributionsProvider.getContributions()) {
if (contrib.onStart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
*/

import { inject, injectable } from "inversify"
import {
CommandContribution, Command, CommandRegistry, Endpoint,
MenuContribution, MenuModelRegistry,
} from '@theia/core/lib/common';
import { FrontendApplication } from '@theia/core/lib/browser';
import { CommandContribution, Command, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core/lib/common';
import { FrontendApplication, Endpoint } from '@theia/core/lib/browser';
import { FileMenus } from '@theia/filesystem/lib/browser/filesystem-commands';
import { TerminalWidgetFactory, TerminalWidgetOptions } from './terminal-widget';

Expand Down
5 changes: 2 additions & 3 deletions packages/terminal/src/browser/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/

import { inject, injectable } from "inversify";
import { Endpoint, Disposable } from '@theia/core/lib/common';
import { Widget, BaseWidget, Message } from '@theia/core/lib/browser';
import { WebSocketConnectionProvider } from '@theia/core/lib/browser';
import { Disposable } from '@theia/core/lib/common';
import { Widget, BaseWidget, Message, WebSocketConnectionProvider, Endpoint } from '@theia/core/lib/browser';
import { WorkspaceService } from "@theia/workspace/lib/browser";
import * as Xterm from 'xterm';
import 'xterm/lib/addons/fit/fit';
Expand Down
12 changes: 6 additions & 6 deletions packages/terminal/src/node/terminal-backend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import * as http from 'http';
import * as pty from 'node-pty';
import * as express from 'express';
import * as bodyParser from 'body-parser';
import { injectable } from 'inversify';
Expand All @@ -14,8 +15,6 @@ import { isWindows } from "@theia/core/lib/common";
import { BackendApplicationContribution } from '@theia/core/lib/node';
import { openSocket } from '@theia/core/lib/node';

const pty = require("node-pty");

@injectable()
export class TerminalBackendContribution implements BackendApplicationContribution {
private terminals: Map<number, any> = new Map()
Expand All @@ -36,8 +35,8 @@ export class TerminalBackendContribution implements BackendApplicationContributi
name: 'xterm-color',
cols: cols || 80,
rows: rows || 24,
cwd: process.env.PWD,
env: process.env
cwd: process.cwd(),
env: process.env as any
});

const root: { uri?: string } | undefined = req.body;
Expand All @@ -47,8 +46,9 @@ export class TerminalBackendContribution implements BackendApplicationContributi
term.write("source ~/.profile\n");
}

this.terminals.set(term.pid, term);
res.send(term.pid.toString());
const pid = (term as any).pid;
this.terminals.set(pid, term);
res.send(pid.toString());
res.end();
});

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function generate(name, cwd, prefix, target) {
const command = 'yo';
const args = ['theia:' + target, '--force'];
console.log(`${name}: ${command} ${args.join(' ')}`);
const p = cp.spawn(command, args, { cwd });
const p = cp.spawn(command, args, { cwd, env: process.env });
p.on('exit', code => {
if (code !== 0) {
process.exit(code)
Expand Down