Skip to content

Commit 66d251a

Browse files
feat: Modernize and publish to JSR (#18)
1 parent 9e378ad commit 66d251a

File tree

8 files changed

+94
-47
lines changed

8 files changed

+94
-47
lines changed

.github/workflows/publish.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish
2+
on:
3+
workflow_dispatch:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install Deno
18+
uses: denoland/setup-deno@v1
19+
with:
20+
deno-version: v1.x
21+
22+
- name: Publish package
23+
run: deno publish

.github/workflows/release.yml

-20
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-present the denosaurs team
3+
Copyright (c) 2020-2024 the denosaurs team
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

deno.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@denosaurs/wait",
3+
"version": "0.2.0",
4+
"exports": {
5+
".": "./mod.ts",
6+
"./spinners": "./spinners.ts",
7+
"./log_symbols": "./log_symbols.ts"
8+
},
9+
"imports": {
10+
"@denosaurs/tty": "jsr:@denosaurs/tty@^0.2.1",
11+
"@std/fmt": "jsr:@std/fmt@^1"
12+
}
13+
}

deno.lock

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps.ts

-2
This file was deleted.

log_symbols.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { colors } from "./deps.ts";
1+
import * as colors from "@std/fmt/colors";
22

33
let supported = true;
44

@@ -7,18 +7,21 @@ if ((await Deno.permissions.query({ name: "env" })).state === "granted") {
77
(!!Deno.env.get("CI") || Deno.env.get("TERM") === "xterm-256color");
88
}
99

10-
const main = {
10+
export type SymbolType = "info" | "success" | "warning" | "error";
11+
export type SymbolRecord = { [key in SymbolType]: string };
12+
13+
export const main: SymbolRecord = {
1114
info: colors.blue("ℹ"),
1215
success: colors.green("✔"),
1316
warning: colors.yellow("⚠"),
1417
error: colors.red("✖"),
1518
};
1619

17-
const fallbacks = {
20+
export const fallbacks: SymbolRecord = {
1821
info: colors.blue("i"),
1922
success: colors.green("√"),
2023
warning: colors.yellow("‼"),
2124
error: colors.red("×"),
2225
};
2326

24-
export const symbols = supported ? main : fallbacks;
27+
export const symbols: SymbolRecord = supported ? main : fallbacks;

mod.ts

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { colors, tty } from "./deps.ts";
1+
import * as colors from "@std/fmt/colors";
2+
import * as tty from "@denosaurs/tty";
23

34
import spinners from "./spinners.ts";
4-
55
import { symbols } from "./log_symbols.ts";
66

7+
export { spinners, symbols };
8+
79
const encoder = new TextEncoder();
810

911
type ColorFunction = (message: string) => string;
@@ -32,7 +34,7 @@ export interface SpinnerOptions {
3234
hideCursor?: boolean;
3335
indent?: number;
3436
interval?: number;
35-
stream?: Deno.WriterSync & { rid: number };
37+
stream?: tty.SyncStream;
3638
enabled?: boolean;
3739
discardStdin?: boolean;
3840
interceptConsole?: boolean;
@@ -62,7 +64,7 @@ export interface Console {
6264
timeLog: typeof console.timeLog;
6365
}
6466

65-
export function wait(opts: string | SpinnerOptions) {
67+
export function wait(opts: string | SpinnerOptions): Spinner {
6668
if (typeof opts === "string") {
6769
opts = { text: opts };
6870
}
@@ -86,7 +88,7 @@ export class Spinner {
8688

8789
isSpinning: boolean;
8890

89-
#stream: Deno.WriterSync & { rid: number };
91+
#stream: tty.SyncStream;
9092
indent: number;
9193
interval: number;
9294

@@ -135,7 +137,7 @@ export class Spinner {
135137
#text = "";
136138
#prefix = "";
137139

138-
#interceptConsole() {
140+
#interceptConsole(): void {
139141
const methods: (keyof Console)[] = [
140142
"log",
141143
"warn",
@@ -174,7 +176,7 @@ export class Spinner {
174176
else this.#spinner = spin;
175177
}
176178

177-
get spinner() {
179+
get spinner(): SpinnerAnimation {
178180
return this.#spinner;
179181
}
180182

@@ -183,7 +185,7 @@ export class Spinner {
183185
else this.#color = color;
184186
}
185187

186-
get color() {
188+
get color(): ColorFunction {
187189
return this.#color;
188190
}
189191

@@ -192,26 +194,26 @@ export class Spinner {
192194
this.updateLines();
193195
}
194196

195-
get text() {
197+
get text(): string {
196198
return this.#text;
197199
}
198200
set prefix(value: string) {
199201
this.#prefix = value;
200202
this.updateLines();
201203
}
202204

203-
get prefix() {
205+
get prefix(): string {
204206
return this.#prefix;
205207
}
206208

207-
private write(data: string) {
209+
#write(data: string): void {
208210
this.#stream.writeSync(encoder.encode(data));
209211
}
210212

211213
start(): Spinner {
212214
if (!this.#enabled) {
213215
if (this.text) {
214-
this.write(`- ${this.text}\n`);
216+
this.#write(`- ${this.text}\n`);
215217
}
216218
return this;
217219
}
@@ -229,7 +231,7 @@ export class Spinner {
229231

230232
render(): void {
231233
this.clear();
232-
this.write(`${this.frame()}\n`);
234+
this.#write(`${this.frame()}\n`);
233235
this.updateLines();
234236
this.#linesToClear = this.#linesCount;
235237
}
@@ -282,7 +284,7 @@ export class Spinner {
282284
}, 0);
283285
}
284286

285-
stop() {
287+
stop(): void {
286288
if (!this.#enabled) return;
287289
clearInterval(this.#id);
288290
this.#id = -1;
@@ -294,7 +296,7 @@ export class Spinner {
294296
}
295297
}
296298

297-
stopAndPersist(options: PersistOptions = {}) {
299+
stopAndPersist(options: PersistOptions = {}): void {
298300
const prefix = options.prefix || this.prefix;
299301
const fullPrefix = typeof prefix === "string" && prefix !== ""
300302
? prefix + " "
@@ -304,22 +306,22 @@ export class Spinner {
304306

305307
this.stop();
306308
// https://github.com/denoland/deno/issues/6001
307-
this.write(`${fullPrefix}${options.symbol || " "}${fullText}\n`);
309+
this.#write(`${fullPrefix}${options.symbol || " "}${fullText}\n`);
308310
}
309311

310-
succeed(text?: string) {
312+
succeed(text?: string): void {
311313
return this.stopAndPersist({ symbol: symbols.success, text });
312314
}
313315

314-
fail(text?: string) {
316+
fail(text?: string): void {
315317
return this.stopAndPersist({ symbol: symbols.error, text });
316318
}
317319

318-
warn(text?: string) {
320+
warn(text?: string): void {
319321
return this.stopAndPersist({ symbol: symbols.warning, text });
320322
}
321323

322-
info(text?: string) {
324+
info(text?: string): void {
323325
return this.stopAndPersist({ symbol: symbols.info, text });
324326
}
325327
}

0 commit comments

Comments
 (0)