Skip to content

Commit

Permalink
feat: provide pre-release flow
Browse files Browse the repository at this point in the history
closes #25
  • Loading branch information
davikawasaki authored Dec 23, 2020
1 parent c9aaf28 commit 6a9ce16
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
*/
const analyzeCommits = async (pluginOptions, context) => {
const firstParentBranch = flags.firstParent ? context.branch.name : undefined;
pkg._preRelease = context.branch.prerelease || null;

// Filter commits by directory.
commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead, firstParentBranch);
Expand Down
16 changes: 15 additions & 1 deletion lib/updateDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ const getNextVersion = (pkg) => {
: lastVersion || "1.0.0";
};

/**
* Resolve next package version on prereleases.
*
* @param {Package} pkg Package object.
* @returns {string|undefined} Next pkg version.
* @internal
*/
const getNextPreVersion = (pkg) => {
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;

return lastVersion ? semver.inc(lastVersion, "prerelease", pkg._preRelease) : `1.0.0-${pkg._preRelease}.1`;
};

/**
* Resolve package release type taking into account the cascading dependency update.
*
Expand Down Expand Up @@ -90,7 +103,7 @@ const getDependentRelease = (pkg, bumpStrategy, releaseStrategy, ignore) => {
// 1. Any local dep package itself has changed
// 2. Any local dep package has local deps that have changed.
const nextType = resolveReleaseType(p, bumpStrategy, releaseStrategy,[...ignore, ...localDeps]);
const nextVersion = getNextVersion(p);
const nextVersion = p._preRelease ? getNextPreVersion(p) : getNextVersion(p);
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;

// 3. And this change should correspond to manifest updating rule.
Expand Down Expand Up @@ -169,6 +182,7 @@ const updateManifestDeps = (pkg) => {

module.exports = {
getNextVersion,
getNextPreVersion,
updateManifestDeps,
resolveReleaseType,
resolveNextVersion,
Expand Down
10 changes: 9 additions & 1 deletion test/helpers/file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { basename, join } = require("path");
const { copyFileSync, existsSync, mkdirSync, lstatSync, readdirSync, readFileSync } = require("fs");
const { copyFileSync, existsSync, mkdirSync, lstatSync, readdirSync, readFileSync, writeFileSync } = require("fs");

// Deep copy a directory.
function copyDirectory(source, target) {
Expand Down Expand Up @@ -37,8 +37,16 @@ function isDirectory(path) {
return typeof path === "string" && existsSync(path) && lstatSync(path).isDirectory();
}

// Creates testing files on all specified folders.
function createNewTestingFiles(folders, cwd) {
folders.forEach((fld) => {
writeFileSync(`${cwd}/${fld}test.txt`, fld);
});
}

// Exports.
module.exports = {
copyDirectory,
isDirectory,
createNewTestingFiles,
};
10 changes: 9 additions & 1 deletion test/helpers/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ function gitInitRemote() {
* _Created in a temp folder._
*
* @param {string} cwd The cwd to create and set the origin for.
* @param {string} releaseBranch="null" Optional branch to be added in case of prerelease is activated for a branch.
* @return {Promise<string>} Promise that resolves to string URL of the of the remote origin.
*/
function gitInitOrigin(cwd) {
function gitInitOrigin(cwd, releaseBranch = null) {
// Check params.
check(cwd, "cwd: absolute");

Expand All @@ -76,6 +77,13 @@ function gitInitOrigin(cwd) {

// Set origin on local repo.
execa.sync("git", ["remote", "add", "origin", url], { cwd });

// Set up a release branch. Return to master afterwards.
if (releaseBranch) {
execa.sync("git", ["checkout", "-b", releaseBranch], { cwd });
execa.sync("git", ["checkout", "master"], { cwd });
}

execa.sync("git", ["push", "--all", "origin"], { cwd });

// Return URL for remote.
Expand Down
Loading

0 comments on commit 6a9ce16

Please sign in to comment.