Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ jobs:

- name: Gradle Check Sandbox
working-directory: sandbox
run: ./gradlew check --scan

- name: Gradle Assemble Sandbox
working-directory: sandbox
run: ./gradlew assemble pack --scan
run: ./gradlew check assemble pack publish --scan

- uses: actions/upload-artifact@v3
if: ${{ always() }}
Expand All @@ -81,6 +77,18 @@ jobs:
sandbox/**/build/reports
sandbox/**/build/publications

- name: Gradle Check Samples
working-directory: samples
run: ./gradlew check assemble pack publish --scan

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: samples-${{ runner.os }}
path: |
samples/**/build/reports
samples/**/build/publications

- name: ts-consumer Install
working-directory: sandbox/ts-consumer
run: yarn install
Expand Down
19 changes: 16 additions & 3 deletions npm-publish-gradle-plugin/src/main/kotlin/NpmPublishPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package dev.petuska.npm.publish
import com.moowork.gradle.node.task.SetupTask
import dev.petuska.npm.publish.config.configure
import dev.petuska.npm.publish.extension.NpmPublishExtension
import dev.petuska.npm.publish.task.NodeExecTask
import dev.petuska.npm.publish.task.NpmAssembleTask
import dev.petuska.npm.publish.task.NpmPackTask
import dev.petuska.npm.publish.task.NpmPublishTask
import dev.petuska.npm.publish.util.ProjectEnhancer
import dev.petuska.npm.publish.util.configure
import dev.petuska.npm.publish.util.unsafeCast
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.plugins.PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME
Expand All @@ -33,9 +35,20 @@ public class NpmPublishPlugin : Plugin<Project> {
private fun ProjectEnhancer.apply() {
configure(extension)
pluginManager.withPlugin(NEBULA_NODE_PLUGIN) {
project.tasks.named<SetupTask>(SetupTask.NAME).map(SetupTask::getNodeDir)
.let(project.layout::dir)
.let(extension.nodeHome::convention)
val nebulaNodeHome = project.tasks.named<SetupTask>(SetupTask.NAME)
.map { it.takeIf { it.enabled }.unsafeCast<SetupTask>() }
.map(SetupTask::getNodeDir)
.let(layout::dir)
extension.nodeHome.sysProjectEnvPropertyConvention(
name = "nodeHome",
default = nebulaNodeHome.orElse(
providers.environmentVariable("NODE_HOME").map(layout.projectDirectory::dir)
),
converter = layout.projectDirectory::dir
)
tasks.withType(NodeExecTask::class.java) {
it.dependsOn(nebulaNodeHome)
}
}
pluginManager.withPlugin(KOTLIN_MPP_PLUGIN) {
extensions.configure<KotlinMultiplatformExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ internal fun ProjectEnhancer.configure(extension: NpmPublishExtension) {
configure(extension.registries)
extension.nodeHome.sysProjectEnvPropertyConvention(
name = "nodeHome",
default = providers.environmentVariable("NODE_HOME").map { layout.projectDirectory.dir(it) },
converter = { layout.projectDirectory.dir(it) }
default = providers.environmentVariable("NODE_HOME")
.map(layout.projectDirectory::dir),
converter = layout.projectDirectory::dir
)
extension.readme.sysProjectEnvPropertyConvention("readme") { layout.projectDirectory.file(it) }
extension.npmIgnore.sysProjectEnvPropertyConvention(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal fun ProjectEnhancer.configure(target: KotlinJsTargetDsl) {
)
pkg.types.sysProjectEnvPropertyConvention(
pkg.prefix + "types",
typesFile.map<String> { it.takeIf(File::exists).also { println(">>>>> TYPES $it") }?.name.unsafeCast() }
typesFile.map<String> { it.takeIf(File::exists)?.name.unsafeCast() }
.orElse(pkg.packageJson.flatMap(PackageJson::types))
)
pkg.dependencies.addAllLater(resolveDependencies(target.name, binary))
Expand Down
7 changes: 4 additions & 3 deletions npm-publish-gradle-plugin/src/main/kotlin/config/package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ internal fun ProjectEnhancer.configure(pkg: NpmPackage) {
pkg.project = project
pkg.main.sysProjectEnvPropertyConvention(prefix + "main", pkg.packageJson.flatMap(PackageJson::main))
pkg.types.sysProjectEnvPropertyConvention(prefix + "types", pkg.packageJson.flatMap(PackageJson::types))
pkg.readme.sysProjectEnvPropertyConvention(prefix + "readme", extension.readme) { layout.projectDirectory.file(it) }
pkg.readme.sysProjectEnvPropertyConvention(prefix + "readme", extension.readme, layout.projectDirectory::file)
pkg.npmIgnore.sysProjectEnvPropertyConvention(
prefix + "npmIgnore",
extension.npmIgnore
) { layout.projectDirectory.file(it) }
extension.npmIgnore,
layout.projectDirectory::file
)
pkg.version.sysProjectEnvPropertyConvention(prefix + "version", extension.version)
pkg.packageName.sysProjectEnvPropertyConvention(prefix + "packageName", provider { project.name })
pkg.scope.sysProjectEnvPropertyConvention(prefix + "scope", extension.organization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.io.File
*/
@Suppress("LeakingThis")
public abstract class NodeExecTask : DefaultTask(), PluginLogger {

/**
* Base NodeJS directory used to extract other node executables from. Defaults to 'NODE_HOME' env
* variable.
Expand Down Expand Up @@ -61,9 +60,10 @@ public abstract class NodeExecTask : DefaultTask(), PluginLogger {
* @return execution result
*/
@Suppress("SpreadOperator")
public fun nodeExec(args: Collection<Any?>, config: Action<ExecSpec> = Action {}): ExecResult = project.exec {
val cmd = listOfNotNull(node.get(), *args.toTypedArray()).toTypedArray()
it.commandLine(*cmd)
public fun nodeExec(args: Collection<String?>, config: Action<ExecSpec> = Action {}): ExecResult = project.exec {
val cmd = listOfNotNull(node.get(), *args.toTypedArray())
info { "Executing: ${cmd.joinToString(" ")}" }
it.commandLine(*cmd.toTypedArray())
config.execute(it)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public abstract class NpmExecTask : NodeExecTask() {
* @param config to be applied to the execution process
* @return execution result
*/
public fun npmExec(args: Collection<Any?>, config: Action<ExecSpec> = Action {}): ExecResult =
nodeExec(listOf(npm.get()) + args, config)
public fun npmExec(args: Collection<String?>, config: Action<ExecSpec> = Action {}): ExecResult =
nodeExec(listOf("${npm.get().asFile}") + args, config)
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public abstract class NpmPackTask : NpmExecTask() {
"Packing package at ${pDir.path} to ${oDir.parentFile.path} ${if (d) "with" else "without"} --dry-run flag"
}
val tmpDir = temporaryDir
val args = buildList {
val args: List<String> = buildList {
add("pack")
add(pDir)
add("$pDir")
if (d) add("--dry-run")
}
npmExec(args) { it.workingDir(tmpDir) }.rethrowFailure()
Expand Down
20 changes: 10 additions & 10 deletions npm-publish-gradle-plugin/src/main/kotlin/task/NpmPublishTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ public abstract class NpmPublishTask : NpmExecTask() {
val uri = reg.uri.get()
val repo = "${uri.authority.trim()}${uri.path.trim()}/"
val d = dry.get()
debug {
"Publishing package at ${pDir.path} to ${reg.name} registry ${if (d) "with" else "without"} --dry-run flag"
info {
"Publishing package at $pDir to ${reg.name} registry ${if (d) "with" else "without"} --dry-run flag"
}
val args = buildList {
val args: List<String> = buildList {
add("publish")
add(pDir)
add(listOf("--access", reg.access.get()))
add(listOf("--registry", "${uri.scheme.trim()}://$repo"))
if (reg.otp.isPresent) add(listOf("--otp", reg.otp.get()))
add("$pDir")
add("--access=${reg.access.get()}")
add("--registry=${uri.scheme.trim()}://$repo")
if (reg.otp.isPresent) add("--otp=${reg.otp.get()}")
if (reg.authToken.isPresent) add("--//$repo:_authToken=${reg.authToken.get()}")
if (d) add("--dry-run")
if (tag.isPresent) add(listOf("--tag", tag.get()))
add("${uri.scheme.trim()}://$repo")
if (tag.isPresent) add("--tag=${tag.get()}")
// add("${uri.scheme.trim()}://$repo")
}
npmExec(args) { it.workingDir(packageDir.get()) }.rethrowFailure()
if (!d) info { "Published package at ${pDir.path} to ${reg.name} registry" }
if (!d) info { "Published package at $pDir to ${reg.name} registry" }
}
}
2 changes: 1 addition & 1 deletion samples/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ group=mpetuska
version=0.0.0

npm.publish.registry.github.authToken=NONE
npm.publish.registry.github.dry=true
npm.publish.dry=true
8 changes: 7 additions & 1 deletion samples/no-kotlin-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("convention.base")
id("dev.petuska.npm.publish")
id("com.netflix.nebula.node") version "+"
}

tasks {
Expand All @@ -16,8 +17,13 @@ tasks {
}
}

node {
download = true
}

npmPublish {
nodeHome.set(File("${System.getProperty("user.home")}/.gradle/nodejs/node-v16.13.0-linux-x64/"))
// Not needed thanks to `com.netflix.nebula.node` plugin
// nodeHome.set(File("/path/to/your/node/home"))
packages {
register("standalone") {
version.set("4.20.69")
Expand Down