├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── examples
├── JavaTypescriptWebapp
│ ├── .gitignore
│ ├── WebContent
│ │ └── META-INF
│ │ │ └── MANIFEST.MF
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── demo
│ │ │ └── EchoServlet.java
│ │ ├── ts
│ │ ├── demo.ts
│ │ ├── demo2.ts
│ │ └── folder with spaces
│ │ │ └── demo.ts
│ │ └── webapp
│ │ └── WEB-INF
│ │ └── web.xml
├── ts15options
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ └── ts
│ │ └── root
│ │ ├── base.ts
│ │ └── helloworld.ts
└── tsconfigjson
│ ├── build.gradle
│ ├── index.html
│ ├── src
│ └── main
│ │ └── ts
│ │ ├── helloworld.ts
│ │ └── thisshouldnotbecompiled.ts
│ └── tsconfig.json
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── typescript-gradle-plugin
├── build.gradle
└── src
├── main
├── groovy
│ └── de
│ │ └── richsource
│ │ └── gradle
│ │ └── plugins
│ │ └── typescript
│ │ ├── CompileTypeScript.groovy
│ │ ├── Jsx.groovy
│ │ ├── Module.groovy
│ │ ├── ModuleResoltion.groovy
│ │ ├── Newline.groovy
│ │ ├── Target.groovy
│ │ └── TypescriptPlugin.groovy
└── resources
│ └── META-INF
│ └── gradle-plugins
│ └── de.richsource.gradle.plugins.typescript.properties
└── test
└── java
└── de
└── richsource
└── gradle
└── plugins
└── typescript
└── TypeScriptGradlePluginTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .gradle/
4 | .settings/
5 | build/
6 | bin/
7 | /repo/
8 | .metadata/
9 | /log.txt
10 | .idea/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sothmann/typescript-gradle-plugin/554b8bd040ae61a197f54fe3d8f5e09ddd8700b7/LICENSE
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TypeScript Gradle Plugin
2 |
3 | This plugin makes it easy to build TypeScript projects using Gradle.
4 | Among other things, the plugin provides a task to run the TypeScript compiler.
5 |
6 |
7 | # Quickstart
8 |
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
25 |
26 | Add a plugin dependency for the Node plugin and for the TypeScript Gradle plugin.
27 |
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...
87 |
88 | You need to have installed node.js and installed the typescript node module:
89 |
90 | npm install -g typescript
91 |
92 | Alternatively on windows you can install the Typescript SDK and configure the `compilerExecutable` config option to `tsc` - see *Available configuration options*.
93 |
94 |
95 | ### Add plugin dependency
96 |
97 | If you are using Gradle 2.1 or later, define the plugin dependency as follows:
98 |
99 | plugins {
100 | id "de.richsource.gradle.plugins.typescript" version "1.8.0"
101 | }
102 |
103 |
104 | If you are using Gradle 2.0 or earlier, define the plugin dependency as follows:
105 |
106 | buildscript {
107 | repositories {
108 | maven {
109 | url "https://plugins.gradle.org/m2/"
110 | }
111 | }
112 | dependencies {
113 | classpath "de.richsource.gradle.plugins:typescript-gradle-plugin:1.8.0"
114 | }
115 | }
116 |
117 | apply plugin: "de.richsource.gradle.plugins.typescript"
118 |
119 |
120 | ## Configuring the TypeScript compile task
121 |
122 | You can configure the TypeScript compile task as shown below:
123 |
124 | compileTypeScript {
125 | sourcemap = true
126 | // additional configuration options
127 | }
128 |
129 |
130 | ## Run the TypeScript compiler
131 |
132 | gradle compileTypeScript
133 |
134 |
135 | # Available configuration options
136 |
137 | Here is a list of the available configuration options of the _compileTypeScript_ task:
138 |
139 | | Option | Type | Description |
140 | | ---------------------------------- | --------- | --------------------------------------------------------------------------------------------------------- |
141 | | `source` | `File` | directories to compile, defaults to `src/main/ts` |
142 | | `outputDir` | `File` | the output directory, defaults to _buildDir_/ts |
143 | | `out` | `File` | DEPRECATED. Use `outFile` instead. |
144 | | `outFile` | `File` | Concatenate and emit output to single file, e.g. `file("${buildDir}/js/out.js")`. The order of concatenation is determined by the list of files passed to the compiler on the command line along with triple-slash references and imports. See output file order documentation for more details. |
145 | | `module` | [Module] | Specify module code generation (`AMD`, `COMMONJS`, `SYSTEM`, `UMD`, `ES6` or `ES2015`) |
146 | | `target` | [Target] | Specify ECMAScript target version (`ES3`, `ES5`, `ES6` or `ES2015`) |
147 | | `declaration` | `boolean` | Generates corresponding .d.ts file |
148 | | `noImplicitAny` | `boolean` | Warn on expressions and declarations with an implied 'any' type |
149 | | `noResolve` | `boolean` | Skip resolution and preprocessing |
150 | | `removeComments` | `boolean` | Do not emit comments to output |
151 | | `sourcemap` | `boolean` | Generates corresponding .map file |
152 | | `sourceRoot` | `File` | Specifies the location where debugger should locate TypeScript files instead of source locations |
153 | | `codepage` | `Integer` | Specify the codepage to use when opening source files |
154 | | `mapRoot` | `File` | Specifies the location where debugger should locate map files instead of generated locations |
155 | | `compilerExecutable` | `String` | The tsc compiler executable to use. Defaults to `cmd /c tsc.cmd` on windows and `tsc` on other systems. |
156 | | `noEmitOnError` | `boolean` | Do not emit outputs if any type checking errors were reported |
157 | | `noEmit` | `boolean` | Do not emit outputs |
158 | | `experimentalDecorators` | `boolean` | Enables experimental support for ES7 decorators |
159 | | `newline` | [Newline] | Specifies the end of line sequence to be used when emitting files (`CRLF` or `LF`) |
160 | | `preserveConstEnums` | `boolean` | Do not erase const enum declarations in generated code |
161 | | `projectFile` | `File` | Compile the project using the given tsconfig file, or - if a directory is specified - compile the project in the given directory where a tsconfig.json file is present. File specified with the `source` option will be ignore, but you should still explicitly configure the source files as this will make the Gradle UP-TO-DATE check work. |
162 | | `rootDir` | `File` | Specifies the root directory of input files. Use to control the output directory structure with `outDir`. |
163 | | `suppressImplicitAnyIndexErrors` | `boolean` | Suppress noImplicitAny errors for indexing objects lacking index signatures |
164 | | `noEmitHelpers` | `boolean` | Do not emit helpers like `__extends` |
165 | | `inlineSourceMap` | `boolean` | Causes source map files to be written inline in the generated .js files instead of in a independent .js.map file |
166 | | `inlineSources` | `boolean` | Allows for additionally inlining the source .ts file into the .js file when used in combination with `inlineSourceMap` |
167 | | `watch` | `boolean` | Watch input files |
168 | | `charset` | `String` | The character set of the input files |
169 | | `emitBOM` | `boolean` | Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files |
170 | | `emitDecoratorMetadata` | `boolean` | Emit design-type metadata for decorated declarations in source |
171 | | `isolatedModules` | `boolean` | Unconditionally emit imports for unresolved files |
172 | | `jsx` | [Jsx] | Specify JSX code generation (`PRESERVE` or `REACT`) |
173 | | `locale` | `String` | The locale to use to show error messages, e.g. `en-us` |
174 | | `moduleResolution` | [ModuleResoltion] | Specify module resolution strategy (`NODE` or `CLASSIC`) |
175 | | `noLib` | `boolean` | Do not include the default library file (`lib.d.ts`) |
176 | | `stripInternal` | `boolean` | Do not emit declarations for code that has an `/** @internal */` JSDoc annotation |
177 | | `diagnostics` | `boolean` | Show diagnostic information. |
178 | | `reactNamespace` | `String` | Specifies the object invoked for createElement and __spread when targeting 'react' JSX emit. |
179 | | `listFiles` | `boolean` | Print names of files part of the compilation. |
180 | | `skipDefaultLibCheck` | | |
181 | | `pretty` | `boolean` | Stylize errors and messages using color and context. |
182 | | `suppressExcessPropertyErrors` | `boolean` | Suppress excess property checks for object literals |
183 | | `allowUnusedLabels` | `boolean` | Do not report errors on unused labels |
184 | | `noImplicitReturns` | `boolean` | Report error when not all code paths in function return a value |
185 | | `noFallthroughCasesInSwitch` | `boolean` | Report errors for fallthrough cases in switch statement |
186 | | `allowUnreachableCode` | `boolean` | Do not report errors on unreachable code |
187 | | `forceConsistentCasingInFileNames` | `boolean` | Disallow inconsistently-cased references to the same file |
188 | | `allowSyntheticDefaultImports` | `boolean` | Allow default imports from modules with no default export. This does not affect code emit, just typechecking. |
189 | | `allowJs` | `boolean` | Allow JavaScript files to be compiled |
190 | | `noImplicitUseStrict` | `boolean` | Do not emit "use strict" directives in module output |
191 |
192 |
193 | # Examples
194 |
195 | Several example projects can be found in [/examples](examples).
196 |
197 |
198 | # Integrating the compiled files into a WAR file (for Java Webapps)
199 |
200 | If you are integrating TypeScript into a Java web application, you can easily integrate the compiled files into the WAR file.
201 | All you have to do is to configure the war task to pick up the compiled files.
202 | Whenever you call the war task, the TypeScript compiler will compile your TypeScript files first.
203 | In the example below, the compiled files will be put into the js directory in the WAR file.
204 |
205 | apply plugin: "war"
206 |
207 | war {
208 | into("js") {
209 | from compileTypeScript.outputs
210 | }
211 | }
212 |
213 |
214 | # Configuring multiple source directories
215 |
216 | You can configure the TypeScript compile task to use multiple source directories as shown below:
217 |
218 | compileTypeScript {
219 | source = [file("src/main/ts"), file("src/main/additionalts")]
220 | }
221 |
222 | [ModuleResoltion]: typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/ModuleResoltion.groovy
223 | [Jsx]: typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Jsx.groovy
224 | [Newline]: typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Newline.groovy
225 | [Target]: typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Target.groovy
226 | [Module]: typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Module.groovy
227 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sothmann/typescript-gradle-plugin/554b8bd040ae61a197f54fe3d8f5e09ddd8700b7/build.gradle
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /build
3 | /npm-debug.log
4 |
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/WebContent/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/build.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: "war"
18 | apply plugin: "eclipse"
19 | apply plugin: "typescript"
20 |
21 | buildscript {
22 | repositories {
23 | maven {
24 | url new File(projectDir.parentFile.parentFile, 'repo').toURI()
25 | }
26 | }
27 | dependencies {
28 | classpath 'de.richsource.gradle.plugins:typescript-gradle-plugin:1.8.0'
29 | }
30 | }
31 |
32 | repositories {
33 | mavenCentral()
34 | }
35 |
36 | dependencies {
37 | providedCompile "javax.servlet:servlet-api:2.5"
38 | }
39 |
40 | sourceCompatibility = 1.6
41 | targetCompatibility = 1.6
42 |
43 | war {
44 | into("js") {
45 | from compileTypeScript.outputs
46 | }
47 | }
48 |
49 | compileTypeScript {
50 | declaration = true
51 | target = "ES5"
52 | }
53 |
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sothmann/typescript-gradle-plugin/554b8bd040ae61a197f54fe3d8f5e09ddd8700b7/examples/JavaTypescriptWebapp/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 07 11:47:57 CET 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.3-all.zip
7 |
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/src/main/java/demo/EchoServlet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package demo;
18 |
19 | import java.io.IOException;
20 |
21 | import javax.servlet.ServletException;
22 | import javax.servlet.http.HttpServlet;
23 | import javax.servlet.http.HttpServletRequest;
24 | import javax.servlet.http.HttpServletResponse;
25 |
26 | public class EchoServlet extends HttpServlet {
27 | private static final long serialVersionUID = 1L;
28 |
29 | @Override
30 | protected void doGet(HttpServletRequest req, HttpServletResponse resp)
31 | throws ServletException, IOException {
32 | resp.getOutputStream().println("Hello World");
33 | }
34 | }
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/src/main/ts/demo.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | console.log("Hello World");
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/src/main/ts/demo2.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | console.log("Hello World 2");
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/src/main/ts/folder with spaces/demo.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | console.log("Hello World");
--------------------------------------------------------------------------------
/examples/JavaTypescriptWebapp/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | EchoServlet
8 | EchoServlet
9 | demo.EchoServlet
10 | 1
11 |
12 |
13 |
14 | EchoServlet
15 | /echo
16 |
17 |
18 |
--------------------------------------------------------------------------------
/examples/ts15options/build.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: "eclipse"
18 | apply plugin: "typescript"
19 |
20 | buildscript {
21 | repositories {
22 | maven {
23 | url new File(projectDir.parentFile.parentFile, 'repo').toURI()
24 | }
25 | }
26 | dependencies {
27 | classpath 'de.richsource.gradle.plugins:typescript-gradle-plugin:1.8.0'
28 | }
29 | }
30 |
31 | repositories {
32 | mavenCentral()
33 | }
34 |
35 | dependencies {
36 | }
37 |
38 | compileTypeScript {
39 | module = 'UMD'
40 | experimentalDecorators = true
41 | preserveConstEnums = true
42 | rootDir = new File('src/main/ts')
43 | suppressImplicitAnyIndexErrors = true
44 | noEmitHelpers = true
45 | inlineSourceMap = true
46 | inlineSources = true
47 | }
48 |
--------------------------------------------------------------------------------
/examples/ts15options/src/main/ts/root/base.ts:
--------------------------------------------------------------------------------
1 | namespace helloworld {
2 | export class Base {
3 | greet(): void {
4 | console.log("hello from Base");
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/examples/ts15options/src/main/ts/root/helloworld.ts:
--------------------------------------------------------------------------------
1 | namespace helloworld {
2 |
3 | export class Demo extends Base {
4 | greet(): void {
5 | super.greet();
6 | console.log("hello world");
7 | }
8 | }
9 |
10 | }
11 |
12 | var demo = new helloworld.Demo();
13 | demo.greet();
--------------------------------------------------------------------------------
/examples/tsconfigjson/build.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: "eclipse"
18 | apply plugin: "typescript"
19 |
20 | buildscript {
21 | repositories {
22 | maven {
23 | url new File(projectDir.parentFile.parentFile, 'repo').toURI()
24 | }
25 | }
26 | dependencies {
27 | classpath 'de.richsource.gradle.plugins:typescript-gradle-plugin:1.8.0'
28 | }
29 | }
30 |
31 | repositories {
32 | mavenCentral()
33 | }
34 |
35 | dependencies {
36 | }
37 |
38 | compileTypeScript {
39 | projectFileDir = new File('.')
40 | }
41 |
--------------------------------------------------------------------------------
/examples/tsconfigjson/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/examples/tsconfigjson/src/main/ts/helloworld.ts:
--------------------------------------------------------------------------------
1 | namespace helloworld {
2 |
3 | export class Demo {
4 | greet(): void {
5 | console.log("hello world");
6 | }
7 | }
8 |
9 | }
10 |
11 | var demo = new helloworld.Demo();
12 | demo.greet();
--------------------------------------------------------------------------------
/examples/tsconfigjson/src/main/ts/thisshouldnotbecompiled.ts:
--------------------------------------------------------------------------------
1 | console.log("this should not be compiled as this file is not referenced in the tsconfig.json file");
--------------------------------------------------------------------------------
/examples/tsconfigjson/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "amd",
4 | "noImplicitAny": true,
5 | "removeComments": true,
6 | "preserveConstEnums": true,
7 | "inlineSourceMap": true,
8 | "inlineSources": true
9 | },
10 | "files": [
11 | "src/main/ts/helloworld.ts"
12 | ]
13 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | version=1.8.0
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sothmann/typescript-gradle-plugin/554b8bd040ae61a197f54fe3d8f5e09ddd8700b7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 07 11:47:57 CET 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'typescript-gradle-plugin'
--------------------------------------------------------------------------------
/typescript-gradle-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.gradle.plugin-publish" version "0.9.2"
3 | }
4 |
5 | repositories {
6 | mavenCentral()
7 | jcenter()
8 | }
9 |
10 | apply plugin: 'groovy'
11 | apply plugin: 'eclipse'
12 | apply plugin: 'maven-publish'
13 |
14 | // Write the plugin's classpath to a file to share with the tests
15 | task createClasspathManifest {
16 | def outputDir = file("$buildDir/$name")
17 |
18 | inputs.files sourceSets.main.runtimeClasspath
19 | outputs.dir outputDir
20 |
21 | doLast {
22 | outputDir.mkdirs()
23 | file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n")
24 | }
25 | }
26 |
27 | sourceCompatibility = 1.6
28 | targetCompatibility = 1.6
29 |
30 | dependencies {
31 | compile gradleApi()
32 |
33 | testCompile gradleTestKit()
34 | testCompile 'junit:junit:4.12'
35 | testRuntime files(createClasspathManifest)
36 | }
37 |
38 | ext {
39 | encoding = "UTF-8"
40 | }
41 |
42 | tasks.eclipse << {
43 | File prefs = project.file('.settings/org.eclipse.core.resources.prefs');
44 | if(!prefs.exists()) {
45 | project.file('.settings/org.eclipse.core.resources.prefs')<< "eclipse.preferences.version=1\nencoding/=$encoding\n";
46 | }
47 | }
48 |
49 | tasks.withType(GroovyCompile) {
50 | options.encoding = encoding
51 | }
52 | tasks.withType(JavaCompile) {
53 | options.encoding = encoding
54 | }
55 |
56 | task sourceJar(type: Jar) {
57 | classifier = 'sources'
58 | from sourceSets.main.allSource
59 | }
60 |
61 | task javadocJar (type: Jar, dependsOn: [javadoc, groovydoc]) {
62 | classifier = 'javadoc'
63 | from javadoc.destinationDir
64 | from groovydoc.destinationDir
65 | }
66 |
67 | javadoc {
68 | options {
69 | links 'http://www.gradle.org/docs/current/javadoc/', 'http://docs.oracle.com/javase/7/docs/api/'
70 | }
71 | }
72 |
73 | group='de.richsource.gradle.plugins'
74 | publishing {
75 | publications {
76 | mavenJava(MavenPublication) {
77 | from components.java
78 | artifact javadocJar { classifier = 'javadoc' }
79 | artifact sourceJar { classifier = 'sources' }
80 | pom.withXml {
81 | def root = asNode()
82 | root.appendNode('name', 'TypeScript Gradle plugin')
83 | root.appendNode('description', 'Gradle plugin to support TypeScript related tasks.')
84 | root.appendNode('inceptionYear', '2014')
85 | def license = root.appendNode('licenses').appendNode('license')
86 | license.appendNode('name', 'Apache License, Version 2.0')
87 | license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt')
88 | }
89 | }
90 | }
91 | repositories {
92 | maven {
93 | url new File(rootProject.projectDir, 'repo').toURI()
94 | }
95 | }
96 | }
97 |
98 | pluginBundle {
99 | website = 'https://github.com/sothmann/typescript-gradle-plugin'
100 | vcsUrl = 'https://github.com/sothmann/typescript-gradle-plugin'
101 | description = 'This plugin makes it easy to build TypeScript projects using Gradle. Among other things, the plugin provides a task to run the TypeScript compiler.'
102 | tags = ['typescript']
103 |
104 | plugins {
105 | typescriptPlugin {
106 | id = 'de.richsource.gradle.plugins.typescript'
107 | displayName = 'TypeScript Gradle Plugin'
108 | }
109 | }
110 |
111 | mavenCoordinates {
112 | groupId = "de.richsource.gradle.plugins"
113 | artifactId = "typescript-gradle-plugin"
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/CompileTypeScript.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | import org.gradle.api.file.FileTree
20 | import org.gradle.api.tasks.OutputFile;
21 | import org.gradle.api.tasks.SourceTask
22 | import org.gradle.api.tasks.Input
23 | import org.gradle.api.tasks.Optional;
24 | import org.gradle.api.tasks.OutputDirectory
25 | import org.gradle.api.tasks.TaskAction
26 | import org.gradle.api.InvalidUserDataException
27 | import org.apache.tools.ant.taskdefs.condition.Os
28 |
29 | public class CompileTypeScript extends SourceTask {
30 |
31 | @OutputDirectory @Optional File outputDir;
32 | @OutputFile @Optional File out
33 | @OutputFile @Optional outFile
34 | @Input @Optional Module module
35 | @Input @Optional Target target
36 | @Input @Optional boolean declaration
37 | @Input @Optional boolean noImplicitAny
38 | @Input @Optional boolean noResolve
39 | @Input @Optional boolean removeComments
40 | @Input @Optional boolean sourcemap
41 | @Input @Optional File sourceRoot
42 | @Input @Optional Integer codepage
43 | @Input @Optional File mapRoot
44 | @Input @Optional boolean noEmitOnError
45 | @Input @Optional boolean noEmit
46 | @Input @Optional boolean experimentalDecorators
47 | @Input @Optional Newline newline
48 | @Input @Optional boolean preserveConstEnums
49 | @Input @Optional File projectFile
50 | @Input @Optional File rootDir
51 | @Input @Optional boolean suppressImplicitAnyIndexErrors
52 | @Input @Optional boolean noEmitHelpers
53 | @Input @Optional boolean inlineSourceMap
54 | @Input @Optional boolean inlineSources
55 | @Input @Optional boolean watch
56 | @Input @Optional String charset
57 | @Input @Optional boolean emitBOM
58 | @Input @Optional boolean emitDecoratorMetadata
59 | @Input @Optional boolean isolatedModules
60 | @Input @Optional Jsx jsx
61 | @Input @Optional String locale
62 | @Input @Optional ModuleResoltion moduleResolution
63 | @Input @Optional boolean noLib
64 | @Input @Optional boolean stripInternal
65 | @Input @Optional boolean diagnostics
66 | @Input @Optional String reactNamespace
67 | @Input @Optional boolean listFiles
68 | @Input @Optional boolean skipDefaultLibCheck
69 | @Input @Optional boolean pretty
70 | @Input @Optional boolean suppressExcessPropertyErrors
71 | @Input @Optional boolean allowUnusedLabels
72 | @Input @Optional boolean noImplicitReturns
73 | @Input @Optional boolean noFallthroughCasesInSwitch
74 | @Input @Optional boolean allowUnreachableCode
75 | @Input @Optional boolean forceConsistentCasingInFileNames
76 | @Input @Optional boolean allowSyntheticDefaultImports
77 | @Input @Optional boolean allowJs
78 | @Input @Optional boolean noImplicitUseStrict
79 | @Input String compilerExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? "cmd /c tsc.cmd" : "tsc"
80 |
81 | @TaskAction
82 | void compile() {
83 | logger.info "compiling TypeScript files..."
84 |
85 | validate()
86 |
87 | File tsCompilerArgsFile = createTsCompilerArgsFile()
88 | logger.debug("Contents of typescript compiler arguments file: " + tsCompilerArgsFile.text)
89 |
90 | List compilerExecutableAndArgs = compilerExecutable.split(" ").findAll { it.length() > 0 }
91 | String exe = compilerExecutableAndArgs[0]
92 | List arguments = compilerExecutableAndArgs.tail() + ('@' + tsCompilerArgsFile)
93 | project.exec {
94 | executable = exe
95 | args = arguments
96 | }
97 |
98 | logger.info "Done TypeScript compilation."
99 | if(tsCompilerArgsFile.exists()) {
100 | tsCompilerArgsFile.delete()
101 | }
102 | }
103 |
104 | private File createTsCompilerArgsFile() {
105 | File tsCompilerArgsFile = File.createTempFile("tsCompiler-", ".args")
106 | tsCompilerArgsFile.deleteOnExit()
107 |
108 | addFlagsIfPresent(tsCompilerArgsFile, [
109 | 'declaration': declaration,
110 | 'noImplicitAny': noImplicitAny,
111 | 'noResolve': noResolve,
112 | 'removeComments': removeComments,
113 | 'sourceMap': sourcemap,
114 | 'noEmitOnError': noEmitOnError,
115 | 'noEmit': noEmit,
116 | 'experimentalDecorators': experimentalDecorators,
117 | 'preserveConstEnums': preserveConstEnums,
118 | 'suppressImplicitAnyIndexErrors': suppressImplicitAnyIndexErrors,
119 | 'noEmitHelpers': noEmitHelpers,
120 | 'inlineSourceMap': inlineSourceMap,
121 | 'inlineSources': inlineSources,
122 | 'watch': watch,
123 | 'emitBOM': emitBOM,
124 | 'emitDecoratorMetadata': emitDecoratorMetadata,
125 | 'isolatedModules': isolatedModules,
126 | 'noLib': noLib,
127 | 'stripInternal': stripInternal,
128 | 'diagnostics': diagnostics,
129 | 'listFiles': listFiles,
130 | 'skipDefaultLibCheck': skipDefaultLibCheck,
131 | 'pretty': pretty,
132 | 'suppressExcessPropertyErrors': suppressExcessPropertyErrors,
133 | 'allowUnusedLabels': allowUnusedLabels,
134 | 'noImplicitReturns': noImplicitReturns,
135 | 'noFallthroughCasesInSwitch': noFallthroughCasesInSwitch,
136 | 'allowUnreachableCode': allowUnreachableCode,
137 | 'forceConsistentCasingInFileNames': forceConsistentCasingInFileNames,
138 | 'allowSyntheticDefaultImports': allowSyntheticDefaultImports,
139 | 'allowJs': allowJs,
140 | 'noImplicitUseStrict': noImplicitUseStrict
141 | ])
142 |
143 | addOptionsIfPresent(tsCompilerArgsFile, [
144 | 'outDir': outputDir,
145 | 'out': out,
146 | 'outFile': outFile,
147 | 'project': projectFile,
148 | 'rootDir': rootDir,
149 | 'mapRoot': mapRoot,
150 | 'sourceRoot': sourceRoot,
151 | 'locale': locale,
152 | 'charset': charset,
153 | 'codepage': codepage,
154 | 'module': module ? module.name().toLowerCase() : null,
155 | 'target': target ? target.name() : null,
156 | 'newLine': newline ? newline.name() : null,
157 | 'jsx': jsx ? jsx.name().toLowerCase() : null,
158 | 'reactNamespace': reactNamespace,
159 | 'moduleResolution': moduleResolution ? moduleResolution.name().toLowerCase() : null
160 | ])
161 |
162 | addSourceFilesIfPresent(tsCompilerArgsFile, source, projectFile)
163 |
164 | return tsCompilerArgsFile
165 | }
166 |
167 | private void addSourceFilesIfPresent(File tsCompilerArgsFile, FileTree source, File projectFile) {
168 | List files = source.collect { File f -> return "\"${f.toString();}\"" };
169 | logger.debug("TypeScript files to compile: " + files.join(" "));
170 | if (files) {
171 | if (projectFile) {
172 | logger.info("Source provided in combination with projectFile. Source option will be ignored.")
173 | } else {
174 | tsCompilerArgsFile.append(" " + files.join(" "))
175 | }
176 | }
177 | }
178 |
179 | private void addFlagsIfPresent(File tsCompilerArgsFile, Map potentialFlags) {
180 | potentialFlags.each { String flagName, Object flagValue ->
181 | if(flagValue) {
182 | tsCompilerArgsFile.append(" --${flagName}")
183 | }
184 | }
185 | }
186 |
187 | private void addOptionsIfPresent(File tsCompilerArgsFile, Map potentialOptions) {
188 | for (Map.Entry entry : potentialOptions.entrySet()) {
189 | String optionName = entry.getKey()
190 | Object optionValue = entry.getValue()
191 | if(optionValue) {
192 | addOption(tsCompilerArgsFile, optionName, optionValue)
193 | }
194 | }
195 | }
196 |
197 | private void addOption(File tsCompilerArgsFile, String optionName, Object option) {
198 | if(option instanceof File) {
199 | tsCompilerArgsFile.append(" --${optionName} \"${option}\"")
200 | } else {
201 | tsCompilerArgsFile.append(" --${optionName} ${option}")
202 | }
203 | }
204 |
205 | private void validate() {
206 | if(sourcemap && inlineSourceMap) {
207 | throw new InvalidUserDataException("Option 'sourcemap' cannot be specified with option 'inlineSourceMap'")
208 | }
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Jsx.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | enum Jsx {
20 | PRESERVE, REACT
21 | }
22 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Module.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | enum Module {
20 | AMD, COMMONJS, SYSTEM, UMD, ES6, ES2015
21 | }
22 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/ModuleResoltion.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | enum ModuleResoltion {
20 | CLASSIC, NODE
21 | }
22 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Newline.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | enum Newline {
20 | CRLF, LF
21 | }
22 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/Target.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | enum Target {
20 | ES3, ES5, ES6, ES2015
21 | }
22 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/groovy/de/richsource/gradle/plugins/typescript/TypescriptPlugin.groovy:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript
18 |
19 | import org.gradle.api.Plugin
20 | import org.gradle.api.Project;
21 |
22 | class TypescriptPlugin implements Plugin {
23 |
24 | public void apply(Project project) {
25 | project.tasks.create("compileTypeScript", CompileTypeScript) {
26 | source = project.file('src/main/ts')
27 | include '**/*.ts'
28 | outputDir = project.file("${project.buildDir}/ts")
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/main/resources/META-INF/gradle-plugins/de.richsource.gradle.plugins.typescript.properties:
--------------------------------------------------------------------------------
1 | implementation-class=de.richsource.gradle.plugins.typescript.TypescriptPlugin
2 |
--------------------------------------------------------------------------------
/typescript-gradle-plugin/src/test/java/de/richsource/gradle/plugins/typescript/TypeScriptGradlePluginTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2014 Sönke Sothmann
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package de.richsource.gradle.plugins.typescript;
18 |
19 | import static org.gradle.testkit.runner.TaskOutcome.FAILED;
20 | import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
21 | import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE;
22 | import static org.junit.Assert.*;
23 |
24 | import java.io.BufferedReader;
25 | import java.io.BufferedWriter;
26 | import java.io.File;
27 | import java.io.FileFilter;
28 | import java.io.FileReader;
29 | import java.io.FileWriter;
30 | import java.io.IOException;
31 | import java.net.URL;
32 | import java.util.*;
33 |
34 | import org.apache.commons.io.FileUtils;
35 | import org.apache.commons.lang.StringUtils;
36 | import org.gradle.testkit.jarjar.org.apache.commons.io.filefilter.NameFileFilter;
37 | import org.gradle.testkit.runner.BuildResult;
38 | import org.gradle.testkit.runner.GradleRunner;
39 | import org.junit.Before;
40 | import org.junit.Rule;
41 | import org.junit.Test;
42 | import org.junit.rules.TemporaryFolder;
43 |
44 | public class TypeScriptGradlePluginTest {
45 | @Rule
46 | public final TemporaryFolder testProjectDir = new TemporaryFolder();
47 | private File buildFile;
48 | private List pluginClasspath;
49 |
50 | @Before
51 | public void setup() throws IOException {
52 | testProjectDir.newFolder("src", "main", "ts");
53 | buildFile = testProjectDir.newFile("build.gradle");
54 | URL pluginClasspathResource = getClass().getClassLoader().getSystemResource("plugin-classpath.txt");
55 | if (pluginClasspathResource == null) {
56 | throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.");
57 | }
58 |
59 | pluginClasspath = readPluginClasspath(pluginClasspathResource);
60 | }
61 |
62 | private List readPluginClasspath(URL pluginClasspathResource) throws IOException {
63 | File pluginClasspathManifest = new File(pluginClasspathResource.getFile());
64 | BufferedReader reader = new BufferedReader(new FileReader(pluginClasspathManifest));
65 | String line;
66 | List files = new ArrayList();
67 | while((line = reader.readLine()) != null) {
68 | files.add(new File(line));
69 | }
70 | return files;
71 | }
72 |
73 | @Test
74 | public void given_declarationOptionIsTrue_when_compileTypeScript_then_expectCompiledJsFileAndDeclarationFile()
75 | throws IOException {
76 | Map compilerOptions = new HashMap();
77 | compilerOptions.put("declaration", "true");
78 | compilerOptions.put("target", "\"ES5\"");
79 | createBuildFile(compilerOptions);
80 | createTSFile("src/main/ts/test.ts", "Test");
81 |
82 | BuildResult result = executeCompileTypeScriptTask();
83 |
84 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
85 | assertFilesInDir(defaultOutputDir(), "test.js", "test.d.ts");
86 | }
87 |
88 | @Test
89 | public void given_sourcemapAndInlineSourceMapOptionsBothPresent_when_compileTypeScript_then_expectValidationError()
90 | throws IOException {
91 | Map compilerOptions = new HashMap();
92 | compilerOptions.put("sourcemap", "true");
93 | compilerOptions.put("inlineSourceMap", "true");
94 | createBuildFile(compilerOptions);
95 |
96 | createTSFile("src/main/ts/test.ts", "Test");
97 |
98 | BuildResult result = GradleRunner.create()
99 | .withProjectDir(testProjectDir.getRoot())
100 | .withArguments("compileTypeScript", "--info")
101 | .withPluginClasspath(pluginClasspath)
102 | .buildAndFail();
103 |
104 | assertEquals(FAILED, result.task(":compileTypeScript").getOutcome());
105 | assertTrue("validation error expected", result.getOutput().contains("Option 'sourcemap' cannot be specified with option 'inlineSourceMap'"));
106 | }
107 |
108 | @Test
109 | public void given_moduleAmdAndOutDir_when_compileTypeScript_then_expectAmdModuleEmittedInOutDir()
110 | throws IOException {
111 | Map compilerOptions = new HashMap();
112 | compilerOptions.put("module", "\"AMD\"");
113 | compilerOptions.put("outputDir", "file(\"build/js\")");
114 | createBuildFile(compilerOptions);
115 |
116 | createTSFile("src/main/ts/test.ts", "TestClass", "import SecondTestClass from \"test2\";\n", "new SecondTestClass();");
117 | createTSFile("src/main/ts/test2.ts", "SecondTestClass", null, "export default SecondTestClass;");
118 |
119 | BuildResult result = executeCompileTypeScriptTask();
120 |
121 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
122 | File tsOutputDir = new File(testProjectDir.getRoot(), "build/js");
123 | assertFilesInDir(tsOutputDir, "test.js", "test2.js");
124 | assertFileContains(new File(tsOutputDir, "test.js"), "TestClass", "define([\"require\", \"exports\", \"test2\"]");
125 | assertFileContains(new File(tsOutputDir, "test2.js"), "define([\"require\", \"exports\"]", "exports[\"default\"] = SecondTestClass;");
126 | }
127 |
128 | @Test
129 | public void given_noSourceFile_when_compileTypeScript_then_expectUpToDate()
130 | throws IOException {
131 | createBuildFile(new HashMap());
132 |
133 | BuildResult result = executeCompileTypeScriptTask();
134 |
135 | assertEquals(UP_TO_DATE, result.task(":compileTypeScript").getOutcome());
136 | }
137 |
138 | @Test
139 | public void given_twoSourceFiles_when_compileTypeScript_then_expectTwoOutputFiles()
140 | throws IOException {
141 | createBuildFile(new HashMap());
142 | createTSFile("src/main/ts/test.ts", "Test");
143 | createTSFile("src/main/ts/test2.ts", "Test2");
144 |
145 | BuildResult result = executeCompileTypeScriptTask();
146 |
147 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
148 | assertFilesInDir(defaultOutputDir(), "test.js", "test2.js");
149 | }
150 |
151 | @Test
152 | public void given_twoSourceFilesAndOutOption_when_compileTypeScript_then_expectSingleOutputFile()
153 | throws IOException {
154 | Map compilerOptions = new HashMap();
155 | compilerOptions.put("out", "file(\"build/js/out.js\")");
156 | createBuildFile(compilerOptions);
157 | createTSFile("src/main/ts/test.ts", "Test");
158 | createTSFile("src/main/ts/test2.ts", "Test2");
159 |
160 | BuildResult result = executeCompileTypeScriptTask();
161 |
162 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
163 | File tsOutputDir = new File(testProjectDir.getRoot(), "build/js");
164 | assertFilesInDir(tsOutputDir, "out.js");
165 | }
166 |
167 | @Test
168 | public void given_TsAndJsFilesAndOutFileAndAllowJsOption_when_compileTypeScript_then_expectSingleOutputFile()
169 | throws IOException {
170 | Map compilerOptions = new HashMap();
171 | compilerOptions.put("outFile", "file(\"build/js/out.js\")");
172 | compilerOptions.put("allowJs", "true");
173 | compilerOptions.put("module", "\"AMD\"");
174 | createBuildFile(compilerOptions);
175 | createTSFile("src/main/ts/typescript.ts", "TypeScriptClass", "import js from \"javascript\";\n", null);
176 | createJSFile("src/main/ts/javascript.js", "jsFunction");
177 |
178 | BuildResult result = executeCompileTypeScriptTask();
179 |
180 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
181 | File tsOutputDir = new File(testProjectDir.getRoot(), "build/js");
182 | assertFilesInDir(tsOutputDir, "out.js");
183 | assertFileContains(new File(tsOutputDir, "out.js"), "TypeScriptClass", "jsFunction", "define(\"javascript\"", "define(\"typescript\"");
184 | }
185 |
186 | private void assertFileContains(File file, String... expectedStrings) throws IOException {
187 | String fileContents = FileUtils.readFileToString(file);
188 | for (String expectedString : expectedStrings) {
189 | assertTrue("expected string " + expectedString, fileContents.contains(expectedString));
190 | }
191 | }
192 |
193 | @Test
194 | public void given_multipleFlagsEnabled_when_compileTypeScript_then_expectSuccess()
195 | throws IOException {
196 | List flags = Arrays.asList("declaration", "noImplicitAny", "noResolve", "removeComments",
197 | "noEmitOnError", "experimentalDecorators", "preserveConstEnums",
198 | "suppressImplicitAnyIndexErrors", "noEmitHelpers", "inlineSourceMap", "inlineSources", "emitBOM",
199 | "emitDecoratorMetadata", "stripInternal", "listFiles", "skipDefaultLibCheck", "pretty",
200 | "suppressExcessPropertyErrors", "allowUnusedLabels", "noImplicitReturns", "noFallthroughCasesInSwitch",
201 | "allowUnreachableCode", "forceConsistentCasingInFileNames", "allowSyntheticDefaultImports",
202 | "noImplicitUseStrict");
203 | Map compilerOptions = new HashMap();
204 | for(String flag : flags) {
205 | compilerOptions.put(flag, "true");
206 | }
207 | createBuildFile(compilerOptions);
208 | createTSFile("src/main/ts/test.ts", "Test");
209 |
210 | BuildResult result = executeCompileTypeScriptTask();
211 |
212 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
213 | assertFilesInDir(defaultOutputDir(), "test.js", "test.d.ts");
214 | }
215 |
216 | @Test
217 | public void given_sourcemapFlagEnabled_when_compileTypeScript_then_expectJsAndMapFile()
218 | throws IOException {
219 | Map compilerOptions = new HashMap();
220 | compilerOptions.put("sourcemap", "true");
221 | createBuildFile(compilerOptions);
222 | createTSFile("src/main/ts/test.ts", "Test");
223 |
224 | BuildResult result = executeCompileTypeScriptTask();
225 |
226 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
227 | assertFilesInDir(defaultOutputDir(), "test.js", "test.js.map");
228 | }
229 |
230 | private BuildResult executeCompileTypeScriptTask() {
231 | return GradleRunner.create()
232 | .withProjectDir(testProjectDir.getRoot())
233 | .withArguments("compileTypeScript", "--info")
234 | .withPluginClasspath(pluginClasspath)
235 | .build();
236 | }
237 |
238 | @Test
239 | public void when_compileTypeScriptSucceeds_expect_noTsCompilerArgsFileRemains()
240 | throws IOException {
241 | createBuildFile(new HashMap());
242 | createTSFile("src/main/ts/test.ts", "Test");
243 |
244 | BuildResult result = executeCompileTypeScriptTask();
245 |
246 | assertEquals(SUCCESS, result.task(":compileTypeScript").getOutcome());
247 | File tempDir = new File(System.getProperty("java.io.tmpdir"));
248 | for(String file : tempDir.list()) {
249 | assertFalse(file.matches("tsCompiler-.*\\.args"));
250 | }
251 | }
252 |
253 | private void assertFilesInDir(File directory, String... filenames) {
254 | assertNotNull(directory.listFiles());
255 | assertEquals(filenames.length, directory.listFiles().length);
256 | for(String filename : filenames) {
257 | assertEquals(
258 | "expected file " + filename + " in directory " + directory,
259 | 1,
260 | directory.listFiles((FileFilter) new NameFileFilter(filename)).length);
261 | }
262 | }
263 |
264 | private void createTSFile(String pathAndFilename, String className) throws IOException {
265 | createTSFile(pathAndFilename, className, null, null);
266 | }
267 |
268 | private void createTSFile(String pathAndFilename, String className, String optionalHeader, String optionalFooter) throws IOException {
269 | File tsFile = testProjectDir.newFile(pathAndFilename);
270 | writeFile(tsFile, (optionalHeader!=null?optionalHeader:"") + "class " + className + " {\n" +
271 | " greet(): void {\n" +
272 | " console.log(\"hello world\");\n" +
273 | " }\n" +
274 | "}\n" +
275 | "\n" +
276 | "new " + className + "().greet();\n" + (optionalFooter!=null?optionalFooter:""));
277 | }
278 |
279 | private void createJSFile(String pathAndFilename, String functionName) throws IOException {
280 | File jsFile = testProjectDir.newFile(pathAndFilename);
281 | writeFile(jsFile, "export default function " + functionName + "() {\n" +
282 | " console.log(\"hello world\");\n" +
283 | "}\n");
284 | }
285 |
286 | private void createBuildFile(Map compilerOptions) throws IOException {
287 | StringBuilder buildFileContent = new StringBuilder("plugins {\n" +
288 | "id 'de.richsource.gradle.plugins.typescript'\n" +
289 | "}\n" +
290 | "compileTypeScript {\n");
291 | for (Map.Entry entry : compilerOptions.entrySet()) {
292 | String optionName = entry.getKey();
293 | Object optionValue = entry.getValue();
294 | buildFileContent.append(optionName + " = " + optionValue + "\n");
295 | }
296 | buildFileContent.append("}");
297 | writeFile(buildFile, buildFileContent.toString());
298 | }
299 |
300 | private void writeFile(File destination, String content) throws IOException {
301 | BufferedWriter output = null;
302 | try {
303 | output = new BufferedWriter(new FileWriter(destination));
304 | output.write(content);
305 | } finally {
306 | if (output != null) {
307 | output.close();
308 | }
309 | }
310 | }
311 |
312 | private File defaultOutputDir() {
313 | return new File(testProjectDir.getRoot(), "build/ts");
314 | }
315 | }
316 |
--------------------------------------------------------------------------------