@shell-shock/core 0.14.5 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/utils-builtin.cjs +1004 -2
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +5 -1
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +5 -1
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +1004 -3
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/plugin.cjs +1 -1
- 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 +1 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +8 -5
- package/dist/resolver/resolve.cjs.map +1 -1
- package/dist/resolver/resolve.mjs +8 -5
- package/dist/resolver/resolve.mjs.map +1 -1
- package/package.json +11 -11
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, 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 framework: \"shell-shock\",\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 skipNodeModulesBundle: true\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 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 if (this.config.reference.includes(\"{commands}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{commands}\"))\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.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 this.debug(\n `Checking for commands using input: ${JSON.stringify(this.config.input)}`\n );\n\n this.commandsPath = await findCommandsRoot(this);\n this.debug(`Resolved commands root path: ${this.commandsPath}`);\n\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 tags: [],\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 types() {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `\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 tags: [],\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;AA4BjC,WA3BG,KAAiB,EAClB,QAAC,EACA,MAAO,UAAU,KAAC,OAAS,MAAQ,OAAA,EACrC,EACA,EAAE,SAAA;KACF,MAAO,WAAU,KAAM;KACvB,OAAO,YAAU,KAAQ;;KAE1B,UAAY;;KAEhB,WAAA;KACK,iBAAgB;KACrB,QAAA;MACK,QAAM;MACH,KAAC;MACN;KACG,OAAC,CAAA,KAAA,OAAA,SAAA,MAAA,QAAA,KAAA,OAAA,MAAA,IAAA,KAAA,OAAA,MAAA,WAAA,KAAA,SAAA,KAAA,OAAA,MAAA,IAAA,OAAA,KAAA,KAAA,OAAA,MAAA,CAAA,WAAA,IAAA,CAAA,UAAA,KAAA,OAAA,MAAA,oBAAA,EAAA,UAAA,KAAA,OAAA,MAAA,qBAAA,CAAA,GAAA;KACL,SAAQ;MACR,UAAS,CAAA,sBAAA;MACH,uBAAE;MACR;KACE,QAAO;MACP,KAAM;MACJ,cAAY;;MAEZ;;;GAIJ,gBAAgB;IACd,OAAO;IACP,MAAM,UAAA;AACJ,UAAG,MAAA,+CAAA;AACH,UAAE,OAAO,uBAAA,YAAA,KAAA,OAAA,cAAA,GAAA,KAAA,OAAA,gBA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W,KAAK,OAAG,KAAO,UAAA,eAAA,MAAA,MAAA,SAAA,CAAA,CAAA,OAAA,QAAA;AAChC,WAAO,OAAO,MAAM,gBAAc,KAAA;KAChC,IAAI,OAAO;AACT,aAAO,OAAM,OAAQ,SAAE;;KAEzB,gBAAe;KACf,WAAU,UAAK,gBAAM,MAAA;MACnB,IAAI,OAAG;AACN,cAAA,CAAA,MAAA;;MAED,IAAI,WAAO;AACT,cAAK,gBAAG,iBAAA,EACN,SAAS,OACV,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 framework: \"shell-shock\",\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 skipNodeModulesBundle: true\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 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 if (this.config.reference.includes(\"{commands}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{commands}\"))\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.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 this.debug(\n `Checking for commands using input: ${JSON.stringify(this.config.input)}`\n );\n\n this.commandsPath = await findCommandsRoot(this);\n this.debug(`Resolved commands root path: ${this.commandsPath}`);\n\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 tags: [],\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 types() {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `\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 tags: [],\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}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : replacePath(command.entry.file, this.config.root)\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,K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gBAAG,iBAAA,EACN,SAAS,OACV,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
|
@@ -36,11 +36,14 @@ async function initialize(input) {
|
|
|
36
36
|
};
|
|
37
37
|
if (!command.isVirtual) {
|
|
38
38
|
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
39
|
-
context.debug(`Adding reflection for
|
|
40
|
-
result.module = await (_powerlines_plugin_esbuild_helpers_resolve.resolveModule.Ω = [["CommandModule", "\"w!"]], (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(context, command.entry.input, {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
context.debug(`Adding reflection for application command: ${command.id} (file: ${command.entry.input.file})`);
|
|
40
|
+
result.module = await (_powerlines_plugin_esbuild_helpers_resolve.resolveModule.Ω = [["CommandModule", "\"w!"]], (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(context, command.entry.input, {
|
|
41
|
+
name: `${command.title} Command Module`,
|
|
42
|
+
plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
|
|
43
|
+
reflection: "default",
|
|
44
|
+
reflectionLevel: "verbose"
|
|
45
|
+
})]
|
|
46
|
+
}));
|
|
44
47
|
}
|
|
45
48
|
return result;
|
|
46
49
|
}
|
|
@@ -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 { 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 tags: parent?.tags ?? [],\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 await Promise.all(\n ctx.input.context.inputs\n .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(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\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\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;CAa3B,MAAM,SAAM;EACR;EACA,QAbO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,MAAE,QAAS,QAAS,EAAA;;GAEpB;GACJ,SAAa,mCAAE,SAAA,QAAA;GACb,MAAA,EAAA;GACA,QAAQ,UAAA;GACN,UAAI,EAAA;GACP;EAIA;AACD,KAAG,CAAA,QAAU,WAAQ;oCAEjB,CAAA,QAAS,GAAA,WAAA,QAA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A;GAAA;GAAA;GAAA,CAAA,CAAA;;AAEP,OAAM,QAAM,IAAI,IAAA,MAAA,QAAA,OACX,OAAK,cAAe,UAAI,MAAA,SAAA,OAAA,cAAA,YAAA,CAAA,6CAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACxB,WACD,IAAI,MAAI,QAAM,SAAQ,OAAO,cAAA,YAAA,CAAA,6CAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,SACzB,KACJ,MAAM,SACJ,MAAK,GAAA,IAAA,MAAA,QAAA,SAAA,OAAA,CACX,MAAA,cAAA,OAAA,UAAA,UAAA,IAAA,MAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACA,IAAA,aAAA,OAAA,UAAA;;;;;;GAEF,SAAkB,IAAA,MAAA;;GAEV,QAAM,IAAQ;GAChB,CAAA;IACF;EAAA;EAAO;EAAO;EAAW,CAAA,CAAA,CAAA;AAC3B,QAAK,IAAM;;AAEf,YAAU,SAAU;CAAA;CAAqB;CAAC;CAAY;CAAA;CAAA;;;;;;;AAOtD,eAAkB,QAAA,OAAA;CACd,MAAM,MAAI,OAAO,WAAY,IAAA,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC7B,KAAI,CAAC,IAAI,OAAO,WAAQ;AACpB,QAAM,kCAAmB,IAAA;AACzB,wCAAoB,IAAE;OAGtB,uCAAI,IAAA;AAER,QAAA,YAAA,IAAA;;AAEJ,QAAQ,SAAO;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 tags: parent?.tags ?? [],\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 application 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 name: `${command.title} Command Module`,\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 await Promise.all(\n ctx.input.context.inputs\n .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(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\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\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;CAa3B,MAAM,SAAM;EACR;EACA,QAbO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,MAAE,QAAS,QAAS,EAAA;;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CAAA;IAC5D,QAAC;IACL;GACH,CAAC,EAAC;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;AAEP,OAAM,QAAM,IAAI,IAAA,MAAA,QAAA,OACX,OAAK,cAAe,UAAI,MAAA,SAAA,OAAA,cAAA,YAAA,CAAA,6CAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACxB,WACD,IAAI,MAAI,QAAM,SAAQ,OAAO,cAAA,YAAA,CAAA,6CAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,SACzB,KACJ,MAAM,SACJ,MAAK,GAAA,IAAA,MAAA,QAAA,SAAA,OAAA,CACX,MAAA,cAAA,OAAA,UAAA,UAAA,IAAA,MAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACA,IAAA,aAAA,OAAA,UAAA;;;;;;GAEF,SAAkB,IAAA,MAAA;;GAEV,QAAM,IAAQ;GAChB,CAAA;IACF;EAAA;EAAO;EAAO;EAAW,CAAA,CAAA,CAAA;AAC3B,QAAK,IAAM;;AAEf,YAAU,SAAU;CAAA;CAAqB;CAAC;CAAY;CAAA;CAAA;;;;;;;AAOtD,eAAkB,QAAA,OAAA;CACd,MAAM,MAAI,OAAO,WAAY,IAAA,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC7B,KAAI,CAAC,IAAI,OAAO,WAAQ;AACpB,QAAM,kCAAmB,IAAA;AACzB,wCAAoB,IAAE;OAGtB,uCAAI,IAAA;AAER,QAAA,YAAA,IAAA;;AAEJ,QAAQ,SAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -35,11 +35,14 @@ async function initialize(input) {
|
|
|
35
35
|
};
|
|
36
36
|
if (!command.isVirtual) {
|
|
37
37
|
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
38
|
-
context.debug(`Adding reflection for
|
|
39
|
-
result.module = await (resolveModule.Ω = [["CommandModule", "\"w!"]], resolveModule(context, command.entry.input, {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
context.debug(`Adding reflection for application command: ${command.id} (file: ${command.entry.input.file})`);
|
|
39
|
+
result.module = await (resolveModule.Ω = [["CommandModule", "\"w!"]], resolveModule(context, command.entry.input, {
|
|
40
|
+
name: `${command.title} Command Module`,
|
|
41
|
+
plugins: [esbuildPlugin(context, {
|
|
42
|
+
reflection: "default",
|
|
43
|
+
reflectionLevel: "verbose"
|
|
44
|
+
})]
|
|
45
|
+
}));
|
|
43
46
|
}
|
|
44
47
|
return result;
|
|
45
48
|
}
|
|
@@ -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 { 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 tags: parent?.tags ?? [],\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 await Promise.all(\n ctx.input.context.inputs\n .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(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\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\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;CAa3B,MAAM,SAAM;EACR;EACA,QAbO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,MAAE,QAAS,QAAS,EAAA;;GAEpB;GACJ,SAAa,iBAAE,SAAA,QAAA;GACb,MAAA,EAAA;GACA,QAAQ,UAAA;GACN,UAAI,EAAA;GACP;EAIA;AACD,KAAG,CAAA,QAAU,WAAQ;oCAEjB,CAAA,QAAS,GAAA,WAAA,QAAA,MAAA,MAAA,KAAA,CACL,OAAC,IAAA,MAAA,GAAA,CAAA,QAAA,MAAA,OAAA,OAAA,YAAA,eAAA,2BAAA,QAAA,KAAA,GAAA;AAEL,UAAQ,MAAM,+CAAM,QAAA,GAAA,UAAA,QAAA,MAAA,MAAA,KAAA,GAAA;AACrB,SAAO,SAAA,OAAA,cAAA,IAAA,CAAA,CAAA,iBAAA,OAAA,CAAA,EAAA,cAAA,SAAA,QAAA,MAAA,OAAA,EACL,SAAA,CACI,cAAiB,SAAS;GAC3B,YAAA;GACQ,iBAAM;GACX,CAAA,CACR;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AAA,IAAA,MAAA,QAAA,SAAA,OAAA,CACX,MAAA,cAAA,OAAA,UAAA,UAAA,IAAA,MAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACA,IAAA,aAAA,OAAA,UAAA;;;;;;GAEF,SAAkB,IAAA,MAAA;;GAEV,QAAM,IAAQ;GAChB,CAAA;IACF;EAAA;EAAO;EAAO;EAAW,CAAA,CAAA,CAAA;AAC3B,QAAK,IAAM;;AAEf,YAAU,SAAU;CAAA;CAAqB;CAAC;CAAY;CAAA;CAAA;;;;;;;AAOtD,eAAkB,QAAA,OAAA;CACd,MAAM,MAAI,OAAO,WAAY,IAAA,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC7B,KAAI,CAAC,IAAI,OAAO,WAAQ;AACpB,QAAM,mBAAmB,IAAA;AACzB,sBAAoB,IAAE;OAGtB,uBAAI,IAAA;AAER,QAAA,YAAA,IAAA;;AAEJ,QAAQ,SAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
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 { 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 tags: parent?.tags ?? [],\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 application 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 name: `${command.title} Command Module`,\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 await Promise.all(\n ctx.input.context.inputs\n .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(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\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\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;CAa3B,MAAM,SAAM;EACR;EACA,QAbO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,MAAE,QAAS,QAAS,EAAA;;GAEpB;GACJ,SAAa,iBAAE,SAAA,QAAA;GACb,MAAA,EAAA;GACA,QAAQ,UAAA;GACN,UAAI,EAAA;GACP;EAIA;AACD,KAAG,CAAA,QAAU,WAAQ;oCAEjB,CAAA,QAAS,GAAA,WAAA,QAAA,MAAA,MAAA,KAAA,CACL,OAAC,IAAA,MAAA,GAAA,CAAA,QAAA,MAAA,OAAA,OAAA,YAAA,eAAA,2BAAA,QAAA,KAAA,GAAA;AAEL,UAAQ,MAAM,8CAAM,QAAA,GAAA,UAAA,QAAA,MAAA,MAA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AAA;EAAA,CAAA,CAAA,CAAA,SACzB,KACJ,MAAM,SACJ,MAAK,GAAA,IAAA,MAAA,QAAA,SAAA,OAAA,CACX,MAAA,cAAA,OAAA,UAAA,UAAA,IAAA,MAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACA,IAAA,aAAA,OAAA,UAAA;;;;;;GAEF,SAAkB,IAAA,MAAA;;GAEV,QAAM,IAAQ;GAChB,CAAA;IACF;EAAA;EAAO;EAAO;EAAW,CAAA,CAAA,CAAA;AAC3B,QAAK,IAAM;;AAEf,YAAU,SAAU;CAAA;CAAqB;CAAC;CAAY;CAAA;CAAA;;;;;;;AAOtD,eAAkB,QAAA,OAAA;CACd,MAAM,MAAI,OAAO,WAAY,IAAA,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC7B,KAAI,CAAC,IAAI,OAAO,WAAQ;AACpB,QAAM,mBAAmB,IAAA;AACzB,sBAAoB,IAAE;OAGtB,uBAAI,IAAA;AAER,QAAA,YAAA,IAAA;;AAEJ,QAAQ,SAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shell-shock/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing the core Shell Shock functionality used to build and manage a command-line application.",
|
|
6
6
|
"keywords": ["shell-shock", "powerlines", "storm-software"],
|
|
@@ -350,12 +350,12 @@
|
|
|
350
350
|
"@alloy-js/core": "0.23.0-dev.8",
|
|
351
351
|
"@alloy-js/markdown": "0.23.0-dev.1",
|
|
352
352
|
"@alloy-js/typescript": "0.23.0-dev.4",
|
|
353
|
-
"@powerlines/deepkit": "^0.6.
|
|
354
|
-
"@powerlines/plugin-alloy": "^0.26.
|
|
355
|
-
"@powerlines/plugin-automd": "^0.1.
|
|
356
|
-
"@powerlines/plugin-deepkit": "^0.11.
|
|
357
|
-
"@powerlines/plugin-nodejs": "^0.1.
|
|
358
|
-
"@powerlines/plugin-tsdown": "^0.1.
|
|
353
|
+
"@powerlines/deepkit": "^0.6.164",
|
|
354
|
+
"@powerlines/plugin-alloy": "^0.26.1",
|
|
355
|
+
"@powerlines/plugin-automd": "^0.1.385",
|
|
356
|
+
"@powerlines/plugin-deepkit": "^0.11.264",
|
|
357
|
+
"@powerlines/plugin-nodejs": "^0.1.308",
|
|
358
|
+
"@powerlines/plugin-tsdown": "^0.1.327",
|
|
359
359
|
"@standard-schema/spec": "^1.1.0",
|
|
360
360
|
"@standard-schema/utils": "^0.3.0",
|
|
361
361
|
"@stryke/cli": "^0.13.36",
|
|
@@ -369,20 +369,20 @@
|
|
|
369
369
|
"@stryke/types": "^0.11.2",
|
|
370
370
|
"@stryke/zod": "^0.3.12",
|
|
371
371
|
"automd": "^0.4.3",
|
|
372
|
-
"defu": "^6.1.
|
|
372
|
+
"defu": "^6.1.6",
|
|
373
373
|
"json-schema": "^0.4.0",
|
|
374
374
|
"tsdown": "^0.21.7"
|
|
375
375
|
},
|
|
376
376
|
"devDependencies": {
|
|
377
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
377
|
+
"@powerlines/plugin-plugin": "^0.12.336",
|
|
378
378
|
"@types/json-schema": "^7.0.15",
|
|
379
379
|
"@types/node": "^25.5.0",
|
|
380
|
-
"powerlines": "^0.42.
|
|
380
|
+
"powerlines": "^0.42.26",
|
|
381
381
|
"typescript": "^5.9.3",
|
|
382
382
|
"zod": "^4.3.6"
|
|
383
383
|
},
|
|
384
384
|
"peerDependencies": { "powerlines": ">=0.42.10", "zod": "^3.25.0 || ^4.0.0" },
|
|
385
385
|
"peerDependenciesMeta": { "zod": { "optional": true } },
|
|
386
386
|
"publishConfig": { "access": "public" },
|
|
387
|
-
"gitHead": "
|
|
387
|
+
"gitHead": "bffe474833b0bb3ca1d4157afe0c1952e4148d81"
|
|
388
388
|
}
|