|
@@ -35,13 +35,30 @@ function setupGit() {
|
35
|
35
|
exec.execSync(`git checkout ${ONLY_ON_BRANCH}`);
|
36
|
36
|
}
|
37
|
37
|
|
38
|
|
-function calcNewVersion() {
|
|
38
|
+function getNextVersion() {
|
39
|
39
|
const packageVersion = semver.clean(process.env.npm_package_version);
|
40
|
40
|
console.log(`package version: ${packageVersion}`);
|
41
|
|
- exec.execSync(`git fetch --unshallow`);
|
42
|
|
- const commitCount = exec.execSyncRead(`git rev-list --count ${ONLY_ON_BRANCH}`);
|
43
|
|
- console.log(`commits in ${ONLY_ON_BRANCH}: ${commitCount}`);
|
44
|
|
- return `${semver.major(packageVersion)}.${semver.minor(packageVersion)}.${commitCount}`;
|
|
41
|
+ const current = exec.execSyncRead(`npm view ${process.env.npm_package_name} dist-tags.${VERSION_TAG}`);
|
|
42
|
+ console.log(`current published version: ${current}`);
|
|
43
|
+
|
|
44
|
+ if (semver.gt(packageVersion, current)) {
|
|
45
|
+ return packageVersion;
|
|
46
|
+ } else {
|
|
47
|
+ return semver.inc(current, VERSION_INC);
|
|
48
|
+ }
|
|
49
|
+}
|
|
50
|
+
|
|
51
|
+function calcNewVersion() {
|
|
52
|
+ let candidate = getNextVersion();
|
|
53
|
+ while (isAlreadyPublished(candidate)) {
|
|
54
|
+ console.log(`${candidate} already published`);
|
|
55
|
+ candidate = semver.inc(candidate, VERSION_INC);
|
|
56
|
+ }
|
|
57
|
+ return candidate;
|
|
58
|
+}
|
|
59
|
+
|
|
60
|
+function isAlreadyPublished(version) {
|
|
61
|
+ return exec.execSyncRead(`npm view ${process.env.npm_package_name}@${version} version`).length > 0;
|
45
|
62
|
}
|
46
|
63
|
|
47
|
64
|
function createNpmRc() {
|