enhanced-publish 1.0.3 → 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 CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  const { spawn } = require("child_process")
2
4
  const { readFileSync } = require("fs")
3
5
  const pacote = require("pacote")
@@ -24,21 +26,37 @@ async function existsPackageInRegistry(pkg) {
24
26
  )
25
27
  }
26
28
 
29
+ const newFlags = ["--if-possible", "--use-preid-as-tag"]
30
+
27
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
+
28
39
  const pkg = getPackageInfo()
29
40
  const isPublished = await existsPackageInRegistry(pkg)
30
41
 
31
42
  if (process.argv.includes("--if-possible") && isPublished) {
32
43
  console.log(`${pkg.name} with version ${pkg.version} is already published.`)
33
44
  process.exit(0)
34
- } else {
35
- let args = [...process.argv]
36
- args.splice(0, 2)
37
- args = args.filter((arg) => arg !== "--if-possible")
45
+ }
38
46
 
39
- const child = spawn("npm", ["publish", ...args], { stdio: "inherit" })
40
- child.on("exit", (code) => process.exit(code))
47
+ let args = [...process.argv]
48
+ args.splice(0, 2)
49
+ args = args.filter((arg) => !newFlags.includes(arg))
50
+
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)
41
56
  }
57
+
58
+ const child = spawn("npm", ["publish", ...args], { stdio: "inherit" })
59
+ child.on("exit", (code) => process.exit(code))
42
60
  }
43
61
 
44
62
  run()
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "enhanced-publish",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Npm publish command with lerna's from-package publish behaviour.",
5
5
  "repository": "github:js-soft/enhanced-npm-publish",
6
6
  "license": "MIT",
7
7
  "author": "js-soft GmbH",
8
8
  "bin": "index.js",
9
+ "files": [
10
+ "index.js"
11
+ ],
9
12
  "dependencies": {
10
13
  "pacote": "^12.0.3"
11
14
  },
@@ -1,28 +0,0 @@
1
- name: "CodeQL"
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
- branches: [main]
8
- schedule:
9
- - cron: "45 19 * * 4"
10
-
11
- jobs:
12
- analyze:
13
- name: Analyze
14
- runs-on: ubuntu-latest
15
- permissions:
16
- security-events: write
17
-
18
- steps:
19
- - name: Checkout repository
20
- uses: actions/checkout@v2
21
-
22
- - name: Initialize CodeQL
23
- uses: github/codeql-action/init@v1
24
- with:
25
- languages: javascript
26
-
27
- - name: Perform CodeQL Analysis
28
- uses: github/codeql-action/analyze@v1
@@ -1,21 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- publish-npm:
10
- runs-on: ubuntu-latest
11
- container: jssoft/node_browsertests
12
- steps:
13
- - uses: actions/checkout@v2
14
- - uses: actions/setup-node@v2
15
- with:
16
- node-version: 16
17
- registry-url: https://registry.npmjs.org/
18
- - run: npm ci
19
- - run: node index.js --if-possible
20
- env:
21
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}