I want the auto-generated package.json to be configured in a way that it points to the Kotlin generated JavaScript file. This is my current gradle configuration:
apply plugin: 'kotlin-platform-js'
apply from: "$project.rootDir/gradle/deploy.gradle"
dependencies {
expectedBy project(":")
// Compile/implementation dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
apply plugin: 'org.jetbrains.kotlin.frontend'
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
}
kotlinFrontend {
sourceMaps = true
npm {
dependency("kotlin")
replaceVersion("kotlin-js-library", "1.1.0")
}
define "PRODUCTION", true
webpackBundle {
bundleName = "${project.name}"
sourceMapEnabled = true
}
}
This outputs both a myProject.js file located in $project.builDir.path/classes/nain which is what I hoped would be reflected in the generated package.json file. But the outputted package.json file (located in the project's build directory) is like this:
{
"name": "myProject",
"version": "1.2.0-10-SNAPSHOT",
"description": "simple description",
"main": "myProject",
"dependencies": {
"kotlin": "*"
},
"devDependencies": {
"webpack": "*",
"webpack-dev-server": "*",
"source-map-loader": "*",
"karma": "*",
"qunitjs": "1.23.1",
"karma-qunit": "*",
"karma-sourcemap-loader": "*",
"karma-phantomjs-launcher": "*",
"phantomjs-prebuilt": "*",
"karma-webpack": "*"
}
}
The problem is this, the "main" attribute in the package.json does not point to the bundle file located in classes/main/myProject.js. I tried looking through the documentation to find how to set the main attribute to the to a specific directory and js file but could not find it. I can only change the name by setting bundleName property in webpackBundle portion of the gradle file. Thanks for the help in advance!
So I found a work around to be able to use gradle to publish to npm. I added the following bit to my code:
apply plugin: "com.moowork.node"
//Must copy the output javascript file
//to the location that the package.json expects it to be
//This is semi-workaround since I have not found a way to
//configure the outputted package.json file
task copyJSFile(type: Copy){
from "$project.buildDir.path/classes/main/"
into "${project.buildDir}"
include "*.js"
}
//We publish our project to npm
task npmPublish(dependsOn: copyJSFile, type: NpmTask) {
description = "publishes the project to npm"
workingDir = file("${project.buildDir}")
args = ['publish']
}
What this does is copy the outputted JavaScript generated files to a place where the package.json is configured when you call the npmPublish gradle task.
Related
Inside my Monorepo I have one packages in which I want all the dependencies inside its node_modules.
But whatever I do, it's node_modules remains empty.
So, for the purpose of my question I was able to reproduce the issue with the following setup
/
package.json
lerna.json
node_modules
packages/
A/
node_modules
package.json
index.ts
B/
node_modules
package.json
index.ts
I've created a repo for this!
Main package.json
{
"name": "A-B-test",
"private": true,
"workspaces": {
"packages": ["packages/*"],
"nohoist": [ "**/B" ]
},
...
"devDependencies": {
"lerna": "^3.13.4"
}
}
B/package.json looks like
{
"name": "#scaljeri/B",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"angular": "^1.7.8"
},
"devDependencies": {
"browserify": "^16.2.3",
"typescript": "^3.5.2"
}
}
Now when I run yarn in the root of the project, all dependencies are installed in the root node_modules.
yarn version: 1.16.0
node: 12.4.0
Any suggestions what might be the problem?
In my experience, it has been necessary to doubly specify each package in the following manner:
{
"nohoist": [
"**/B",
"**/B/**",
"**/C",
"**/C/**"
]
}
In addition, I have found it necessary to delete all existing node_modules folders after modifying the nohoist settings. So, if your projects are in packages, and you are in your project directory, you can delete all of those node_modules folders like this:
# delete node_modules on linux
rm -rf ./packages/*/node_modules
rm -rf ./node_modules
# install again
yarn install --check-files
I tried a few options but the only one that finally worked for me was specifying the nohoist option in the child package. No need to specify anything at the root level.
So my package.json in B package is:
{
...
"workspaces": {
"nohoist": ["**"]
},
...
}
Applying the nohoist to the child package's package.json did it for me.
"workspaces": {
"nohoist": [
"*react-native*",
"*react-native*/**"
]
},
If you want to exclude package B node modules from hoisting you can do that in you package.json:
"workspaces": {
"nohoist": [
"**/B",
"**/B/**"
]
},
after that remove node_modules and yarn.lock and run yarn install again now you should see packages/B/node_modules not being hoisted to the top level of the project
I have gradle task swagger-codegen with the following configuration:
swaggerSources {
testProject {
inputFile = file("$buildDir/generated/input.json")
code {
language = 'csharp'
configFile = file('swaggergen-config.json')
}
}
}
The file swaggergen-config.json contains:
{
"packageName": "Package.Test",
"packageVersion" : {version},
"netCoreProjectFile": true
}
How to properly replace {version} placeholder with project.version?
The swagger generator plugin looks for a file which makes this a little bit more complicated than just parsing the string and replacing the token.
A solution could be to treat the configuration file as a generated input to the generateSwaggerCode task. This can be done via a copy task that copies your swaggergen-config.json "template" and replaces the {version} with token rootProject.version using an ant ReplaceTokens filter during copy. Note: You'll want to switch {version} to the ant-style token format (e.g. #version#), though.
The swaggerSources.code.configFile closure could then be set to use the newly generated configuration.
This would be added to your build.gradle:
task generateSwaggerGenConfig(type: Copy) {
from swaggergen-config.json
into $buildDir/generated/swaggergen-config.json
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:['version:rootProject.version])
}
generateSwaggerCode.dependsOn generateSwaggerGenConfig
swaggerSources {
testProject {
inputFile = file("$buildDir/generated/input.json")
code {
language = 'csharp'
configFile = file("$buildDir/generated/swaggergen-config.json")
}
}
}
The generated swaggergen-config.json would look like this
{
"packageName": "Package.Test",
"packageVersion" : #version#,
"netCoreProjectFile": true
}
Goal:
Use a declarative Jenkins pipeline to download an artifact from Artifactory, run a test, and set a property value of the artifact in Artifactory based on the test result.
Trouble area:
How to set artifact properties of existing artifacts using the Artifactory plugin in a Jenkins pipeline?
Some of the code:
pipeline {
stages {
stage("Load") {
steps {
// Get the firmware from Artifactory
script {
def artServer = Artifactory.newServer url: '~~~'
def downloadSpecInline = """{
"files": [
{
"pattern": "${artRepo}/*thing-*${artBuildNo}*-class.zip",
"recursive": "true",
"flat": "true"
}
]
}"""
def artifactBuildInfo = artServer.download(downloadSpecInline)
// Unknown part
doSomeTest()
artifactBuildInfo.setProperty qa.level, awesome
}
}
}
}
}
You could just use the plugin.
def server = Artifactory.server "${_artifactoryServer}"
def propsSpec = """{
"files": [
{
"pattern": "${my_repo}/*/*/${_filename}"
}
]
}"""
server.setProps spec: propsSpec, props: "${_property}=${_value}", failNoOp: true
One thing to be careful of: If you don't specify a filename, ie. it is zero length, the API will write the property to every artifact in the repo.
I created a simple Gradle build that exports the contents of ./src/main/groovy to a zip file. The zip file contains a folder with the exact same name as the zip file. I cannot figure out how to get the files into the root of the zip file using the distribution plugin.
i.e. gradlew clean distZip produces:
helloDistribution-1.0.zip -> helloDistribution-1.0 -> files
what I would like:
helloDistribution-1.0.zip -> files
My build.gradle file:
apply plugin: 'groovy'
apply plugin: 'distribution'
version = '1.0'
distributions {
main {
contents {
from {
'src/main/groovy'
}
}
}
}
I have attempted to fix the problem by adding into { 'dir' } but to no avail.
Using into '/' seems to do the trick:
contents {
from {
'src/main/groovy'
}
into '/'
}
Unfortunately, penfold's answer did not work for me. Here is the solution I came up with:
task Package(type: Zip) {
from {
def rootScriptFiles = [] // collection of script files at the root of the src folder
new File('src/main/groovy/').eachFile { if (it.name.endsWith('.groovy')) rootScriptFiles.add(it) }
['build/libs/', // build binaries
'src/res/', // resources
rootScriptFiles, // groovy root source files
]
}
baseName = pluginName
}
To copy files into the root of helloDistribution-1.0.zip -> helloDistribution-1.0 -> use
contents {
from {
'some/file'
}
into ''
}
I created a simple Gradle build that exports the contents of ./src/main/groovy to a zip file. The zip file contains a folder with the exact same name as the zip file. I cannot figure out how to get the files into the root of the zip file using the distribution plugin.
i.e. gradlew clean distZip produces:
helloDistribution-1.0.zip -> helloDistribution-1.0 -> files
what I would like:
helloDistribution-1.0.zip -> files
My build.gradle file:
apply plugin: 'groovy'
apply plugin: 'distribution'
version = '1.0'
distributions {
main {
contents {
from {
'src/main/groovy'
}
}
}
}
I have attempted to fix the problem by adding into { 'dir' } but to no avail.
Using into '/' seems to do the trick:
contents {
from {
'src/main/groovy'
}
into '/'
}
Unfortunately, penfold's answer did not work for me. Here is the solution I came up with:
task Package(type: Zip) {
from {
def rootScriptFiles = [] // collection of script files at the root of the src folder
new File('src/main/groovy/').eachFile { if (it.name.endsWith('.groovy')) rootScriptFiles.add(it) }
['build/libs/', // build binaries
'src/res/', // resources
rootScriptFiles, // groovy root source files
]
}
baseName = pluginName
}
To copy files into the root of helloDistribution-1.0.zip -> helloDistribution-1.0 -> use
contents {
from {
'some/file'
}
into ''
}