Skip to content

Commit

Permalink
Merge pull request #60 from zowe/add-dep-reg
Browse files Browse the repository at this point in the history
Add dep reg
  • Loading branch information
zFernand0 authored Oct 14, 2019
2 parents 9e1b4a6 + 339353c commit 2ced6a2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 15 deletions.
34 changes: 30 additions & 4 deletions src/org/zowe/pipelines/nodejs/NodeJSPipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@ class NodeJSPipeline extends GenericPipeline {
steps.sh "npm shrinkwrap"

// Install devDependencies to prevent any prepublishOnly from failing
_processDeps(branch.devDependencies, true)
steps.sh "npm install --only=dev --no-shrinkwrap"

steps.sh "npm publish --tag ${branch.tag}"

sendHtmlEmail(
Expand Down Expand Up @@ -824,9 +824,8 @@ class NodeJSPipeline extends GenericPipeline {

if (protectedBranches.isProtected(branch)) {
def branchProps = protectedBranches.get(branch)

branchProps.dependencies.each { npmPackage, version -> steps.sh "npm install --save --save-exact $npmPackage@$version" }
branchProps.devDependencies.each { npmPackage, version -> steps.sh "npm install --save-dev --save-exact $npmPackage@$version" }
_processDeps(branchProps.dependencies, false)
_processDeps(branchProps.devDependencies, true)

// Commits will be avoided on PRs
if (!changeInfo.isPullRequest) {
Expand Down Expand Up @@ -889,6 +888,33 @@ class NodeJSPipeline extends GenericPipeline {
super.testGeneric(arguments)
}

/**
* Process provided dependencies in different approaches depending on the data.
*
* @param depName Map containing all dependencies to be processed
* @param isDevDep Specifies if the function is processing regualr dependencies or devDependencies
*
* @Note Dependencies can be processed in two different ways
* <ul>
* <li>Simple format: <code>["@my-org/my-pkg" : "<version-number-OR-pkg-tag>"]</code></li>
* <li>Structured format: <code>["my-pkg-description": ["name":"@my-org/my-pkg", "version": "<version-number-OR-pkg-tag>", "registry?":"https://my-registry-URL"]]</code></li>
* </ul>
*/
protected void _processDeps(Map<String, Object> deps, Boolean isDevDep) {
deps.each { depName, depInfo ->
steps.echo "Installing: ${depName}"
if (depInfo instanceof CharSequence) {
// Since this is a string, we just need to do what we did before
steps.sh "npm install --save${isDevDep ? '-dev' : ''} --save-exact $depName@$depInfo"
} else {
// Let's parse the object we got
def depScope = "${depInfo.name.indexOf('/') >= 0 ? depInfo.name.substring(0, depInfo.name.indexOf('/')) : ''}"
def depReg = depScope ? "--$depScope:registry=$depInfo.registry" : "--registry=$depInfo.registry"
steps.sh "npm install --save${isDevDep ? '-dev' : ''} --save-exact $depInfo.name@$depInfo.version ${depInfo.registry ? depReg : ''}"
}
}
}

/**
* Login to the specified registry.
*
Expand Down
35 changes: 35 additions & 0 deletions src/org/zowe/pipelines/nodejs/models/DependencyDefinition.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.pipelines.nodejs.models

class DependencyDefinition {
/**
* Package name of the specified dependency
*
* @Note Remember to use the pull package name which can include a scope
*/
String name

/**
* Package version or tag of the specified depencency
*/
String version

/**
* Registry URL to which the specified dependecy should be associated
*
* <p>If the registry is not specified, it will default to the public NPM registry</p>
*
* @default "https://registry.npmjs.org/"
*/
String registry = "https://registry.npmjs.org/"
}

23 changes: 12 additions & 11 deletions src/org/zowe/pipelines/nodejs/models/NodeJSProtectedBranch.groovy
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.pipelines.nodejs.models

import org.zowe.pipelines.base.models.ProtectedBranch
import org.zowe.pipelines.nodejs.models.DependencyDefinition

/**
* @see org.zowe.pipelines.base.models.ProtectedBranch
Expand All @@ -32,7 +33,7 @@ class NodeJSProtectedBranch extends ProtectedBranch {
* with the latest versions in the protected branch. For pull requests into a protected branch,
* the dependencies required by the protected branch will be installed but not committed.</p>
*/
Map<String, String> dependencies = [:]
Map<String, Object> dependencies = [:]

/**
* A map of devDependencies and their required installable tags for this
Expand All @@ -42,7 +43,7 @@ class NodeJSProtectedBranch extends ProtectedBranch {
* with the latest versions in the protected branch. For pull requests into a protected branch,
* the devDependencies required by the protected branch will be installed but not committed.</p>
*/
Map<String, String> devDependencies = [:]
Map<String, Object> devDependencies = [:]

/**
* The max release level that will be prompted for the branch.
Expand Down

0 comments on commit 2ced6a2

Please sign in to comment.