@stacksjs/router 0.64.0 → 0.64.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -295,7 +295,7 @@
|
|
|
295
295
|
"import { collect } from '@stacksjs/collections'\n\nexport * as kolorist from 'kolorist'\n\nexport {\n stripAnsi,\n centerAlign,\n rightAlign,\n leftAlign,\n align,\n box,\n colors,\n getColor,\n colorize,\n} from 'consola/utils'\n\nexport {\n ansi256Bg,\n bgBlack,\n bgBlue,\n bgCyan,\n bgGray,\n bgGreen,\n bgLightBlue,\n bgLightCyan,\n bgLightGray,\n bgLightGreen,\n bgLightMagenta,\n bgLightRed,\n bgLightYellow,\n bgMagenta,\n bgRed,\n bgWhite,\n bgYellow,\n black,\n blue,\n bold,\n cyan,\n dim,\n gray,\n green,\n hidden,\n inverse,\n italic,\n lightBlue,\n lightCyan,\n lightGray,\n lightGreen,\n lightMagenta,\n lightRed,\n lightYellow,\n link,\n magenta,\n red,\n reset,\n strikethrough,\n underline,\n white,\n yellow,\n ansi256,\n trueColor,\n trueColorBg,\n stripColors,\n} from 'kolorist'\n\nexport const quotes = collect([\n // could be queried from any API or database\n 'The best way to get started is to quit talking and begin doing.',\n 'The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.',\n 'Don’t let yesterday take up too much of today.',\n 'You learn more from failure than from success. Don’t let it stop you. Failure builds character.',\n 'It’s not whether you get knocked down, it’s whether you get up.',\n 'If you are working on something that you really care about, you don’t have to be pushed. The vision pulls you.',\n 'People who are crazy enough to think they can change the world, are the ones who do.',\n 'Failure will never overtake me if my determination to succeed is strong enough.',\n 'Entrepreneurs are great at dealing with uncertainty and also very good at minimizing risk. That’s the classic entrepreneur.',\n 'We may encounter many defeats but we must not be defeated.',\n 'Knowing is not enough; we must apply. Wishing is not enough; we must do.',\n 'Imagine your life is perfect in every respect; what would it look like?',\n 'We generate fears while we sit. We overcome them by action.',\n 'Whether you think you can or think you can’t, you’re right.',\n 'Security is mostly a superstition. Life is either a daring adventure or nothing.',\n])\n",
|
|
296
296
|
"import type { Result } from '@stacksjs/error-handling'\nimport type { CliOptions, CommandError, Subprocess } from '@stacksjs/types'\nimport { ExitCode } from '@stacksjs/types'\nimport { log } from './console'\nimport { exec, execSync } from './exec'\nimport { italic } from './utils'\n\n/**\n * Run a command.\n *\n * @param command The command to run.\n * @param options The options to pass to the command.\n * @returns The result of the command.\n * @example\n * ```ts\n * const result = await runCommand('ls')\n *\n * if (result.isErr())\n * console.error(result.error)\n * else\n * console.log(result)\n * ```\n * @example\n * ```ts\n * const result = await runCommand('ls', { cwd: '/home' })\n *\n * if (result.isErr())\n * console.error(result.error)\n * else\n * console.log(result)\n * ```\n */\nexport async function runCommand(command: string, options?: CliOptions): Promise<Result<Subprocess, CommandError>> {\n log.debug('runCommand:', command)\n log.debug('options:', options)\n\n return await exec(command, options)\n}\n\nexport async function runProcess(command: string, options?: CliOptions): Promise<Result<Subprocess, CommandError>> {\n log.debug('runProcess:', italic(command))\n log.debug('runProcess Options:', options)\n\n return await exec(command, options)\n}\n\n/**\n * Run a command.\n *\n * @param command The command to run.\n * @param options The options to pass to the command.\n * @returns The result of the command.\n * @example\n * ```ts\n * const result = runCommandSync('ls')\n *\n * if (result.isErr())\n * console.error(result.error)\n * else\n * console.log(result)\n * ```\n * @example\n * ```ts\n * const result = runCommandSync('ls', { cwd: '/home' })\n *\n * if (result.isErr())\n * console.error(result.error)\n * else\n * console.log(result)\n * ```\n */\nexport async function runCommandSync(command: string, options?: CliOptions): Promise<string> {\n log.debug('runCommandSync:', italic(command))\n log.debug('runCommandSync Options:', options)\n\n const result = await execSync(command, options)\n\n // if (result.isErr())\n // return err(result.error)\n\n // return ok(result.value)\n\n return result\n}\n\n/**\n * Run many commands.\n *\n * @param commands The command to run.\n * @param options The options to pass to the command.\n * @returns The result of the command.\n */\nexport async function runCommands(commands: string[], options?: CliOptions) {\n const results = []\n\n for (const command of commands) {\n const result = await runCommand(command, options)\n\n if (result.isErr()) {\n log.error(result.error)\n process.exit(ExitCode.FatalError)\n }\n\n results.push(result)\n }\n\n return results\n}\n",
|
|
297
297
|
"import type { CliOptions } from '@stacksjs/types'\nimport { runCommand } from './run'\n\ntype CommandOptionTuple = [string, string, { default: boolean }]\ninterface CommandOptionObject {\n name: string\n description: string\n default: boolean | string\n}\ntype CommandOptions = CommandOptionTuple | CommandOptionObject[]\ninterface Options {\n name: string\n description: string\n active: boolean\n options: CommandOptions\n run: (options?: CliOptions) => Promise<any>\n onFail: (error: Error) => void\n onSuccess: () => void\n}\n\nexport class Command {\n name: Options['name']\n description: Options['description']\n options: Options['options']\n run: Options['run']\n onFail: Options['onFail']\n onSuccess: Options['onSuccess']\n\n constructor({ name, description, options, run, onFail, onSuccess }: Options) {\n this.name = name\n this.description = description\n this.options = options\n this.run = run\n this.onFail = onFail\n this.onSuccess = onSuccess\n }\n}\n\nexport const command = {\n run: async (command: string, options?: CliOptions) => {\n return await runCommand(command, options)\n },\n\n runSync: async (command: string, options?: CliOptions) => {\n return await runCommand(command, options)\n },\n}\n",
|
|
298
|
-
"import { handleError } from '@stacksjs/error-handling'\nimport { log } from '@stacksjs/logging'\nimport type { IntroOptions, OutroOptions } from '@stacksjs/types'\nimport { ExitCode } from '@stacksjs/types'\nimport { bgCyan, bold, cyan, dim, gray, green, italic } from 'kolorist'\nimport { version } from '../package.json'\n\n/**\n * Prints the intro message.\n */\nexport async function intro(command: string, options?: IntroOptions): Promise<number> {\n return new Promise((resolve) => {\n if (options?.quiet === false) {\n console.log()\n console.log(cyan(bold('Stacks CLI')) + dim(` v${version}`))\n console.log()\n }\n\n log.info(`Running ${bgCyan(italic(bold(` ${command} `)))}
|
|
298
|
+
"import { handleError } from '@stacksjs/error-handling'\nimport { log } from '@stacksjs/logging'\nimport type { IntroOptions, OutroOptions } from '@stacksjs/types'\nimport { ExitCode } from '@stacksjs/types'\nimport { bgCyan, bold, cyan, dim, gray, green, italic } from 'kolorist'\nimport { version } from '../package.json'\n\n/**\n * Prints the intro message.\n */\nexport async function intro(command: string, options?: IntroOptions): Promise<number> {\n return new Promise((resolve) => {\n if (options?.quiet === false) {\n console.log()\n console.log(cyan(bold('Stacks CLI')) + dim(` v${version}`))\n console.log()\n }\n\n log.info(`Running ${bgCyan(italic(bold(` ${command} `)))}`)\n\n if (options?.showPerformance === false || options?.quiet) return resolve(0)\n\n return resolve(performance.now())\n })\n}\n\n/**\n * Prints the outro message.\n */\nexport function outro(text: string, options?: OutroOptions, error?: Error | string) {\n const opts = {\n type: 'success',\n useSeconds: true,\n ...options,\n }\n\n opts.message = options?.message || text\n\n return new Promise((resolve) => {\n if (error) return handleError(error)\n\n if (opts?.startTime) {\n let time = performance.now() - opts.startTime\n\n if (opts.useSeconds) {\n time = time / 1000\n time = Math.round(time * 100) / 100 // https://stackoverflow.com/a/11832950/7811162\n }\n\n if (opts.quiet === true) return resolve(ExitCode.Success)\n\n if (error) log.error(`[${time.toFixed(2)}${opts.useSeconds ? 's' : 'ms'}] Failed`)\n else if (opts.type === 'info')\n log.info(`${dim(gray(`[${time.toFixed(2)}${opts.useSeconds ? 's' : 'ms'}]`))} ${opts.message ?? 'Complete'}`)\n else\n log.success(\n `${dim(gray(bold(`[${time.toFixed(2)}${opts.useSeconds ? 's' : 'ms'}]`)))} ${bold(\n green(opts.message ?? 'Complete'),\n )}`,\n )\n } else {\n if (opts?.type === 'info') log.info(text)\n // the following condition triggers in the case of \"Cleaned up\" messages\n else if (opts?.type === 'success' && opts?.quiet !== true) log.success(text)\n }\n\n return resolve(ExitCode.Success)\n })\n}\n",
|
|
299
299
|
"import process from 'node:process'\nimport { log } from '@stacksjs/logging'\n\ninterface ParsedArgv {\n args: string[]\n options: {\n [k: string]: string | boolean | number\n }\n}\n\nfunction isLongOption(arg?: string): boolean {\n if (!arg) return false\n\n return arg.startsWith('--')\n}\n\nfunction isShortOption(arg: string): boolean {\n return arg.startsWith('-') && !isLongOption(arg)\n}\n\nfunction parseValue(value: string): string | boolean | number {\n if (value === 'true') return true\n\n if (value === 'false') return false\n\n const numberValue = Number.parseFloat(value)\n if (!Number.isNaN(numberValue)) return numberValue\n\n return value.replace(/\"/g, '')\n}\n\nfunction parseLongOption(\n arg: string,\n argv: string[],\n index: number,\n options: { [k: string]: string | boolean | number },\n): number {\n const [key, value] = arg.slice(2).split('=')\n if (value !== undefined) {\n options[key as string] = parseValue(value)\n } else if (index + 1 < argv.length && !argv[index + 1]?.startsWith('-')) {\n options[key as string] = argv[index + 1] as string\n index++\n } else {\n options[key as string] = true\n }\n return index\n}\n\nfunction parseShortOption(\n arg: string,\n argv: string[],\n index: number,\n options: { [k: string]: string | boolean | number },\n): number {\n const [key, value] = arg.slice(1).split('=')\n\n // Check if key is undefined and handle it\n if (key === undefined) return index\n\n if (value !== undefined && key !== undefined) {\n for (let j = 0; j < key.length; j++) options[key[j] as string] = parseValue(value)\n } else {\n for (let j = 0; j < key.length; j++) {\n if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1]?.startsWith('-')) {\n options[key[j] as string] = parseValue(argv[index + 1] as string)\n index++\n } else {\n options[key[j] as string] = true\n }\n }\n }\n\n return index\n}\n\nexport function parseArgv(argv?: string[]): ParsedArgv {\n if (argv === undefined) argv = process.argv.slice(2)\n\n const args: string[] = []\n const options: { [k: string]: string | boolean | number } = {}\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]\n if (!arg) continue\n if (isLongOption(arg)) i = parseLongOption(arg, argv, i, options)\n else if (isShortOption(arg)) i = parseShortOption(arg, argv, i, options)\n else args.push(arg)\n }\n\n return { args, options }\n}\n\nexport function parseArgs(argv?: string[]): string[] {\n if (argv === undefined) argv = process.argv.slice(2)\n\n return parseArgv(argv).args\n}\n\ninterface CliOptions {\n dryRun?: boolean\n quiet?: boolean\n verbose?: boolean\n [k: string]: string | boolean | number | undefined\n}\n\nexport function parseOptions(options?: CliOptions): CliOptions {\n options = options || {}\n const args = process.argv.slice(2)\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n if (arg?.startsWith('--')) {\n const key = arg.substring(2) // remove the --\n const camelCaseKey = key.replace(\n /-([a-z])/gi,\n (g) => (g[1] ? g[1].toUpperCase() : ''), // convert kebab-case to camelCase\n )\n\n if (i + 1 < args.length) {\n // if the next arg exists\n if (args[i + 1] === 'true' || args[i + 1] === 'false') {\n // if the next arg is a boolean\n options[camelCaseKey] = args[i + 1] === 'true' // set the value to the boolean\n i++\n } else {\n options[camelCaseKey] = args[i + 1]\n i++\n }\n } else {\n options[camelCaseKey] = true\n }\n }\n }\n\n // if options has no keys, return undefined, e.g. `buddy release`\n if (Object.keys(options).length === 0) return { dryRun: false, quiet: false, verbose: false }\n\n // convert the string 'true' or 'false' to a boolean\n Object.keys(options).forEach((key) => {\n if (!options) return { dryRun: false, quiet: false, verbose: false }\n\n const value = options[key]\n\n if (value === 'true' || value === 'false') options[key] = value === 'true'\n })\n\n return options\n}\n// interface BuddyOptions {\n// dryRun?: boolean\n// verbose?: boolean\n// }\nexport function buddyOptions(options?: any): string {\n if (!options) {\n options = process.argv.slice(2)\n options = Array.from(new Set(options))\n // delete the 0 element if it does not start with a -\n // e.g. is used when buddy changelog --dry-run is used\n if (options[0] && !options[0].startsWith('-')) options.shift()\n }\n\n if (options?.verbose) {\n log.debug('process.argv', process.argv)\n log.debug('process.argv.slice(2)', process.argv.slice(2))\n log.debug('options inside buddyOptions', options)\n }\n\n return options.join(' ')\n}\n",
|
|
300
300
|
"export * from './actions'\nexport * from './cli'\nexport * from './command'\nexport * from './console'\nexport * from './helpers'\nexport * from './parse'\nexport * from './exec'\nexport * from './run'\nexport * from './spinner'\nexport * from './utils'\n",
|
|
301
301
|
"export { toString } from '@stacksjs/strings'\n\n// export function assert(condition: boolean, message: string): asserts condition {\n// if (!condition)\n// throw new Error(message)\n// }\n\n// export function noop() {}\n\nexport async function loop(times: number, callback: any) {\n ;[...Array(times)].forEach(async (item, i) => await callback(i))\n}\n",
|