Last active
July 12, 2017 04:33
-
-
Save patrickmarabeas/68cb15303c2f427a3270136673253a07 to your computer and use it in GitHub Desktop.
Lerna publishing only changed packages (ignore transitive dependants)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/** | |
* Accepts a string of space separated files generated by git | |
* Returns a string of comma separated @scoped/package names | |
*/ | |
const commander = require('commander'); | |
const packageRootMatch = /^packages\//; | |
const packageNameCapture = /^packages\/(.+?)\//; | |
console.log(commander | |
.parse(process.argv).args | |
// Filter out non package files | |
.filter(filePath => filePath.match(packageRootMatch)) | |
// Map file paths to package names (assumes package names === containing folder names bar scope) | |
.map(filePath => filePath.match(packageNameCapture)[1]) | |
// Filter out duplicates | |
.filter((packageName, idx, arr) => arr.indexOf(packageName) === idx) | |
// Map package names to scoped package names | |
// .map(packageName => `@SCOPE/${packageName}`) | |
// Return as a comma separated string for consumption by `lerna publish --scope={...}` | |
.join(',')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"publish/transitive": "lerna publish", | |
"publish/changed": "./scripts/publish.changed.sh" | |
}, | |
"dependencies": { | |
"commander": "^2.11.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BIN_PATH=$(yarn bin) | |
LERNA="$BIN_PATH/lerna" | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
if [ "$BRANCH" != "master" ]; then | |
exit 1 | |
fi | |
LAST_PUBLISH_SHA=$(git log :/Publish --pretty=format:"%H" -1) | |
FILES_CHANGED=$(git diff --name-only ${LAST_PUBLISH_SHA}) | |
PKGS=$(./_filePathsToPackageNames.js ${FILES_CHANGED}) | |
PACKAGE_NUMBER=${PKGS//[^ ]} | |
[[ "${#PACKAGE_NUMBER}" -gt 0 ]] && SCOPE={${PKGS// /,}} || SCOPE=${PKGS} | |
${LERNA} publish --scope=${SCOPE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment