Skip to content

Commit

Permalink
Feature/add only prerelease flag (#2)
Browse files Browse the repository at this point in the history
* feat: add only-prerelease flag

* chore: version bump
  • Loading branch information
jkoenig134 authored Apr 17, 2024
1 parent 5e2e24a commit f8af15c
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 49 deletions.
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ async function run() {
}

const pkg = getPackageInfo()

const semverWithPreidRegex = /^\d+\.\d+\.\d+(?:-([a-z]+)(?:\.\d+)+)?$/
const semverMatches = semverWithPreidRegex.exec(pkg.version)

if (process.argv.includes("--only-prerelease")) {
console.log("Only prerelease packages will be published.")

if (!semverMatches || !semverMatches[1]) {
console.error(`The version '${pkg.version}' of package '${pkg.name}' is not a prerelease version, aborting.`)
process.exit(0)
}
}

const isPublished = await existsPackageInRegistry(pkg)

if (process.argv.includes("--if-possible") && isPublished) {
Expand All @@ -50,8 +63,6 @@ async function run() {
args.splice(0, 2)
args = args.filter((arg) => !newFlags.includes(arg))

const semverWithPreidRegex = /^\d+\.\d+\.\d+(?:-([a-z]+)(?:\.\d+)+)?$/
const semverMatches = semverWithPreidRegex.exec(pkg.version)
if (process.argv.includes("--use-preid-as-tag") && semverMatches && semverMatches[1]) {
const preid = semverMatches[1]
args.push("--tag", preid)
Expand Down
152 changes: 107 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enhanced-publish",
"version": "1.1.2",
"version": "1.1.3",
"description": "Npm publish command with lerna's from-package publish behaviour.",
"repository": "github:js-soft/enhanced-npm-publish",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
"index.js"
],
"dependencies": {
"pacote": "^17.0.6"
"pacote": "^18.0.0"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit f8af15c

Please # to comment.