@shell-shock/core 0.13.0 → 0.13.2
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/README.md +1 -1
- package/dist/components/utils-builtin.cjs +19 -0
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.mjs +19 -0
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +9 -9
- package/dist/helpers/utilities.cjs.map +1 -1
- package/dist/helpers/utilities.mjs +9 -9
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/plugin.cjs +26 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +27 -3
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/helpers.cjs +5 -0
- package/dist/resolver/helpers.cjs.map +1 -1
- package/dist/resolver/helpers.mjs +6 -1
- package/dist/resolver/helpers.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +1 -1
- package/dist/resolver/resolve.cjs.map +1 -1
- package/dist/resolver/resolve.mjs +2 -2
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/command.cjs +4 -2
- package/dist/types/command.cjs.map +1 -1
- package/dist/types/command.d.cts +11 -0
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +11 -0
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/command.mjs +4 -2
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +17 -5
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.cts +30 -6
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +30 -6
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +17 -6
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +2 -2
- package/package.json +21 -21
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath, relativePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { tsdown } from \"powerlines/tsdown\";\nimport { resolveInputs } from \"powerlines/utils\";\nimport type { BuildContext, RolldownChunk, TsdownHooks } from \"tsdown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n findCommandsRoot,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/paths\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getDefaultOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport { resolve } from \"./resolver/resolve\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n buildPath: joinPaths(this.config.root, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n platform: \"node\",\n projectType: \"application\",\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: false\n },\n input:\n !this.config.input ||\n (Array.isArray(this.config.input) &&\n this.config.input.length === 0) ||\n (isObject(this.config.input) &&\n Object.keys(this.config.input).length === 0)\n ? [\n joinPaths(this.config.root, \"src/**/command.ts\"),\n joinPaths(this.config.root, \"src/**/command.tsx\")\n ]\n : undefined,\n resolve: {\n external: [\"@powerlines/deepkit\"]\n },\n tsdown: {\n dts: false,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getDefaultOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.hooks ??= {} as TsdownHooks;\n (this.config.tsdown.hooks as TsdownHooks)[\"build:done\"] = async (\n _: BuildContext & {\n chunks: RolldownChunk[];\n }\n ) => {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(this.workspaceConfig.workspaceRoot, this.config.root)\n );\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding hashbang to binary executable output file: ${path}`\n );\n\n const content = await this.fs.read(path);\n if (content && !content.startsWith(\"#!\")) {\n await this.fs.write(\n path,\n `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n\\n${content}`\n );\n }\n\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${\n path\n }`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Expected binary output file not found at path: ${\n path\n }. Skipping adding hashbang and executable permissions (chmod+x).`\n );\n }\n })\n );\n };\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAE,YAAA;;;;AAKF,MAAE,UAAiB,UAAA,EAAA,KAAA;AACjB,QAAA;EAAA,QAAU;EAAA,SAAA;EAAA,QAAA;EAAA;GACV,MAAA;GACA,MAAA,SAAA;AACA,SAAA,MAAA,2CAAoB;AACpB,UAAA,wBAAA,KAAA;AA0BI,WAzBW,KAAM,EACf,QAAC,EACA,WAAA,UAAmB,KAAQ,OAAO,MAAM,OAAA,EACxC,EACF,EAAA,SAAO;KACP,MAAO,WAAU,KAAM;KACvB,OAAO,YAAU,KAAQ;;KAE1B,UAAY;;KAEhB,iBAAA;KACK,QAAK;MACV,QAAA;MACK,KAAM;MACJ;KACJ,OAAA,CAAA,KAAA,OAAA,SAAA,MAAA,QAAA,KAAA,OAAA,MAAA,IAAA,KAAA,OAAA,MAAA,WAAA,KAAA,SAAA,KAAA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KAAK,OAAC,OAAS,cAAA,EAAA;KACnB,UAAU,SAAQ,KAAA;KACnB;;GAEH,MAAM,OAAO;AACX,SAAK,MAAM,oEAA4C;IACvD,MAAM,WAAI,KAAA,OAAA,KAAA,UAAA,eAAA,MAAA,MAAA,SAAA,CAAA,CAAA,OAAA,QAAA;AACV,WAAO,OAAI,MAAS,gBAAE,KAAA;KACpB,IAAI,OAAC;;;KAGL,gBAAe;KACf,WAAK,UAAA,gBAAA,MAAA;;AAED,cAAK,CAAA,MAAS;;MAEhB,IAAI,WAAW;iDAEX,SAAM,OACP,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath, relativePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { tsdown } from \"powerlines/tsdown\";\nimport { resolveInputs } from \"powerlines/utils\";\nimport type { BuildContext, RolldownChunk, TsdownHooks } from \"tsdown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n findCommandsRoot,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/paths\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getGlobalOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport { resolve } from \"./resolver/resolve\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport { CommandParameterKinds } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n path: joinPaths(this.config.root, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n platform: \"node\",\n projectType: \"application\",\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: false\n },\n input:\n !this.config.input ||\n (Array.isArray(this.config.input) &&\n this.config.input.length === 0) ||\n (isObject(this.config.input) &&\n Object.keys(this.config.input).length === 0)\n ? [\n joinPaths(this.config.root, \"src/**/command.ts\"),\n joinPaths(this.config.root, \"src/**/command.tsx\")\n ]\n : undefined,\n resolve: {\n external: [\"@powerlines/deepkit\"]\n },\n tsdown: {\n dts: false,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getGlobalOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n if (isSetString(this.config.reference)) {\n if (this.config.reference.includes(\"{command}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{command}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else {\n this.config.reference = {\n app: this.config.reference\n };\n }\n }\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n typegen(code: string) {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `${code}\n\n/**\n * The global options available for every command in the ${getAppTitle(\n this,\n true\n )} command-line application.\n */\nexport interface GlobalOptions {\n ${this.options\n .map(\n option =>\n `${\n option.description\n ? `\n/**\n * ${option.description}${\n option.default\n ? `\n *\n * @defaultValue ${\n option.kind === CommandParameterKinds.string\n ? `\"${option.default}\"`\n : option.default\n }`\n : \"\"\n }\n */\n`\n : \"\"\n }${option.name}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };${\n option.alias && option.alias.length > 0\n ? option.alias\n .map(\n alias =>\n `${alias}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };`\n )\n .join(\"\\n\\n\")\n : \"\"\n }`\n )\n .join(\"\\n\\n\")}\n}\n`;\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.hooks ??= {} as TsdownHooks;\n (this.config.tsdown.hooks as TsdownHooks)[\"build:done\"] = async (\n _: BuildContext & {\n chunks: RolldownChunk[];\n }\n ) => {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(this.workspaceConfig.workspaceRoot, this.config.root)\n );\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding hashbang to binary executable output file: ${path}`\n );\n\n const content = await this.fs.read(path);\n if (content && !content.startsWith(\"#!\")) {\n await this.fs.write(\n path,\n `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n\\n${content}`\n );\n }\n\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${\n path\n }`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Expected binary output file not found at path: ${\n path\n }. Skipping adding hashbang and executable permissions (chmod+x).`\n );\n }\n })\n );\n };\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,YAAY;;;;AAKlB,MAAY,UAAA,UAAA,EAAA,KAAA;AACV,QAAA;EAAA,QAAW;EAAA,SAAA;EAAA,QAAA;EAAA;GACX,MAAA;GACA,MAAA,SAAA;AACA,SAAA,MAAA,2CAAA;AACI,UAAI,wBAAqB,KAAQ;AA0BjC,WAzBG,KAAiB,EAClB,QAAC,EACA,MAAO,UAAU,KAAC,OAAS,MAAQ,OAAA,EACrC,EACA,EAAE,SAAA;KACF,MAAO,WAAU,KAAM;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,SAAS,KAAI;KACxB;;GAEH,MAAM,OAAO;AACX,SAAK,MAAM,oEAAyC;IACpD,MAAM,WAAW,KAAA,OAAM,KAAA,UAAA,eAAA,MAAA,MAAA,SAAA,CAAA,CAAA,OAAA,QAAA;AACvB,WAAO,OAAO,MAAG,gBAAM,KAAA;KACrB,IAAI,OAAK;AACP,aAAC,OAAA,OAAA,SAAA;;KAEH,gBAAa;KACb,WAAS,UAAG,gBAAA,MAAA;MACV,IAAI,OAAI;AACN,cAAO,CAAC,MAAG;;MAEb,IAAI,WAAW;AACb,cAAO,gBAAiB,iBAAkB,EACxC,SAAS,OACV,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
|
@@ -113,6 +113,11 @@ applyArgsDefaults.__type = [
|
|
|
113
113
|
];
|
|
114
114
|
function applyDefaults(ctx) {
|
|
115
115
|
ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
116
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(ctx.input.context.config.reference?.commands) && ctx.input.context.config.reference.commands.includes("{command}")) ctx.output.reference ??= ctx.input.context.config.reference.commands ? ctx.input.context.config.reference.commands.replace("{command}", ctx.input.command.segments.filter(__assignType((segment) => !require_context_helpers.isDynamicPathSegment(segment), [
|
|
117
|
+
"segment",
|
|
118
|
+
"",
|
|
119
|
+
"P\"2!\"/\""
|
|
120
|
+
])).join("/")) : void 0;
|
|
116
121
|
}
|
|
117
122
|
applyDefaults.__type = [
|
|
118
123
|
"ResolverContext",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AAsCX,SAAE,gCAAA,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACF,QAAO,IAAQ,YAAC,CAAA,eAAA,eAA+B,GAAA,gBAAA,SAAA,4CAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,4CAAA,UACvC,YACA,WACK,mBACA,mBAAK,GAAA,OAAA,MAAA,oDAAA,KAAA,CAAA,GAAA,SAAA,4CAAA,UACR,cACR,GAAA,SAAe,4CAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAEjB,gCAA0B,SAAe;CAAC;CAAE;CAA8B;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAY1E,SAAU,kCAAkB,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACxB,QAAK,KAAA,YAAA,CAAA,eAAA,cAAA,GAAA,oCAAA,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AM;EAAA;EAAA,CAAA,CAAA;;AAEnB,kBAAe,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACf,SAAU,cAAW,KAAA;AACjB,KAAI,OAAI,gBAAmB,OAAC,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,CAAA;;AAEhC,cAAc,SAAI;CAAA;CAAA;CAAA;CAAA;CAAA;AAClB,SAAc,sBAAW,KAAA;AACrB,KAAI,OAAM,0DAAe,IAAA,MAAA,QAAA,KAAA;AACzB,KAAI,OAAM,gBAAgB,6BAA8B,IAAG,OAAO,MAAA,QAAQ,oBAAA,GAAA,CAAA,MAAA,oDAChE,IAAK,MAAA,QAAA,KAAA,CAAA,qCAAA,oCAAA,IAAA,MAAA,SAAA,KAAA,CAAA;;AAEnB,sBAAa,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQb,MAAO,6CAAA,cAAA,KAAA,KAAA,UAAA;AACH,iDAAC,IAAA,KAAA,gDAAA,MAAA,EAAA;AACF,yDAAA,MAAA,CACH,KAAA,OAAA;AAEO,SAAQ;YAEL,MAAO,QAAU,IAAG,KAAM,IAAI,MAAE,QAAA,MAAA,EAAA;AACtC,MAAM,MAAQ,SAAS;;;;;AAGnB,SAAI;;AAER,QAAO;GACR;CAAC;CAAE;CAAW;CAAA;CAAA;CAAA,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"helpers.cjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport {\n getAppTitle,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n if (\n isSetString(ctx.input.context.config.reference?.commands) &&\n ctx.input.context.config.reference.commands.includes(\"{command}\")\n ) {\n ctx.output.reference ??= ctx.input.context.config.reference.commands\n ? ctx.input.context.config.reference.commands.replace(\n \"{command}\",\n ctx.input.command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\")\n )\n : undefined;\n }\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AAsCX,SAAgB,gCAA2B,MAAW,MAAG,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrD,QAAM,IAAA,YAAe,CAAG,eAAe,eAAe,GAAA,gBAAc,SAAA,4CAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,4CAAA,UACpE,YACF,WACK,mBACO,mBAAA,GAAA,OAAA,MAAA,oDAAA,KAAA,CAAA,GAAA,SAAA,4CAAA,UACN,cACE,GAAG,SAAK,4CAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAElB,gCAAgB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYhB,SAAa,kCAAsB,MAAA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AA;GAAA;GAAA;GAAA,CAAA,CAAA;AAET,SAAA;;AAEJ,QAAM;GACP;CAAC;CAAM;CAAI;CAAQ;CAAA;CAAA,CAAA,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAppTitle } from "../plugin-utils/context-helpers.mjs";
|
|
1
|
+
import { getAppTitle, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
|
|
2
2
|
import { CommandParameterKinds } from "../types/command.mjs";
|
|
3
3
|
import { constantCase } from "@stryke/string-format/constant-case";
|
|
4
4
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
@@ -112,6 +112,11 @@ applyArgsDefaults.__type = [
|
|
|
112
112
|
];
|
|
113
113
|
function applyDefaults(ctx) {
|
|
114
114
|
ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
115
|
+
if (isSetString(ctx.input.context.config.reference?.commands) && ctx.input.context.config.reference.commands.includes("{command}")) ctx.output.reference ??= ctx.input.context.config.reference.commands ? ctx.input.context.config.reference.commands.replace("{command}", ctx.input.command.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
116
|
+
"segment",
|
|
117
|
+
"",
|
|
118
|
+
"P\"2!\"/\""
|
|
119
|
+
])).join("/")) : void 0;
|
|
115
120
|
}
|
|
116
121
|
applyDefaults.__type = [
|
|
117
122
|
"ResolverContext",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AAsCX,SAAE,gCAAA,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACF,QAAO,IAAQ,YAAC,CAAA,eAAA,eAA+B,GAAA,gBAAA,SAAA,sBAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,sBAAA,UACvC,YACA,WACK,mBACA,mBAAK,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UACR,cACR,GAAA,SAAe,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAEjB,gCAA0B,SAAe;CAAC;CAAE;CAA8B;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAY1E,SAAU,kCAAkB,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACxB,QAAK,KAAA,YAAA,CAAA,eAAA,cAAA,GAAA,oCAAA,SAAA,sBAAA,UACJ,YACL,8BAEE,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA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A;CAAA;CAAA;AACf,SAAU,cAAW,KAAA;AACjB,KAAI,OAAI,gBAAmB,OAAC,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,CAAA;;AAEhC,cAAc,SAAI;CAAA;CAAA;CAAA;CAAA;CAAA;AAClB,SAAc,sBAAW,KAAA;AACrB,KAAI,OAAM,UAAO,UAAQ,IAAA,MAAA,QAAA,KAAA;AACzB,KAAI,OAAM,gBAAgB,6BAA8B,IAAG,OAAO,MAAA,QAAQ,oBAAA,GAAA,CAAA,MAAA,IACtE,UAAM,IAAK,MAAA,QAAA,KAAA,CAAA,qCAAA,YAAA,IAAA,MAAA,SAAA,KAAA,CAAA;;AAEnB,sBAAa,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQb,MAAO,wBAAA,WAAA,cAAA,KAAA,KAAA,UAAA;AACH,KAAC,SAAA,IAAA,KAAA,IAAA,SAAA,MAAA,EAAA;AACF,MAAA,YAAA,MAAA,CACH,KAAA,OAAA;AAEO,SAAQ;YAEL,MAAO,QAAU,IAAG,KAAM,IAAI,MAAE,QAAA,MAAA,EAAA;AACtC,MAAM,MAAQ,SAAS;;;;;AAGnB,SAAI;;AAER,QAAO;GACR;CAAC;CAAE;CAAW;CAAA;CAAA;CAAA,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport {\n getAppTitle,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n if (\n isSetString(ctx.input.context.config.reference?.commands) &&\n ctx.input.context.config.reference.commands.includes(\"{command}\")\n ) {\n ctx.output.reference ??= ctx.input.context.config.reference.commands\n ? ctx.input.context.config.reference.commands.replace(\n \"{command}\",\n ctx.input.command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\")\n )\n : undefined;\n }\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AAsCX,SAAgB,gCAA2B,MAAW,MAAG,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrD,QAAM,IAAA,YAAe,CAAG,eAAe,eAAe,GAAA,gBAAc,SAAA,sBAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,sBAAA,UACpE,YACF,WACK,mBACO,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UACN,cACE,GAAG,SAAK,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAElB,gCAAgB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYhB,SAAa,kCAAsB,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,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AA,OAAA,KAAA,UAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AAET,SAAA;;AAEJ,QAAM;GACP;CAAC;CAAM;CAAI;CAAQ;CAAA;CAAA,CAAA,CAAA"}
|
|
@@ -27,7 +27,7 @@ async function initialize(input) {
|
|
|
27
27
|
icon: parent?.icon,
|
|
28
28
|
...command,
|
|
29
29
|
title,
|
|
30
|
-
options: require_utilities.
|
|
30
|
+
options: require_utilities.getGlobalOptions(context, command),
|
|
31
31
|
args: [],
|
|
32
32
|
parent: parent ?? null,
|
|
33
33
|
children: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.cjs","names":[],"sources":["../../src/resolver/resolve.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getDefaultOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of ctx.input.context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every((value, index) => value === ctx.input.command.segments[index])\n )) {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n }\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,eAAE,WAAiB,OAAA;CACjB,MAAA,EAAA,SAAa,SAAA,WAAA;CACb,MAAA,QAAA,QAAoB,SACpB,GAAA,QAAA,QACQ,GAAO,OAAC,YACT,OAAA,MAAqB,QAAQ,oBAAO,GAAA,CAAA,MAAA,GAC/B,OAAA,MAAiB;CAY3B,MAAM,SAAS;EACX;EACA,QAZO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,GAAE;;GAEF,SAAM,oCAAA,SAAA,QAAA;GACV,MAAQ,EAAA;GACN,QAAA,UAAA;GACA,UAAQ,EAAA;GACT;EAIA;AACD,KAAI,CAAC,QAAE,WAAA;AACJ,MAAA,CAAA,QAAU,MAAQ,OAAQ,yDAEzB,OAAS,IAAA,MAAA,GAAA,CAAA,QAAA,MAAA,OAAA,OAAA,YAAA,eAAA,2BAAA,QAAA,KAAA,GAAA;AAET,UAAQ,MAAM,+CAAA,QAAA,GAAA,UAAA,QAAA,MAAA,MAAA,KAAA,GAAA;AACf,SAAO,SAAA,OAAA,yDAAA,IAAA,CAAA,CAAA,iBAAA,OAAA,CAAA,gEAAA,SAAA,QAAA,MAAA,OAAA,EACL,SAAA,uDACqB,SAAS;GAC3B,YAAA;GACQ,iBAAM;GACX,CAAA,CACR;;AAGH,QAAK;;AAET,WAAG,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;AAEC,KAAG,OAAQ,UAAU,qCAAC,IAAA;AACtB,KAAG,OAAA,OAAA,kCAAA,IAAA;AAEH,KAAG,OAAQ,KAAG,QAAU,cAAc,KAAC,UAAU;EAC/C,MAAA,QAAA,IAAA,OAAA,KAAA,UAAA,cAA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AAA;EAAA,CAAA,EAAA,QAAA;EACA,SAAA,IAAA,MAAA;;EAEF,QAAkB,IAAA;;AAGhB,QAAI,IAAA;;AAER,YAAS,SAAO;CAAM;CAAmB;CAAI;CAAA;CAAA;CAAA;;;;;;;AAO7C,eAAkB,QAAY,OAAO;CACjC,MAAM,MAAE,OAAS,WAAO,IAAO,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC/B,KAAI,CAAC,IAAG,OAAM,WAAA;AACV,QAAM,kCAAmB,IAAA;AACzB,wCAAoB,IAAA;OAGpB,uCAAkB,IAAA;AAEtB,QAAO,YAAC,IAAA;;AAEZ,QAAI,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
1
|
+
{"version":3,"file":"resolve.cjs","names":[],"sources":["../../src/resolver/resolve.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getGlobalOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getGlobalOptions(context, command),\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of ctx.input.context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every((value, index) => value === ctx.input.command.segments[index])\n )) {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n }\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,eAAE,WAAiB,OAAA;CACjB,MAAA,EAAA,SAAa,SAAA,WAAA;CACb,MAAA,QAAA,QAAoB,SACpB,GAAA,QAAA,QACQ,GAAO,OAAC,YACT,OAAA,MAAqB,QAAQ,oBAAO,GAAA,CAAA,MAAA,GAC/B,OAAA,MAAiB;CAY3B,MAAM,SAAS;EACX;EACA,QAZO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,GAAE;;GAEF,SAAM,mCAAA,SAAA,QAAA;GACV,MAAQ,EAAA;GACN,QAAA,UAAA;GACA,UAAQ,EAAA;GACT;EAIA;AACD,KAAI,CAAC,QAAE,WAAA;AACJ,MAAA,CAAA,QAAU,MAAQ,OAAQ,yDAEzB,OAAS,IAAA,MAAA,GAAA,CAAA,QAAA,MAAA,OAAA,OAAA,YAAA,eAAA,2BAAA,QAAA,KAAA,GAAA;AAET,UAAQ,MAAM,+CAAA,QAAA,GAAA,UAAA,QAAA,MAAA,MAAA,KAAA,GAAA;AACf,SAAO,SAAA,OAAA,yDAAA,IAAA,CAAA,CAAA,iBAAA,OAAA,CAAA,gEAAA,SAAA,QAAA,MAAA,OAAA,EACL,SAAA,uDACqB,SAAS;GAC3B,YAAA;GACQ,iBAAM;GACX,CAAA,CACR;;AAGH,QAAK;;AAET,WAAG,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;AAEC,KAAG,OAAQ,UAAU,qCAAC,IAAA;AACtB,KAAG,OAAA,OAAA,kCAAA,IAAA;AAEH,KAAG,OAAQ,KAAG,QA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,KAAA,OAAA,SAAA,MAAA,QAAA,OAAA,QAAA,IAAA,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,QAAA;EACA,SAAA,IAAA,MAAA;;EAEF,QAAkB,IAAA;;AAGhB,QAAI,IAAA;;AAER,YAAS,SAAO;CAAM;CAAmB;CAAI;CAAA;CAAA;CAAA;;;;;;;AAO7C,eAAkB,QAAY,OAAO;CACjC,MAAM,MAAE,OAAS,WAAO,IAAO,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC/B,KAAI,CAAC,IAAG,OAAM,WAAA;AACV,QAAM,kCAAmB,IAAA;AACzB,wCAAoB,IAAA;OAGpB,uCAAkB,IAAA;AAEtB,QAAO,YAAC,IAAA;;AAEZ,QAAI,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getDynamicPathSegmentName, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
|
|
2
2
|
import { extractType } from "../plugin-utils/deepkit.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { getGlobalOptions } from "../helpers/utilities.mjs";
|
|
4
4
|
import { applyArgsDefaults, applyDefaults, applyOptionsDefaults, resolveVirtualCommand } from "./helpers.mjs";
|
|
5
5
|
import { resolveFromBytecode } from "./deepkit.mjs";
|
|
6
6
|
import { resolveFromExports } from "./module.mjs";
|
|
@@ -26,7 +26,7 @@ async function initialize(input) {
|
|
|
26
26
|
icon: parent?.icon,
|
|
27
27
|
...command,
|
|
28
28
|
title,
|
|
29
|
-
options:
|
|
29
|
+
options: getGlobalOptions(context, command),
|
|
30
30
|
args: [],
|
|
31
31
|
parent: parent ?? null,
|
|
32
32
|
children: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":[],"sources":["../../src/resolver/resolve.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getDefaultOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of ctx.input.context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every((value, index) => value === ctx.input.command.segments[index])\n )) {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n }\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,eAAE,WAAiB,OAAA;CACjB,MAAA,EAAA,SAAa,SAAA,WAAA;CACb,MAAA,QAAA,QAAoB,SACpB,GAAA,QAAA,QACQ,GAAO,OAAC,YACT,OAAA,MAAqB,QAAQ,oBAAO,GAAA,CAAA,MAAA,GAC/B,OAAA,MAAiB;CAY3B,MAAM,SAAS;EACX;EACA,QAZO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,GAAE;;GAEF,SAAM,kBAAA,SAAA,Q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names":[],"sources":["../../src/resolver/resolve.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getGlobalOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getGlobalOptions(context, command),\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of ctx.input.context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every((value, index) => value === ctx.input.command.segments[index])\n )) {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n }\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,eAAE,WAAiB,OAAA;CACjB,MAAA,EAAA,SAAa,SAAA,WAAA;CACb,MAAA,QAAA,QAAoB,SACpB,GAAA,QAAA,QACQ,GAAO,OAAC,YACT,OAAA,MAAqB,QAAQ,oBAAO,GAAA,CAAA,MAAA,GAC/B,OAAA,MAAiB;CAY3B,MAAM,SAAS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AEZ,QAAI,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/dist/types/command.cjs
CHANGED
|
@@ -182,9 +182,10 @@ const __ΩCommandBase = [
|
|
|
182
182
|
"description",
|
|
183
183
|
"alias",
|
|
184
184
|
"icon",
|
|
185
|
+
"reference",
|
|
185
186
|
"isVirtual",
|
|
186
187
|
"CommandBase",
|
|
187
|
-
"PP&,J4!&4\"P&,J4#&F4$&4%8&4&8&F4'8&4(8)4
|
|
188
|
+
"PP&,J4!&4\"P&,J4#&F4$&4%8&4&8&F4'8&4(8&4)8)4*Mw+y"
|
|
188
189
|
];
|
|
189
190
|
const __ΩCommandConfig = [
|
|
190
191
|
() => __ΩCommandBase,
|
|
@@ -228,8 +229,9 @@ const __ΩCommandMetadata = [
|
|
|
228
229
|
"description",
|
|
229
230
|
"alias",
|
|
230
231
|
"icon",
|
|
232
|
+
"reference",
|
|
231
233
|
"CommandMetadata",
|
|
232
|
-
"P&4!8&4\"8P&&FJ4#8&4$8Mw
|
|
234
|
+
"P&4!8&4\"8P&&FJ4#8&4$8&4%8Mw&y"
|
|
233
235
|
];
|
|
234
236
|
const __ΩCommandModule = [
|
|
235
237
|
() => __ΩCommandMetadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.cjs","names":[],"sources":["../../src/types/command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema7TupleType } from \"@stryke/json\";\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport type { JSONSchema7Object } from \"json-schema\";\nimport type { ResolvedEntryTypeDefinition } from \"powerlines\";\nimport type * as z3 from \"zod/v3\";\n\nexport type CommandParameterType =\n | string\n | number\n | boolean\n | (string | number)[];\n\nexport const CommandParameterKinds = {\n string: \"string\",\n number: \"number\",\n boolean: \"boolean\"\n} as const;\n\nexport type CommandParameterKind =\n (typeof CommandParameterKinds)[keyof typeof CommandParameterKinds];\n\nexport interface BaseCommandParameter {\n /**\n * The option name.\n */\n name: string;\n /**\n * The option kind.\n */\n kind: CommandParameterKind;\n /**\n * The display title.\n */\n title: string;\n /**\n * The option description.\n */\n description: string;\n /**\n * Alternative option names.\n */\n alias: string[];\n /**\n * The environment variable name or false to disable.\n */\n env: string | false;\n /**\n * Whether the option is optional.\n */\n optional: boolean;\n}\n\nexport interface StringCommandParameter extends BaseCommandParameter {\n /**\n * The option kind.\n */\n kind: \"string\";\n /**\n * The default value.\n */\n default?: string;\n /**\n * A standard string format to validate the option value against.\n */\n format?:\n | \"email\"\n | \"uri\"\n | \"uuid\"\n | \"ipv4\"\n | \"ipv6\"\n | \"date\"\n | \"time\"\n | \"date-time\"\n | \"duration\";\n /**\n * Whether the option accepts multiple values.\n */\n variadic: boolean;\n\n /**\n * The allowed choices for the option value.\n */\n choices?: string[];\n}\n\nexport interface NumberCommandParameter extends BaseCommandParameter {\n /**\n * The option kind.\n */\n kind: \"number\";\n /**\n * The default value.\n */\n default?: number;\n /**\n * Whether the option accepts multiple values.\n */\n variadic: boolean;\n\n /**\n * The allowed choices for the option value.\n */\n choices?: number[];\n}\n\nexport interface BooleanCommandParameter extends BaseCommandParameter {\n /**\n * The option kind.\n */\n kind: \"boolean\";\n /**\n * The default value.\n */\n default?: boolean;\n}\n\nexport type CommandParameter =\n | StringCommandParameter\n | NumberCommandParameter\n | BooleanCommandParameter;\n\nexport type AsCommandParameterConfig<T extends BaseCommandParameter> = Pick<\n T,\n \"kind\" | \"alias\"\n> &\n Partial<Omit<T, \"kind\" | \"alias\">> & {\n alias?: string | string[];\n };\n\nexport type StringCommandParameterConfig =\n AsCommandParameterConfig<StringCommandParameter>;\nexport type NumberCommandParameterConfig =\n AsCommandParameterConfig<NumberCommandParameter>;\nexport type BooleanCommandParameterConfig =\n AsCommandParameterConfig<BooleanCommandParameter>;\n\nexport type CommandParameterConfig =\n | StringCommandParameterConfig\n | NumberCommandParameterConfig\n | BooleanCommandParameterConfig;\n\nexport interface BooleanCommandOption extends BooleanCommandParameter {\n /**\n * The option this negates.\n */\n isNegativeOf?: string;\n /**\n * Whether to skip adding a negative option.\n */\n skipAddingNegative?: boolean;\n}\n\nexport type CommandOption =\n | StringCommandParameter\n | NumberCommandParameter\n | BooleanCommandOption;\nexport type CommandOptionConfig = AsCommandParameterConfig<CommandOption>;\n\nexport type CommandArgument =\n | StringCommandParameter\n | NumberCommandParameter\n | BooleanCommandParameter;\nexport type CommandArgumentConfig = AsCommandParameterConfig<CommandArgument>;\n\nexport interface CommandBase {\n /**\n * The command id.\n */\n id: string | null;\n\n /**\n * The command name.\n */\n name: string;\n\n /**\n * The full command path value.\n */\n path: string | null;\n\n /**\n * The path segments.\n */\n segments: string[];\n\n /**\n * The display title.\n */\n title?: string;\n\n /**\n * The command description.\n */\n description?: string;\n\n /**\n * Alternative command names.\n */\n alias?: string[];\n\n /**\n * The command icon.\n */\n icon?: string;\n\n /**\n * Whether the command is virtual.\n *\n * @remarks\n * Virtual commands are considered forks in the command tree and are not directly executable. They are used to group related subcommands together without having an actual command handler or entry point.\n */\n isVirtual: boolean;\n}\n\nexport interface CommandConfig extends CommandBase {\n /**\n * The command id.\n */\n id: string;\n\n /**\n * The resolved entry definition.\n */\n entry: ResolvedEntryTypeDefinition;\n}\n\nexport type CommandTree = CommandConfig & {\n /**\n * The display title.\n */\n title: string;\n /**\n * The command description.\n */\n description: string;\n /**\n * Alternative command names.\n */\n alias: string[];\n /**\n * The command options.\n */\n options: Record<string, CommandOption>;\n /**\n * The positional arguments provided to the command.\n */\n args: CommandArgument[];\n /**\n * The parent command.\n */\n parent: null | CommandTree;\n /**\n * Child commands.\n */\n children: Record<string, CommandTree>;\n};\n\nexport type SerializedCommandTree = Omit<CommandTree, \"parent\" | \"children\"> & {\n /**\n * The parent command id.\n */\n parent: null | string;\n /**\n * Serialized child commands.\n */\n children: Record<string, SerializedCommandTree>;\n};\n\nexport interface CommandMetadata {\n /**\n * The display name of the command.\n *\n * @remarks\n * This value will be used in various displays of the user interface and documentation. If not provided, a formatted value of the command name will be used.\n */\n title?: string;\n\n /**\n * A brief description of what the command does.\n *\n * @remarks\n * This value will be used in various displays of the user interface and documentation. If not provided, a default message may be shown.\n */\n description?: string;\n\n /**\n * One or more alternative names for the command.\n */\n alias?: string | string[];\n\n /**\n * An optional icon to visually represent the command in user interfaces.\n *\n * @remarks\n * This can be a string containing an emoji, a Unicode character, or any other symbol that helps to visually identify the command. If not provided, no icon will be displayed.\n */\n icon?: string;\n}\n\nexport interface CommandModule {\n metadata?: CommandMetadata;\n options?:\n | Record<string, CommandOptionConfig>\n | JSONSchema7Object\n | StandardJSONSchemaV1<Record<string, CommandParameterType>>\n | z3.AnyZodObject;\n args?:\n | CommandArgumentConfig[]\n | JsonSchema7TupleType\n | StandardJSONSchemaV1<CommandParameterType[]>\n | z3.AnyZodTuple;\n default?: AnyFunction;\n}\n"],"mappings":";;;AAAA,MAAM,UAAU;CAAC;CAAK;CAAK;CAAQ;CAA4B;;;;;;AAE/D,MAAM,UAAU;CAAC;CAAG;OAAM;OAAiB;CAAA;CAAA;CAAA;;;;;;;AAE3C,MAAM,aAAS;CAAA;CAAS;CAAG;CAAY;CAA2B;AAClE,MAAI,0BAA4B,CAAC,wBAAqB,gBAAa;AAEnE,MAAK,wBAA0B;;CAE9B,QAAW;CACX,SAAY;CACZ;AACD,MAAC,0BAA+B;OAAG;OAAkB;CAAA;CAAA;CAAA;AAErD,MAAM,0BAAqB;CAAM;OAAG;CAAA;C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BAAW;OAAW;CAAA;OAAA;OAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
1
|
+
{"version":3,"file":"command.cjs","names":[],"sources":["../../src/types/command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema7TupleType } from \"@stryke/json\";\nimport type { AnyFunction } from \"@stryke/types/base\";\nimport type { JSONSchema7Object } from \"json-schema\";\nimport type { ResolvedEntryTypeDefinition } from \"powerlines\";\nimport type * as z3 from \"zod/v3\";\n\nexport type CommandParameterType =\n | string\n | number\n | boolean\n | (string | number)[];\n\nexport const CommandParameterKinds = {\n string: \"string\",\n number: \"number\",\n boolean: \"boolean\"\n} as const;\n\nexport type CommandParameterKind =\n (typeof CommandParameterKinds)[keyof typeof CommandParameterKinds];\n\nexport interface BaseCommandParameter {\n /**\n * The option name.\n */\n name: string;\n\n /**\n * The option kind.\n */\n kind: CommandParameterKind;\n\n /**\n * The display title.\n */\n title: string;\n\n /**\n * The option description.\n */\n description: string;\n\n /**\n * Alternative option names.\n */\n alias: string[];\n\n /**\n * The environment variable name or false to disable.\n */\n env: string | false;\n\n /**\n * Whether the option is optional.\n */\n optional: boolean;\n}\n\nexport interface StringCommandParameter extends BaseCommandParameter {\n /**\n * The option kind.\n */\n kind: \"string\";\n\n /**\n * The default value.\n */\n default?: string;\n\n /**\n * A standard string format to validate the option value against.\n */\n format?:\n | \"email\"\n | \"uri\"\n | \"uuid\"\n | \"ipv4\"\n | \"ipv6\"\n | \"date\"\n | \"time\"\n | \"date-time\"\n | \"duration\";\n\n /**\n * Whether the option accepts multiple values.\n */\n variadic: boolean;\n\n /**\n * The allowed choices for the option value.\n */\n choices?: string[];\n}\n\nexport interface NumberCommandParameter extends BaseCommandParameter {\n /**\n * The option kind.\n */\n kind: \"number\";\n\n /**\n * The default value.\n */\n default?: number;\n\n /**\n * Whether the option accepts multiple values.\n */\n variadic: boolean;\n\n /**\n * The allowed choices for the option value.\n */\n choices?: number[];\n}\n\nexport interface BooleanCommandParameter extends BaseCommandParameter {\n /**\n * The option kind.\n */\n kind: \"boolean\";\n\n /**\n * The default value.\n */\n default?: boolean;\n}\n\nexport type CommandParameter =\n | StringCommandParameter\n | NumberCommandParameter\n | BooleanCommandParameter;\n\nexport type AsCommandParameterConfig<T extends BaseCommandParameter> = Pick<\n T,\n \"kind\" | \"alias\"\n> &\n Partial<Omit<T, \"kind\" | \"alias\">> & {\n alias?: string | string[];\n };\n\nexport type StringCommandParameterConfig =\n AsCommandParameterConfig<StringCommandParameter>;\nexport type NumberCommandParameterConfig =\n AsCommandParameterConfig<NumberCommandParameter>;\nexport type BooleanCommandParameterConfig =\n AsCommandParameterConfig<BooleanCommandParameter>;\n\nexport type CommandParameterConfig =\n | StringCommandParameterConfig\n | NumberCommandParameterConfig\n | BooleanCommandParameterConfig;\n\nexport interface BooleanCommandOption extends BooleanCommandParameter {\n /**\n * The option this negates.\n */\n isNegativeOf?: string;\n\n /**\n * Whether to skip adding a negative option.\n */\n skipAddingNegative?: boolean;\n}\n\nexport type CommandOption =\n | StringCommandParameter\n | NumberCommandParameter\n | BooleanCommandOption;\nexport type CommandOptionConfig = AsCommandParameterConfig<CommandOption>;\n\nexport type CommandArgument =\n | StringCommandParameter\n | NumberCommandParameter\n | BooleanCommandParameter;\nexport type CommandArgumentConfig = AsCommandParameterConfig<CommandArgument>;\n\nexport interface CommandBase {\n /**\n * The command id.\n */\n id: string | null;\n\n /**\n * The command name.\n */\n name: string;\n\n /**\n * The full command path value.\n */\n path: string | null;\n\n /**\n * The path segments.\n */\n segments: string[];\n\n /**\n * The display title.\n */\n title?: string;\n\n /**\n * The command description.\n */\n description?: string;\n\n /**\n * Alternative command names.\n */\n alias?: string[];\n\n /**\n * The command icon.\n */\n icon?: string;\n\n /**\n * A URL to the command documentation or reference.\n */\n reference?: string;\n\n /**\n * Whether the command is virtual.\n *\n * @remarks\n * Virtual commands are considered forks in the command tree and are not directly executable. They are used to group related subcommands together without having an actual command handler or entry point.\n */\n isVirtual: boolean;\n}\n\nexport interface CommandConfig extends CommandBase {\n /**\n * The command id.\n */\n id: string;\n\n /**\n * The resolved entry definition.\n */\n entry: ResolvedEntryTypeDefinition;\n}\n\nexport type CommandTree = CommandConfig & {\n /**\n * The display title.\n */\n title: string;\n\n /**\n * The command description.\n */\n description: string;\n\n /**\n * Alternative command names.\n */\n alias: string[];\n\n /**\n * The command options.\n */\n options: Record<string, CommandOption>;\n\n /**\n * The positional arguments provided to the command.\n */\n args: CommandArgument[];\n\n /**\n * The parent command.\n */\n parent: null | CommandTree;\n\n /**\n * Child commands.\n */\n children: Record<string, CommandTree>;\n};\n\nexport type SerializedCommandTree = Omit<CommandTree, \"parent\" | \"children\"> & {\n /**\n * The parent command id.\n */\n parent: null | string;\n /**\n * Serialized child commands.\n */\n children: Record<string, SerializedCommandTree>;\n};\n\nexport interface CommandMetadata {\n /**\n * The display name of the command.\n *\n * @remarks\n * This value will be used in various displays of the user interface and documentation. If not provided, a formatted value of the command name will be used.\n */\n title?: string;\n\n /**\n * A brief description of what the command does.\n *\n * @remarks\n * This value will be used in various displays of the user interface and documentation. If not provided, a default message may be shown.\n */\n description?: string;\n\n /**\n * One or more alternative names for the command.\n */\n alias?: string | string[];\n\n /**\n * An optional icon to visually represent the command in user interfaces.\n *\n * @remarks\n * This can be a string containing an emoji, a Unicode character, or any other symbol that helps to visually identify the command. If not provided, no icon will be displayed.\n */\n icon?: string;\n\n /**\n * A URL to the command documentation or reference.\n *\n * @remarks\n * This URL can be used in various displays of the user interface and documentation to provide users with a reference for the command. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{referenceLink}/command/subcommand`.\n */\n reference?: string;\n}\n\nexport interface CommandModule {\n metadata?: CommandMetadata;\n options?:\n | Record<string, CommandOptionConfig>\n | JSONSchema7Object\n | StandardJSONSchemaV1<Record<string, CommandParameterType>>\n | z3.AnyZodObject;\n args?:\n | CommandArgumentConfig[]\n | JsonSchema7TupleType\n | StandardJSONSchemaV1<CommandParameterType[]>\n | z3.AnyZodTuple;\n default?: AnyFunction;\n}\n"],"mappings":";;;AAAA,MAAM,UAAU;CAAC;CAAK;CAAK;CAAQ;CAA4B;;;;;;AAE/D,MAAM,UAAU;CAAC;CAAG;OAAM;OAAiB;CAAA;CAAA;CAAA;;;;;;;AAE3C,MAAM,aAAS;CAAA;CAAS;CAAG;CAAY;CAA2B;AAClE,MAAI,0BAA4B,CAAC,wBAAqB,gBAAa;AAEnE,MAAK,wBAA0B;;CAE9B,QAAW;CACX,SAAY;CACZ;AACD,MAAC,0BAA+B;OAAG;OAAkB;CAAA;CAAA;CAAA;AAErD,MAAM,0BAAqB;CAAM;OAAG;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEpC,MAAM,4BAA4B;OAAO;CAAyB;CAAI;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEtE,MAAM,4BAA4B;OAAO;CAAwB;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEjE,MAAM,6BAA6B;OAAO;CAAW;CAAA;CAAA;CAAA;CAAA;CAAA;AAErD,MAAM,sBAAQ;OAAA;OAA+C;OAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;;;AAI7D,MAAI,kCAAA;OAAA;OAAA;CAAA;CAAA;CAAA;AAEJ,MAAI,kCAAA;OAAA;OAAA;CAAA;CAAA;CAAA;;;;;;;AAIJ,MAAE,4BAAgB;OAAA;OAAA;OAAA;CAAA;CAAA;CAAA;AAElB,MAAE,0BAAiB;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAInB,MAAG,yBAA4B;OAAO;OAA8B;CAAA;CAAA;CAAA;AAEpE,MAAM,qBAAW;OAAA;OAAqB;OAAA;CAAA;CAAA;CAAA;AAEtC,MAAK,2BAAe;OAAA;OAAA;CAAA;CAAA;CAAA;AAEpB,MAAM,iBAAQ;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEd,MAAI,mBAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEJ,MAAI,iBAAA;OAAA;CAAA;CAAA;CAAA;OAAA;OAAA;CAAA;OAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;;AAIJ,MAAK,qBAAiB;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAEtB,MAAE,mBAAa;OAAA;CAAA;OAAA;OAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/dist/types/command.d.cts
CHANGED
|
@@ -148,6 +148,10 @@ interface CommandBase {
|
|
|
148
148
|
* The command icon.
|
|
149
149
|
*/
|
|
150
150
|
icon?: string;
|
|
151
|
+
/**
|
|
152
|
+
* A URL to the command documentation or reference.
|
|
153
|
+
*/
|
|
154
|
+
reference?: string;
|
|
151
155
|
/**
|
|
152
156
|
* Whether the command is virtual.
|
|
153
157
|
*
|
|
@@ -232,6 +236,13 @@ interface CommandMetadata {
|
|
|
232
236
|
* This can be a string containing an emoji, a Unicode character, or any other symbol that helps to visually identify the command. If not provided, no icon will be displayed.
|
|
233
237
|
*/
|
|
234
238
|
icon?: string;
|
|
239
|
+
/**
|
|
240
|
+
* A URL to the command documentation or reference.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the command. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{referenceLink}/command/subcommand`.
|
|
244
|
+
*/
|
|
245
|
+
reference?: string;
|
|
235
246
|
}
|
|
236
247
|
interface CommandModule {
|
|
237
248
|
metadata?: CommandMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.cts","names":[],"sources":["../../src/types/command.ts"],"mappings":";;;;;;;;KAyBY,oBAAA;AAAA,cAMC,qBAAA;EAAA;;;;KAMD,oBAAA,WACF,qBAAA,eAAoC,qBAAA;AAAA,UAE7B,oBAAA;EALP;;;EASR,IAAA;;;;
|
|
1
|
+
{"version":3,"file":"command.d.cts","names":[],"sources":["../../src/types/command.ts"],"mappings":";;;;;;;;KAyBY,oBAAA;AAAA,cAMC,qBAAA;EAAA;;;;KAMD,oBAAA,WACF,qBAAA,eAAoC,qBAAA;AAAA,UAE7B,oBAAA;EALP;;;EASR,IAAA;;;;EAKA,IAAA,EAAM,oBAAA;EAZI;;;EAiBV,KAAA;EAhBiE;AAEnE;;EAmBE,WAAA;EAV0B;;;EAe1B,KAAA;EAVA;;;EAeA,GAAA;EAKA;;;EAAA,QAAA;AAAA;AAAA,UAGe,sBAAA,SAA+B,oBAAA;EAAoB;;;EAIlE,IAAA;EAUA;;;EALA,OAAA;EAwBO;AAGT;;EAtBE,MAAA;EAsBkE;;;EARlE,QAAA;EAsBA;;;EAjBA,OAAA;AAAA;AAAA,UAGe,sBAAA,SAA+B,oBAAA;;;;EAI9C,IAAA;EA2BA;;;EAtBA,OAAA;EAyB0B;;;EApB1B,QAAA;EAuBE;;;EAlBF,OAAA;AAA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F0B;;;EAsF1B,OAAA,EAAS,MAAA,SAAe,aAAA;EAnExB;;;EAwEA,IAAA,EAAM,eAAA;EApDN;;;EAyDA,MAAA,SAAe,WAAA;EA5CN;AAGX;;EA8CE,QAAA,EAAU,MAAA,SAAe,WAAA;AAAA;AAAA,KAGf,qBAAA,GAAwB,IAAA,CAAK,WAAA;EA7CvC;;;EAiDA,MAAA;EA5CkC;AAGpC;;EA6CE,QAAA,EAAU,MAAA,SAAe,qBAAA;AAAA;AAAA,UAGV,eAAA;EA7BN;;;;;;EAoCT,KAAA;EAvDwB;;;;;;EA+DxB,WAAA;EAvCA;;;EA4CA,KAAA;EAlCA;;;;;AAGF;EAuCE,IAAA;;;;;;;EAQA,SAAA;AAAA;AAAA,UAGe,aAAA;EACf,QAAA,GAAW,eAAA;EACX,OAAA,GACI,MAAA,SAAe,mBAAA,IACf,iBAAA,GACA,oBAAA,CAAqB,MAAA,SAAe,oBAAA,KACpC,EAAA,CAAG,YAAA;EACP,IAAA,GACI,qBAAA,KACA,oBAAA,GACA,oBAAA,CAAqB,oBAAA,MACrB,EAAA,CAAG,WAAA;EACP,OAAA,GAAU,WAAA;AAAA"}
|
package/dist/types/command.d.mts
CHANGED
|
@@ -148,6 +148,10 @@ interface CommandBase {
|
|
|
148
148
|
* The command icon.
|
|
149
149
|
*/
|
|
150
150
|
icon?: string;
|
|
151
|
+
/**
|
|
152
|
+
* A URL to the command documentation or reference.
|
|
153
|
+
*/
|
|
154
|
+
reference?: string;
|
|
151
155
|
/**
|
|
152
156
|
* Whether the command is virtual.
|
|
153
157
|
*
|
|
@@ -232,6 +236,13 @@ interface CommandMetadata {
|
|
|
232
236
|
* This can be a string containing an emoji, a Unicode character, or any other symbol that helps to visually identify the command. If not provided, no icon will be displayed.
|
|
233
237
|
*/
|
|
234
238
|
icon?: string;
|
|
239
|
+
/**
|
|
240
|
+
* A URL to the command documentation or reference.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the command. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{referenceLink}/command/subcommand`.
|
|
244
|
+
*/
|
|
245
|
+
reference?: string;
|
|
235
246
|
}
|
|
236
247
|
interface CommandModule {
|
|
237
248
|
metadata?: CommandMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.mts","names":[],"sources":["../../src/types/command.ts"],"mappings":";;;;;;;;KAyBY,oBAAA;AAAA,cAMC,qBAAA;EAAA;;;;KAMD,oBAAA,WACF,qBAAA,eAAoC,qBAAA;AAAA,UAE7B,oBAAA;EALP;;;EASR,IAAA;;;;
|
|
1
|
+
{"version":3,"file":"command.d.mts","names":[],"sources":["../../src/types/command.ts"],"mappings":";;;;;;;;KAyBY,oBAAA;AAAA,cAMC,qBAAA;EAAA;;;;KAMD,oBAAA,WACF,qBAAA,eAAoC,qBAAA;AAAA,UAE7B,oBAAA;EALP;;;EASR,IAAA;;;;EAKA,IAAA,EAAM,oBAAA;EAZI;;;EAiBV,KAAA;EAhBiE;AAEnE;;EAmBE,WAAA;EAV0B;;;EAe1B,KAAA;EAVA;;;EAeA,GAAA;EAKA;;;EAAA,QAAA;AAAA;AAAA,UAGe,sBAAA,SAA+B,oBAAA;EAAoB;;;EAIlE,IAAA;EAUA;;;EALA,OAAA;EAwBO;AAGT;;EAtBE,MAAA;EAsBkE;;;EARlE,QAAA;EAsBA;;;EAjBA,OAAA;AAAA;AAAA,UAGe,sBAAA,SAA+B,oBAAA;;;;EAI9C,IAAA;EA2BA;;;EAtBA,OAAA;EAyB0B;;;EApB1B,QAAA;EAuBE;;;EAlBF,OAAA;AAAA;AAAA,UAGe,uBAAA,SAAgC,oBAAA;EAetB;;AAE3B;EAbE,IAAA;EAakC;;;EARlC,OAAA;AAAA;AAAA,KAGU,gBAAA,GACR,sBAAA,GACA,sBAAA,GACA,uB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