Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:

jobs:
ci:
runs-on: ubuntu-slim
steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: 🍞 Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0

- name: 📦 Install dependencies
run: bun install

- name: ⚙️ Generate
run: bun run generate

- name: 🔎 Typecheck
run: bun run typecheck

- name: 💅 Check formatting
run: bun format:check

- name: 🔍 Lint
run: bun lint

- name: 🧪 Test
run: bun test

- name: 🔨 Build
run: bun run build
81 changes: 81 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Release

on:
push:
tags:
- "v*"

permissions:
contents: write

jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-24.04-slim
target: bun-linux-x64
artifact: kronan-linux-x64
- os: ubuntu-24.04-slim
target: bun-linux-arm64
artifact: kronan-linux-arm64
- os: macos-latest
target: bun-darwin-arm64
artifact: kronan-darwin-arm64
- os: macos-latest
target: bun-darwin-x64
artifact: kronan-darwin-x64

runs-on: ${{ matrix.os }}

steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: 🍞 Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0

- name: 📦 Install dependencies
run: bun install

- name: 🔨 Build binary
env:
TARGET: ${{ matrix.target }}
OUTFILE: dist/${{ matrix.artifact }}
run: bun run build

- name: ⬆️ Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ matrix.artifact }}
path: dist/${{ matrix.artifact }}

release:
needs: build
runs-on: ubuntu-24.04-slim

steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: ⬇️ Download artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: artifacts

- name: 🚀 Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir -p release
for dir in artifacts/kronan-*; do
name=$(basename "$dir")
cp "$dir/$name" "release/$name"
chmod +x "release/$name"
done

gh release create "${{ github.ref_name }}" \
release/kronan-* \
--title "kronan-cli ${{ github.ref_name }}" \
--generate-notes \
--latest
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# dependencies (bun install)
node_modules

# generated
generated/
COMMANDS.md

# output
out
dist
*.tgz

# code coverage
coverage
*.lcov

# logs
logs
*.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# caches
.eslintcache
.cache
*.tsbuildinfo

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store

# Claude local settings
.claude/settings.local.json
3 changes: 3 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignorePatterns": ["generated/"]
}
115 changes: 115 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
description: Use Bun instead of Node.js, npm, pnpm, or vite.
globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json"
alwaysApply: false
---

Default to using Bun instead of Node.js.

- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
- Use `bun test` instead of `jest` or `vitest`
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
- Use `bunx <package> <command>` instead of `npx <package> <command>`
- Bun automatically loads .env, so don't use dotenv.

## APIs

- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
- `Bun.redis` for Redis. Don't use `ioredis`.
- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
- `WebSocket` is built-in. Don't use `ws`.
- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
- Bun.$`ls` instead of execa.

## Testing

Use `bun test` to run tests.

```ts#index.test.ts
import { test, expect } from "bun:test";

test("hello world", () => {
expect(1).toBe(1);
});
```

## Frontend

Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.

Server:

```ts#index.ts
import index from "./index.html"

Bun.serve({
routes: {
"/": index,
"/api/users/:id": {
GET: (req) => {
return new Response(JSON.stringify({ id: req.params.id }));
},
},
},
// optional websocket support
websocket: {
open: (ws) => {
ws.send("Hello, world!");
},
message: (ws, message) => {
ws.send(message);
},
close: (ws) => {
// handle close
}
},
development: {
hmr: true,
console: true,
}
})
```

HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.

```html#index.html
<html>
<body>
<h1>Hello, world!</h1>
<script type="module" src="./frontend.tsx"></script>
</body>
</html>
```

With the following `frontend.tsx`:

```tsx#frontend.tsx
import React from "react";
import { createRoot } from "react-dom/client";

// import .css files directly and it works
import './index.css';

const root = createRoot(document.body);

export default function Frontend() {
return <h1>Hello, world!</h1>;
}

root.render(<Frontend />);
```

Then, run index.ts

```sh
bun --hot ./index.ts
```

For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.

## Git Commits

Always use [Conventional Commits](https://www.conventionalcommits.org/) format: `<type>[optional scope]: <description>`
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# kronan-cli

A command-line interface for [Kronan](https://kronan.is). Built with [Umbra](https://github.com/ihs7/umbra), it auto-generates commands directly from the [Kronan Public API](https://api.kronan.is/api/v1/schema/redoc/)'s OpenAPI specification.

## Installation

### From GitHub Releases

```bash
curl -fsSL https://raw.githubusercontent.com/thor-coding-cowboys/kronan-cli/main/install.sh | bash
```

Supports **macOS** (Intel & Apple Silicon) and **Linux** (x64 & ARM64).

### Build from source

Requires [Bun](https://bun.sh) v1.3+:

```bash
bun install
bun run build
bun run install-local # installs to ~/.local/bin/kronan
```

## Authentication

1. Generate an API token from your [Kronan account settings](https://kronan.is/adgangur/adgangslyklar)
2. Run `kronan auth login` and paste the token when prompted

The token is stored securely in your system keychain. You can update it at any time by running `kronan auth login` again.

## Usage

```bash
kronan --help # list all available commands
kronan --version # show version

# Examples
kronan me list
kronan products retrieve --sku ABC123
kronan checkout add --sku ABC123 --quantity 2
kronan orders list
```

Every resource in the [Kronan Public API](https://api.kronan.is/api/v1/schema/redoc/) is available as a CLI command. See [COMMANDS.md](COMMANDS.md) for the full reference.

## Development

```bash
bun run generate # regenerate CLI from OpenAPI spec (https://api.kronan.is/api/v1/schema/)
bun run lint # run oxlint
bun run format # format with oxfmt
bun test # run tests
```
Loading