From d846e338b222599c7da9f67aa536099ad3c34dc4 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Fri, 17 Jan 2025 18:39:53 -0500 Subject: [PATCH] Publish to JSR (#2) * Added properties to deno.json needed by JSR * Added workflow to publish to JSR --- .github/workflows/publish.yaml | 33 ++++++++++++++++----------------- deno.json | 11 ++++++++--- main.ts | 16 ++++------------ staticalize.ts | 6 +++--- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 71e0dac..6d2711b 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -9,33 +9,32 @@ permissions: contents: write jobs: - build: + jsr: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - + - uses: actions/checkout@v4 - uses: denoland/setup-deno@v2 with: deno-version: v2.x + - run: deno publish --token=${{ secrets.JSR_API }} - - run: mkdir bin + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - - name: Get Version - id: vars - run: echo "version=$(echo $GITHUB_REF_NAME | sed 's/^v//')" >> $GITHUB_OUTPUT + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x - - name: Write Version file - run: | - touch VERSION - echo ${{steps.vars.outputs.version}} > VERSION + - run: mkdir bin - name: Compile for Linux arm64 run: | deno compile \ --target=aarch64-unknown-linux-gnu \ --output=bin/staticalize-linux-arm64 \ - --include=VERSION \ + --include=deno.json \ --allow-read --allow-write --allow-net --allow-env main.ts - name: Compile for macOS arm64 @@ -43,7 +42,7 @@ jobs: deno compile \ --target=aarch64-apple-darwin \ --output=bin/staticalize-macos-arm64 \ - --include=VERSION \ + --include=deno.json \ --allow-read --allow-write --allow-net --allow-env main.ts - name: Compile for Linux x64 @@ -51,7 +50,7 @@ jobs: deno compile \ --target=x86_64-unknown-linux-gnu \ --output=bin/staticalize-linux \ - --include=VERSION \ + --include=deno.json \ --allow-read --allow-write --allow-net --allow-env main.ts - name: Compile for Windows x64 @@ -59,7 +58,7 @@ jobs: deno compile \ --target=x86_64-pc-windows-msvc \ --output=bin/staticalize-windows \ - --include=VERSION \ + --include=deno.json \ --allow-read --allow-write --allow-net --allow-env main.ts - name: Compile for macOS x64 @@ -67,7 +66,7 @@ jobs: deno compile \ --target=x86_64-apple-darwin \ --output=bin/staticalize-macos \ - --include=VERSION \ + --include=deno.json \ --allow-read --allow-write --allow-net --allow-env main.ts - name: Compress binaries diff --git a/deno.json b/deno.json index 17e08d2..802053d 100644 --- a/deno.json +++ b/deno.json @@ -1,4 +1,8 @@ { + "name": "@frontside/staticalize", + "version": "0.1.0", + "exports": "./mod.ts", + "license": "MIT", "tasks": { "dev": "deno run --watch main.ts", "compile": "deno compile --allow-read --allow-write --allow-env --allow-sys --allow-run --allow-net -o staticalize main.ts" @@ -7,9 +11,10 @@ "@std/assert": "jsr:@std/assert@1", "@std/cli": "jsr:@std/cli@1", "@std/testing": "jsr:@std/testing@^1.0.0", - "@std/fs": "jsr:@std/fs", - "@libs/xml": "jsr:@libs/xml", - "deno-dom": "jsr:@b-fuze/deno-dom", + "@std/fs": "jsr:@std/fs@1", + "@std/path": "jsr:@std/path@1", + "@libs/xml": "jsr:@libs/xml@^6.0.0", + "deno-dom": "jsr:@b-fuze/deno-dom@0.1.49", "effection": "npm:effection@4.0.0-alpha.4" }, "lint": { diff --git a/main.ts b/main.ts index 22fdbce..d1f767d 100644 --- a/main.ts +++ b/main.ts @@ -1,8 +1,8 @@ -import { call, main } from "effection"; +import { main } from "effection"; import { parser } from "npm:zod-opts"; import { z } from "npm:zod"; import { staticalize } from "./staticalize.ts"; -import { join } from "jsr:@std/path"; +import denoJson from "./deno.json" with { type: "json" }; const url = () => z.string().refine((str) => str.match(/^http/), { @@ -15,7 +15,7 @@ await main(function* (args) { .description( "Create a static version of a website by traversing a dynamically evaluated sitemap.xml", ) - .version(yield* version()) + .version(denoJson.version) .options({ site: { alias: "s", @@ -41,12 +41,4 @@ await main(function* (args) { host: new URL(options.site), dir: options.output, }); -}); - -function* version() { - try { - return yield* call(() => Deno.readTextFile(join(import.meta.dirname ?? "./", "VERSION"))); - } catch { - return "0.0.0" - } -} \ No newline at end of file +}); \ No newline at end of file diff --git a/staticalize.ts b/staticalize.ts index 7422ce9..0ff2ffa 100644 --- a/staticalize.ts +++ b/staticalize.ts @@ -1,8 +1,8 @@ -import { call, Operation, resource, spawn, useAbortSignal } from "effection"; -import { dirname, join, normalize } from "jsr:@std/path"; +import { call, type Operation, resource, spawn, useAbortSignal } from "effection"; +import { dirname, join, normalize } from "@std/path"; import { ensureDir } from "@std/fs/ensure-dir"; import { stringify } from "@libs/xml/stringify"; -import { DOMParser, Element } from "deno-dom"; +import { DOMParser, type Element } from "deno-dom"; import { parse } from "@libs/xml/parse"; import { useTaskBuffer } from "./task-buffer.ts";