Skip to content

Commit

Permalink
chore: remove usage of jq since it cannot parse jsonc
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Nov 20, 2024
1 parent d06b0cd commit 5c19708
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .github/deno_config_parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// deno-lint-ignore-file no-console
// Imports
import * as JSONC from "@std/jsonc"
import { parseArgs } from "@std/cli"
import type { record } from "@libs/typing"

// Parse arguments
const { cwd, _: [keypath] } = parseArgs(Deno.args, { string: ["cwd"] })
if (cwd) {
Deno.chdir(cwd)
}

// Resolve config path and parse JSONC
let node = JSONC.parse(await Deno.readTextFile("./deno.jsonc")) as record

// Resolve keypath
const keys = `${keypath ?? ""}`.split(/\.(?![^\[]*\])/).filter(Boolean).map((key) => key.replace(/^\[(.*)\]$/, "$1"))
for (const key of keys) {
node = node?.[key] as record
}
console.log(node ?? "")
12 changes: 6 additions & 6 deletions .github/workflows/ci_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ jobs:
- name: Check package requirements
id: package
run: |
echo "has_build=$(jq -r 'if .tasks.build then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "has_npm=$(jq -r 'if .npm then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "has_x=$(jq -r 'if .["deno.land/x"] then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "has_build=$(deno task jq .tasks.build)" >> "$GITHUB_OUTPUT"
echo "has_npm=$(deno task jq .npm)" >> "$GITHUB_OUTPUT"
echo "has_x=$(deno task jq .["deno.land/x"])" >> "$GITHUB_OUTPUT"
# Build
- run: deno task build
if: ${{ steps.package.outputs.has_build }}
Expand All @@ -153,10 +153,10 @@ jobs:
- name: Compute tag and semantic version
id: tag
run: |
CURRENT_SEMVER="$(jq -r .version deno.jsonc)"
CURRENT_SEMVER="$(deno task jq .version)"
CURRENT_TAG="$(git tag --list '${{ inputs.package }}-*' | tail -1)"
TAG="${{ steps.tag-next.outputs.tag }}"
SEMVER="${{ steps.tag-next.outputs.semver }}"
TAG="${{ steps.tag-next.outputs.tag }}"
SEMVER="${{ steps.tag-next.outputs.semver }}"
echo "┌──────────────┬──────────────────────┬──────────────────────┐"
printf "│ %-12s │ %-20s │ %-20s │\n" "" "CURRENT" "NEXT"
printf "│ %-12s │ %-20s │ %-20s │\n" "TAG" "$CURRENT_TAG" "$TAG"
Expand Down
8 changes: 6 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
// Generate README.md
"make:readme": "deno run --allow-env=LOG_LEVEL --allow-read=. --allow-write=README.md .github/deno_readme.ts && deno fmt README.md",
// Generate html coverage
"make:coverage": "deno task test:deno --clean --coverage --fail-fast --reporter=dot && deno coverage --exclude=.js --html && sleep 1 && deno run --allow-read --allow-net=img.shields.io --allow-write=coverage jsr:@libs/bundle/ts/cli/coverage --root=coverage"
"make:coverage": "deno task test:deno --clean --coverage --fail-fast --reporter=dot && deno coverage --exclude=.js --html && sleep 1 && deno run --allow-read --allow-net=img.shields.io --allow-write=coverage jsr:@libs/bundle/ts/cli/coverage --root=coverage",
// Query in JSONC
"jq": "deno run --allow-read .github/deno_config_parser.ts --cwd=$INIT_CWD"
},
"imports": {
// Standard library dependencies
Expand Down Expand Up @@ -69,6 +71,8 @@
"hast": "npm:@types/hast@3",
"hastscript": "npm:hastscript@9",
"highlight.js": "npm:highlight.js@11",
"highlight.js/lib/core": "npm:highlight.js@11/lib/core",
"highlight.js/lib/languages/typescript": "npm:highlight.js@11/lib/languages/typescript",
"octokit": "npm:octokit@4",
"playwright": "npm:playwright@1",
"rehype-autolink-headings": "npm:rehype-autolink-headings@7",
Expand Down Expand Up @@ -103,7 +107,7 @@
"zod-to-json-schema": "npm:zod-to-json-schema@3",
// Stubs
"bun:test": "./testing/_stub.ts",
"node:test": "./testing/_stub.ts",
"node:test": "./testing/_stub.ts"
},
"nodeModulesDir": "auto",
"workspace": [
Expand Down

0 comments on commit 5c19708

Please sign in to comment.