-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for NPM to update before checking + Ignore tag errors (#29)
- Loading branch information
1 parent
70d4d6a
commit 40e7f90
Showing
3 changed files
with
46 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
import { Spinner } from "./script_deps.ts"; | ||
|
||
type CommandResult = { | ||
ok: true; | ||
output: string; | ||
} | { | ||
ok: false; | ||
error: string; | ||
}; | ||
|
||
const getCommandOutput = async ( | ||
command: Deno.Command, | ||
ignoreErrors = false, | ||
) => { | ||
): Promise<CommandResult> => { | ||
const { code, stdout, stderr } = await command.output(); | ||
const error = new TextDecoder().decode(stderr); | ||
if ((code || error) && !ignoreErrors) { | ||
console.error(error); | ||
Deno.exit(1); | ||
return { ok: false, error: error || "Unknown error" }; | ||
} | ||
const output = new TextDecoder().decode(stdout); | ||
return output; | ||
return { ok: true, output }; | ||
}; | ||
|
||
// The command might terminate the program. | ||
export const run = async (command: string, ignoreErrors = false) => { | ||
export const run = async ( | ||
command: string, | ||
spinnerMessage?: string, | ||
ignoreErrors = false, | ||
) => { | ||
const spinner = spinnerMessage | ||
? new Spinner({ message: spinnerMessage }) | ||
: undefined; | ||
if (spinner) spinner.start(); | ||
|
||
const words = command.split(" "); | ||
const cmd = words[0]; | ||
const args = words.slice(1); | ||
const denoCmd = new Deno.Command(cmd, { args }); | ||
|
||
const output = await getCommandOutput(denoCmd, ignoreErrors); | ||
return output; | ||
const result = await getCommandOutput(denoCmd, ignoreErrors); | ||
if (spinner) spinner.stop(); | ||
|
||
if (!result.ok) { | ||
console.error(result.error); | ||
Deno.exit(1); | ||
} | ||
return result.output; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { gt, parse } from "https://deno.land/std@0.212.0/semver/mod.ts"; | ||
export { Spinner } from "https://deno.land/std@0.212.0/cli/mod.ts"; | ||
export * as colors from "https://deno.land/std@0.212.0/fmt/colors.ts"; | ||
export { delay } from "https://deno.land/std@0.212.0/async/delay.ts"; | ||
|
||
export { build, emptyDir } from "https://deno.land/x/dnt@0.39.0/mod.ts"; |