Skip to content

Commit

Permalink
chore: automate publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 27, 2024
1 parent e2ecb46 commit 819d5bc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish JSR

on:
push:
branches:
- fresh-2.0

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4

- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: deno run --allow-write --allow-read tools/pre_publish.ts
- run: npx jsr publish
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marvinh-test/fresh",
"version": "2.0.0-prealpha.7",
"version": "2.0.0-prealpha.8",
"exports": {
".": "./src/mod.ts",
"./runtime": "./src/runtime/client/mod.tsx",
Expand Down
29 changes: 29 additions & 0 deletions tools/pre_publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from "@std/path";
import { DenoConfig } from "../src/dev/dev_app.ts";

const denoJsonPath = path.join(import.meta.dirname!, "..", "deno.json");
const denoJson = JSON.parse(
await Deno.readTextFile(denoJsonPath),
) as DenoConfig;

const replaceLibs = ["preact", "preact-render-to-string", "@preact/signals"];

if (denoJson.imports) {
for (const replace of replaceLibs) {
const value = denoJson.imports[replace];
if (value === undefined) continue;

// Remove url expansion imports. They are not neede with
// `npm:` or `jsr:` prefixes.
delete denoJson.imports[replace + "/"];

const match = value.match(
/^https:\/\/esm\.sh\/((@\w+\/)?[^@\?]+)(@[^\?]+)?.*$/,
);
if (match !== null) {
denoJson.imports[replace] = `npm:${match[1]}${match[3]}`;
}
}
}

await Deno.writeTextFile(denoJsonPath, JSON.stringify(denoJson, null, 2));

0 comments on commit 819d5bc

Please sign in to comment.