Skip to content

Commit 6a9ce16

Browse files
authored
feat: provide pre-release flow
closes #25
1 parent c9aaf28 commit 6a9ce16

File tree

6 files changed

+353
-5
lines changed

6 files changed

+353
-5
lines changed

lib/createInlinePluginCreator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
8686
*/
8787
const analyzeCommits = async (pluginOptions, context) => {
8888
const firstParentBranch = flags.firstParent ? context.branch.name : undefined;
89+
pkg._preRelease = context.branch.prerelease || null;
8990

9091
// Filter commits by directory.
9192
commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead, firstParentBranch);

lib/updateDeps.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ const getNextVersion = (pkg) => {
1717
: lastVersion || "1.0.0";
1818
};
1919

20+
/**
21+
* Resolve next package version on prereleases.
22+
*
23+
* @param {Package} pkg Package object.
24+
* @returns {string|undefined} Next pkg version.
25+
* @internal
26+
*/
27+
const getNextPreVersion = (pkg) => {
28+
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;
29+
30+
return lastVersion ? semver.inc(lastVersion, "prerelease", pkg._preRelease) : `1.0.0-${pkg._preRelease}.1`;
31+
};
32+
2033
/**
2134
* Resolve package release type taking into account the cascading dependency update.
2235
*
@@ -90,7 +103,7 @@ const getDependentRelease = (pkg, bumpStrategy, releaseStrategy, ignore) => {
90103
// 1. Any local dep package itself has changed
91104
// 2. Any local dep package has local deps that have changed.
92105
const nextType = resolveReleaseType(p, bumpStrategy, releaseStrategy,[...ignore, ...localDeps]);
93-
const nextVersion = getNextVersion(p);
106+
const nextVersion = p._preRelease ? getNextPreVersion(p) : getNextVersion(p);
94107
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;
95108

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

170183
module.exports = {
171184
getNextVersion,
185+
getNextPreVersion,
172186
updateManifestDeps,
173187
resolveReleaseType,
174188
resolveNextVersion,

test/helpers/file.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { basename, join } = require("path");
2-
const { copyFileSync, existsSync, mkdirSync, lstatSync, readdirSync, readFileSync } = require("fs");
2+
const { copyFileSync, existsSync, mkdirSync, lstatSync, readdirSync, readFileSync, writeFileSync } = require("fs");
33

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

40+
// Creates testing files on all specified folders.
41+
function createNewTestingFiles(folders, cwd) {
42+
folders.forEach((fld) => {
43+
writeFileSync(`${cwd}/${fld}test.txt`, fld);
44+
});
45+
}
46+
4047
// Exports.
4148
module.exports = {
4249
copyDirectory,
4350
isDirectory,
51+
createNewTestingFiles,
4452
};

test/helpers/git.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ function gitInitRemote() {
6565
* _Created in a temp folder._
6666
*
6767
* @param {string} cwd The cwd to create and set the origin for.
68+
* @param {string} releaseBranch="null" Optional branch to be added in case of prerelease is activated for a branch.
6869
* @return {Promise<string>} Promise that resolves to string URL of the of the remote origin.
6970
*/
70-
function gitInitOrigin(cwd) {
71+
function gitInitOrigin(cwd, releaseBranch = null) {
7172
// Check params.
7273
check(cwd, "cwd: absolute");
7374

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

7778
// Set origin on local repo.
7879
execa.sync("git", ["remote", "add", "origin", url], { cwd });
80+
81+
// Set up a release branch. Return to master afterwards.
82+
if (releaseBranch) {
83+
execa.sync("git", ["checkout", "-b", releaseBranch], { cwd });
84+
execa.sync("git", ["checkout", "master"], { cwd });
85+
}
86+
7987
execa.sync("git", ["push", "--all", "origin"], { cwd });
8088

8189
// Return URL for remote.

0 commit comments

Comments
 (0)