Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Modernize and publish to JSR #18

Merged
merged 1 commit into from
Sep 22, 2024
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
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
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
20 changes: 0 additions & 20 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 28 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions deps.ts

This file was deleted.

11 changes: 7 additions & 4 deletions log_symbols.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colors } from "./deps.ts";
import * as colors from "@std/fmt/colors";

let supported = true;

Expand All @@ -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;
42 changes: 22 additions & 20 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
}
Expand All @@ -86,7 +88,7 @@ export class Spinner {

isSpinning: boolean;

#stream: Deno.WriterSync & { rid: number };
#stream: tty.SyncStream;
indent: number;
interval: number;

Expand Down Expand Up @@ -135,7 +137,7 @@ export class Spinner {
#text = "";
#prefix = "";

#interceptConsole() {
#interceptConsole(): void {
const methods: (keyof Console)[] = [
"log",
"warn",
Expand Down Expand Up @@ -174,7 +176,7 @@ export class Spinner {
else this.#spinner = spin;
}

get spinner() {
get spinner(): SpinnerAnimation {
return this.#spinner;
}

Expand All @@ -183,7 +185,7 @@ export class Spinner {
else this.#color = color;
}

get color() {
get color(): ColorFunction {
return this.#color;
}

Expand All @@ -192,26 +194,26 @@ export class Spinner {
this.updateLines();
}

get text() {
get text(): string {
return this.#text;
}
set prefix(value: string) {
this.#prefix = value;
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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -282,7 +284,7 @@ export class Spinner {
}, 0);
}

stop() {
stop(): void {
if (!this.#enabled) return;
clearInterval(this.#id);
this.#id = -1;
Expand All @@ -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 + " "
Expand All @@ -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 });
}
}
Loading