Skip to content

Commit 88450f4

Browse files
author
Oleksandr Dzhychko
committed
build(ts-model-api): do not change version when running publish task
Running `publish` resulted in changing the version in the `package.json`. This led to an unnecessary rebuild. Now the version is set by the npm-publish extension.
1 parent 62884ed commit 88450f4

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

ts-model-api/build.gradle.kts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import com.github.gradle.node.npm.task.NpmTask
2-
31
plugins {
42
base
53
alias(libs.plugins.node)
64
id("org.jlleitschuh.gradle.ktlint") apply false
5+
alias(libs.plugins.npm.publish)
76
}
87

9-
tasks.named("npm_run_build") {
8+
val npmRunBuild = tasks.named("npm_run_build") {
109
inputs.dir("src")
1110
inputs.file("package.json")
1211
inputs.file("package-lock.json")
@@ -38,24 +37,49 @@ val patchKotlinExternals = tasks.create("patchKotlinExternals") {
3837
}
3938
}
4039

41-
tasks.named("assemble") {
40+
tasks.assemble {
4241
dependsOn("npm_run_build")
4342
dependsOn("npm_run_generateKotlin")
4443
dependsOn(patchKotlinExternals)
4544
}
4645

47-
tasks.named("npm_run_generateKotlin") {
48-
finalizedBy(patchKotlinExternals)
46+
tasks.check {
47+
dependsOn("npm_run_lint")
4948
}
5049

51-
val updateVersion = tasks.register<NpmTask>("updateVersion") {
52-
args.set(listOf("version", "$version"))
50+
tasks.named("npm_run_generateKotlin") {
51+
finalizedBy(patchKotlinExternals)
5352
}
5453

55-
tasks.named("npm_publish") {
56-
dependsOn(updateVersion)
54+
// To copy the files is a workaround for https://github.com/mpetuska/npm-publish/issues/87
55+
// With `NpmPackage.files` we cannot copy the "dist" directory into `destinationDir`.
56+
// We can only either copy the files from "dist" directly into `destinationDir`
57+
// or copy all files from `projectDir` into `destinationDir`.
58+
val copyBuildTypeScriptForPackaging = tasks.create<Copy>("copyBuildTypeScriptForPackaging") {
59+
dependsOn(npmRunBuild)
60+
from(projectDir)
61+
include("dist")
62+
into(layout.buildDirectory.dir("typeScriptForPackaging"))
5763
}
5864

59-
tasks.named("publish") {
60-
dependsOn("npm_publish")
65+
npmPublish {
66+
registries {
67+
register("itemis-npm-open") {
68+
uri.set("https://artifacts.itemis.cloud/repository/npm-open")
69+
System.getenv("NODE_AUTH_TOKEN").takeIf { !it.isNullOrBlank() }?.let {
70+
authToken.set(it)
71+
}
72+
}
73+
}
74+
packages {
75+
create("js") {
76+
packageJsonTemplateFile.set(projectDir.resolve("package.json"))
77+
packageJson {
78+
version.set("${project.version}")
79+
}
80+
files {
81+
setFrom(copyBuildTypeScriptForPackaging.outputs)
82+
}
83+
}
84+
}
6185
}

ts-model-api/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"clean": "shx rm -rf dist/ .*cache *.log",
2929
"lint": "npm run lint:debug -- --config tslint.prod.json",
3030
"lint:debug": "tslint --project tsconfig.json --format stylish",
31-
"prepublishOnly": "npm run lint && npm run build",
3231
"test": "shx echo 'Write your own tests'",
3332
"ts": "tsc",
3433
"watch": "tsc --watch",
@@ -47,9 +46,5 @@
4746
"engines": {
4847
"node": ">= 10.18.1",
4948
"npm": ">= 6.13.4"
50-
},
51-
"publishConfig": {
52-
"access": "public",
53-
"registry": "https://artifacts.itemis.cloud/repository/npm-open/"
5449
}
5550
}

0 commit comments

Comments
 (0)