|
|
1 | NO CONTENT: new file 100644 |
| @@ -1,234 +1,236 | |||
|
|
1 | 1 | plugins { |
|
|
2 | 2 | id "org.implab.gradle-typescript" version "1.3.3" |
|
|
3 | 3 | id "org.implab.gradle-hg" |
|
|
4 | 4 | id "ivy-publish" |
|
|
5 | 5 | } |
|
|
6 | 6 | |
|
|
7 | 7 | if (!symbols in ['local', 'pack', 'none']) |
|
|
8 | 8 | throw new Exception("The symbols property value is invalid: $symbols"); |
|
|
9 | 9 | |
|
|
10 | 10 | if (!flavour in ['browser', 'node']) |
|
|
11 | 11 | throw new Exception("The flavour property value is invalid: $flavour"); |
|
|
12 | 12 | |
|
|
13 | 13 | ext { |
|
|
14 | 14 | packageName = flavour == 'browser' ? "@$npmScope/$name-amd" : "@$npmScope/$name" |
|
|
15 | 15 | lint = project.hasProperty('lint') ? project.lint ?: true : false |
|
|
16 | 16 | } |
|
|
17 | 17 | |
|
|
18 | 18 | sources { |
|
|
19 | 19 | amd { |
|
|
20 | 20 | typings { |
|
|
21 | 21 | srcDir main.output.typingsDir |
|
|
22 | 22 | } |
|
|
23 | 23 | } |
|
|
24 | 24 | |
|
|
25 | 25 | cjs { |
|
|
26 | 26 | typings { |
|
|
27 | 27 | srcDir main.output.typingsDir |
|
|
28 | 28 | } |
|
|
29 | 29 | } |
|
|
30 | 30 | |
|
|
31 | 31 | testAmd { |
|
|
32 | 32 | typings { |
|
|
33 | 33 | srcDir main.output.typingsDir |
|
|
34 | 34 | srcDir amd.output.typingsDir |
|
|
35 | 35 | srcDir test.output.typingsDir |
|
|
36 | 36 | } |
|
|
37 | 37 | } |
|
|
38 | 38 | |
|
|
39 | 39 | testCjs { |
|
|
40 | 40 | typings { |
|
|
41 | 41 | srcDir main.output.typingsDir |
|
|
42 | 42 | srcDir cjs.output.typingsDir |
|
|
43 | 43 | srcDir test.output.typingsDir |
|
|
44 | 44 | } |
|
|
45 | 45 | } |
|
|
46 | 46 | } |
|
|
47 | 47 | |
|
|
48 | 48 | typescript { |
|
|
49 | 49 | compilerOptions { |
|
|
50 | 50 | types = [] |
|
|
51 | 51 | declaration = true |
|
|
52 | experimentalDecorators = true | |
|
|
53 | //strict = true | |
|
|
52 | 54 | |
|
|
53 | 55 | if(symbols != 'none') { |
|
|
54 | 56 | sourceMap = true |
|
|
55 | 57 | sourceRoot = packageName |
|
|
56 | 58 | } |
|
|
57 | 59 | |
|
|
58 | 60 | if (flavour == 'node') { |
|
|
59 | 61 | module = "commonjs" |
|
|
60 | 62 | target = "es2017" |
|
|
61 | 63 | lib = ["es2017", "dom", "scripthost"] |
|
|
62 | 64 | } else if (flavour == 'browser') { |
|
|
63 | 65 | module = "amd" |
|
|
64 | 66 | target = "es5" |
|
|
65 | 67 | lib = ["es5", "dom", "scripthost", "es2015.promise", "es2015.symbol", "es2015.iterable" ] |
|
|
66 | 68 | } |
|
|
67 | 69 | } |
|
|
68 | 70 | tscCmd = "$projectDir/node_modules/.bin/tsc" |
|
|
69 | 71 | tsLintCmd = "$projectDir/node_modules/.bin/tslint" |
|
|
70 | 72 | esLintCmd = "$projectDir/node_modules/.bin/eslint" |
|
|
71 | 73 | } |
|
|
72 | 74 | |
|
|
73 | 75 | tasks.matching{ it.name =~ /^lint/ }.configureEach { |
|
|
74 | 76 | onlyIf { lint } |
|
|
75 | 77 | } |
|
|
76 | 78 | |
|
|
77 | 79 | if (symbols == 'local') { |
|
|
78 | 80 | tasks.matching{ it.name =~ /^configureTs/ }.configureEach { |
|
|
79 | 81 | compilerOptions { |
|
|
80 | 82 | sourceRoot = "file://" + it.rootDir |
|
|
81 | 83 | } |
|
|
82 | 84 | } |
|
|
83 | 85 | } |
|
|
84 | 86 | |
|
|
85 | 87 | task printVersion { |
|
|
86 | 88 | doLast { |
|
|
87 | 89 | println "packageName: $packageName"; |
|
|
88 | 90 | println "version: $version"; |
|
|
89 | 91 | println "flavour: $flavour"; |
|
|
90 | 92 | println "target: $typescript.compilerOptions.target"; |
|
|
91 | 93 | println "module: $typescript.compilerOptions.module"; |
|
|
92 | 94 | println "lint: $lint"; |
|
|
93 | 95 | println "symbols: $symbols"; |
|
|
94 | 96 | } |
|
|
95 | 97 | } |
|
|
96 | 98 | |
|
|
97 | 99 | npmPackMeta { |
|
|
98 | 100 | meta { |
|
|
99 | 101 | name = packageName |
|
|
100 | 102 | } |
|
|
101 | 103 | } |
|
|
102 | 104 | |
|
|
103 | 105 | configureTsCjs { |
|
|
104 | 106 | dependsOn sources.main.output |
|
|
105 | 107 | compilerOptions { |
|
|
106 | 108 | types += [ "node" ] |
|
|
107 | 109 | } |
|
|
108 | 110 | } |
|
|
109 | 111 | |
|
|
110 | 112 | configureTsAmd { |
|
|
111 | 113 | dependsOn sources.main.output |
|
|
112 | 114 | compilerOptions { |
|
|
113 | 115 | types += [ "requirejs", "dojo-typings" ] |
|
|
114 | 116 | } |
|
|
115 | 117 | } |
|
|
116 | 118 | |
|
|
117 | 119 | test { |
|
|
118 | 120 | workingDir layout.buildDirectory.dir("test"); |
|
|
119 | 121 | commandLine "node", "tests/index.js" |
|
|
120 | 122 | } |
|
|
121 | 123 | |
|
|
122 | 124 | assemble { |
|
|
123 | 125 | if (flavour == 'browser') { |
|
|
124 | 126 | dependsOn sources.amd.output |
|
|
125 | 127 | from sources.amd.output.compiledDir |
|
|
126 | 128 | from sources.amd.resources |
|
|
127 | 129 | } |
|
|
128 | 130 | if (flavour == 'node') { |
|
|
129 | 131 | dependsOn sources.cjs.output |
|
|
130 | 132 | from sources.cjs.output.compiledDir |
|
|
131 | 133 | from sources.cjs.resources |
|
|
132 | 134 | } |
|
|
133 | 135 | } |
|
|
134 | 136 | |
|
|
135 | 137 | assembleTest { |
|
|
136 | 138 | if (flavour == 'browser') { |
|
|
137 | 139 | dependsOn sources.amd.output, sources.testAmd.output |
|
|
138 | 140 | |
|
|
139 | 141 | from sources.amd.output.compiledDir |
|
|
140 | 142 | from sources.testAmd.output.compiledDir |
|
|
141 | 143 | from sources.amd.resources |
|
|
142 | 144 | from sources.testAmd.resources |
|
|
143 | 145 | } |
|
|
144 | 146 | if (flavour == 'node') { |
|
|
145 | 147 | dependsOn sources.cjs.output, sources.testCjs.output |
|
|
146 | 148 | |
|
|
147 | 149 | from sources.cjs.output.compiledDir |
|
|
148 | 150 | from sources.testCjs.output.compiledDir |
|
|
149 | 151 | from sources.cjs.resources |
|
|
150 | 152 | from sources.testCjs.resources |
|
|
151 | 153 | } |
|
|
152 | 154 | } |
|
|
153 | 155 | |
|
|
154 | 156 | typings { |
|
|
155 | 157 | if (flavour == 'browser') { |
|
|
156 | 158 | dependsOn sources.amd.output |
|
|
157 | 159 | from sources.amd.output.typingsDir |
|
|
158 | 160 | } |
|
|
159 | 161 | if (flavour == 'node') { |
|
|
160 | 162 | dependsOn sources.cjs.output |
|
|
161 | 163 | from sources.cjs.output.typingsDir |
|
|
162 | 164 | } |
|
|
163 | 165 | } |
|
|
164 | 166 | |
|
|
165 | 167 | task npmPackTypings(type: Copy) { |
|
|
166 | 168 | npmPackContents.dependsOn it |
|
|
167 | 169 | dependsOn sources.main.output |
|
|
168 | 170 | |
|
|
169 | 171 | from sources.main.output.typingsDir |
|
|
170 | 172 | |
|
|
171 | 173 | if (flavour == 'browser') { |
|
|
172 | 174 | dependsOn sources.amd.output |
|
|
173 | 175 | from sources.amd.output.typingsDir |
|
|
174 | 176 | } |
|
|
175 | 177 | if (flavour == 'node') { |
|
|
176 | 178 | dependsOn sources.cjs.output |
|
|
177 | 179 | from sources.cjs.output.typingsDir |
|
|
178 | 180 | } |
|
|
179 | 181 | |
|
|
180 | 182 | into npm.packageDir |
|
|
181 | 183 | } |
|
|
182 | 184 | |
|
|
183 | 185 | task npmPackSources(type: Copy) { |
|
|
184 | 186 | from sources.main.ts |
|
|
185 | 187 | if (symbols == 'pack') { |
|
|
186 | 188 | npmPackContents.dependsOn npmPackSources |
|
|
187 | 189 | } |
|
|
188 | 190 | |
|
|
189 | 191 | if (flavour == 'browser') { |
|
|
190 | 192 | from sources.amd.ts |
|
|
191 | 193 | } |
|
|
192 | 194 | if (flavour == 'node') { |
|
|
193 | 195 | from sources.cjs.ts |
|
|
194 | 196 | } |
|
|
195 | 197 | |
|
|
196 | 198 | into npm.packageDir.dir("_src") |
|
|
197 | 199 | } |
|
|
198 | 200 | |
|
|
199 | 201 | |
|
|
200 | 202 | |
|
|
201 | 203 | task packJsTar(type: Tar) { |
|
|
202 | 204 | dependsOn assemble; |
|
|
203 | 205 | |
|
|
204 | 206 | archiveBaseName = provider { packageName } |
|
|
205 | 207 | |
|
|
206 | 208 | destinationDirectory = buildDir |
|
|
207 | 209 | archiveClassifier = provider { typescript.compilerOptions.module } |
|
|
208 | 210 | compression = Compression.GZIP |
|
|
209 | 211 | |
|
|
210 | 212 | from(assemble.outputs) |
|
|
211 | 213 | |
|
|
212 | 214 | doLast { |
|
|
213 | 215 | println archiveName; |
|
|
214 | 216 | } |
|
|
215 | 217 | } |
|
|
216 | 218 | |
|
|
217 | 219 | task packTypingsTar(type: Tar) { |
|
|
218 | 220 | } |
|
|
219 | 221 | |
|
|
220 | 222 | publishing { |
|
|
221 | 223 | publications { |
|
|
222 | 224 | local(IvyPublication) { |
|
|
223 | 225 | artifact(packJsTar) { |
|
|
224 | 226 | type = "js" |
|
|
225 | 227 | } |
|
|
226 | 228 | } |
|
|
227 | 229 | } |
|
|
228 | 230 | |
|
|
229 | 231 | repositories { |
|
|
230 | 232 | ivy { |
|
|
231 | 233 | url "ivy-repo" |
|
|
232 | 234 | } |
|
|
233 | 235 | } |
|
|
234 | 236 | } No newline at end of file |
| @@ -1,37 +1,50 | |||
|
|
1 | 1 | import { Constructor } from "../interfaces"; |
|
|
2 | 2 | |
|
|
3 | 3 | export interface InjectOptions { |
|
|
4 | 4 | lazy?: boolean; |
|
|
5 | 5 | } |
|
|
6 | 6 | |
|
|
7 | 7 | type Setter<T = any> = (v: T) => void; |
|
|
8 | 8 | |
|
|
9 | 9 | type Injector<T> = { |
|
|
10 | 10 | [k in keyof T]: Setter; |
|
|
11 | 11 | }; |
|
|
12 | 12 | |
|
|
13 | type Compatible<T1, T2> = T1 extends T2 ? any : never; | |
|
|
14 | ||
|
|
15 | type SetterType<T> = T extends (v: infer V) => void ? V : never; | |
|
|
16 | ||
|
|
17 | type Tuple<T = any> = Parameters<(...args: T[]) => void>; | |
|
|
18 | ||
|
|
19 | interface Newable<A extends Tuple, T> { | |
|
|
20 | new (...params: A): T; | |
|
|
21 | prototype: T; | |
|
|
22 | } | |
|
|
23 | ||
|
|
24 | type MapTuple<T, A extends (keyof T)[]> = { [K in keyof A] : K extends number ? T[ A[K] ] : A[K] }; | |
|
|
25 | ||
|
|
13 | 26 | export class Builder<T, S> { |
|
|
14 |
provides( |
|
|
|
27 | provides() { | |
|
|
15 | 28 | return <C extends Constructor<T>>(constructor: C) => { |
|
|
16 | 29 | return constructor; |
|
|
17 | 30 | }; |
|
|
18 | 31 | } |
|
|
19 | 32 | |
|
|
20 | 33 | inject<K extends keyof S>(dependency: K) { |
|
|
21 | return <M extends keyof T>(target: any, memberName: M, descriptor: TypedPropertyDescriptor<Setter<S[K]>> ) => { | |
|
|
34 | // K = "bar" | |
|
|
35 | // M = "setValue" | |
|
|
36 | // S[K] = Bar | |
|
|
37 | // T[M] = (value: string) => void | |
|
|
38 | // P[m] = (value: V) => void | |
|
|
39 | return <P, M extends keyof (T | P)>(target: P, memberName: M, descriptor: TypedPropertyDescriptor<Compatible<T[M], Setter<S[K]>>>) => { | |
|
|
22 | 40 | |
|
|
23 | 41 | }; |
|
|
24 | 42 | } |
|
|
25 | 43 | |
|
|
26 |
|
|
|
|
27 | return <M extends keyof T>(target: any, memberName: M, descriptor: TypedPropertyDescriptor<S[K]> ) => { | |
|
|
44 | dependencies<D extends (keyof S)[]>(...deps: D) { | |
|
|
45 | return <C extends Constructor<T>>(constructor: MapTuple<S, D> extends ConstructorParameters<C> ? C : never) => { | |
|
|
46 | return constructor; | |
|
|
47 | } ; | |
|
|
48 | } | |
|
|
28 | 49 | |
|
|
29 | }; | |
|
|
30 | } | |
|
|
31 | 50 | } |
|
|
32 | ||
|
|
33 | export function inject<I extends Injector<I> >(dependency: string) { | |
|
|
34 | return <M extends keyof I>(target: any, memberName: M, descriptor: TypedPropertyDescriptor<I[M]> ) => { | |
|
|
35 | ||
|
|
36 | }; | |
|
|
37 | } | |
| @@ -1,12 +1,18 | |||
|
|
1 | 1 | import { Foo } from "./Foo"; |
|
|
2 | 2 | |
|
|
3 | 3 | export class Bar { |
|
|
4 | 4 | name = "bar"; |
|
|
5 | 5 | |
|
|
6 | foo: Foo; | |
|
|
6 | foo: Foo | undefined; | |
|
|
7 | 7 | |
|
|
8 | constructor(_opts) { | |
|
|
8 | constructor(_opts?: { foo?: Foo; }) { | |
|
|
9 | 9 | if (_opts && _opts.foo) |
|
|
10 | 10 | this.foo = _opts.foo; |
|
|
11 | 11 | } |
|
|
12 | ||
|
|
13 | getFoo() { | |
|
|
14 | if (this.foo === undefined) | |
|
|
15 | throw new Error("The foo isn't set"); | |
|
|
16 | return this.foo; | |
|
|
17 | } | |
|
|
12 | 18 | } |
| @@ -1,23 +1,33 | |||
|
|
1 | 1 | import { Builder } from "../di/Annotations"; |
|
|
2 | 2 | import { Bar } from "./Bar"; |
|
|
3 | 3 | import { Foo } from "./Foo"; |
|
|
4 | 4 | |
|
|
5 | export interface Injector<T> { | |
|
|
6 | setValue(value: T); | |
|
|
7 | } | |
|
|
5 | const builder = new Builder<Box<Bar>, { bar: Bar; foo: Foo; obj: object }>(); | |
|
|
8 | 6 | |
|
|
9 | const builder = new Builder<Box<any>, { bar: Bar; foo: Foo}>(); | |
|
|
7 | @builder.provides() | |
|
|
8 | @builder.dependencies("bar") | |
|
|
9 | export class Box<T> { | |
|
|
10 | private _value: T | undefined; | |
|
|
10 | 11 | |
|
|
11 | @builder.provides("barBox") | |
|
|
12 | export class Box<T> implements Injector<T> { | |
|
|
13 | private _value: T; | |
|
|
12 | constructor(value: T) { | |
|
|
13 | this._value = value; | |
|
|
14 | } | |
|
|
14 | 15 | |
|
|
15 | 16 | @builder.inject("bar") |
|
|
16 | 17 | setValue(value: T) { |
|
|
17 | 18 | this._value = value; |
|
|
18 | 19 | } |
|
|
19 | 20 | |
|
|
21 | ||
|
|
22 | @builder.inject("foo") | |
|
|
23 | setObj(value: object) { | |
|
|
24 | ||
|
|
25 | } | |
|
|
26 | ||
|
|
20 | 27 | getValue() { |
|
|
28 | if (this._value === undefined) | |
|
|
29 | throw new Error("Trying to get a value from the empty box"); | |
|
|
30 | ||
|
|
21 | 31 | return this._value; |
|
|
22 | 32 | } |
|
|
23 |
} |
|
|
|
33 | } No newline at end of file | |
| @@ -1,14 +1,14 | |||
|
|
1 | 1 | { |
|
|
2 | 2 | "extends": "../tsconfig", |
|
|
3 | 3 | "compilerOptions": { |
|
|
4 | "rootDir": "ts", | |
|
|
4 | //"rootDir": "ts", | |
|
|
5 | 5 | "baseUrl": ".", |
|
|
6 | 6 | "rootDirs": [ |
|
|
7 | 7 | "ts", |
|
|
8 | 8 | "../main/ts" |
|
|
9 | 9 | ] |
|
|
10 | 10 | }, |
|
|
11 | 11 | "include" : [ |
|
|
12 | 12 | "ts/**/*.ts" |
|
|
13 | 13 | ] |
|
|
14 | 14 | } No newline at end of file |
| @@ -1,11 +1,12 | |||
|
|
1 | 1 | { |
|
|
2 | 2 | "compilerOptions": { |
|
|
3 | 3 | "moduleResolution": "node", |
|
|
4 | 4 | "experimentalDecorators": true, |
|
|
5 | 5 | "noEmitOnError": true, |
|
|
6 | 6 | "listFiles": true, |
|
|
7 | "strict": true, | |
|
|
7 | 8 | "types": [], |
|
|
8 | 9 | "target": "ES5", |
|
|
9 | 10 | "lib": ["es5", "es2015.promise", "es2015.symbol", "es2015.iterable", "dom", "scripthost"] |
|
|
10 | 11 | } |
|
|
11 | 12 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now
