Compare commits

...

11 Commits

Author SHA1 Message Date
Anton Bannykh
d3d17bb2d8 fixup 2017-11-28 17:49:04 +03:00
Anton Bannykh
7f7338c24c fixup: automatic Teamcity detection in runMocha; set dependencies
Also revert readme to an older state since it doesn't make much sense
to make users go to some other folder and launch gradle from there.
2017-11-28 15:48:09 +03:00
Anton Bannykh
b9637c1fbd use findProperty instead of properties[...] 2017-11-24 19:15:36 +03:00
Anton Bannykh
6fc676dd9e Use gradle properties instead of system properties 2017-11-24 16:38:35 +03:00
Anton Bannykh
f0af609fbd take path to kotlinc from the root project 2017-11-24 14:26:45 +03:00
Anton Bannykh
ea91756333 fixup: task("publishAll") { 2017-11-23 14:16:57 +03:00
Anton Bannykh
67d9ecc626 fixup 2017-11-22 19:53:22 +03:00
Anton Bannykh
44e9488de3 fixup: better dsl 2017-11-22 19:32:10 +03:00
Anton Bannykh
be4004002d Move nodejs tests to js.tests subproject 2017-11-21 20:29:35 +03:00
Anton Bannykh
b264faab5c fixup 2017-11-21 17:01:41 +03:00
Anton Bannykh
4ef860f5fc Migrate node_utils.xml to Gradle 2017-11-17 14:34:09 +03:00
15 changed files with 137 additions and 161 deletions

1
.idea/ant.xml generated
View File

@@ -18,6 +18,5 @@
</properties>
</buildFile>
<buildFile url="file://$PROJECT_DIR$/TeamCityRelay.xml" />
<buildFile url="file://$PROJECT_DIR$/node_utils.xml" />
</component>
</project>

View File

@@ -342,6 +342,7 @@ tasks {
"jsCompilerTest" {
dependsOn(":js:js.tests:test")
dependsOn(":js:js.tests:runMocha")
}
"scriptingTest" {

View File

@@ -3869,6 +3869,7 @@
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
"node": "com.moowork.gradle.node.NodeExtension",
"kotlin": "org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension",
"kapt": "org.jetbrains.kotlin.gradle.plugin.KaptExtension",
"defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet",
@@ -3910,6 +3911,20 @@
"reporting": "org.gradle.api.reporting.ReportingExtension"
}
},
":js:npm": {
"conventions": {
"base": "org.gradle.api.plugins.BasePluginConvention"
},
"configurations": [
"archives",
"default"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
"node": "com.moowork.gradle.node.NodeExtension",
"defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet"
}
},
":kotlin-allopen:plugin-marker": {
"conventions": {
"base": "org.gradle.api.plugins.BasePluginConvention",

View File

@@ -1,3 +1,12 @@
import com.moowork.gradle.node.npm.NpmTask
plugins {
id("com.moowork.node").version("1.2.0")
}
node {
download = true
}
apply { plugin("kotlin") }
@@ -52,3 +61,15 @@ projectTest("quickTest") {
}
val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateJsTestsKt")
val runMocha by task<NpmTask> {
setWorkingDir(project(":js:js.translator").projectDir.resolve("testData"))
val target = if (project.hasProperty("teamcity")) "runOnTeamcity" else "test"
setArgs(listOf("run", target))
dependsOn("npm_install", "test")
val check by tasks
check.dependsOn(this)
}

View File

@@ -7,6 +7,7 @@
"mocha-teamcity-reporter": "1.1.1"
},
"scripts": {
"test": "mocha --reporter mocha-teamcity-reporter"
"runOnTeamcity": "mocha --reporter mocha-teamcity-reporter",
"test": "mocha"
}
}
}

96
js/npm/build.gradle.kts Normal file
View File

@@ -0,0 +1,96 @@
import com.moowork.gradle.node.npm.NpmTask
plugins {
id("com.moowork.node").version("1.2.0")
base
}
description = "Node utils"
node {
download = true
}
val deployDir = "$buildDir/deploy_to_npm"
val templateDir = "$projectDir/templates"
val kotlincDir = rootProject.extra["distKotlinHomeDir"] as String
fun getProperty(name: String, default: String = "") = findProperty(name)?.toString() ?: default
val deployVersion = getProperty("kotlin.deploy.version", "0.0.0")
val deployTag = getProperty("kotlin.deploy.tag", "dev")
val authToken = getProperty("kotlin.npmjs.auth.token")
val dryRun = getProperty("dryRun", "false") // Pack instead of publish
fun Project.createCopyTemplateTask(templateName: String): Copy {
return task<Copy>("copy-$templateName-template") {
from("$templateDir/$templateName")
into("$deployDir/$templateName")
expand(hashMapOf("version" to deployVersion))
}
}
fun Project.createCopyLibraryFilesTask(libraryName: String, fromJar: String): Copy {
return task<Copy>("copy-$libraryName-library") {
from(zipTree(fromJar).matching {
include("$libraryName.js")
include("$libraryName.meta.js")
include("$libraryName.js.map")
include("$libraryName/**")
})
into("$deployDir/$libraryName")
}
}
fun Project.createPublishToNpmTask(templateName: String): NpmTask {
return task<NpmTask>("publish-$templateName-to-npm") {
val deployDir = File("$deployDir/$templateName")
setWorkingDir(deployDir)
val deployArgs = listOf("publish", "--//registry.npmjs.org/:_authToken=$authToken", "--tag=$deployTag")
if (dryRun == "true") {
println("$deployDir \$ npm arguments: $deployArgs");
setArgs(listOf("pack"))
}
else {
setArgs(deployArgs)
}
}
}
fun sequential(first: Task, vararg tasks: Task): Task {
tasks.fold(first) { previousTask, currentTask ->
currentTask.dependsOn(previousTask)
}
return tasks.last()
}
val publishKotlinJs = sequential(
createCopyTemplateTask("kotlin"),
createCopyLibraryFilesTask("kotlin", "$kotlincDir/lib/kotlin-stdlib-js.jar"),
createPublishToNpmTask("kotlin")
)
val publishKotlinCompiler = sequential(
createCopyTemplateTask("kotlin-compiler"),
task<Copy>("copy-kotlin-compiler") {
from(kotlincDir)
into("$deployDir/kotlin-compiler")
},
task<Exec>("chmod-kotlinc-bin") {
commandLine = listOf("chmod", "-R", "ugo+rx", "$deployDir/kotlin-compiler/bin")
},
createPublishToNpmTask("kotlin-compiler")
)
val publishKotlinTest = sequential(
createCopyTemplateTask("kotlin-test"),
createCopyLibraryFilesTask("kotlin-test", "$kotlincDir/lib/kotlin-test-js.jar"),
createPublishToNpmTask("kotlin-test")
)
task("publishAll") {
dependsOn(publishKotlinJs, publishKotlinTest, publishKotlinCompiler)
}

View File

@@ -1,158 +0,0 @@
<project name="Node.js utils" xmlns:if="ant:if" xmlns:unless="ant:unless">
<import file="common.xml" optional="false"/>
<!-- Expected that these properties will be overridden by system properties -->
<property name="kotlin.deploy.version" value="0.0.0"/>
<property name="kotlin.deploy.tag" value="dev"/>
<property name="kotlin.npmjs.auth.token" value="AUTH"/>
<property name="node.version" value="v6.3.1"/>
<property name="node.dir" value="${dependencies}/node"/>
<property name="node.executable" value="${node.dir}/bin/node"/>
<target name="download-nodejs-and-npm" depends="make-dependency-dirs">
<property name="linux-x86" value="linux-x86"/>
<property name="platform" value="win-x86" if:set="isWindows"/>
<property name="platform" value="darwin-x64" if:set="isMac"/>
<property name="platform" value="${linux-x86}" if:set="isLinux"/>
<property name="node.tar.gz" value="${dependencies}/download/node.tar.gz"/>
<property name="node.exe" value="${node.executable}.exe"/>
<property name="node.name.prefix" value="${platform}" unless:set="isWindows"/>
<property name="node.name.prefix" value="${linux-x86}" if:set="isWindows"/>
<property name="node.full.name" value="node-${node.version}-${node.name.prefix}"/>
<property name="url.node.tar.gz" value="https://nodejs.org/dist/${node.version}/${node.full.name}.tar.gz"/>
<property name="url.node.exe" value="https://nodejs.org/dist/${node.version}/${platform}/node.exe"/>
<get src="${url.node.tar.gz}" dest="${node.tar.gz}" usetimestamp="true"/>
<exec executable="tar" unless:set="isWindows">
<arg value="-zxf"/>
<arg path="${node.tar.gz}"/>
<arg value="-C"/>
<arg path="${dependencies}"/>
</exec>
<untar src="${node.tar.gz}" dest="${dependencies}" compression="gzip" if:set="isWindows"/>
<move file="${dependencies}/${node.full.name}" tofile="${dependencies}/node"/>
<delete dir="${dependencies}/${node.full.name}"/>
<delete file="${node.tar.gz}"/>
<sequential if:set="isWindows">
<get src="${url.node.exe}" dest="${node.exe}" usetimestamp="true"/>
<delete file="${node.executable}"/>
</sequential>
</target>
<macrodef name="node">
<attribute name="dir" default="."/>
<attribute name="failonerror" default="true"/>
<element name="args" implicit="true"/>
<sequential>
<exec executable="${node.executable}" dir="@{dir}" failonerror="@{failonerror}">
<args/>
</exec>
</sequential>
</macrodef>
<macrodef name="npm">
<attribute name="command"/>
<attribute name="dir" default="."/>
<attribute name="failonerror" default="true"/>
<element name="args" optional="true" implicit="true"/>
<sequential>
<node dir="@{dir}" failonerror="@{failonerror}">
<arg file="${node.dir}/lib/node_modules/npm/bin/npm-cli.js"/>
<arg value="@{command}"/>
<args/>
</node>
</sequential>
</macrodef>
<macrodef name="publish-to-npm">
<attribute name="template"/>
<attribute name="version"/>
<attribute name="tag"/>
<element name="actions" optional="true" implicit="true"/>
<sequential>
<property name="deploy_to_npm_dir" value="${output}/deploy_to_npm"/>
<property name="package_deploy_dir" value="${deploy_to_npm_dir}/@{template}"/>
<delete dir="${deploy_to_npm_dir}"/>
<mkdir dir="${deploy_to_npm_dir}"/>
<copy todir="${package_deploy_dir}">
<fileset dir="js/npm.templates/@{template}"/>
</copy>
<actions/>
<replace file="${package_deploy_dir}/package.json" token="$version" value="@{version}" />
<npm command="publish" dir="${package_deploy_dir}">
<arg value="--//registry.npmjs.org/:_authToken=${kotlin.npmjs.auth.token}"/>
<arg value="--tag"/>
<arg value="@{tag}"/>
</npm>
</sequential>
</macrodef>
<target name="publish-kotlin-js-to-npm">
<publish-to-npm template="kotlin" version="${kotlin.deploy.version}" tag="${kotlin.deploy.tag}">
<copy file="${js.stdlib.output.dir}/kotlin.js" todir="${package_deploy_dir}" failonerror="true" />
<copy file="${js.stdlib.output.dir}/kotlin.meta.js" todir="${package_deploy_dir}" failonerror="true" />
<copy file="${js.stdlib.output.dir}/kotlin.js.map" todir="${package_deploy_dir}" failonerror="true" />
<copy todir="${package_deploy_dir}/kotlin" failonerror="true">
<fileset dir="${js.stdlib.output.dir}/kotlin"/>
</copy>
</publish-to-npm>
</target>
<target name="publish-kotlin-compiler-to-npm">
<publish-to-npm template="kotlin-compiler" version="${kotlin.deploy.version}" tag="${kotlin.deploy.tag}">
<copy todir="${package_deploy_dir}" failonerror="true" >
<fileset dir="${output}/kotlinc" />
</copy>
<chmod perm="ugo+rx" dir="dist/deploy_to_npm/kotlin-compiler/bin" includes="*" />
</publish-to-npm>
</target>
<target name="publish-kotlin-test-js-to-npm">
<publish-to-npm template="kotlin-test" version="${kotlin.deploy.version}" tag="${kotlin.deploy.tag}">
<copy file="${js.stdlib.output.dir}/kotlin-test.js" todir="${package_deploy_dir}" failonerror="true" />
<copy file="${js.stdlib.output.dir}/kotlin-test.meta.js" todir="${package_deploy_dir}" failonerror="true" />
<copy file="${js.stdlib.output.dir}/kotlin-test.js.map" todir="${package_deploy_dir}" failonerror="true" />
<copy todir="${package_deploy_dir}/kotlin-test" failonerror="true">
<fileset dir="${js.stdlib.output.dir}/kotlin-test"/>
</copy>
</publish-to-npm>
</target>
<!-- Used on TeamCity-->
<target name="unzip-jslib.jar">
<unzip src="${output}/kotlinc/lib/kotlin-stdlib-js.jar" dest="${js.stdlib.output.dir}"/>
</target>
<!-- Used on TeamCity-->
<target name="unzip-test-jslib.jar">
<unzip src="${output}/kotlinc/lib/kotlin-test-js.jar" dest="${js.stdlib.output.dir}"/>
</target>
<target name="run-nodejs-tests" description="Run JS backend tests in node.js" depends="download-nodejs-and-npm">
<npm command="install" dir="js/js.translator/testData" />
<npm command="run" dir="js/js.translator/testData" failonerror="false">
<arg value="test"/>
</npm>
</target>
</project>

View File

@@ -47,6 +47,7 @@ include ":kotlin-build-common",
":js:js.translator",
":js:js.dce",
":js:js.tests",
":js:npm",
":jps-plugin",
":kotlin-jps-plugin",
":core:descriptors",