enhanced-publish 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +22 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -26,21 +26,37 @@ async function existsPackageInRegistry(pkg) {
|
|
|
26
26
|
)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const newFlags = ["--if-possible", "--use-preid-as-tag"]
|
|
30
|
+
|
|
29
31
|
async function run() {
|
|
32
|
+
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
33
|
+
console.log(`This command will publish your package to the npm registry. It adds the following flags to the original publish command:
|
|
34
|
+
--if-possible - If the package is already published, it will not publish it again.
|
|
35
|
+
--use-preid-as-tag - Will use the 'preid' as the tag. e.g. '1.0.0-alpha.1' -> '--tag alpha'`)
|
|
36
|
+
process.exit(0)
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
const pkg = getPackageInfo()
|
|
31
40
|
const isPublished = await existsPackageInRegistry(pkg)
|
|
32
41
|
|
|
33
42
|
if (process.argv.includes("--if-possible") && isPublished) {
|
|
34
43
|
console.log(`${pkg.name} with version ${pkg.version} is already published.`)
|
|
35
44
|
process.exit(0)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let args = [...process.argv]
|
|
48
|
+
args.splice(0, 2)
|
|
49
|
+
args = args.filter((arg) => !newFlags.includes(arg))
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
const semverWithPreidRegex = /^\d+\.\d+\.\d+(?:-([a-z]+)(?:\.\d+)+)?$/
|
|
52
|
+
const semverMatches = semverWithPreidRegex.exec(pkg.version)
|
|
53
|
+
if (process.argv.includes("--use-preid-as-tag") && semverMatches && semverMatches[1]) {
|
|
54
|
+
const preid = semverMatches[1]
|
|
55
|
+
args.push("--tag", preid)
|
|
43
56
|
}
|
|
57
|
+
|
|
58
|
+
const child = spawn("npm", ["publish", ...args], { stdio: "inherit" })
|
|
59
|
+
child.on("exit", (code) => process.exit(code))
|
|
44
60
|
}
|
|
45
61
|
|
|
46
62
|
run()
|