Skip to content

Commit

Permalink
get rid of generator-theia
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 Sep 25, 2017
1 parent 2aac32f commit 0e06afa
Show file tree
Hide file tree
Showing 75 changed files with 442 additions and 3,943 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
node_modules
build
lib
!dev-packages/cli/lib
*.log
.idea
.metadata
Expand All @@ -11,5 +10,6 @@ lerna-debug.log
.nyc_output
coverage
examples/*/src-gen
examples/*/webpack.config.js
.browser_modules
**/docs/api
10 changes: 8 additions & 2 deletions dev-packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
## Commands

- `theia clean` - remove the built output (`lib` folder)
- `theia copy` - copies static resources to the built output
- `theia build` - packages the frontend code with webpack
- `theia copy` - copy static resources to the built output
- `theia generate` - generate configurations for the given target
- `theia generate --target=browser`
- `theia generate --target=electron`
- `theia rebuild` - rebuild native modules for the given target
- `theia rebuild --target=browser`
- `theia rebuild --target=electron`
- `theia build` - package the frontend code with webpack
- arguments passed to webpack, e.g. `theia build --watch` to package the frontned code incrementally
- `theia browser` - start the backend node process
- by default on port `3000`
Expand Down
58 changes: 0 additions & 58 deletions dev-packages/cli/lib/rebuild.js

This file was deleted.

19 changes: 12 additions & 7 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
"theia": "./bin/theia"
},
"scripts": {
"clean": "echo 'skip'",
"build": "echo 'skip'",
"watch": "echo 'skip'",
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib",
"build": "tsc",
"watch": "tsc -w",
"test": "echo 'skip'",
"docs": "echo 'skip'"
},
"dependencies": {
"@types/request": "^2.0.3",
"@types/semver": "^5.4.0",
"@types/yargs": "^8.0.2",
"bunyan": "^1.8.10",
"circular-dependency-plugin": "^2.0.0",
"copy-webpack-plugin": "^4.0.1",
Expand All @@ -37,14 +41,15 @@
"electron-rebuild": "^1.5.11",
"file-loader": "^0.11.1",
"font-awesome-webpack": "0.0.5-beta.2",
"generator-theia": "^0.1.1",
"ignore-loader": "^0.1.2",
"less": "^2.7.2",
"request": "^2.82.0",
"rimraf": "^2.6.1",
"semver": "^5.4.1",
"source-map-loader": "^0.2.1",
"source-map-support": "^0.4.18",
"url-loader": "^0.5.8",
"webpack": "^2.2.1",
"yargs": "^9.0.1",
"yo": "^2.0.0"
"yargs": "^9.0.1"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,21 @@
*/

import * as os from 'os';
import * as path from 'path';
import Base = require('yeoman-generator');

import * as fs from 'fs-extra';
import { Model } from "./generator-model";

export type FileSystem = Base.MemFsEditor;

export abstract class AbstractGenerator {

constructor(
protected readonly model: Model
) { }

abstract generate(fs: FileSystem): void;

protected srcGen(...paths: string[]): string {
return path.join('src-gen', ...paths);
}

protected backend(...paths: string[]): string {
return this.srcGen('backend', ...paths);
}

protected frontend(...paths: string[]): string {
return this.srcGen('frontend', ...paths);
}

protected compileFrontendModuleImports(modules: Map<string, string>): string {
return this.compileModuleImports(modules, 'require')
return this.compileModuleImports(modules, 'require');
}

protected compileBackendModuleImports(modules: Map<string, string>): string {
return this.compileModuleImports(modules, 'require')
return this.compileModuleImports(modules, 'require');
}

protected compileModuleImports(modules: Map<string, string>, fn: 'import' | 'require'): string {
Expand All @@ -55,29 +37,17 @@ export abstract class AbstractGenerator {
return os.EOL + lines.join(os.EOL);
}

protected compileCopyright(): string {
const copyright = this.model.config.copyright;
return copyright ? copyright + os.EOL : '';
protected ifBrowser(value: string, defaultValue: string = '') {
return this.model.ifBrowser(value, defaultValue);
}

protected node_modulesPath(): string {
return this.model.config.node_modulesPath;
}

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

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

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

protected ifElectron(value: string, defaultValue: string = '') {
return this.isElectron() ? value : defaultValue;
protected write(path: string, content: string): void {
fs.ensureFileSync(path);
fs.writeFileSync(path, content);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { AbstractGenerator, FileSystem } from "../common";
import { AbstractGenerator } from "./abstract-generator";

export abstract class AbstractBackendGenerator extends AbstractGenerator {
export class BackendGenerator extends AbstractGenerator {

protected doGenerate(fs: FileSystem, backendModules: Map<string, string>): void {
fs.write(this.backend('server.js'), this.compileServer(backendModules));
fs.write(this.backend('main.js'), this.compileMain(backendModules));
generate(): void {
const backendModules = this.model.targetBackendModules;
this.write(this.model.backend('server.js'), this.compileServer(backendModules));
this.write(this.model.backend('main.js'), this.compileMain(backendModules));
}

protected compileServer(backendModules: Map<string, string>): string {
return `${this.compileCopyright()}
// @ts-check
return `// @ts-check
require('reflect-metadata');
const path = require('path');
const express = require('express');
Expand Down Expand Up @@ -57,8 +57,7 @@ module.exports = (port, host) => Promise.resolve()${this.compileBackendModuleImp
}

protected compileMain(backendModules: Map<string, string>): string {
return `${this.compileCopyright()}
// @ts-check
return `// @ts-check
const { port, hostname } = require('yargs').argv;
console.info("Starting express on port '" + port + "'.")
Expand Down
34 changes: 34 additions & 0 deletions dev-packages/cli/src/generator/common-app-generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { ProjectOptions, Model } from "./generator-model";
import { WebpackGenerator } from "./webpack-generator";
import { BackendGenerator } from "./backend-generator";
import { FrontendGenerator } from "./frontend-generator";

export class CommonAppGenerator {

protected readonly model: Model;
protected readonly webpack: WebpackGenerator;
protected readonly backend: BackendGenerator;
protected readonly frontend: FrontendGenerator;

constructor(options: ProjectOptions) {
this.model = new Model(options);
this.webpack = new WebpackGenerator(this.model)
this.backend = new BackendGenerator(this.model);
this.frontend = new FrontendGenerator(this.model);
}

async generate(): Promise<void> {
await this.model.ready;
this.webpack.generate();
this.backend.generate();
this.frontend.generate();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { AbstractGenerator, FileSystem } from "../common";
import { AbstractGenerator } from "./abstract-generator";

export abstract class AbstractFrontendGenerator extends AbstractGenerator {
export class FrontendGenerator extends AbstractGenerator {

protected doGenerate(fs: FileSystem, frontendModules: Map<string, string>): void {
fs.write(this.frontend('index.html'), this.compileIndexHtml(frontendModules))
fs.write(this.frontend('index.js'), this.compileIndexJs(frontendModules));
generate(): void {
const frontendModules = this.model.targetFrontendModules;
this.write(this.model.frontend('index.html'), this.compileIndexHtml(frontendModules))
this.write(this.model.frontend('index.js'), this.compileIndexJs(frontendModules));
if (this.model.isElectron()) {
this.write(this.model.frontend('electron-main.js'), this.compileElectronMain());
}
}

protected compileIndexHtml(frontendModules: Map<string, string>): string {
return `<!DOCTYPE html>
<html>
<head>${this.compileIndexHead(frontendModules)}
<head>${this.compileIndexHead(frontendModules)}${this.ifBrowser(`
<script type="text/javascript" src="./require.js" charset="utf-8"></script>`)}
<script type="text/javascript" src="./bundle.js" charset="utf-8"></script>
</head>
Expand All @@ -36,8 +41,7 @@ export abstract class AbstractFrontendGenerator extends AbstractGenerator {
}

protected compileIndexJs(frontendModules: Map<string, string>): string {
return `${this.compileCopyright()}
// @ts-check
return `// @ts-check
require('reflect-metadata');
const { Container } = require('inversify');
const { FrontendApplication } = require('@theia/core/lib/browser');
Expand Down Expand Up @@ -70,4 +74,34 @@ module.exports = Promise.resolve()${this.compileFrontendModuleImports(frontendMo
});`;
}

}
protected compileElectronMain(): string {
return `// @ts-check
// Workaround for https://github.com/electron/electron/issues/9225. Chrome has an issue where
// in certain locales (e.g. PL), image metrics are wrongly computed. We explicitly set the
// LC_NUMERIC to prevent this from happening (selects the numeric formatting category of the
// C locale, http://en.cppreference.com/w/cpp/locale/LC_categories).
if (process.env.LC_ALL) {
process.env.LC_ALL = 'C';
}
process.env.LC_NUMERIC = 'C';
const electron = require('electron');
const path = require('path');
electron.app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
electron.app.quit();
}
});
electron.app.on('ready', function () {
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}\`);
}).catch(() => {
electron.app.exit(1);
});
mainWindow.on('closed', function () {
electron.app.exit(0);
});
});`;
}

}
Loading

0 comments on commit 0e06afa

Please sign in to comment.