Skip to content

Commit

Permalink
[extension-generator] added testSupport option
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 Jul 15, 2017
1 parent db155d4 commit 0387e4a
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 26 deletions.
4 changes: 2 additions & 2 deletions config/generator-theia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"yeoman-generator"
],
"scripts": {
"prepublish": "npm run clean && npm run compile",
"prepublishOnly": "npm run clean && npm run compile",
"compile": "tsc",
"watch": "tsc -w",
"clean": "rimraf generators"
Expand All @@ -25,4 +25,4 @@
"rimraf": "^2.6.1",
"typescript": "^2.4.1"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export abstract class AbstractAppGenerator extends BaseGenerator {
}

configuring(): void {
this.config.save();
this.model.readLocalExtensionPackages((extension, path) => {
const extensionPath = paths.join(process.cwd(), `${path}/package.json`);
return this.fs.readJSON(extensionPath, undefined);
Expand Down
6 changes: 6 additions & 0 deletions config/generator-theia/src/common/generator-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export interface Config {
copyright: string;
}

export interface ExtensionConfig {
testSupport: boolean;
}

export function sortByKey(object: { [key: string]: any }): { [key: string]: any } {
return Object.keys(object).sort().reduce((sorted, key) => {
Expand All @@ -50,6 +53,9 @@ export class Model {
host: 'localhost',
copyright: ''
}
extensionConfig: ExtensionConfig = {
testSupport: true
}

protected _frontendModules: Map<string, string> | undefined;
protected _frontendElectronModules: Map<string, string> | undefined;
Expand Down
5 changes: 5 additions & 0 deletions config/generator-theia/src/extension/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"generator-theia": {
"testSupport": false
}
}
6 changes: 6 additions & 0 deletions config/generator-theia/src/extension/extension-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export class TheiaExtensionGenerator extends BaseGenerator {

initializing(): void {
this.model.pck = this.fs.readJSON(`extension.package.json`) || {};
this.config.defaults(this.model.extensionConfig);
Object.assign(this.model.extensionConfig, this.config.getAll());
}

configuring(): void {
this.config.save();
}

writing(): void {
Expand Down
49 changes: 34 additions & 15 deletions config/generator-theia/src/extension/extension-package-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import Base = require('yeoman-generator');
import { AbstractGenerator, sortByKey } from '../common';
import { AbstractGenerator, sortByKey, NodePackage } from '../common';

export class ExtensionPackageGenerator extends AbstractGenerator {

Expand All @@ -18,6 +18,38 @@ export class ExtensionPackageGenerator extends AbstractGenerator {
}

protected compilePackage(): object {
const pck = this.compileCommonPackage()
if (!this.model.extensionConfig.testSupport) {
return pck
}
return {
...pck,
"nyc": pck.nyc || {
"extends": "../nyc.json"
},
"scripts": {
...pck.scripts,
"clean": "npm run compile:clean && npm run test:clean",
"test": "nyc mocha --opts ../mocha.opts src/**/*.spec.ts",
"test:watch": "mocha -w --opts ../mocha.opts src/**/*.spec.ts",
"test:clean": "rimraf .nyc_output && rimraf coverage",
...this.model.pck.scripts
},
"devDependencies": sortByKey({
...pck.devDependencies,
"@types/chai": "^4.0.1",
"@types/chai-as-promised": "0.0.31",
"@types/mocha": "^2.2.41",
"chai": "^4.1.0",
"chai-as-promised": "^7.1.1",
"mocha": "^3.4.2",
"nyc": "^11.0.3",
...this.model.pck.devDependencies
})
};
}

protected compileCommonPackage(): NodePackage {
return {
...this.model.pck,
"license": this.model.pck.license || "Apache-2.0",
Expand All @@ -33,30 +65,17 @@ export class ExtensionPackageGenerator extends AbstractGenerator {
"lib",
"src"
],
"nyc": this.model.pck.nyc || {
"extends": "../nyc.json"
},
"scripts": {
"clean": "npm run compile:clean && npm run test:clean",
"clean": "npm run compile:clean",
"build": "concurrently -n compile,lint -c blue,green \"npm run compile\" \"npm run lint\"",
"compile": "tsc -p compile.tsconfig.json",
"compile:clean": "rimraf lib",
"lint": "tslint -c ../tslint.json --project compile.tsconfig.json",
"watch": "tsc -w -p compile.tsconfig.json",
"test": "nyc mocha --opts ../mocha.opts src/**/*.spec.ts",
"test:watch": "mocha -w --opts ../mocha.opts src/**/*.spec.ts",
"test:clean": "rimraf .nyc_output && rimraf coverage",
...this.model.pck.scripts
},
"devDependencies": sortByKey({
"@types/chai": "^4.0.1",
"@types/chai-as-promised": "0.0.31",
"@types/mocha": "^2.2.41",
"chai": "^4.1.0",
"chai-as-promised": "^7.1.1",
"concurrently": "^3.5.0",
"mocha": "^3.4.2",
"nyc": "^11.0.3",
"rimraf": "^2.6.1",
"tslint": "^4.5.1",
"typescript": "^2.4.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": true
}
}
5 changes: 5 additions & 0 deletions packages/cpp/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/editor/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/filesystem/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": true
}
}
5 changes: 5 additions & 0 deletions packages/java/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/languages/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/monaco/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/navigator/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/preferences/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": true
}
}
5 changes: 5 additions & 0 deletions packages/python/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/terminal/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": false
}
}
4 changes: 3 additions & 1 deletion packages/workspace/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"generator-theia": {}
"generator-theia": {
"testSupport": false
}
}

0 comments on commit 0387e4a

Please sign in to comment.