Sfoglia il codice sorgente

feat: publish to JSR workflow

Sv443 10 mesi fa
parent
commit
5a2e5290a2
5 ha cambiato i file con 36 aggiunte e 8 eliminazioni
  1. 5 2
      .github/workflows/build-and-publish.yml
  2. 6 0
      jsr.json
  3. 0 5
      jsr.jsonc
  4. 2 1
      package.json
  5. 23 0
      tools/update-jsr-version.mts

+ 5 - 2
.github/workflows/build-and-publish.yml

@@ -14,6 +14,9 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
 jobs:
   publish:
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      id-token: write
     strategy:
       matrix:
         node-version: [20.x]
@@ -28,13 +31,13 @@ jobs:
         run: |
           npm run build
           npm run build-all
-      - name: Create dist folder artifact
+      - name: Create artifact
         uses: actions/upload-artifact@v4
         with:
           name: dist
           path: dist/
           retention-days: 2
-      - name: Create Release
+      - name: Create release
         uses: changesets/action@v1
         id: changesets
         with:

+ 6 - 0
jsr.json

@@ -0,0 +1,6 @@
+{
+  "$schema": "https://jsr.io/schema/config-file.v1.json",
+  "name": "@sv443-network/userutils",
+  "version": "7.1.0",
+  "exports": "./lib/index.ts"
+}

+ 0 - 5
jsr.jsonc

@@ -1,5 +0,0 @@
-{
-  "name": "@sv443-network/userutils",
-  "version": "6.3.0",
-  "exports": "./lib/index.ts"
-}

+ 2 - 1
package.json

@@ -15,7 +15,8 @@
     "build": "npm run build-common -- && npm run build-types",
     "post-build-global": "npm run node-ts -- ./tools/post-build-global.mts",
     "dev": "npm run build-common -- --sourcemap --watch --onSuccess \"npm run build-types && echo Finished building.\"",
-    "publish-package": "changeset publish",
+    "update-jsr-version": "npm run node-ts -- ./tools/update-jsr-version.mts",
+    "publish-package": "changeset publish && npm run update-jsr-version && npx jsr publish",
     "node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm",
     "test-serve": "npm run node-ts -- ./test/TestPage/server.mts",
     "test-dev": "cd test/TestScript && npm run dev",

+ 23 - 0
tools/update-jsr-version.mts

@@ -0,0 +1,23 @@
+import { readFile, writeFile } from "node:fs/promises";
+
+async function run() {
+  try {
+    const pkgJson = JSON.parse(String(await readFile("package.json", "utf8")));
+    const { version } = pkgJson;
+
+    const jsrJson = JSON.parse(String(await readFile("jsr.json", "utf8")));
+
+    jsrJson.version = version;
+
+    await writeFile("jsr.json", JSON.stringify(jsrJson, undefined, 2) + "\n");
+    console.log(`Updated jsr.json to version ${version}`);
+
+    setImmediate(() => process.exit(0));
+  }
+  catch(err) {
+    console.error("Couldn't update jsr.json:", err);
+    setImmediate(() => process.exit(1));
+  }
+}
+
+run();