Plugin for the Gradle build system for projects that use the TypeScript programming language
Simply add the plugin to your Gradle build
apply plugin: 'typescript'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'at.irian.typescript', name: 'gradle-typescript-plugin', version: '0.12'
}
}
Have a look at the sample project to see how to structure your project, reference libraries and test your code.
- Gradle >=1.10
- Node.js, PhantomJS, RequireJS, TypeScript
- Your source and your libraries use AMD modules
Run
gradle tasks --all
to see all available tasks.
you can set various configuration properties of the plugin to reflect your project structure:
typescript {
configProp1 = "someValue"
configProp2 = "someOtherValue"
}
The following configurations properties are available:
sourcePath
- path (relative to project root) to the directory containing your TypeScript sources. Default issrc/main/typescript
testSourcePath
- path (relative to project root) to the directory containing your TypeScript tests sources. Default issrc/test/typescript
generatedJsPath
- output directory (relative to project root) for the TypeScript compiler. Default is${project.buildDir}/generatedJs
(=build/generatedJs
unless you have configured yourbuildDir
differently)requireJsConfig
- the filename of your RequireJS config (paths, shims for your libraries). Must be insourcePath
and define a global variable with the namerequireConfig
. Default isrequirejsConfig.js
requireConfigGlobalVarName
- allows you to change the name of the global variable described in previous point. Default isrequireConfig
tscOptions
- a string array with additional that will be passed to the TypeScript compiler. Default is empty.cleanMainExcludes
- a list of path patterns that will not be deleted when cleaninggeneratedJs
during thecleanMain
task. This is usefull when pointinggeneratedJsPath
to the same directory assourcePath
. Default is empty.vendorPath
- path (relative tosourcePath
) to the directory that conains your 3rd party JavaScript libraries. Default isvendor
combineJsModules
- list of names of modules that will be passed to the RequireJS optimizer when generating a single JavaScript file with all your code. This should be the modules(s) that contain the entry-point(s) to your application. See the sample project for details. Default is empty.includeLibsInCombinedJs
- whether or not 3rd parth JavaScript libraries (configured in yourrequireJsConfig
) should be included in the result of the RequireJS optimizer. Default istrue
#Tests#
##Writing tests##
This plugin supports compiling and running Jasmine tests written in TypeScript. You can run the task initTypeScriptTestResources
to copy the Jasmine type definition file (jasmine.d.ts) into your test folder. The Jasmine test runner is provided and automatically configured by this plugin.
##Running tests##
This plugin allows you to run tests as part of your build cycle. There are two different modes for running tests:
- On the command line - the
test
task. This is useful for quickly checking that everything still works (TDD) or for your CI-build. A nice report is written to the console showing the test results. Any test failures will lead to a build failure. - In the browser - the
runTypeScriptTestsInBrowser
task. This is useful debugging failing tests. This tasks starts your default browser and loads the tests for execution.
By default all tests from your testSourcePath
are compiled and executed. If you want to run only a certain tests(s) you can do so using a Gradle propery:
./gradlew -Pat.irian.typescript.test=myTest,someSubfolder/myOtherTest test
(comma-separated list of paths to your tests relative to testSourcePath
, the ".ts" suffixes can be omitted).