-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
80 lines (65 loc) · 2.04 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import com.google.gson.Gson
import com.google.gson.JsonParser
plugins {
id("org.jetbrains.kotlin.js") version "1.3.61"
}
group = "org.stvad"
version = "0.1.5"
description = "Alfred workflow to convert human date to computer date"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-js"))
}
kotlin {
sourceSets["main"].dependencies {
implementation(npm("alfy", "0.9.1"))
implementation(npm("chrono-node", "1.4.2"))
implementation(npm("dateformat", "^4"))
}
target.useCommonJs()
target.nodejs {
}
}
val packageLocation = "build/js/packages/${project.name}"
val copyWorkflowResources by tasks.registering(Copy::class) {
from("README.md", "workflow_resources", "illustrations")
into(packageLocation)
}
/**
* Updates autogenerated package.json to be ready for publishing in NPM
* Hopefully at some point KotlinJs plugin would have native facilities for this
*/
val updatePackageJson by tasks.creating {
doLast {
val targetFile = file("$packageLocation/package.json")
val packageJson = JsonParser().parse(targetFile.readText()).asJsonObject
val gson = Gson()
packageJson.apply {
// It's not required and is not present in NPM
get("dependencies").asJsonObject.remove("kotlin-test-js-runner")
addProperty("description", project.description)
add(
"scripts",
gson.toJsonTree(
mapOf(
"postinstall" to "alfy-init",
"preuninstall" to "alfy-cleanup"
)
)
)
add(
"author",
gson.toJsonTree(
mapOf(
"email" to "[email protected]",
"name" to "Vladyslav Sitalo"
)
)
)
}
targetFile.writeText(gson.toJson(packageJson))
}
}
tasks.assemble { dependsOn(copyWorkflowResources, updatePackageJson) }