Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.

Commit 67782b2

Browse files
committed
Reintroduce gradle build and introduce mocha-backed tests
1 parent 6d5ee9a commit 67782b2

File tree

14 files changed

+224
-3810
lines changed

14 files changed

+224
-3810
lines changed

.idea/runConfigurations/build.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/test.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,23 @@ Where possible options include:<br/>
3434
git submodule update
3535
```
3636

37-
3. install dependencies
38-
* using installed node.js:
39-
40-
```shell
41-
npm install
42-
```
43-
44-
* without installing node.js:
45-
46-
```shell
47-
ant -f build.xml update.tools
48-
ant -f build.xml update.node.modules
49-
```
50-
51-
4. setup path to node interpreter in IDEA (Languages & Frameworks | Node.js and NPM)
52-
53-
5. Convert the tool to Javascript (and run the unit tests)
37+
3. Build javascript target (and run the unit tests)
5438

5539
```shell
5640
./gradlew build
5741
```
5842

59-
6. (optional) Run the unit tests
43+
4. (optional) Run the unit tests
6044

6145
```shell
62-
ant -f build.xml run.test.for.testData
46+
./gradlew test
6347
```
6448

65-
7. Run the tool in one of these ways:
49+
5. Run the tool in one of these ways:
6650
* Run it with node.js (Note: the root of the project should be working dir):
6751

6852
```shell
69-
node out/production/ts2kt/ts2kt.js path/to/input.d.ts path/to/output.kt
53+
node build/distrib/ts2kt.js path/to/input.d.ts path/to/output.kt
7054
```
7155
* Directly call translateToFile_puj7f4$ from JS (translateToFile in code).
7256
* Create run configuration like shared jq and run it.

build.gradle

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
plugins {
2+
id("kotlin2js")
3+
id "com.moowork.node" version "1.2.0"
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
jcenter()
9+
}
10+
11+
dependencies {
12+
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:$gradle.kotlinVersion")
13+
}
14+
15+
def testDistribPath = "${project.buildDir}/test"
16+
def distribPath = "${project.buildDir}/distrib"
17+
def testNodeModulesPath = "${testDistribPath}/node_modules"
18+
19+
node {
20+
download = true
21+
version = '11.1.0'
22+
}
23+
24+
task addTestPackageJson(type: Copy) {
25+
from "${projectDir}/test/config/package.test.json"
26+
into testDistribPath
27+
rename "package.test.json", "package.json"
28+
}
29+
30+
task installTestNpmDependencies(type: NpmTask) {
31+
dependsOn = [
32+
nodeSetup,
33+
addTestPackageJson,
34+
]
35+
args = ['install', '--prefix', testDistribPath]
36+
}
37+
38+
compileKotlin2Js {
39+
kotlinOptions {
40+
outputFile = "${distribPath}/ts2kt.js"
41+
sourceMap = true
42+
freeCompilerArgs += ["-output-prefix", "${projectDir}/shebang.txt"]
43+
44+
moduleKind = 'commonjs'
45+
}
46+
}
47+
48+
task fetchBuildableDependencies(type: Copy) {
49+
from "${distribPath}/ts2kt.js"
50+
into testNodeModulesPath
51+
}
52+
53+
task copyTestFiles(type: Copy) {
54+
from "${projectDir}/test"
55+
into testDistribPath
56+
57+
include "**/*.js"
58+
}
59+
60+
task prepareTestDistrib {
61+
dependsOn = [
62+
copyTestFiles,
63+
fetchBuildableDependencies,
64+
installTestNpmDependencies,
65+
]
66+
}
67+
68+
task runTests(type: NodeTask) {
69+
dependsOn = [prepareTestDistrib]
70+
script = file("${testDistribPath}/node_modules/mocha/bin/mocha")
71+
72+
def reporter = project.findProperty('reporter') ?: 'mocha-simple-html-reporter'
73+
args = [
74+
"--reporter", reporter
75+
]
76+
77+
if (reporter == 'mocha-simple-html-reporter') {
78+
args += ["--reporter-options", "output=${project.buildDir}/report.html"]
79+
}
80+
81+
82+
def testsGrep = project.findProperty('testsGrep') ?: 'short:'
83+
if (testsGrep != "ALL") {
84+
args += ["--grep", testsGrep]
85+
}
86+
87+
args += [
88+
"${testDistribPath}/test_runner.js"
89+
]
90+
}
91+
92+
fetchBuildableDependencies.dependsOn = [compileKotlin2Js]
93+
test.dependsOn = [
94+
runTests
95+
]

build.gradle.kts

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)