@@ -23,92 +23,110 @@ fun registerNpmPackageTasks(
2323 openApiGeneratorName : String , // e.g., "typescript-fetch"
2424) {
2525 val clientBuildDir = layout.buildDirectory.dir(" generate" ).map { it.dir(openApiGeneratorName) }
26- val publicationFile = clientBuildDir.map { it.file(" modelix-${npmPackageName} -${project.version} .tgz" ) }
27-
28- val generatorTask = tasks.register(" generateTypescript$clientType " , GenerateTask ::class ) {
29- dependsOn(" :redocly:npm_run_join" )
30- group = " openapi tools"
31- inputSpec = project(" :redocly" ).layout.buildDirectory.file(" joined.yaml" ).get().asFile.absolutePath
32- configOptions = mapOf (
33- " npmRepository" to " https://artifacts.itemis.cloud/repository/npm-open/" ,
34- " npmVersion" to project.version.toString(),
35- " npmName" to " @modelix/$npmPackageName " ,
36- )
37- gitUserId = " modelix"
38- gitRepoId = " modelix.openapi"
39- generatorName = openApiGeneratorName
40- outputDir = layout.buildDirectory.dir(" generate/$openApiGeneratorName " ).get().asFile.absolutePath
41- }
26+ val publicationFile = clientBuildDir.map { it.file(" modelix-$npmPackageName -${project.version} .tgz" ) }
27+
28+ val generatorTask =
29+ tasks.register(" generateTypescript$clientType " , GenerateTask ::class ) {
30+ dependsOn(" :redocly:npm_run_join" )
31+ group = " openapi tools"
32+ inputSpec =
33+ project(" :redocly" )
34+ .layout.buildDirectory
35+ .file(" joined.yaml" )
36+ .get()
37+ .asFile.absolutePath
38+ configOptions =
39+ mapOf (
40+ " npmRepository" to " https://artifacts.itemis.cloud/repository/npm-open/" ,
41+ " npmVersion" to project.version.toString(),
42+ " npmName" to " @modelix/$npmPackageName " ,
43+ )
44+ gitUserId = " modelix"
45+ gitRepoId = " modelix.openapi"
46+ generatorName = openApiGeneratorName
47+ outputDir =
48+ layout.buildDirectory
49+ .dir(" generate/$openApiGeneratorName " )
50+ .get()
51+ .asFile.absolutePath
52+ }
4253
4354 // Task to run 'pnpm install'
44- val pnpmInstallTask = tasks.register<PnpmTask >(" pnpmInstall${clientType.capitalize()} " ) {
45- group = " build"
46- description = " Run pnpm install for $openApiGeneratorName client"
47- dependsOn(generatorTask) // Must run after generation
48-
49- workingDir.set(clientBuildDir)
50- pnpmCommand = listOf (" install" )
51-
52- // Define inputs/outputs for better up-to-date checks and caching
53- // inputs.dir(clientBuildDir.map { it.dir("src") }).withPathSensitivity(PathSensitivity.RELATIVE) // Source might change
54- inputs.file(clientBuildDir.map { it.file(" package.json" ) }).withPathSensitivity(PathSensitivity .RELATIVE )
55- // Add pnpm-lock.yaml if you commit/use it
56- // inputs.file(clientBuildDir.map { it.file("pnpm-lock.yaml") }).optional().withPathSensitivity(PathSensitivity.RELATIVE)
57- outputs.dir(clientBuildDir.map { it.dir(" node_modules" ) })
58- // If 'pnpm install' triggers a build (via 'prepare' script) that creates a 'dist' folder:
59- // outputs.dir(clientBuildDir.map { it.dir("dist") })
60- }
55+ val pnpmInstallTask =
56+ tasks.register<PnpmTask >(" pnpmInstall${clientType.capitalize()} " ) {
57+ group = " build"
58+ description = " Run pnpm install for $openApiGeneratorName client"
59+ dependsOn(generatorTask) // Must run after generation
60+
61+ workingDir.set(clientBuildDir)
62+ pnpmCommand = listOf (" install" )
63+
64+ // Define inputs/outputs for better up-to-date checks and caching
65+ // inputs.dir(clientBuildDir.map { it.dir("src") }).withPathSensitivity(PathSensitivity.RELATIVE) // Source might change
66+ inputs.file(clientBuildDir.map { it.file(" package.json" ) }).withPathSensitivity(PathSensitivity .RELATIVE )
67+ // Add pnpm-lock.yaml if you commit/use it
68+ // inputs.file(clientBuildDir.map { it.file("pnpm-lock.yaml") }).optional().withPathSensitivity(PathSensitivity.RELATIVE)
69+ outputs.dir(clientBuildDir.map { it.dir(" node_modules" ) })
70+ // If 'pnpm install' triggers a build (via 'prepare' script) that creates a 'dist' folder:
71+ // outputs.dir(clientBuildDir.map { it.dir("dist") })
72+ }
6173
6274 // Task to run 'npm pack'
63- val npmPackTask = tasks.register<NpmTask >(" npmPack${clientType.capitalize()} " ) {
64- group = " build"
65- description = " Run npm pack for $npmPackageName "
66- dependsOn(pnpmInstallTask) // Must run after pnpm install
67-
68- // npm pack creates the .tgz in the *current* working directory
69- workingDir.set(clientBuildDir.get().asFile) // Run npm pack from the project root
70- npmCommand = listOf (" pack" )
71- // Argument is the path to the directory containing package.json
72- args.set(listOf (clientBuildDir.get().asFile.absolutePath))
73-
74- inputs.dir(clientBuildDir)
75- inputs.files(pnpmInstallTask.map { it.outputs.files })
76-
77- outputs.file(publicationFile)
78- }
75+ val npmPackTask =
76+ tasks.register<NpmTask >(" npmPack${clientType.capitalize()} " ) {
77+ group = " build"
78+ description = " Run npm pack for $npmPackageName "
79+ dependsOn(pnpmInstallTask) // Must run after pnpm install
80+
81+ // npm pack creates the .tgz in the *current* working directory
82+ workingDir.set(clientBuildDir.get().asFile) // Run npm pack from the project root
83+ npmCommand = listOf (" pack" )
84+ // Argument is the path to the directory containing package.json
85+ args.set(listOf (clientBuildDir.get().asFile.absolutePath))
86+
87+ inputs.dir(clientBuildDir)
88+ inputs.files(pnpmInstallTask.map { it.outputs.files })
89+
90+ outputs.file(publicationFile)
91+ }
7992
80- val publishPackageTasks = tasks.register<NpmTask >(" publish${clientType.capitalize()} " ) {
81- group = " publishing" // Standard Gradle group for publishing
82- description = " Publishes the $npmPackageName package to the configured NPM registry."
83- dependsOn(npmPackTask) // Must run after the package is copied
84-
85- // Input: The specific .tgz file to be published
86- inputs.file(publicationFile)
87-
88- workingDir.set(project.projectDir) // Can run from project root
89- npmCommand.set(listOf (" publish" ))
90- // Argument is the path to the .tgz file in the build/packages directory
91- args.set(listOf (
92- publicationFile.get().asFile.absolutePath,
93- " --registry=https://artifacts.itemis.cloud/repository/npm-open/" ,
94- " --//artifacts.itemis.cloud/repository/npm-open/:_authToken=${project.findProperty(" artifacts.itemis.cloud.npm.token" ).toString()} "
95- ))
96-
97- // Add --access public if publishing public packages to npmjs.com scoped or not
98- // if (isPublicPackage) {
99- // args.add("--access")
100- // args.add("public")
101- // }
102-
103- // Ensure registry/auth is configured via .npmrc or node {} block
104- doFirst {
105- logger.lifecycle(" Attempting to publish ${publicationFile.get().asFile.name} ..." )
106- logger.info(" Ensure NPM registry and authentication are configured (e.g., via .npmrc)" )
107- if (! publicationFile.get().asFile.exists()) {
108- throw GradleException (" Package file to publish does not exist: ${publicationFile.get().asFile.absolutePath} " )
93+ val publishPackageTasks =
94+ tasks.register<NpmTask >(" publish${clientType.capitalize()} " ) {
95+ group = " publishing" // Standard Gradle group for publishing
96+ description = " Publishes the $npmPackageName package to the configured NPM registry."
97+ dependsOn(npmPackTask) // Must run after the package is copied
98+
99+ // Input: The specific .tgz file to be published
100+ inputs.file(publicationFile)
101+
102+ workingDir.set(project.projectDir) // Can run from project root
103+ npmCommand.set(listOf (" publish" ))
104+ // Argument is the path to the .tgz file in the build/packages directory
105+ args.set(
106+ listOf (
107+ publicationFile.get().asFile.absolutePath,
108+ " --registry=https://artifacts.itemis.cloud/repository/npm-open/" ,
109+ " --//artifacts.itemis.cloud/repository/npm-open/:_authToken=${project.findProperty(
110+ " artifacts.itemis.cloud.npm.token" ,
111+ )} " ,
112+ ),
113+ )
114+
115+ // Add --access public if publishing public packages to npmjs.com scoped or not
116+ // if (isPublicPackage) {
117+ // args.add("--access")
118+ // args.add("public")
119+ // }
120+
121+ // Ensure registry/auth is configured via .npmrc or node {} block
122+ doFirst {
123+ logger.lifecycle(" Attempting to publish ${publicationFile.get().asFile.name} ..." )
124+ logger.info(" Ensure NPM registry and authentication are configured (e.g., via .npmrc)" )
125+ if (! publicationFile.get().asFile.exists()) {
126+ throw GradleException (" Package file to publish does not exist: ${publicationFile.get().asFile.absolutePath} " )
127+ }
109128 }
110129 }
111- }
112130
113131 packageAllClients {
114132 dependsOn(npmPackTask)
@@ -122,17 +140,17 @@ fun registerNpmPackageTasks(
122140registerNpmPackageTasks(
123141 clientType = " fetch" ,
124142 npmPackageName = " api-client-ts-fetch" ,
125- openApiGeneratorName = " typescript-fetch"
143+ openApiGeneratorName = " typescript-fetch" ,
126144)
127145registerNpmPackageTasks(
128146 clientType = " axios" ,
129147 npmPackageName = " api-client-ts-axios" ,
130- openApiGeneratorName = " typescript-axios"
148+ openApiGeneratorName = " typescript-axios" ,
131149)
132150registerNpmPackageTasks(
133151 clientType = " redux" ,
134152 npmPackageName = " api-client-ts-redux" ,
135- openApiGeneratorName = " typescript-redux-query"
153+ openApiGeneratorName = " typescript-redux-query" ,
136154)
137155
138156tasks.assemble {
@@ -141,4 +159,4 @@ tasks.assemble {
141159
142160tasks.publish {
143161 dependsOn(publishAllClients)
144- }
162+ }
0 commit comments