|
|
if (release != 'rtm') {
|
|
|
version += "-$release"
|
|
|
}
|
|
|
|
|
|
if(!npmName)
|
|
|
npmName = name;
|
|
|
|
|
|
if(!["amd", "commonjs", "system", "umd", "es6", "esnext"].contains(jsmodule))
|
|
|
throw new Exception("Invalid jsmodule specified: $jsmodule");
|
|
|
if(!["es3", "es5", "es6", "es2016", "es2017", "esnext"].contains(target))
|
|
|
throw new Exception("Invalid target specified: $target")
|
|
|
|
|
|
def targetLibs = [
|
|
|
"es3" : "es5,es2015.promise,es2015.symbol,dom,scripthost",
|
|
|
"es5" : "es5,es2015.promise,es2015.symbol,dom,scripthost"
|
|
|
];
|
|
|
|
|
|
ext.packageName="$npmScope/$npmName";
|
|
|
|
|
|
def srcDir = "$projectDir/src"
|
|
|
def typingsDir = "$srcDir/typings"
|
|
|
def distDir = "$buildDir/dist"
|
|
|
def testDir = "$buildDir/test"
|
|
|
def lib = targetLibs[target] ?: "${target},dom";
|
|
|
|
|
|
println "lib: $lib";
|
|
|
|
|
|
def sourceSets = ["main", "amd", "cjs"];
|
|
|
def testSets = ["test", "testAmd", "testCjs"];
|
|
|
|
|
|
task beforeBuild {
|
|
|
}
|
|
|
|
|
|
def createSoursetTasks = { String name, String outDir ->
|
|
|
def setName = name.capitalize();
|
|
|
|
|
|
def destDir = "$buildDir/compile/$name"
|
|
|
def declDir = "$typingsDir/$name"
|
|
|
def setDir = "$projectDir/src/$name"
|
|
|
|
|
|
def beforeBuildTask = task "beforeBuild$setName"(dependsOn: beforeBuild) {
|
|
|
}
|
|
|
|
|
|
def copyJsTask = task "copyJs$setName"(dependsOn: beforeBuildTask, type: Copy) {
|
|
|
from "$setDir/js"
|
|
|
into outDir
|
|
|
}
|
|
|
|
|
|
def compileTsTask = task "compileTs$setName"(dependsOn: beforeBuildTask, type: Exec) {
|
|
|
inputs.dir("$setDir/ts")
|
|
|
inputs.file("$srcDir/tsconfig.json")
|
|
|
inputs.file("$setDir/tsconfig.json")
|
|
|
outputs.dir(destDir)
|
|
|
outputs.dir(declDir)
|
|
|
|
|
|
commandLine 'node_modules/.bin/tsc',
|
|
|
'-p', "$setDir/tsconfig.json",
|
|
|
'-t', target,
|
|
|
'-m', jsmodule,
|
|
|
'-d',
|
|
|
'--outDir', destDir,
|
|
|
'--declarationDir', declDir
|
|
|
|
|
|
if (lib)
|
|
|
args '--lib', lib
|
|
|
}
|
|
|
|
|
|
def copyTsOutputTask = task "copyTsOutput$setName"(dependsOn: compileTsTask, type: Copy) {
|
|
|
from destDir
|
|
|
into outDir
|
|
|
}
|
|
|
|
|
|
def copyTypingsTask = task "copyTypings$setName"(dependsOn: compileTsTask, type: Copy) {
|
|
|
from declDir
|
|
|
into outDir
|
|
|
}
|
|
|
|
|
|
task "build$setName"(dependsOn: [copyTypingsTask, copyTsOutputTask, copyJsTask]) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
task printVersion {
|
|
|
doLast {
|
|
|
println "version: $version"
|
|
|
println "packageName: $packageName"
|
|
|
println "target: $target"
|
|
|
println "module: $jsmodule"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
task clean {
|
|
|
doLast {
|
|
|
delete buildDir
|
|
|
delete typingsDir
|
|
|
}
|
|
|
}
|
|
|
|
|
|
task _initBuild {
|
|
|
mustRunAfter clean
|
|
|
|
|
|
def buildInfoFile = "$buildDir/platform";
|
|
|
inputs.property('target',target);
|
|
|
inputs.property('jsmodule',jsmodule);
|
|
|
outputs.file(buildInfoFile);
|
|
|
|
|
|
doLast {
|
|
|
delete buildDir
|
|
|
mkdir buildDir
|
|
|
|
|
|
def f = new File(buildInfoFile);
|
|
|
f << "$target-$jsmodule";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
task cleanNpm {
|
|
|
doLast {
|
|
|
delete 'node_modules'
|
|
|
}
|
|
|
}
|
|
|
|
|
|
task _npmInstall() {
|
|
|
inputs.file("package.json")
|
|
|
outputs.dir("node_modules")
|
|
|
doLast {
|
|
|
exec {
|
|
|
commandLine 'npm', 'install'
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
beforeBuild {
|
|
|
dependsOn _initBuild
|
|
|
dependsOn _npmInstall
|
|
|
}
|
|
|
|
|
|
sourceSets.each { createSoursetTasks(it, distDir) }
|
|
|
|
|
|
testSets.each { createSoursetTasks(it, testDir) }
|
|
|
|
|
|
compileTsAmd {
|
|
|
dependsOn compileTsMain
|
|
|
}
|
|
|
|
|
|
compileTsCjs {
|
|
|
dependsOn compileTsMain
|
|
|
}
|
|
|
|
|
|
task build(dependsOn: buildMain) {
|
|
|
if (jsmodule == "amd")
|
|
|
dependsOn buildAmd
|
|
|
if (jsmodule == "commonjs")
|
|
|
dependsOn buildCjs
|
|
|
}
|
|
|
|
|
|
compileTsTest {
|
|
|
dependsOn build
|
|
|
}
|
|
|
|
|
|
compileTsTestAmd {
|
|
|
dependsOn compileTsTest
|
|
|
}
|
|
|
|
|
|
compileTsTestCjs {
|
|
|
dependsOn compileTsTest
|
|
|
}
|
|
|
|
|
|
task _installLocalCjsDependency(dependsOn: [buildTestCjs, "_packageMeta"], type: Exec) {
|
|
|
inputs.file("$distDir/package.json")
|
|
|
outputs.upToDateWhen {
|
|
|
new File("$testDir/$packageName").exists()
|
|
|
}
|
|
|
|
|
|
workingDir testDir
|
|
|
|
|
|
commandLine 'npm', 'install', '--no-save', '--force', distDir
|
|
|
}
|
|
|
|
|
|
task test(dependsOn: [buildTest], type: Exec) {
|
|
|
if (jsmodule == "amd")
|
|
|
dependsOn buildTestAmd
|
|
|
if (jsmodule == "commonjs") {
|
|
|
dependsOn buildTestCjs
|
|
|
dependsOn _installLocalCjsDependency
|
|
|
}
|
|
|
|
|
|
commandLine 'node', "$testDir/run-tests.js"
|
|
|
}
|
|
|
|
|
|
task _packageMeta(type: Copy) {
|
|
|
mustRunAfter build
|
|
|
|
|
|
inputs.property("version", version)
|
|
|
from('.') {
|
|
|
include '.npmignore', 'readme.md', 'license', 'history.md'
|
|
|
}
|
|
|
from("$srcDir/package.${jsmodule}.tmpl.json") {
|
|
|
expand project.properties
|
|
|
rename { "package.json" }
|
|
|
}
|
|
|
into distDir
|
|
|
}
|
|
|
|
|
|
task pack(dependsOn: [build, _packageMeta], type: Exec) {
|
|
|
workingDir distDir
|
|
|
|
|
|
commandLine 'npm', 'pack'
|
|
|
}
|