From a29f29c24b63113af58590ce1b9ab516e53e333b Mon Sep 17 00:00:00 2001 From: Phil Cockfield Date: Sun, 17 Jul 2016 08:59:56 +1200 Subject: [PATCH 01/15] Move global DSL type definitions into an `index` file. To produce an `index.d.ts` file. --- package.json | 5 ++++- src/index.ts | 15 +++++++++++++++ tsconfig.json | 9 +++++---- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/index.ts diff --git a/package.json b/package.json index 5d6d6c2..32f8df8 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,12 @@ "version": "3.16.2", "description": "Create, isolate and test modular UI components in React.", "main": "./lib/server", + "typings": "./index.d.ts", "scripts": { + "build": "npm run build:babel && npm run build:typescript", + "build:babel": "./node_modules/babel-cli/bin/babel.js src --out-dir lib --source-maps", + "build:typescript": "./node_modules/typescript/bin/tsc", "build:watch": "npm run build -- --watch", - "build": "./node_modules/babel-cli/bin/babel.js src --out-dir lib --source-maps", "dev": "QUICK_BUILD=true ./node_modules/.bin/nodemon -x \"./node_modules/babel-cli/bin/babel-node.js start.js\"", "lint": "eslint --ext .js,.jsx ./src && tslint src/**/*.ts{,x}", "prepublish": "npm test && npm run lint && rm -rf lib && npm run build", diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..a00673f --- /dev/null +++ b/src/index.ts @@ -0,0 +1,15 @@ +import * as React from 'react'; + +type UIComponentType = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; +declare class IUIHarnessContext { + public component: (component: UIComponentType) => this; + public header: (title: string) => this; +} + +type ActionType = (this: IUIHarnessContext) => void; +type BDDType = (labelOrAction: string | ActionType, action?: ActionType) => void; + +declare var describe: BDDType; +declare var before: BDDType; +declare var section: BDDType; +declare var it: BDDType; diff --git a/tsconfig.json b/tsconfig.json index 67c300c..8263066 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,7 @@ { "compilerOptions": { + "rootDir": "src", + "outDir": "lib", "target": "es6", "sourceMap": true, "module": "commonjs", @@ -8,14 +10,13 @@ "jsx": "react", "experimentalDecorators": true, "emitDecoratorMetadata": true, - "declaration": false, + "declaration": true, "noImplicitAny": false, "removeComments": true, "noLib": false, "preserveConstEnums": true, "suppressImplicitAnyIndexErrors": true, - "strictNullChecks": true, - "outDir": "dist" + "strictNullChecks": true }, "exclude": [ "node_modules" @@ -23,4 +24,4 @@ "awesomeTypescriptLoaderOptions": { "forkChecker": true } -} \ No newline at end of file +} From bb4df1e5b10debf4427b5f08d3266ca99c966f73 Mon Sep 17 00:00:00 2001 From: Phil Cockfield Date: Sun, 17 Jul 2016 09:05:55 +1200 Subject: [PATCH 02/15] Exclude specs in master TS build operation. --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 8263066..4cd7bd2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,8 @@ "strictNullChecks": true }, "exclude": [ - "node_modules" + "node_modules", + "src/specs" ], "awesomeTypescriptLoaderOptions": { "forkChecker": true From 42380ec144d1562878af3a3ac3b4ae105e672d58 Mon Sep 17 00:00:00 2001 From: Phil Cockfield Date: Sun, 17 Jul 2016 09:08:50 +1200 Subject: [PATCH 03/15] Comment out to get build passing. --- src/index.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index a00673f..6215282 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ -import * as React from 'react'; - -type UIComponentType = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; -declare class IUIHarnessContext { - public component: (component: UIComponentType) => this; - public header: (title: string) => this; -} - -type ActionType = (this: IUIHarnessContext) => void; -type BDDType = (labelOrAction: string | ActionType, action?: ActionType) => void; - -declare var describe: BDDType; -declare var before: BDDType; -declare var section: BDDType; -declare var it: BDDType; +// import * as React from 'react'; +// +// type UIComponentType = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; +// declare class IUIHarnessContext { +// public component: (component: UIComponentType) => this; +// public header: (title: string) => this; +// } +// +// type ActionType = (this: IUIHarnessContext) => void; +// type BDDType = (labelOrAction: string | ActionType, action?: ActionType) => void; +// +// declare var describe: BDDType; +// declare var before: BDDType; +// declare var section: BDDType; +// declare var it: BDDType; From 149f99a3a40bcf2e72c11e7f8ddfb77f57936da6 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 14:49:51 +1200 Subject: [PATCH 04/15] Rename index.ts to index.d.ts and write definition --- src/index.d.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 15 -------------- 2 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 src/index.d.ts delete mode 100644 src/index.ts diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..f6854e8 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,54 @@ + +declare namespace UIHarness { + import React = __React; + type IUIHComponent = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; + + interface ICropMarks { + (enabled: boolean): IUIHarnessContext; + size(value: number): IUIHarnessContext; + offset(value: number): IUIHarnessContext; + } + + class IUIHarnessContext { + toValues(): {}; + reset(options: {}): void; + props(value: {}): {}; + context(value: {}): {}; + component(component: IUIHComponent): this; + unload(): this; + + log(...value: any[]): this; + + // property setters + children(children: React.ReactType[] | React.ReactType): this; + childContextTypes(value: {}): this; + width(value: string | number): this; + height(value: string | number): this; + cropMarks: ICropMarks; + margin(value: number): this; + align(value: string): this; // TODO: Type this.align() better + header(value: string): this; + footer(value: string): this; + hr(enabled: boolean): this; + backdrop(value: string | number): this; + background(value: string | number): this; + scroll(value: boolean | 'x' | 'y' | 'x:y'): this; + style(value: React.CSSProperties): this; + } + var UIHarness: IUIHarnessContext; + + interface ActionType { (this: IUIHarnessContext): void; } + + interface IBDDFunction { + (label: string, action?: ActionType): void; + (action: ActionType): void; + } + + + +} +declare var describe: UIHarness.IBDDFunction; +declare var before: UIHarness.IBDDFunction; +declare var section: UIHarness.IBDDFunction; +declare var it: UIHarness.IBDDFunction; + diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 6215282..0000000 --- a/src/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -// import * as React from 'react'; -// -// type UIComponentType = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; -// declare class IUIHarnessContext { -// public component: (component: UIComponentType) => this; -// public header: (title: string) => this; -// } -// -// type ActionType = (this: IUIHarnessContext) => void; -// type BDDType = (labelOrAction: string | ActionType, action?: ActionType) => void; -// -// declare var describe: BDDType; -// declare var before: BDDType; -// declare var section: BDDType; -// declare var it: BDDType; From 8916203b3d8a2e4f16b02d45aacb8c1365ff02b1 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 14:50:30 +1200 Subject: [PATCH 05/15] Remove type definitions from typescript component --- src/specs/typescript.spec.tsx | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/specs/typescript.spec.tsx b/src/specs/typescript.spec.tsx index ed5bf87..6d5238a 100644 --- a/src/specs/typescript.spec.tsx +++ b/src/specs/typescript.spec.tsx @@ -1,30 +1,5 @@ import * as React from 'react'; - -/* - UIHarness type definitions for now -*/ - -type UIComponentType = React.ReactElement<{}> | React.Component<{}, {}> | React.StatelessComponent<{}> | string; -declare class IUIHarnessContext { - public component: (component: UIComponentType) => this; - public header: (title: string) => this; -} - -type ActionType = (this: IUIHarnessContext) => void; -type BDDType = (labelOrAction: string | ActionType, action?: ActionType) => void; - -declare var describe: BDDType; -declare var before: BDDType; -declare var section: BDDType; -declare var it: BDDType; - -/* Type definitions end */ - - - - - // tslint:disable-next-line // Using class as enums cannot use strings. http://stackoverflow.com/questions/15490560/create-an-enum-with-string-values-in-typescript class UIBGColors { @@ -49,10 +24,9 @@ const TypeScriptComponent = ({ return
; }; -describe('TypeScript', function (this: IUIHarnessContext): void { +describe('TypeScript', function (): void { // Temporary fix until UIHarness core is typed correctly - const self: IUIHarnessContext = this; - self.header(`## A React component written in TypeScript.`); + this.header(`## A React component written in TypeScript.`); before(() => this.component()); From 58c53a3abeb04e668982ac3f8d250d55263a0563 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 14:50:55 +1200 Subject: [PATCH 06/15] Update tsconfig.json --- tsconfig.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 4cd7bd2..f2380fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,9 +18,14 @@ "suppressImplicitAnyIndexErrors": true, "strictNullChecks": true }, + "include": [ + "typings/index.d.ts", + "src/**/*.ts", + "src/**/*.tsx" + ], "exclude": [ "node_modules", - "src/specs" + "src/specs" // Comment this line to check type definitions in specs ], "awesomeTypescriptLoaderOptions": { "forkChecker": true From 251b6fd927522dc28ec5d94671630e38a91db88b Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 14:51:23 +1200 Subject: [PATCH 07/15] Fix typescript build step --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 32f8df8..3803de3 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,10 @@ "main": "./lib/server", "typings": "./index.d.ts", "scripts": { - "build": "npm run build:babel && npm run build:typescript", + "build": "npm run build:babel && npm run build:copy-types", "build:babel": "./node_modules/babel-cli/bin/babel.js src --out-dir lib --source-maps", "build:typescript": "./node_modules/typescript/bin/tsc", + "build:copy-types": "cp src/index.d.ts lib/index.d.ts", "build:watch": "npm run build -- --watch", "dev": "QUICK_BUILD=true ./node_modules/.bin/nodemon -x \"./node_modules/babel-cli/bin/babel-node.js start.js\"", "lint": "eslint --ext .js,.jsx ./src && tslint src/**/*.ts{,x}", @@ -79,7 +80,7 @@ "sinon": "^1.16.1", "tslint": "^3.11.0", "tslint-react": "^0.4.0", - "typescript": "^1.9.0-dev.20160617-1.0", + "typescript": "^2.1.0-dev.20160716", "typings": "^1.3.0" }, "repository": { From c95a8c3ef53eed2529ef45ad55c664baf10c9a35 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 15:30:28 +1200 Subject: [PATCH 08/15] Update tsconfig --- tsconfig.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index f2380fe..477c70d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ "declaration": true, "noImplicitAny": false, "removeComments": true, - "noLib": false, "preserveConstEnums": true, "suppressImplicitAnyIndexErrors": true, "strictNullChecks": true @@ -24,8 +23,8 @@ "src/**/*.tsx" ], "exclude": [ - "node_modules", - "src/specs" // Comment this line to check type definitions in specs + "src/specs", // Comment this line to check type definitions in specs + "node_modules" ], "awesomeTypescriptLoaderOptions": { "forkChecker": true From 9d1640465598a9135fc5225b55c009f1044a7ada Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 15:30:35 +1200 Subject: [PATCH 09/15] Allow namespaces --- tslint.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tslint.json b/tslint.json index b904617..dc22fbe 100644 --- a/tslint.json +++ b/tslint.json @@ -8,6 +8,7 @@ "quotemark": [ true, "single" ], - "jsx-no-lambda": true + "jsx-no-lambda": true, + "no-namespace": false } } From 402508a5ddacb7cf66040eb2ecc5dd4eae335d4d Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 15:30:54 +1200 Subject: [PATCH 10/15] Added index.js file to export describe et al. --- src/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/index.js diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..8aa3cef --- /dev/null +++ b/src/index.js @@ -0,0 +1,14 @@ +import server from './server/index.js'; +import bdd from 'js-bdd'; + +// Server API - Maintain backwards compatibility +export default { + start: server.start, + build: server.build, +}; + +export const before = bdd.before; +export const describe = bdd.describe; +export const it = bdd.it; +export const section = bdd.section; + From 4db015756cd29dad3e3bfaeb5d512426ab5c5b02 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 15:31:12 +1200 Subject: [PATCH 11/15] Fix tslint and convert to module format --- src/index.d.ts | 67 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index f6854e8..da2abec 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -10,45 +10,46 @@ declare namespace UIHarness { } class IUIHarnessContext { - toValues(): {}; - reset(options: {}): void; - props(value: {}): {}; - context(value: {}): {}; - component(component: IUIHComponent): this; - unload(): this; - - log(...value: any[]): this; - + public toValues(): {}; + public reset(options: {}): void; + public props(value: {}): {}; + public context(value: {}): {}; + public component(component: IUIHComponent): this; + public unload(): this; + + public log(...value: any[]): this; + // property setters - children(children: React.ReactType[] | React.ReactType): this; - childContextTypes(value: {}): this; - width(value: string | number): this; - height(value: string | number): this; - cropMarks: ICropMarks; - margin(value: number): this; - align(value: string): this; // TODO: Type this.align() better - header(value: string): this; - footer(value: string): this; - hr(enabled: boolean): this; - backdrop(value: string | number): this; - background(value: string | number): this; - scroll(value: boolean | 'x' | 'y' | 'x:y'): this; - style(value: React.CSSProperties): this; + public children(children: React.ReactType[] | React.ReactType): this; + public childContextTypes(value: {}): this; + public width(value: string | number): this; + public height(value: string | number): this; + public cropMarks: ICropMarks; // tslint:disable-line:member-ordering + public margin(value: number): this; + public align(value: string): this; // TODO: Type this.align() better + public header(value: string): this; + public footer(value: string): this; + public hr(enabled: boolean): this; + public backdrop(value: string | number): this; + public background(value: string | number): this; + public scroll(value: boolean | 'x' | 'y' | 'x:y'): this; + public style(value: React.CSSProperties): this; } - var UIHarness: IUIHarnessContext; - interface ActionType { (this: IUIHarnessContext): void; } - + interface IActionType { (this: IUIHarnessContext): void; } + interface IBDDFunction { - (label: string, action?: ActionType): void; - (action: ActionType): void; + (label: string, action?: IActionType): void; + (action: IActionType): void; } +} +export declare var describe: UIHarness.IBDDFunction; +export declare var before: UIHarness.IBDDFunction; +export declare var section: UIHarness.IBDDFunction; +export declare var it: UIHarness.IBDDFunction; -} -declare var describe: UIHarness.IBDDFunction; -declare var before: UIHarness.IBDDFunction; -declare var section: UIHarness.IBDDFunction; -declare var it: UIHarness.IBDDFunction; +declare var defaultExport: { start: Function, build: Function } +export default defaultExport; From b4f8f7b9987f3d30adb77c332733370bf7641098 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 15:31:25 +1200 Subject: [PATCH 12/15] Update typescript spec file --- src/specs/typescript.spec.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/specs/typescript.spec.tsx b/src/specs/typescript.spec.tsx index 6d5238a..cfb54a3 100644 --- a/src/specs/typescript.spec.tsx +++ b/src/specs/typescript.spec.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { describe, before, it } from '../'; // tslint:disable-next-line // Using class as enums cannot use strings. http://stackoverflow.com/questions/15490560/create-an-enum-with-string-values-in-typescript @@ -27,6 +28,7 @@ const TypeScriptComponent = ({ describe('TypeScript', function (): void { // Temporary fix until UIHarness core is typed correctly this.header(`## A React component written in TypeScript.`); + this. before(() => this.component()); From 65fa2cfcddc38d6d0e9967d68fa230634579972f Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 19:37:20 +1200 Subject: [PATCH 13/15] Fix package.json --- package.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3803de3..6c5cb6d 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "ui-harness", "version": "3.16.2", "description": "Create, isolate and test modular UI components in React.", - "main": "./lib/server", - "typings": "./index.d.ts", + "main": "./lib", + "typings": "./lib/index.d.ts", "scripts": { "build": "npm run build:babel && npm run build:copy-types", "build:babel": "./node_modules/babel-cli/bin/babel.js src --out-dir lib --source-maps", @@ -101,5 +101,10 @@ "bugs": { "url": "https://github.com/philcockfield/ui-harness/issues" }, - "homepage": "http://uiharness.com" + "homepage": "http://uiharness.com", + "files": [ + "lib", + "typings.json", + "LICENSE" + ] } From 99ea7c1225843f72818156473e5fcbc94f2ca5c7 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 19:37:33 +1200 Subject: [PATCH 14/15] Fix typescript definition --- src/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.d.ts b/src/index.d.ts index da2abec..f0d7d78 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -50,6 +50,6 @@ export declare var before: UIHarness.IBDDFunction; export declare var section: UIHarness.IBDDFunction; export declare var it: UIHarness.IBDDFunction; -declare var defaultExport: { start: Function, build: Function } +declare var defaultExport: { start: any, build: any }; export default defaultExport; From 8faf56b2c9b956bed33798df92ffec1b0d1a5202 Mon Sep 17 00:00:00 2001 From: Frederick Fogerty Date: Sun, 17 Jul 2016 19:37:39 +1200 Subject: [PATCH 15/15] Fix lint --- src/specs/typescript.spec.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/specs/typescript.spec.tsx b/src/specs/typescript.spec.tsx index cfb54a3..8b8cd5b 100644 --- a/src/specs/typescript.spec.tsx +++ b/src/specs/typescript.spec.tsx @@ -1,5 +1,5 @@ +import { before, describe, it } from '../'; import * as React from 'react'; -import { describe, before, it } from '../'; // tslint:disable-next-line // Using class as enums cannot use strings. http://stackoverflow.com/questions/15490560/create-an-enum-with-string-values-in-typescript @@ -28,7 +28,6 @@ const TypeScriptComponent = ({ describe('TypeScript', function (): void { // Temporary fix until UIHarness core is typed correctly this.header(`## A React component written in TypeScript.`); - this. before(() => this.component());