diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..bddf42e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: Publish +on: + workflow_dispatch: + release: + types: [published] + +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 + + - name: Publish package + run: deno publish diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index aff1c96..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: release - -on: - push: - tags: - - "*.*.*" -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Release - uses: softprops/action-gh-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - draft: true diff --git a/LICENSE b/LICENSE index fd029c9..3e5e81a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-present the denosaurs team +Copyright (c) 2020-2024 the denosaurs team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..956829e --- /dev/null +++ b/deno.json @@ -0,0 +1,13 @@ +{ + "name": "@denosaurs/wait", + "version": "0.2.0", + "exports": { + ".": "./mod.ts", + "./spinners": "./spinners.ts", + "./log_symbols": "./log_symbols.ts" + }, + "imports": { + "@denosaurs/tty": "jsr:@denosaurs/tty@^0.2.1", + "@std/fmt": "jsr:@std/fmt@^1" + } +} diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..31a62d8 --- /dev/null +++ b/deno.lock @@ -0,0 +1,28 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denosaurs/tty@^0.2.0": "jsr:@denosaurs/tty@0.2.0", + "jsr:@denosaurs/tty@^0.2.1": "jsr:@denosaurs/tty@0.2.1", + "jsr:@std/fmt@^1.0.2": "jsr:@std/fmt@1.0.2" + }, + "jsr": { + "@denosaurs/tty@0.2.0": { + "integrity": "7bffd8da2faf026ed71e6a2292f058f49beda831bc9d8d8e141fb2f844f23b08" + }, + "@denosaurs/tty@0.2.1": { + "integrity": "f1fc651cc9021c90bf230a45c6eb893c26a54fae6a855e9cd26aad0083d772dd" + }, + "@std/fmt@1.0.2": { + "integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7" + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "jsr:@denosaurs/tty@^0.2.0", + "jsr:@std/fmt@^1.0.2" + ] + } +} diff --git a/deps.ts b/deps.ts deleted file mode 100644 index 0df6359..0000000 --- a/deps.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * as colors from "https://deno.land/std@0.170.0/fmt/colors.ts"; -export * as tty from "https://deno.land/x/tty@0.1.4/mod.ts"; diff --git a/log_symbols.ts b/log_symbols.ts index 68b4e9b..78d8dc2 100644 --- a/log_symbols.ts +++ b/log_symbols.ts @@ -1,4 +1,4 @@ -import { colors } from "./deps.ts"; +import * as colors from "@std/fmt/colors"; let supported = true; @@ -7,18 +7,21 @@ if ((await Deno.permissions.query({ name: "env" })).state === "granted") { (!!Deno.env.get("CI") || Deno.env.get("TERM") === "xterm-256color"); } -const main = { +export type SymbolType = "info" | "success" | "warning" | "error"; +export type SymbolRecord = { [key in SymbolType]: string }; + +export const main: SymbolRecord = { info: colors.blue("ℹ"), success: colors.green("✔"), warning: colors.yellow("⚠"), error: colors.red("✖"), }; -const fallbacks = { +export const fallbacks: SymbolRecord = { info: colors.blue("i"), success: colors.green("√"), warning: colors.yellow("‼"), error: colors.red("×"), }; -export const symbols = supported ? main : fallbacks; +export const symbols: SymbolRecord = supported ? main : fallbacks; diff --git a/mod.ts b/mod.ts index 801773a..9e4aece 100644 --- a/mod.ts +++ b/mod.ts @@ -1,9 +1,11 @@ -import { colors, tty } from "./deps.ts"; +import * as colors from "@std/fmt/colors"; +import * as tty from "@denosaurs/tty"; import spinners from "./spinners.ts"; - import { symbols } from "./log_symbols.ts"; +export { spinners, symbols }; + const encoder = new TextEncoder(); type ColorFunction = (message: string) => string; @@ -32,7 +34,7 @@ export interface SpinnerOptions { hideCursor?: boolean; indent?: number; interval?: number; - stream?: Deno.WriterSync & { rid: number }; + stream?: tty.SyncStream; enabled?: boolean; discardStdin?: boolean; interceptConsole?: boolean; @@ -62,7 +64,7 @@ export interface Console { timeLog: typeof console.timeLog; } -export function wait(opts: string | SpinnerOptions) { +export function wait(opts: string | SpinnerOptions): Spinner { if (typeof opts === "string") { opts = { text: opts }; } @@ -86,7 +88,7 @@ export class Spinner { isSpinning: boolean; - #stream: Deno.WriterSync & { rid: number }; + #stream: tty.SyncStream; indent: number; interval: number; @@ -135,7 +137,7 @@ export class Spinner { #text = ""; #prefix = ""; - #interceptConsole() { + #interceptConsole(): void { const methods: (keyof Console)[] = [ "log", "warn", @@ -174,7 +176,7 @@ export class Spinner { else this.#spinner = spin; } - get spinner() { + get spinner(): SpinnerAnimation { return this.#spinner; } @@ -183,7 +185,7 @@ export class Spinner { else this.#color = color; } - get color() { + get color(): ColorFunction { return this.#color; } @@ -192,7 +194,7 @@ export class Spinner { this.updateLines(); } - get text() { + get text(): string { return this.#text; } set prefix(value: string) { @@ -200,18 +202,18 @@ export class Spinner { this.updateLines(); } - get prefix() { + get prefix(): string { return this.#prefix; } - private write(data: string) { + #write(data: string): void { this.#stream.writeSync(encoder.encode(data)); } start(): Spinner { if (!this.#enabled) { if (this.text) { - this.write(`- ${this.text}\n`); + this.#write(`- ${this.text}\n`); } return this; } @@ -229,7 +231,7 @@ export class Spinner { render(): void { this.clear(); - this.write(`${this.frame()}\n`); + this.#write(`${this.frame()}\n`); this.updateLines(); this.#linesToClear = this.#linesCount; } @@ -282,7 +284,7 @@ export class Spinner { }, 0); } - stop() { + stop(): void { if (!this.#enabled) return; clearInterval(this.#id); this.#id = -1; @@ -294,7 +296,7 @@ export class Spinner { } } - stopAndPersist(options: PersistOptions = {}) { + stopAndPersist(options: PersistOptions = {}): void { const prefix = options.prefix || this.prefix; const fullPrefix = typeof prefix === "string" && prefix !== "" ? prefix + " " @@ -304,22 +306,22 @@ export class Spinner { this.stop(); // https://github.com/denoland/deno/issues/6001 - this.write(`${fullPrefix}${options.symbol || " "}${fullText}\n`); + this.#write(`${fullPrefix}${options.symbol || " "}${fullText}\n`); } - succeed(text?: string) { + succeed(text?: string): void { return this.stopAndPersist({ symbol: symbols.success, text }); } - fail(text?: string) { + fail(text?: string): void { return this.stopAndPersist({ symbol: symbols.error, text }); } - warn(text?: string) { + warn(text?: string): void { return this.stopAndPersist({ symbol: symbols.warning, text }); } - info(text?: string) { + info(text?: string): void { return this.stopAndPersist({ symbol: symbols.info, text }); } }