-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
96 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { colors } from "../log"; | ||
|
||
export function help(exit: number | false = 0) { | ||
// If exiting with a non-zero exit code, | ||
// print the error message to stderr | ||
console[exit !== false && exit !== 0 ? "error" : "log"]( | ||
colors.reset(`${colors.magenta.bold("Usage:")} ${colors.green( | ||
"fast-asar" | ||
)} ${colors.blue("<command>")} | ||
${colors.blue.bold("Commands:")} | ||
${colors.blue("extract")} ${colors.yellow( | ||
"<archive> <output>" | ||
)} Extract an archive | ||
${colors.blue("pack")} ${colors.yellow( | ||
"<input> <archive>" | ||
)} Pack a directory into an archive | ||
${colors.blue("list")} ${colors.yellow( | ||
"<archive>" | ||
)} List the contents of an archive | ||
${colors.blue("help")} Show this help message | ||
${colors.magenta.bold("Examples:")} | ||
${colors.magenta("bunx")} ${colors.green("fast-asar")} ${colors.blue( | ||
"extract" | ||
)} ${colors.yellow("app.asar app/")} | ||
${colors.magenta("bunx")} ${colors.green("fast-asar")} ${colors.blue( | ||
"pack" | ||
)} ${colors.yellow("app/ app.asar")} | ||
${colors.magenta("bunx")} ${colors.green("fast-asar")} ${colors.blue( | ||
"list" | ||
)} ${colors.yellow("app.asar")} | ||
${colors.magenta("bunx")} ${colors.green("fast-asar")} ${colors.blue( | ||
"help" | ||
)}`) | ||
); | ||
|
||
if (exit !== false) { | ||
process.exit(exit); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env node | ||
|
||
import { help } from "./help"; | ||
import { colors } from "../log"; | ||
|
||
const command = process.argv[2]; | ||
|
||
if (!command) { | ||
console.error( | ||
colors.red("error") + colors.gray(":"), | ||
"No command specified\n" | ||
); | ||
help(2); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
let colors: typeof import("ansi-colors"); | ||
try { | ||
colors = await import("ansi-colors"); | ||
} catch { | ||
// If ansi-colors is not installed, return a proxy that returns itself | ||
// when any property is accessed | ||
// @ts-expect-error | ||
colors = new Proxy((a: string) => a, { | ||
get() { | ||
return colors; | ||
}, | ||
}); | ||
|
||
// This is done so that if color functions are called, they will | ||
// just return the string that was passed to them without any | ||
// colors, instead of throwing an error because the function | ||
// doesn't exist. | ||
|
||
// So for example, the following code would log "Hello, world!" | ||
// in red if ansi-colors is installed, and just "Hello, world!" | ||
// with no colors if it isn't installed: | ||
// | ||
// console.log(colors.red("Hello, world!")); | ||
} | ||
|
||
export { colors }; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { colors } from "./colors"; | ||
|
||
export function error(message: string) { | ||
console.error(colors.red("error") + colors.gray(":"), message); | ||
} | ||
|
||
export const ok = colors.ok; | ||
|
||
export { colors }; |