diff --git a/package.json b/package.json index fc08a69..45052b3 100644 --- a/package.json +++ b/package.json @@ -135,9 +135,7 @@ }, "pnpm": { "overrides": { - "simple-git@<3.3.0": ">=3.3.0", - "simple-git@<3.5.0": ">=3.5.0", - "sharp@<0.30.5": ">=0.30.5" + "simple-git@<3.5.0": ">=3.5.0" } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 726fa25..8e78e8e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,7 +3,6 @@ lockfileVersion: 5.4 overrides: simple-git@<3.3.0: '>=3.3.0' simple-git@<3.5.0: '>=3.5.0' - sharp@<0.30.5: '>=0.30.5' specifiers: '@types/command-line-args': ^5.2.0 @@ -2364,7 +2363,7 @@ packages: engines: {node: '>=0.10.0'} /events/1.1.1: - resolution: {integrity: sha512-kEcvvCBByWXGnZy6JUlgAp2gBIUjfCAV6P6TgT1/aaQKcmuAEC4OZTV1I4EWQLz2gxZw76atuVyvHhTxvi0Flw==} + resolution: {integrity: sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=} engines: {node: '>=0.4.x'} dev: false @@ -4920,7 +4919,7 @@ packages: punycode: 2.3.0 /url/0.10.3: - resolution: {integrity: sha512-hzSUW2q06EqL1gKM/a+obYHLIO6ct2hwPuviqTTOcfFVc61UbfJ2Q32+uGL/HCPxKqrdGB5QUwIe7UqlDgwsOQ==} + resolution: {integrity: sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=} dependencies: punycode: 1.3.2 querystring: 0.2.0 diff --git a/src/commands/autoindex/parts/autoindex.ts b/src/commands/autoindex/parts/autoindex.ts index c7da39a..4f65e57 100644 --- a/src/commands/autoindex/parts/autoindex.ts +++ b/src/commands/autoindex/parts/autoindex.ts @@ -20,6 +20,7 @@ import { getMonoRepoPackages, getSubdirectories } from "src/shared/file"; * the file's current directory */ export const handler: DoDevopsHandler = async ({ opts, observations, argv }) => { + // the sfc flag on CLI is inverted logically opts = { ...opts, diff --git a/src/commands/autoindex/parts/description.ts b/src/commands/autoindex/parts/description.ts index 591a46e..ac6dab5 100644 --- a/src/commands/autoindex/parts/description.ts +++ b/src/commands/autoindex/parts/description.ts @@ -1,12 +1,19 @@ -import chalk from "chalk"; + import { IDoDevopsCommand } from "src/@types"; -const autoindex = chalk.bgWhite.black`autoindex`; +// const autoindex = chalk.bgWhite.black`autoindex`; +// const autoindexComment = chalk.bgWhiteBright.blackBright`// autoindex`; export const description: IDoDevopsCommand["description"] = { - short: `Automates the building of ${chalk.italic`index.ts`} files to aggregate folder's content`, - complete: `Automates the building of ${chalk.italic`index`} files; if you include a comment starting with ${chalk.bold.yellow`\n// #autoindex\n`}in a index file it will be auto-indexed when calling ${chalk.blue`do autoindex`}. - -By default ${autoindex} will assume that you are using ${chalk.italic`named`} exports but this can be configured to what you need. Options are: ${chalk.italic`named, default,`} and ${chalk.italic`named-offset`}. To configure, simply add something like ${chalk.bold.yellow`\n// #autoindex:default\n`}to your file. - -If you need to exclude certain files you can state the exclusions after the autoindex declaration: ${chalk.bold.yellow`#autoindex, exclude:a,b,c`}`, + short: `Automates the building of index files`, + complete: `Automates the building of index files` }; + + +// { +// short: `Automates the building of ${chalk.italic`index.[ts | js]`} files`, +// complete: `Automates the building of ${chalk.italic`index`} files in a given repo. + +// Any index file (JS or TS) which is either completely empty ${chalk.italic`or`} contains a comment +// which looks has a line that starts with ${autoindexComment} will be managed by the ${autoindex} +// command.`, +// }; diff --git a/src/commands/autoindex/parts/options.ts b/src/commands/autoindex/parts/options.ts index 000be15..d552775 100644 --- a/src/commands/autoindex/parts/options.ts +++ b/src/commands/autoindex/parts/options.ts @@ -1,10 +1,12 @@ -import chalk from "chalk"; import { IOptionDefinition } from "src/@types/option-types"; export interface IAutoindexOptions { config: boolean; add: string; glob: string; + /** + * Reports what would happen _if_ you were to run the command without actually making any changes + */ dryRun: boolean; /** * boolean flag to indicate whether VueJS SFC files should have their default @@ -35,7 +37,7 @@ export const options: IOptionDefinition = { multiple: true, type: String, group: "local", - description: `${chalk.italic`optionally`} state one or more explicit autoindex files to evaluate instead of glob patterns`, + description: `optionally state one or more explicit autoindex files to evaluate instead of glob patterns`, typeLabel: "string[]", }, @@ -71,7 +73,7 @@ export const options: IOptionDefinition = { alias: "w", type: Boolean, group: "local", - description: `watches for changes and runs ${chalk.italic`autoindex`} when detected`, + description: `watches for changes and runs autoindex when detected`, }, force: { alias: "f", @@ -84,6 +86,6 @@ export const options: IOptionDefinition = { alias: "p", type: Boolean, group: "local", - description: `exports -- by default -- will ${chalk.italic`not`} include the file's ${chalk.blue`.js`} extension but sometimes with ES modules you want to include this. If you do then you should set this flag.`, + description: `by default exports do not include the file's .js extension but sometimes with ES modules you want to include this. If you do then you should set this flag.`, }, }; diff --git a/src/commands/info/parts/thisRepo.ts b/src/commands/info/parts/thisRepo.ts index 11ea1f3..d1abf21 100644 --- a/src/commands/info/parts/thisRepo.ts +++ b/src/commands/info/parts/thisRepo.ts @@ -15,7 +15,7 @@ import { } from "src/shared/git"; import { askConfirmQuestion, resolvePackageManagerConflict } from "src/shared/interactive"; import { getExternalPackageJson, getPackageJson } from "src/shared/npm"; -import { dim, emoji, green } from "src/shared/ui"; +import { emoji, green } from "src/shared/ui"; import { monorepoInfo } from "./components/monorepo"; import { currentDirectory } from "src/shared/file/base-paths/currentDirectory"; import { symlinks } from "src/shared/file/utility/symlinks"; diff --git a/src/dd.ts b/src/dd.ts index 39728a2..24509ea 100755 --- a/src/dd.ts +++ b/src/dd.ts @@ -57,6 +57,7 @@ import { isDevopsError } from "./@type-guards"; // Show help on the command if (cmdInput.opts.help) { commandAnnouncement(cmdDefn, cmdInput); + help(observations, cmdDefn); process.exit(); } diff --git a/src/shared/core/help.ts b/src/shared/core/help.ts index 706c4a1..8438330 100644 --- a/src/shared/core/help.ts +++ b/src/shared/core/help.ts @@ -29,6 +29,9 @@ export function help( options: globalOptions, } as Finalized); + console.log({kind,subCommands,description,syntax,options}); + + const sections: commandLineUsage.Section[] = [ { header: "Description", diff --git a/src/shared/core/helpContent.ts b/src/shared/core/helpContent.ts index 29432e6..6393f02 100644 --- a/src/shared/core/helpContent.ts +++ b/src/shared/core/helpContent.ts @@ -18,17 +18,18 @@ import { getObservations } from "../observations"; * command. If not provided a default syntax will be used. */ export function getSyntax(fn?: string): string { - if (!fn) { - return "dd [command] "; - } else { + if (fn) { const validCommands = keys(commands); if ((validCommands as string[]).includes(fn)) { const defn: IDoDevopsCommand = commands[fn as keyof typeof commands]; const hasSubCommands = defn?.subCommands ? true : false; return defn.syntax ?? `do ${fn} ${hasSubCommands ? "[command] " : ""}`; } else { - return `dd [command] \nnote: the command {red ${fn}} is not recognized!`; + const fnName = chalk.red(fn); + return `dd [command] \nnote: the command ${fnName} is not recognized!`; } + } else { + return "dd [command] "; } } diff --git a/src/shared/core/parseCmdArgs.ts b/src/shared/core/parseCmdArgs.ts index 20e6f41..977da1d 100644 --- a/src/shared/core/parseCmdArgs.ts +++ b/src/shared/core/parseCmdArgs.ts @@ -49,8 +49,8 @@ export function parseCmdArgs(cmd: IDoDevopsCommand, incomingArgv: string[]) { } ); - // opts come from both "local" and "global" options - const opts = { ...(global ? global : {}), ...(local ? local : {}) }; + // combine "local" and "global" options + const opts = { ...global, ...local }; const sc = subCommand ? (cmd.greedy ? subCommand?.command[0] : subCommand?.command) : undefined; diff --git a/src/shared/core/util/argv.ts b/src/shared/core/util/argv.ts index f776dc2..857cb10 100644 --- a/src/shared/core/util/argv.ts +++ b/src/shared/core/util/argv.ts @@ -3,7 +3,7 @@ import { IDoDevopsCommand } from "src/@types/command"; import { IOptionDefinition } from "src/@types/option-types"; /** - * Determines if a given commmand has an `argv` parameter + * Determines if a given command has an `argv` parameter */ export function hasArgv(cmd: IDoDevopsCommand) { return !Object.keys(cmd?.options || {}).every( diff --git a/src/shared/core/util/commandAnnouncement.ts b/src/shared/core/util/commandAnnouncement.ts index fa6847f..90354d7 100644 --- a/src/shared/core/util/commandAnnouncement.ts +++ b/src/shared/core/util/commandAnnouncement.ts @@ -10,23 +10,26 @@ import { doDevopsVersion } from "./doDevopsVersion"; export function commandAnnouncement(cmdDefn?: IDoDevopsCommand, cmd?: ICommandParsing) { const log = logger(cmd ? cmd.opts : {}); const version = doDevopsVersion(); - - const argv = cmd && cmd.argv.length > 0 ? ` ${chalk.italic(cmd.argv.join(" "))}` : ""; - + const argv = cmd && cmd.argv.length > 0 + ? chalk.italic` ${cmd.argv.join(" ")}` + : ""; + const subCmd = cmd && cmd.subCommand ? chalk.dim` ${cmd.subCommand}` : ""; const helpText = (!cmdDefn && !cmd) || (cmd && cmd.opts?.help) ? cmdDefn - ? chalk.gray` [help, v${version}]` - : chalk.gray` v${version}` + ? ` [ help, v${version} ]` + : ` v${version}` : ""; + const brand = cmdDefn + ? chalk.green.italic.bold(`${cmdDefn.kind}${subCmd}${argv}`) + : chalk.green.italic.bold("Help"); + log.info( chalk.bold( - `\ndo-devops ${chalk.green.italic.bold( - cmdDefn ? `${cmdDefn.kind}${subCmd}${argv}` : "Help" - )}${helpText}\n` + `\ndo-devops ${brand}${chalk.gray(helpText)}\n` ) ); } diff --git a/src/shared/core/util/finalizeCommandDefinition.ts b/src/shared/core/util/finalizeCommandDefinition.ts index 00644fe..0e77aeb 100644 --- a/src/shared/core/util/finalizeCommandDefinition.ts +++ b/src/shared/core/util/finalizeCommandDefinition.ts @@ -34,9 +34,12 @@ export function finalizeCommandDefinition( ? cmdDefn.subCommands(observations, options) : cmdDefn.subCommands; - const argv = hasArgv(cmdDefn) ? chalk.italic.dim` argv[]}}` : ""; + const argv = hasArgv(cmdDefn) ? chalk.italic.dim` argv[]` : ""; + const argvStatic = chalk.bold.blue("[argv]:"); + console.log({argvOption: getArgvOption(cmdDefn)?.description, argvStatic}); + const argvDescription = getArgvOption(cmdDefn)?.description - ? `\n\n\t\t${chalk.bold.blue`[argv]:`} ${getArgvOption(cmdDefn)?.description}` + ? `\n\n\t\t${argvStatic} ${getArgvOption(cmdDefn)?.description}` : ""; const subCommandSyntax = @@ -51,7 +54,7 @@ export function finalizeCommandDefinition( handler: cmdDefn.handler, syntax: cmdDefn.syntax || - `dd ${cmdDefn.kind}${subCommandSyntax}${argv} [${chalk.italic`options`}]${argvDescription}`, + `dd ${cmdDefn.kind}${subCommandSyntax}${argv} [${chalk.dim.italic`options`}]${argvDescription}`, description, subCommands, options: { ...cmdDefn.options, ...globalOptions }, diff --git a/src/shared/file/crud/write.ts b/src/shared/file/crud/write.ts index f8235d6..12217d7 100644 --- a/src/shared/file/crud/write.ts +++ b/src/shared/file/crud/write.ts @@ -5,6 +5,7 @@ import { IWriteOptions } from "src/@types"; import { interpolateFilePath } from "../../../shared/file/helpers"; import path from "node:path"; import { isClassification } from "../../../@type-guards"; +import chalk from "chalk"; /** * **write** @@ -31,7 +32,7 @@ export function write(filename: string, data: any, options: IWriteOptions = {}) filename = interpolateFilePath(filename); - // avoid collisions if offset avoidence is enabled + // avoid collisions if offset avoidance is enabled let offset: number | undefined; while (options.offsetIfExists && fileExists(filename)) { const before = new RegExp(`-${offset}.(.*)$`); diff --git a/src/shared/ui/highlightFilepath.ts b/src/shared/ui/highlightFilepath.ts index e30fcc2..2b465f4 100644 --- a/src/shared/ui/highlightFilepath.ts +++ b/src/shared/ui/highlightFilepath.ts @@ -37,5 +37,5 @@ export function highlightFilepath( ? chalk[highForeground]`${file}}` : `${file}}`; - return `${filePath}${fileName}`; + return `${fp}${fileName}`; } diff --git a/test/hashcode.spec.ts b/test/hashcode.spec.ts index cec7017..16b11db 100644 --- a/test/hashcode.spec.ts +++ b/test/hashcode.spec.ts @@ -1,20 +1,17 @@ -import { describe, it, expect, beforeAll } from "vitest"; -import xxhash, { Exports } from "xxhash-wasm"; +import { describe, it, expect } from "vitest"; +import xxhash from "xxhash-wasm"; +const { h32 } = await xxhash(); + describe("Validate that same inputs produce same hash", () => { const person1 = { id: 1, name: "Bob", age: 35 }; const person2 = { id: 2, name: "Jane", age: 22 }; const person3 = { id: 3, name: "Max", age: 12 }; - let xx: Exports["h32"]; - beforeAll(async () => { - const { h32 } = await xxhash(); - xx = h32; - }); it("different data is different with same seed", () => { - const t1 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE); - const t2 = xx(JSON.stringify(person2), 0xCA_FE_BA_BE); - const t3 = xx(JSON.stringify(person3), 0xCA_FE_BA_BE); + const t1 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE); + const t2 = h32(JSON.stringify(person2), 0xCA_FE_BA_BE); + const t3 = h32(JSON.stringify(person3), 0xCA_FE_BA_BE); expect(t1).not.toBe(t2); expect(t1).not.toBe(t3); @@ -23,9 +20,9 @@ describe("Validate that same inputs produce same hash", () => { }); it("same hash is always the same, even with same seed", () => { - const t1 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE); - const t2 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE); - const t3 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE); + const t1 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE); + const t2 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE); + const t3 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE); expect(t1).toBe(t2); expect(t1).toBe(t3);