| @@ -0,0 +1,14 | |||
|
|
1 | { | |
|
|
2 | "version": "0.2.0", | |
|
|
3 | "configurations": [ | |
|
|
4 | { | |
|
|
5 | "name": "Launch browser tests", | |
|
|
6 | "type": "node", | |
|
|
7 | "request": "launch", | |
|
|
8 | "program": "${workspaceFolder}/build/test/tests/index.js", | |
|
|
9 | "cwd": "${workspaceFolder}/build/test", | |
|
|
10 | "sourceMaps": true, | |
|
|
11 | "preLaunchTask": "Build browser test" | |
|
|
12 | } | |
|
|
13 | ] | |
|
|
14 | } No newline at end of file | |
| @@ -0,0 +1,15 | |||
|
|
1 | { | |
|
|
2 | "version": "2.0.0", | |
|
|
3 | "command": "./gradlew", | |
|
|
4 | "type": "shell", | |
|
|
5 | "tasks": [ | |
|
|
6 | { | |
|
|
7 | "label": "Build browser test", | |
|
|
8 | "args": [ | |
|
|
9 | "assembleTest", | |
|
|
10 | "-Psymbols=local", | |
|
|
11 | "-Pflavour=browser" | |
|
|
12 | ] | |
|
|
13 | } | |
|
|
14 | ] | |
|
|
15 | } No newline at end of file | |
| @@ -1,260 +1,225 | |||
|
|
1 | 1 | plugins { |
|
|
2 | 2 | id "org.implab.gradle-typescript" version "1.0.1-rc3" |
|
|
3 | 3 | id "org.implab.gradle-hg" |
|
|
4 | 4 | id "ivy-publish" |
|
|
5 | 5 | } |
|
|
6 | 6 | |
|
|
7 | // Π΅ΡΠ»ΠΈ Π²Π΅ΡΡΠΈΡ ΡΠ²Π½ΠΎ Π½Π΅ Π·Π°Π΄Π°Π½Ρ Π²ΡΡΠΈΡΠ»ΡΠ΅ΠΌ Π΅Π΅ ΠΈΠ· ΡΡΠ³Π° ΡΠ΅Π²ΠΈΠ·ΠΈΠΈ v.{num}*** | |
|
|
8 | // ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠΌ Π±ΡΠ΄Π΅Ρ Π²Π΅ΡΡΠΈΡ '{num}.{distance}' Π³Π΄Π΅ distance - ΡΠ°ΡΡΡΠΎΡΠ½ΠΈΠ΅ ΠΎΡ | |
|
|
9 | // ΡΠ΅ΠΊΡΡΠ΅ΠΉ ΡΠ΅Π²ΠΈΠ·ΠΈΠΈ Π΄ΠΎ ΡΠ΅Π²ΠΈΠ·ΠΈΠΈ Ρ ΡΡΠ³ΠΎΠΌ | |
|
|
10 | def tagDistance = 0; | |
|
|
7 | if (!symbols in ['local', 'pack', 'none']) | |
|
|
8 | throw new Exception("The symbols property value is invalid: $symbols"); | |
|
|
9 | ||
|
|
10 | if (!flavour in ['browser', 'node']) | |
|
|
11 | throw new Exception("The flavour property value is invalid: $flavour"); | |
|
|
11 | 12 | |
|
|
12 | 13 | ext { |
|
|
13 | packageName = "@$npmScope/$name" | |
|
|
14 | lint = project.hasProperty('lint') ? lint : false | |
|
|
15 | } | |
|
|
16 | ||
|
|
17 | configurations { | |
|
|
18 | ||
|
|
14 | packageName = flavour == 'browser' ? "@$npmScope/$name-amd" : "@$npmScope/$name" | |
|
|
15 | lint = project.hasProperty('lint') ? project.lint : false | |
|
|
19 | 16 | } |
|
|
20 | 17 | |
|
|
21 | 18 | sources { |
|
|
22 | 19 | amd { |
|
|
23 | 20 | typings { |
|
|
24 | 21 | srcDir main.output.typingsDir |
|
|
25 | 22 | } |
|
|
26 | 23 | } |
|
|
27 | 24 | |
|
|
28 | 25 | cjs { |
|
|
29 | 26 | typings { |
|
|
30 | 27 | srcDir main.output.typingsDir |
|
|
31 | 28 | } |
|
|
32 | 29 | } |
|
|
33 | 30 | |
|
|
34 | 31 | testAmd { |
|
|
35 | 32 | typings { |
|
|
36 | 33 | srcDir main.output.typingsDir |
|
|
37 | 34 | srcDir amd.output.typingsDir |
|
|
38 | 35 | srcDir test.output.typingsDir |
|
|
39 | 36 | } |
|
|
40 | 37 | } |
|
|
41 | 38 | |
|
|
42 | 39 | testCjs { |
|
|
43 | 40 | typings { |
|
|
44 | 41 | srcDir main.output.typingsDir |
|
|
45 | 42 | srcDir cjs.output.typingsDir |
|
|
46 | 43 | srcDir test.output.typingsDir |
|
|
47 | 44 | } |
|
|
48 | 45 | } |
|
|
49 | 46 | } |
|
|
50 | 47 | |
|
|
51 | 48 | typescript { |
|
|
52 | 49 | compilerOptions { |
|
|
53 | 50 | types = [] |
|
|
54 | 51 | declaration = true |
|
|
55 | sourceMap = true | |
|
|
56 | sourceRoot = "_src" | |
|
|
52 | ||
|
|
53 | if(symbols != 'none') { | |
|
|
54 | sourceMap = true | |
|
|
55 | sourceRoot = "_src" | |
|
|
56 | } | |
|
|
57 | ||
|
|
58 | if (flavour == 'node') { | |
|
|
59 | module = "commonjs" | |
|
|
60 | target = "es2017" | |
|
|
61 | lib = ["es2017", "dom", "scripthost"] | |
|
|
62 | } else if (flavour == 'browser') { | |
|
|
63 | module = "amd" | |
|
|
64 | target = "es5" | |
|
|
65 | lib = ["es5", "dom", "scripthost", "es2015.promise", "es2015.symbol", "es2015.iterable" ] | |
|
|
66 | } | |
|
|
57 | 67 | } |
|
|
58 | 68 | tscCmd = "$projectDir/node_modules/.bin/tsc" |
|
|
59 | 69 | tsLintCmd = "$projectDir/node_modules/.bin/tslint" |
|
|
60 | 70 | esLintCmd = "$projectDir/node_modules/.bin/eslint" |
|
|
61 | 71 | npmCmd = "npm" |
|
|
62 | 72 | } |
|
|
63 | 73 | |
|
|
64 | tasks.matching{ it.name =~ /^configureTs/ }.configureEach { | |
|
|
65 | dependsOn "prepare" | |
|
|
66 | } | |
|
|
67 | ||
|
|
68 | 74 | tasks.matching{ it.name =~ /^lint/ }.configureEach { |
|
|
69 | 75 | onlyIf { lint } |
|
|
70 | 76 | } |
|
|
71 | 77 | |
|
|
72 | task prepare { | |
|
|
73 | ||
|
|
78 | if (symbols == 'local') { | |
|
|
79 | tasks.matching{ it.name =~ /^configureTs/ }.configureEach { | |
|
|
80 | compilerOptions { | |
|
|
81 | sourceRoot = "file://" + it.rootDir | |
|
|
82 | } | |
|
|
83 | } | |
|
|
74 | 84 | } |
|
|
75 | 85 | |
|
|
76 | 86 | task printVersion { |
|
|
77 | dependsOn prepare | |
|
|
78 | ||
|
|
79 | 87 | doLast { |
|
|
88 | println "packageName: ${-> packageName}"; | |
|
|
80 | 89 | println "version: ${-> version}"; |
|
|
81 |
println " |
|
|
|
90 | println "flavour: ${-> flavour}"; | |
|
|
82 | 91 | println "target: ${-> typescript.compilerOptions.target}"; |
|
|
83 | 92 | println "module: ${-> typescript.compilerOptions.module}"; |
|
|
93 | println "lint: ${-> lint}"; | |
|
|
94 | println "symbols: ${-> symbols}"; | |
|
|
84 | 95 | } |
|
|
85 | 96 | } |
|
|
86 | 97 | |
|
|
87 | 98 | task clean { |
|
|
88 | prepare.mustRunAfter it | |
|
|
89 | ||
|
|
90 | 99 | doLast { |
|
|
91 | 100 | delete buildDir |
|
|
92 | 101 | } |
|
|
93 | 102 | } |
|
|
94 | 103 | |
|
|
95 | 104 | npmPackMeta { |
|
|
96 | 105 | meta { |
|
|
97 | 106 | name = packageName |
|
|
98 | 107 | } |
|
|
99 | 108 | } |
|
|
100 | 109 | |
|
|
101 | 110 | configureTsCjs { |
|
|
102 | 111 | dependsOn sources.main.output |
|
|
103 | 112 | compilerOptions { |
|
|
104 | 113 | types += [ "node" ] |
|
|
105 | 114 | } |
|
|
106 | 115 | } |
|
|
107 | 116 | |
|
|
108 | 117 | configureTsAmd { |
|
|
109 | 118 | dependsOn sources.main.output |
|
|
110 | 119 | compilerOptions { |
|
|
111 | 120 | types += [ "requirejs", "dojo-typings" ] |
|
|
112 | 121 | } |
|
|
113 | 122 | } |
|
|
114 | 123 | |
|
|
115 | 124 | test { |
|
|
116 | 125 | workingDir layout.buildDirectory.dir("test"); |
|
|
117 | 126 | commandLine "node", "tests/index.js" |
|
|
118 | 127 | } |
|
|
119 | 128 | |
|
|
120 | 129 | assemble { |
|
|
121 | mustRunAfter sources.amd.output, | |
|
|
122 |
sources. |
|
|
|
123 | ||
|
|
124 | from sources.amd.output.compiledDir | |
|
|
125 | from sources.cjs.output.compiledDir | |
|
|
126 | } | |
|
|
127 | ||
|
|
128 | assembleTest { | |
|
|
129 | mustRunAfter sources.amd.output, | |
|
|
130 | sources.cjs.output, | |
|
|
131 | sources.testAmd.output, | |
|
|
132 | sources.testCjs.output | |
|
|
133 | ||
|
|
134 | from sources.amd.output.compiledDir | |
|
|
135 | from sources.cjs.output.compiledDir | |
|
|
136 | from sources.testAmd.output.compiledDir | |
|
|
137 | from sources.testCjs.output.compiledDir | |
|
|
138 | } | |
|
|
139 | ||
|
|
140 | task prepareLocalDebug { | |
|
|
141 | prepare.mustRunAfter it | |
|
|
142 | ||
|
|
143 | doLast { | |
|
|
144 | tasks.matching{ it.name =~ /^configureTs/ }.configureEach { | |
|
|
145 | compilerOptions { | |
|
|
146 | sourceRoot = "file://" + it.rootDir | |
|
|
147 | } | |
|
|
148 | } | |
|
|
130 | if (flavour == 'browser') { | |
|
|
131 | dependsOn sources.amd.output | |
|
|
132 | from sources.amd.output.compiledDir | |
|
|
133 | } | |
|
|
134 | if (flavour == 'node') { | |
|
|
135 | dependsOn sources.cjs.output | |
|
|
136 | from sources.cjs.output.compiledDir | |
|
|
149 | 137 | } |
|
|
150 | 138 | } |
|
|
151 | 139 | |
|
|
152 | task prepareNode { | |
|
|
153 | prepare.mustRunAfter it | |
|
|
140 | assembleTest { | |
|
|
141 | if (flavour == 'browser') { | |
|
|
142 | dependsOn sources.amd.output, sources.testAmd.output | |
|
|
154 | 143 | |
|
|
155 | doLast { | |
|
|
156 | typescript { | |
|
|
157 | compilerOptions { | |
|
|
158 | module = "commonjs" | |
|
|
159 | target = "es2017" | |
|
|
160 | lib = ["es2017", "dom", "scripthost"] | |
|
|
161 | } | |
|
|
162 | } | |
|
|
144 | from sources.amd.output.compiledDir | |
|
|
145 | from sources.testAmd.output.compiledDir | |
|
|
146 | } | |
|
|
147 | if (flavour == 'node') { | |
|
|
148 | dependsOn sources.cjs.output, sources.testCjs.output | |
|
|
149 | ||
|
|
150 | from sources.cjs.output.compiledDir | |
|
|
151 | from sources.testCjs.output.compiledDir | |
|
|
163 | 152 | } |
|
|
164 | 153 | } |
|
|
165 | 154 | |
|
|
166 | task prepareBrowser { | |
|
|
167 | prepare.mustRunAfter it | |
|
|
168 | ||
|
|
169 | doLast { | |
|
|
170 | packageName = "@$npmScope/$project.name-amd" | |
|
|
155 | task npmPackTypings(type: Copy) { | |
|
|
156 | npmPack.dependsOn it | |
|
|
157 | dependsOn sources.main.output | |
|
|
158 | ||
|
|
159 | from sources.main.output.typingsDir | |
|
|
171 | 160 | |
|
|
172 | typescript { | |
|
|
173 | compilerOptions { | |
|
|
174 | module = "amd" | |
|
|
175 | target = "es5" | |
|
|
176 | lib = ["es5", "dom", "scripthost", "es2015.promise", "es2015.symbol", "es2015.iterable"] | |
|
|
177 | } | |
|
|
178 | } | |
|
|
161 | if (flavour == 'browser') { | |
|
|
162 | dependsOn sources.amd.output | |
|
|
163 | from sources.amd.output.typingsDir | |
|
|
179 | 164 | } |
|
|
180 | } | |
|
|
181 | ||
|
|
182 | task npmPackTypingsAmd(type: Copy) { | |
|
|
183 | dependsOn sources.main.output | |
|
|
184 | dependsOn sources.amd.output | |
|
|
185 | npmPack.mustRunAfter it | |
|
|
186 | ||
|
|
187 | from sources.main.output.typingsDir | |
|
|
188 | from sources.amd.output.typingsDir | |
|
|
165 | if (flavour == 'node') { | |
|
|
166 | dependsOn sources.cjs.output | |
|
|
167 | from sources.cjs.output.typingsDir | |
|
|
168 | } | |
|
|
189 | 169 | |
|
|
190 | 170 | into "${->buildDir}/npm/pack" |
|
|
191 | 171 | } |
|
|
192 | 172 | |
|
|
193 |
task npmPackSources |
|
|
|
173 | task npmPackSources(type: Copy) { | |
|
|
194 | 174 | from sources.main.ts |
|
|
195 | from sources.amd.ts | |
|
|
196 | ||
|
|
197 | npmPack.mustRunAfter it | |
|
|
175 | ||
|
|
176 | if (flavour == 'browser') { | |
|
|
177 | from sources.amd.ts | |
|
|
178 | } | |
|
|
179 | if (flavour == 'node') { | |
|
|
180 | from sources.cjs.ts | |
|
|
181 | } | |
|
|
198 | 182 | |
|
|
199 | 183 | into "${->buildDir}/npm/pack/_src" |
|
|
200 | 184 | } |
|
|
201 | 185 | |
|
|
202 | task assembleBrowser { | |
|
|
203 | dependsOn prepareBrowser, assemble, sources.amd.output | |
|
|
204 | } | |
|
|
205 | ||
|
|
206 | task assembleNode { | |
|
|
207 | dependsOn prepareNode, assemble, sources.cjs.output | |
|
|
208 | } | |
|
|
209 | ||
|
|
210 | task assembleTestBrowser { | |
|
|
211 | dependsOn prepareBrowser, prepareLocalDebug, assembleTest, sources.amd.output, sources.testAmd.output | |
|
|
186 | if (symbols == 'pack') { | |
|
|
187 | npmPack { | |
|
|
188 | dependsOn npmPackSources | |
|
|
189 | } | |
|
|
212 | 190 | } |
|
|
213 | 191 | |
|
|
214 | task testBrowser { | |
|
|
215 | dependsOn prepareBrowser, test, sources.amd.output, sources.testAmd.output | |
|
|
216 | } | |
|
|
217 | ||
|
|
218 | task testNode { | |
|
|
219 | dependsOn prepareNode, test, sources.cjs.output, sources.testCjs.output | |
|
|
220 | } | |
|
|
221 | ||
|
|
222 | task npmPackBrowser { | |
|
|
223 | dependsOn assembleBrowser, npmPack, npmPackSourcesAmd, npmPackTypingsAmd | |
|
|
224 | } | |
|
|
225 | ||
|
|
226 | ||
|
|
227 | 192 | task packJsTar(type: Tar) { |
|
|
228 | 193 | dependsOn assemble; |
|
|
229 | 194 | |
|
|
230 | 195 | archiveBaseName = provider { packageName } |
|
|
231 | 196 | |
|
|
232 | 197 | destinationDirectory = buildDir |
|
|
233 | 198 | archiveClassifier = provider { typescript.compilerOptions.module } |
|
|
234 | 199 | compression = Compression.GZIP |
|
|
235 | 200 | |
|
|
236 | 201 | from(assemble.outputs) |
|
|
237 | 202 | |
|
|
238 | 203 | doLast { |
|
|
239 | 204 | println archiveName; |
|
|
240 | 205 | } |
|
|
241 | 206 | } |
|
|
242 | 207 | |
|
|
243 | 208 | task packTypingsTar(type: Tar) { |
|
|
244 | 209 | } |
|
|
245 | 210 | |
|
|
246 | 211 | publishing { |
|
|
247 | 212 | publications { |
|
|
248 | 213 | local(IvyPublication) { |
|
|
249 | 214 | artifact(packJsTar) { |
|
|
250 | 215 | type = "js" |
|
|
251 | 216 | } |
|
|
252 | 217 | } |
|
|
253 | 218 | } |
|
|
254 | 219 | |
|
|
255 | 220 | repositories { |
|
|
256 | 221 | ivy { |
|
|
257 | 222 | url "ivy-repo" |
|
|
258 | 223 | } |
|
|
259 | 224 | } |
|
|
260 | 225 | } No newline at end of file |
| @@ -1,7 +1,9 | |||
|
|
1 | 1 | group=org.implab |
|
|
2 | 2 | version= |
|
|
3 | 3 | author=Implab team |
|
|
4 | 4 | description=Dependency injection, logging, simple and fast text processing tools |
|
|
5 | 5 | license=BSD-2-Clause |
|
|
6 | 6 | repository=https://bitbucket.org/implab/implabjs-core |
|
|
7 | npmScope=implab No newline at end of file | |
|
|
7 | npmScope=implab | |
|
|
8 | flavour=browser | |
|
|
9 | symbols=pack No newline at end of file | |
| @@ -1,45 +1,45 | |||
|
|
1 | 1 | import { Uuid } from "../Uuid"; |
|
|
2 | 2 | import { argumentNotEmptyString, getGlobal } from "../safe"; |
|
|
3 | 3 | import { TraceSource } from "../log/TraceSource"; |
|
|
4 | 4 | import m = require("module"); |
|
|
5 | 5 | |
|
|
6 | 6 | const sandboxId = Uuid(); |
|
|
7 | define(sandboxId, ["require"], r => r); | |
|
|
7 | define(sandboxId, ["require"], (r: any) => r); | |
|
|
8 | 8 | |
|
|
9 | 9 | const globalRequire = getGlobal().require as Require || requirejs; |
|
|
10 | 10 | |
|
|
11 | 11 | const trace = TraceSource.get(m.id); |
|
|
12 | 12 | trace.debug("globalRequire = {0}", globalRequire); |
|
|
13 | 13 | |
|
|
14 | 14 | class ModuleResolver { |
|
|
15 | 15 | _base: string; |
|
|
16 | 16 | _require: Require; |
|
|
17 | 17 | |
|
|
18 | 18 | constructor(req: Require, base?: string) { |
|
|
19 | 19 | this._base = base; |
|
|
20 | 20 | this._require = req; |
|
|
21 | 21 | } |
|
|
22 | 22 | |
|
|
23 | 23 | resolve(moduleName: string) { |
|
|
24 | 24 | argumentNotEmptyString(moduleName, "moduleName"); |
|
|
25 | 25 | const resolvedName = moduleName[0] === "." && this._base ? [this._base, moduleName].join("/") : moduleName; |
|
|
26 | 26 | trace.debug(`${moduleName} -> ${resolvedName}`); |
|
|
27 | 27 | |
|
|
28 | 28 | const req = this._require; |
|
|
29 | 29 | |
|
|
30 | 30 | return new Promise<any>((cb, eb) => { |
|
|
31 | 31 | req([resolvedName], cb, eb); |
|
|
32 | 32 | }); |
|
|
33 | 33 | } |
|
|
34 | 34 | } |
|
|
35 | 35 | |
|
|
36 | 36 | export function makeResolver(moduleName: string, contextRequire: Require) { |
|
|
37 | 37 | const base = moduleName && moduleName.split("/").slice(0, -1).join("/"); |
|
|
38 | 38 | |
|
|
39 | 39 | const req = contextRequire || globalRequire; |
|
|
40 | 40 | if (!req) |
|
|
41 | 41 | throw new Error("A global require isn't defined, the contextRequire parameter is mandatory"); |
|
|
42 | 42 | |
|
|
43 | 43 | const resolver = new ModuleResolver(req, base); |
|
|
44 | 44 | return (id: string) => resolver.resolve(id); |
|
|
45 | 45 | } |
General Comments 0
You need to be logged in to leave comments.
Login now
