-
Notifications
You must be signed in to change notification settings - Fork 73
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
1 parent
5bc68f3
commit 491e6e8
Showing
33 changed files
with
287 additions
and
284 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
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
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
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
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
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
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
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,15 @@ | ||
import {ArgInput} from '../interfaces/parser' | ||
import {Command} from '../command' | ||
|
||
/** | ||
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which | ||
* defined args as an array. | ||
* | ||
* @param args Either an array of args or an object of args | ||
* @returns ArgInput | ||
*/ | ||
export function ensureArgObject(args?: any[] | ArgInput | {[name: string]: Command.Arg.Cached}): ArgInput { | ||
return ( | ||
Array.isArray(args) ? (args ?? []).reduce((x, y) => ({...x, [y.name]: y}), {} as ArgInput) : args ?? {} | ||
) as ArgInput | ||
} |
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,57 @@ | ||
import {access, readFile, stat} from 'node:fs/promises' | ||
import {join} from 'node:path' | ||
import {readFileSync} from 'node:fs' | ||
|
||
const debug = require('debug') | ||
|
||
export function requireJson<T>(...pathParts: string[]): T { | ||
return JSON.parse(readFileSync(join(...pathParts), 'utf8')) | ||
} | ||
|
||
export async function exists(path: string): Promise<boolean> { | ||
try { | ||
await access(path) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
export const dirExists = async (input: string): Promise<string> => { | ||
if (!(await exists(input))) { | ||
throw new Error(`No directory found at ${input}`) | ||
} | ||
|
||
const fileStat = await stat(input) | ||
if (!fileStat.isDirectory()) { | ||
throw new Error(`${input} exists but is not a directory`) | ||
} | ||
|
||
return input | ||
} | ||
|
||
export const fileExists = async (input: string): Promise<string> => { | ||
if (!(await exists(input))) { | ||
throw new Error(`No file found at ${input}`) | ||
} | ||
|
||
const fileStat = await stat(input) | ||
if (!fileStat.isFile()) { | ||
throw new Error(`${input} exists but is not a file`) | ||
} | ||
|
||
return input | ||
} | ||
|
||
export async function readJson<T = unknown>(path: string): Promise<T> { | ||
debug('config')('readJson %s', path) | ||
const contents = await readFile(path, 'utf8') | ||
return JSON.parse(contents) as T | ||
} | ||
|
||
export function readJsonSync(path: string, parse: false): string | ||
export function readJsonSync<T = unknown>(path: string, parse?: true): T | ||
export function readJsonSync<T = unknown>(path: string, parse = true): T | string { | ||
const contents = readFileSync(path, 'utf8') | ||
return parse ? (JSON.parse(contents) as T) : contents | ||
} |
Oops, something went wrong.