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

Commit 554b8bd

Browse files
Soenke SothmannSoenke Sothmann
Soenke Sothmann
authored and
Soenke Sothmann
committed
Update README.md - how to use with Node plugin
1 parent 65cd59c commit 554b8bd

File tree

1 file changed

+88
-13
lines changed

1 file changed

+88
-13
lines changed

README.md

+88-13
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,86 @@ This plugin makes it easy to build TypeScript projects using Gradle.
44
Among other things, the plugin provides a task to run the TypeScript compiler.
55

66

7-
# Examples
7+
# Quickstart
88

9-
Several example projects can be found in [/examples](examples).
9+
This will guide you through the steps needed to set up typescript-gradle-plugin for a TypeScript application project
10+
using Maven/Gradle standard layout.
11+
You can either use this plugin in combination with the Gradle Node plugin (recommended) or alternatively
12+
use it standalone with a local Node and TypeScript installation.
13+
14+
15+
## Usage with Node plugin
16+
17+
This is the recommended way to use the TypeScript Gradle plugin.
18+
Using the [Node plugin](https://github.com/srs/gradle-node-plugin) has the advantage
19+
that you do not need to have Node or TypeScript installed manually on the system
20+
to execute the TypeScript compile task.
21+
You can define a TypeScript compiler version which gets downloaded automatically.
22+
23+
24+
### Add plugin dependencies
1025

26+
Add a plugin dependency for the Node plugin and for the TypeScript Gradle plugin.
1127

12-
# Prerequisites
28+
If you are using Gradle 2.1 or later, define the plugin dependency as follows:
29+
30+
plugins {
31+
id "com.moowork.node" version "0.12"
32+
id "de.richsource.gradle.plugins.typescript" version "1.8.0"
33+
}
34+
35+
If you are using Gradle 2.0 or earlier, define the plugin dependency as follows:
36+
37+
buildscript {
38+
repositories {
39+
maven {
40+
url "https://plugins.gradle.org/m2/"
41+
}
42+
}
43+
dependencies {
44+
classpath "com.moowork.gradle:gradle-node-plugin:0.12"
45+
classpath "de.richsource.gradle.plugins:typescript-gradle-plugin:1.8.0"
46+
}
47+
}
48+
49+
apply plugin: 'com.moowork.node'
50+
apply plugin: 'de.richsource.gradle.plugins.typescript'
51+
52+
53+
### Configure the TypeScript task to use the Node executable
54+
55+
Configure the TypeScript task to use the Node executable as follows:
56+
57+
import com.moowork.gradle.node.NodeExtension
58+
import com.moowork.gradle.node.variant.VariantBuilder
59+
60+
node {
61+
download = true
62+
}
63+
64+
String nodeExecutable() {
65+
NodeExtension nodeExt = NodeExtension.get(project)
66+
return new VariantBuilder(nodeExt).build().nodeExec
67+
}
68+
69+
compileTypeScript {
70+
compilerExecutable "${nodeExecutable()} node_modules/typescript/lib/tsc.js"
71+
dependsOn "npmInstall"
72+
}
73+
74+
75+
### Create package.json with TypeScript version
76+
77+
Create a `package.json` file next to the `build.gradle` file and declare the TypeScript compiler version to use
78+
as follows:
79+
80+
{ "dependencies": { "typescript": "1.8.7" } }
81+
82+
83+
## Usage with local Node and TypeScript installation
84+
85+
This is not the recommended way of using the plugin. You should prefer to use it with the Node plugin.
86+
But if you have good reasons to do so, here is how...
1387

1488
You need to have installed node.js and installed the typescript node module:
1589

@@ -18,14 +92,16 @@ You need to have installed node.js and installed the typescript node module:
1892
Alternatively on windows you can install the Typescript SDK and configure the `compilerExecutable` config option to `tsc` - see *Available configuration options*.
1993

2094

21-
# Quickstart
95+
### Add plugin dependency
2296

23-
This will guide you through the steps needed to set up typescript-gradle-plugin for a TypeScript application project using Maven/Gradle standard layout.
97+
If you are using Gradle 2.1 or later, define the plugin dependency as follows:
2498

99+
plugins {
100+
id "de.richsource.gradle.plugins.typescript" version "1.8.0"
101+
}
25102

26-
## Plugin dependency
27103

28-
Build script snippet for use in all Gradle versions:
104+
If you are using Gradle 2.0 or earlier, define the plugin dependency as follows:
29105

30106
buildscript {
31107
repositories {
@@ -39,12 +115,6 @@ Build script snippet for use in all Gradle versions:
39115
}
40116

41117
apply plugin: "de.richsource.gradle.plugins.typescript"
42-
43-
Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:
44-
45-
plugins {
46-
id "de.richsource.gradle.plugins.typescript" version "1.8.0"
47-
}
48118

49119

50120
## Configuring the TypeScript compile task
@@ -120,6 +190,11 @@ Here is a list of the available configuration options of the _compileTypeScript_
120190
| `noImplicitUseStrict` | `boolean` | Do not emit "use strict" directives in module output |
121191

122192

193+
# Examples
194+
195+
Several example projects can be found in [/examples](examples).
196+
197+
123198
# Integrating the compiled files into a WAR file (for Java Webapps)
124199

125200
If you are integrating TypeScript into a Java web application, you can easily integrate the compiled files into the WAR file.

0 commit comments

Comments
 (0)