Skip to content

Commit

Permalink
chore: remove custom ora implementation and add excludes option in up…
Browse files Browse the repository at this point in the history
…date script
  • Loading branch information
brc-dd committed Jun 7, 2024
1 parent 0a6cb30 commit 001e01b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 70 deletions.
1 change: 1 addition & 0 deletions deno.lock

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

81 changes: 12 additions & 69 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* Credits:
*
* - ora, np, new-github-release-url, is-in-ci, cli-spinners - MIT License
* - np, new-github-release-url, is-in-ci - MIT License
* Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
* https://github.com/sindresorhus/ora/blob/main/license
* https://github.com/sindresorhus/np/blob/main/license
* https://github.com/sindresorhus/new-github-release-url/blob/main/license
* https://github.com/sindresorhus/is-in-ci/blob/main/license
* https://github.com/sindresorhus/cli-spinners/blob/main/license
*
* - bumpp, version-bump-prompt - MIT License
* Copyright (c) 2022 Anthony Fu
Expand All @@ -34,7 +32,8 @@ import {
type SelectOptions,
} from 'jsr:@cliffy/[email protected]'
import { $ } from 'jsr:@david/dax'
import { black, blue, bold, cyan, dim, gray, green, magenta, red, white, yellow } from 'jsr:@std/fmt/colors'
import { Spinner } from 'jsr:@std/cli'
import { bold, cyan, dim, green, magenta } from 'jsr:@std/fmt/colors'
import { escape } from 'jsr:@std/regexp'
import { canParse, format, increment, parse, type ReleaseType } from 'jsr:@std/semver'

Expand Down Expand Up @@ -119,61 +118,17 @@ class Input extends _Input {

// #endregion

// #region Ora

const colors = { black, red, green, yellow, blue, magenta, cyan, white, gray }

type Color = keyof typeof colors
// #region Step

const env = Deno.env.toObject()

const isEnabled = Deno.stdout.isTerminal() &&
!(env.CI !== '0' && env.CI !== 'false' &&
('CI' in env || 'CONTINUOUS_INTEGRATION' in env || Object.keys(env).some((key) => key.startsWith('CI_'))))

type Spinner = { interval?: number; frames: string[] }

const spinners: Record<'dots', Spinner> = {
dots: { interval: 80, frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] },
}

const okMark = '\x1b[32m✓\x1b[0m'
const failMark = '\x1b[31m✗\x1b[0m'

type OraOptions = {
/**
* Text to display after the spinner.
*/
text?: string

/**
* The spinner to use. On Windows, it will always use the line spinner as the Windows command-line doesn't have proper Unicode support.
*
* @example
* ```ts
* {
* interval: 80, // Optional
* frames: ['-', '+', '-']
* }
* ```
*/
spinner?: Spinner

/**
* The color of the spinner.
*
* @default 'cyan'
*/
color?: Color

/**
* Indent the spinner with the given number of spaces.
*
* @default 0
*/
indent?: number
}

/**
* Run a function with a spinner.
*
Expand All @@ -182,40 +137,28 @@ type OraOptions = {
* await step('Loading...', async () => {})
* ```
*/
async function step(options: OraOptions | string = {}, fn: () => Promise<void>): Promise<void> {
if (typeof options === 'string') options = { text: options }

let { text, spinner = spinners.dots, color = 'cyan', indent = 0 } = options

async function step(text: string, fn: () => Promise<void>): Promise<void> {
if (!isEnabled) {
console.log(`${' '.repeat(indent)}${text}`)
console.log(text)
await fn()
return
}

text = text ? bold(` ${text}`) : ''
if (Deno.build.os === 'windows') spinner = { frames: ['-', '\\', '|', '/'] }

let currentFrame = 0
text = bold(text)

const interval = setInterval(() => {
Deno.stdout.write(
new TextEncoder().encode(`\r${' '.repeat(indent)}${colors[color](spinner.frames[currentFrame]!)}${text}`),
)
currentFrame = (currentFrame + 1) % spinner.frames.length
}, spinner.interval ?? 100)
const spinner = new Spinner({ message: text, color: 'cyan' })
spinner.start()

let success = false

try {
await fn()
success = true
} finally {
clearInterval(interval)
Deno.stdout.write(new TextEncoder().encode('\r\x1b[K'))
spinner.stop()

if (success) console.log(`${' '.repeat(indent)}${okMark}${text}`)
else console.log(`${' '.repeat(indent)}${failMark}${text}`)
if (success) console.log(`${okMark} ${text}`)
else console.log(`${failMark} ${text}`)
}
}

Expand Down
6 changes: 5 additions & 1 deletion scripts/update.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { $ } from 'jsr:@david/dax'
import { parse, resolveLatestVersion, stringify } from 'jsr:@molt/core'
import { parseArgs } from 'jsr:@std/cli'
import { expandGlob } from 'jsr:@std/fs'
import { relative } from 'jsr:@std/path'

const args = parseArgs(Deno.args, { collect: ['x'] })
const excludes = (args.x ?? []) as string[]

const denoJson = JSON.parse(await Deno.readTextFile('deno.json')) as { imports: Record<string, string> }
const newImports = { ...denoJson.imports }

for (const [key, value] of Object.entries(denoJson.imports)) {
if (!value.includes(':')) continue
if (!value.includes(':') || excludes.includes(key)) continue

const parsed = parse(value)
let rangeSpecifier: string | undefined = undefined
Expand Down

0 comments on commit 001e01b

Please sign in to comment.