-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create new canary version from published pkg
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require("fs/promises"); | ||
const path = require("path"); | ||
const { execSync } = require("child_process"); | ||
const { compareVersions } = require("compare-versions"); | ||
|
||
const ROOT_DIR = path.join(__dirname, ".."); | ||
|
||
main().catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
|
||
async function main() { | ||
const pkg = require(path.join(ROOT_DIR, "package.json")); | ||
const { name, version } = pkg; | ||
const canaryVersion = getCanaryVersion(name); | ||
|
||
const versionCompare = compareVersions(version, canaryVersion); | ||
|
||
if (versionCompare > 0) { | ||
console.info( | ||
`${name} v${version} is greater than the published canary v${canaryVersion}! Creating new canary version.` | ||
); | ||
|
||
createNewCanaryVersion(); | ||
return; | ||
} else { | ||
console.info( | ||
`${name} v${version} is less than the published canary v${canaryVersion}! Creating the next canary version.` | ||
); | ||
|
||
// set the current version to package.json | ||
setPackageVersion(canaryVersion); | ||
|
||
// create the next canary version | ||
createNewCanaryVersion(); | ||
} | ||
} | ||
|
||
function getCanaryVersion(name) { | ||
const manifestStr = execSync(`npm show ${name} dist-tags --json`).toString(); | ||
const manifest = JSON.parse(manifestStr); | ||
return manifest.canary; | ||
} | ||
|
||
function createNewCanaryVersion() { | ||
execSync(`yarn version --prerelease --preid=canary --no-git-tag-version`); | ||
} | ||
|
||
function setPackageVersion(version) { | ||
execSync(`npm pkg set version=${version}`); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2519,6 +2519,11 @@ commander@^4.0.0: | |
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" | ||
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== | ||
|
||
compare-versions@^6.1.1: | ||
version "6.1.1" | ||
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.1.1.tgz#7af3cc1099ba37d244b3145a9af5201b629148a9" | ||
integrity sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg== | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
|