@shell-shock/core 0.9.7 → 0.11.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.
Files changed (159) hide show
  1. package/dist/api.cjs +1 -2
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.d.cts +1 -1
  4. package/dist/api.d.mts +1 -1
  5. package/dist/api.mjs +1 -2
  6. package/dist/api.mjs.map +1 -1
  7. package/dist/components/docs.cjs +4 -4
  8. package/dist/components/docs.cjs.map +1 -1
  9. package/dist/components/docs.d.cts +5 -5
  10. package/dist/components/docs.d.mts +5 -5
  11. package/dist/components/helpers.d.cts +6 -6
  12. package/dist/components/helpers.d.mts +6 -6
  13. package/dist/components/helpers.d.mts.map +1 -1
  14. package/dist/components/index.cjs +1 -0
  15. package/dist/components/index.d.cts +2 -2
  16. package/dist/components/index.d.mts +2 -2
  17. package/dist/components/index.mjs +2 -2
  18. package/dist/components/options-parser-logic.cjs +31 -31
  19. package/dist/components/options-parser-logic.cjs.map +1 -1
  20. package/dist/components/options-parser-logic.d.cts +9 -9
  21. package/dist/components/options-parser-logic.d.cts.map +1 -1
  22. package/dist/components/options-parser-logic.d.mts +9 -9
  23. package/dist/components/options-parser-logic.d.mts.map +1 -1
  24. package/dist/components/options-parser-logic.mjs +26 -26
  25. package/dist/components/options-parser-logic.mjs.map +1 -1
  26. package/dist/components/usage.cjs +5 -5
  27. package/dist/components/usage.cjs.map +1 -1
  28. package/dist/components/usage.d.cts +2 -2
  29. package/dist/components/usage.d.cts.map +1 -1
  30. package/dist/components/usage.mjs +4 -4
  31. package/dist/components/usage.mjs.map +1 -1
  32. package/dist/components/utils-builtin.cjs +204 -0
  33. package/dist/components/utils-builtin.cjs.map +1 -1
  34. package/dist/components/utils-builtin.d.cts +13 -9
  35. package/dist/components/utils-builtin.d.cts.map +1 -1
  36. package/dist/components/utils-builtin.d.mts +13 -9
  37. package/dist/components/utils-builtin.d.mts.map +1 -1
  38. package/dist/components/utils-builtin.mjs +208 -5
  39. package/dist/components/utils-builtin.mjs.map +1 -1
  40. package/dist/contexts/options.cjs +2 -2
  41. package/dist/contexts/options.cjs.map +1 -1
  42. package/dist/contexts/options.d.cts +1 -1
  43. package/dist/contexts/options.d.cts.map +1 -1
  44. package/dist/contexts/options.d.mts +1 -1
  45. package/dist/contexts/options.d.mts.map +1 -1
  46. package/dist/contexts/options.mjs +4 -4
  47. package/dist/contexts/options.mjs.map +1 -1
  48. package/dist/helpers/automd.cjs +2 -2
  49. package/dist/helpers/automd.cjs.map +1 -1
  50. package/dist/helpers/automd.mjs.map +1 -1
  51. package/dist/helpers/docs-helpers.cjs +1 -1
  52. package/dist/helpers/docs-helpers.cjs.map +1 -1
  53. package/dist/helpers/docs-helpers.mjs +1 -1
  54. package/dist/helpers/docs-helpers.mjs.map +1 -1
  55. package/dist/helpers/paths.cjs +125 -0
  56. package/dist/helpers/paths.cjs.map +1 -0
  57. package/dist/helpers/paths.mjs +121 -0
  58. package/dist/helpers/paths.mjs.map +1 -0
  59. package/dist/helpers/persistence.cjs +68 -116
  60. package/dist/helpers/persistence.cjs.map +1 -1
  61. package/dist/helpers/persistence.mjs +68 -116
  62. package/dist/helpers/persistence.mjs.map +1 -1
  63. package/dist/helpers/update-package-json.cjs +5 -5
  64. package/dist/helpers/update-package-json.cjs.map +1 -1
  65. package/dist/helpers/update-package-json.mjs +1 -1
  66. package/dist/helpers/update-package-json.mjs.map +1 -1
  67. package/dist/helpers/utilities.cjs +1 -1
  68. package/dist/helpers/utilities.mjs +1 -1
  69. package/dist/helpers/validations.cjs +2 -3
  70. package/dist/helpers/validations.cjs.map +1 -1
  71. package/dist/helpers/validations.mjs +2 -2
  72. package/dist/helpers/validations.mjs.map +1 -1
  73. package/dist/index.cjs +14 -15
  74. package/dist/index.cjs.map +1 -1
  75. package/dist/index.d.cts +2 -4
  76. package/dist/index.d.mts +2 -4
  77. package/dist/index.mjs +3 -5
  78. package/dist/index.mjs.map +1 -1
  79. package/dist/plugin-utils/deepkit.cjs +72 -0
  80. package/dist/plugin-utils/deepkit.cjs.map +1 -0
  81. package/dist/plugin-utils/deepkit.d.cts +24 -0
  82. package/dist/plugin-utils/deepkit.d.cts.map +1 -0
  83. package/dist/plugin-utils/deepkit.d.mts +24 -0
  84. package/dist/plugin-utils/deepkit.d.mts.map +1 -0
  85. package/dist/plugin-utils/deepkit.mjs +70 -0
  86. package/dist/plugin-utils/deepkit.mjs.map +1 -0
  87. package/dist/plugin-utils/get-command-tree.cjs +2 -2
  88. package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
  89. package/dist/plugin-utils/index.cjs +27 -18
  90. package/dist/plugin-utils/index.d.cts +3 -1
  91. package/dist/plugin-utils/index.d.mts +3 -1
  92. package/dist/plugin-utils/index.mjs +3 -1
  93. package/dist/plugin-utils/reflect.cjs +4 -5
  94. package/dist/plugin-utils/reflect.cjs.map +1 -1
  95. package/dist/plugin-utils/reflect.mjs +4 -4
  96. package/dist/plugin-utils/reflect.mjs.map +1 -1
  97. package/dist/plugin-utils/type-checks.cjs +89 -0
  98. package/dist/plugin-utils/type-checks.cjs.map +1 -0
  99. package/dist/plugin-utils/type-checks.d.cts +42 -0
  100. package/dist/plugin-utils/type-checks.d.cts.map +1 -0
  101. package/dist/plugin-utils/type-checks.d.mts +42 -0
  102. package/dist/plugin-utils/type-checks.d.mts.map +1 -0
  103. package/dist/plugin-utils/type-checks.mjs +84 -0
  104. package/dist/plugin-utils/type-checks.mjs.map +1 -0
  105. package/dist/plugin.cjs +48 -45
  106. package/dist/plugin.cjs.map +1 -1
  107. package/dist/plugin.d.cts.map +1 -1
  108. package/dist/plugin.d.mts.map +1 -1
  109. package/dist/plugin.mjs +30 -26
  110. package/dist/plugin.mjs.map +1 -1
  111. package/dist/resolver/deepkit.cjs +129 -0
  112. package/dist/resolver/deepkit.cjs.map +1 -0
  113. package/dist/resolver/deepkit.mjs +128 -0
  114. package/dist/resolver/deepkit.mjs.map +1 -0
  115. package/dist/resolver/helpers.cjs +173 -0
  116. package/dist/resolver/helpers.cjs.map +1 -0
  117. package/dist/resolver/helpers.mjs +168 -0
  118. package/dist/resolver/helpers.mjs.map +1 -0
  119. package/dist/resolver/module.cjs +144 -0
  120. package/dist/resolver/module.cjs.map +1 -0
  121. package/dist/resolver/module.mjs +143 -0
  122. package/dist/resolver/module.mjs.map +1 -0
  123. package/dist/resolver/resolve.cjs +209 -0
  124. package/dist/resolver/resolve.cjs.map +1 -0
  125. package/dist/resolver/resolve.mjs +208 -0
  126. package/dist/resolver/resolve.mjs.map +1 -0
  127. package/dist/types/command.cjs +131 -99
  128. package/dist/types/command.cjs.map +1 -1
  129. package/dist/types/command.d.cts +49 -75
  130. package/dist/types/command.d.cts.map +1 -1
  131. package/dist/types/command.d.mts +49 -75
  132. package/dist/types/command.d.mts.map +1 -1
  133. package/dist/types/command.mjs +119 -91
  134. package/dist/types/command.mjs.map +1 -1
  135. package/dist/types/config.cjs +1 -2
  136. package/dist/types/config.cjs.map +1 -1
  137. package/dist/types/config.d.cts +2 -2
  138. package/dist/types/config.d.cts.map +1 -1
  139. package/dist/types/config.d.mts +2 -2
  140. package/dist/types/config.d.mts.map +1 -1
  141. package/dist/types/config.mjs +1 -2
  142. package/dist/types/config.mjs.map +1 -1
  143. package/dist/types/context.cjs +1 -1
  144. package/dist/types/context.cjs.map +1 -1
  145. package/dist/types/context.d.cts +3 -3
  146. package/dist/types/context.d.cts.map +1 -1
  147. package/dist/types/context.d.mts +3 -3
  148. package/dist/types/context.d.mts.map +1 -1
  149. package/dist/types/context.mjs +1 -1
  150. package/dist/types/context.mjs.map +1 -1
  151. package/dist/types/index.cjs +13 -9
  152. package/dist/types/index.d.cts +2 -2
  153. package/dist/types/index.d.mts +2 -2
  154. package/dist/types/index.mjs +2 -2
  155. package/package.json +34 -79
  156. package/dist/helpers/resolve-command.cjs +0 -410
  157. package/dist/helpers/resolve-command.cjs.map +0 -1
  158. package/dist/helpers/resolve-command.mjs +0 -405
  159. package/dist/helpers/resolve-command.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs","names":["For","Show","render","automd","deepkit","nodejs","tsdown","toArray","chmodX","appendPath","findFilePath","relativePath","isParentPath","joinPaths","replacePath","resolveParentPath","camelCase","constantCase","kebabCase","isSetObject","isSetString","defu","resolveEntries","CommandDocsFile","UtilsBuiltin","commands","getCommandsPersistencePath","readCommandsPersistence","writeCommandsPersistence","findCommandsRoot","reflectCommandTree","resolveCommandId","resolveCommandName","resolveCommandPath","formatBinaryPath","updatePackageJsonBinary","formatCommandTree","getDefaultOptions","validateCommand","getAppDescription","getAppName","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getCommandTree","traverseCommands","MAX_DEPTH","plugin","options","name","config","debug","result","output","buildPath","projectRoot","title","description","envPrefix","env","prefix","isCaseSensitive","format","dts","entry","Array","isArray","length","sourceRoot","undefined","build","platform","nodeProtocol","unbundle","noExternal","type","framework","includes","push","configResolved","order","handler","bin","packageJson","inputs","Object","values","id","path","segments","alias","isVirtual","types","validate","commandsPath","entries","reduce","ret","file","Error","some","existing","split","filter","Boolean","map","segment","index","found","findIndex","replace","join","input","command","prepare","_$createComponent","warn","cmd","depth","parentPath","sort","a","b","skipCache","persistedMeta","checksum","meta","fs","existsSync","option","optional","fromEntries","isValid","failures","error","failure","code","details","info","outputOptions","banner","chunk","isEntry","entryPath","facadeModuleId","fileName","mode","buildEnd","Promise","all","workspaceConfig","workspaceRoot","generators","docs","each","doubleHardline","children","child","when","shellShock"],"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 tsdown from \"@powerlines/plugin-tsdown\";\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 { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { resolveEntries } from \"powerlines/lib/entry\";\nimport type { OutputOptions, RenderedChunk } from \"rolldown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n findCommandsRoot,\n reflectCommandTree,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/resolve-command\";\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 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.projectRoot, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n envPrefix: constantCase(getAppName(this)),\n env: {\n prefix: [] as string[]\n },\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: true\n },\n entry:\n !this.config.entry ||\n (Array.isArray(this.config.entry) &&\n this.config.entry.length === 0)\n ? [\n joinPaths(this.config.sourceRoot, \"**/*.ts\"),\n joinPaths(this.config.sourceRoot, \"**/*.tsx\")\n ]\n : undefined,\n build: {\n dts: false,\n platform: \"node\",\n nodeProtocol: true,\n unbundle: false,\n noExternal: [\"@powerlines/deepkit\"]\n },\n type: \"application\",\n framework: \"shell-shock\"\n }\n );\n\n if (!result.env.prefix || !Array.isArray(result.env.prefix)) {\n result.env.prefix = toArray(result.env.prefix);\n }\n if (!result.env.prefix.includes(result.envPrefix)) {\n result.env.prefix.push(result.envPrefix);\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.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 entries = await resolveEntries(\n this,\n toArray(this.config.entry || [])\n );\n\n this.debug(\n `Found ${\n entries.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = entries.reduce((ret, entry) => {\n if (!isParentPath(entry.file, this.commandsPath)) {\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:reflect-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 reflection initialization 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 reflectCommandTree(this, input);\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.build.outputOptions ??= {} as OutputOptions;\n (this.config.build.outputOptions as OutputOptions).banner = (\n chunk: RenderedChunk\n ) => {\n if (\n chunk.isEntry &&\n joinPaths(this.entryPath, \"bin.ts\") === chunk.facadeModuleId\n ) {\n this.debug(\n `Adding hashbang to binary executable output file: ${chunk.fileName}`\n );\n\n return `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n`;\n }\n return \"\";\n };\n },\n async buildEnd() {\n if (!isSetObject(this.config.bin)) {\n this.warn(\n `No binaries were found for the ${\n this.config.name\n } application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`\n );\n } else {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(\n this.workspaceConfig.workspaceRoot,\n this.config.projectRoot\n )\n );\n\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${path}`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Unable to locate the binary executable output file: ${path}. This may indicate either a misconfiguration in the package.json file or an issue with the build process.`\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAM+C,YAAY;;;;AAKlB,MAAaC,UACXC,UAAmB,EAAE,KAClB;AACH,QAAO;2CACG;4CACC;2CACD;EACR;GACEC,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MAAM,2CAA2C;AAEtD,UAAMjB,oDAAwB,KAAK;IAEnC,MAAMkB,wBACJ,EACEC,QAAQ,EACNC,mDAAqB,KAAKJ,OAAOK,aAAa,OAAM,EACtD,EACD,EACDP,SACA;KACEC,MAAMV,gDAAW,KAAK;KACtBiB,OAAOhB,iDAAY,KAAK;KACxBiB,aAAanB,uDAAkB,KAAK;KACpCoB,kEAAwBnB,gDAAW,KAAK,CAAC;KACzCoB,KAAK,EACHC,QAAQ,EAAA,EACT;KACDC,iBAAiB;KACjBR,QAAQ;MACNS,QAAQ;MACRC,KAAK;MACN;KACDC,OACE,CAAC,KAAKd,OAAOc,SACZC,MAAMC,QAAQ,KAAKhB,OAAOc,MAAM,IAC/B,KAAKd,OAAOc,MAAMG,WAAW,IAC3B,yCACY,KAAKjB,OAAOkB,YAAY,UAAU,0CAClC,KAAKlB,OAAOkB,YAAY,WAAW,CAC9C,GACDC;KACNC,OAAO;MACLP,KAAK;MACLQ,UAAU;MACVC,cAAc;MACdC,UAAU;MACVC,YAAY,CAAC,sBAAqB;MACnC;KACDC,MAAM;KACNC,WAAW;KAEf,CAAC;AAED,QAAI,CAACxB,OAAOO,IAAIC,UAAU,CAACK,MAAMC,QAAQd,OAAOO,IAAIC,OAAO,CACzDR,QAAOO,IAAIC,gDAAiBR,OAAOO,IAAIC,OAAO;AAEhD,QAAI,CAACR,OAAOO,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AAKkC,KACH,kCACE,KAAKlE,OAAOD,KAAI,sHAEnB;QAED,OAAMmG,QAAQC,IACZhE,OAAOC,OAAO,KAAKpC,OAAOgC,IAAI,CAACuB,IAAI,OAAMvB,QAAO;KAC9C,MAAMM,4CACJN,6CAEE,KAAKoE,gBAAgBC,eACrB,KAAKrG,OAAOK,YAEhB,CAAC;AAED,SAAI,KAAKwE,GAAGC,WAAWxC,KAAK,EAAE;AAC5B,WAAKrC,MACH,6EAA6EqC,OAC9E;AAED,4CAAaA,KAAK;WAElB,MAAK4B,KACH,uDAAuD5B,KAAI,4GAC5D;MAGP,CAAC;;GAGN;EACD;GACEvC,MAAM;GACN8B,iBAAiB;AACf,SAAK7B,OAAOhD,WAAW,EAAE;AACzB,SAAKgD,OAAOhD,OAAOsJ,aAAa;KAC9B,GAAI,KAAKtG,OAAOhD,OAAOsJ,cAAc,EAAE;KACvChI,UAAUA,wBAAS,KAAI;KACxB;;GAEH,MAAMiI,OAAO;AACX,SAAKtG,MACH,oEACD;IAED,MAAM3B,aAAW,KAAK4D,OACnBqB,KAAIO,UAASpE,qDAAe,MAAMoE,MAAMvB,SAAS,CAAC,CAClDc,OAAOC,QAAyB;AAEnC,wDACE,uDACCzG,gCAAG;KAAA,IAAC2J,OAAI;AAAA,aAAErE,OAAOC,OAAO9D,WAAS;;KAAEmI,gBAAc;KAAAC,WAC/CC,2DACE7J,iCAAI;MAAA,IAAC8J,OAAI;AAAA,cAAE,CAACD,MAAMlE;;MAAS,IAAAiE,WAAA;AAAA,+DACzBtI,yCAAe,EAAC2F,SAAS4C,OAAK,CAAA;;MAAA,CAAA;KAElC,CAEL,CAAC;;GAEJ;EACF;;AAIH,qBAAe9G"}
1
+ {"version":3,"file":"plugin.cjs","names":["For","Show","render","automd","deepkit","nodejs","toArray","chmodX","appendPath","findFilePath","relativePath","isParentPath","joinPaths","replacePath","resolveParentPath","camelCase","constantCase","kebabCase","isObject","isSetObject","isSetString","defu","tsdown","resolveInputs","CommandDocsFile","UtilsBuiltin","commands","findCommandsRoot","resolveCommandId","resolveCommandName","resolveCommandPath","getCommandsPersistencePath","readCommandsPersistence","writeCommandsPersistence","formatBinaryPath","updatePackageJsonBinary","formatCommandTree","getDefaultOptions","validateCommand","getAppDescription","getAppName","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getCommandTree","traverseCommands","resolve","MAX_DEPTH","plugin","options","name","config","debug","result","output","buildPath","root","title","description","platform","projectType","envPrefix","env","prefix","isCaseSensitive","format","dts","input","Array","isArray","length","Object","keys","undefined","external","nodeProtocol","unbundle","includes","push","configResolved","order","handler","bin","packageJson","inputs","values","id","path","segments","alias","isVirtual","types","validate","commandsPath","reduce","ret","entry","file","Error","some","existing","split","filter","Boolean","map","segment","index","found","findIndex","replace","join","command","prepare","_$createComponent","warn","cmd","depth","parentPath","sort","a","b","skipCache","persistedMeta","checksum","meta","fs","existsSync","context","option","optional","fromEntries","entries","isValid","failures","error","failure","code","details","info","outputOptions","banner","chunk","isEntry","entryPath","facadeModuleId","fileName","mode","buildEnd","Promise","all","workspaceConfig","workspaceRoot","generators","docs","each","doubleHardline","children","child","when","shellShock"],"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 { isSetObject } from \"@stryke/type-checks/is-set-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 { OutputOptions, RenderedChunk } from \"rolldown\";\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 envPrefix: constantCase(getAppName(this)),\n env: {\n prefix: [] as string[]\n },\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: true\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: true,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n if (!result.env.prefix || !Array.isArray(result.env.prefix)) {\n result.env.prefix = toArray(result.env.prefix);\n }\n if (!result.env.prefix.includes(result.envPrefix)) {\n result.env.prefix.push(result.envPrefix);\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.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.outputOptions ??= {} as any;\n if (isObject(this.config.tsdown.outputOptions)) {\n (\n this.config.tsdown.outputOptions as NonNullable<OutputOptions>\n ).banner = (chunk: RenderedChunk) => {\n if (\n chunk.isEntry &&\n joinPaths(this.entryPath, \"bin.ts\") === chunk.facadeModuleId\n ) {\n this.debug(\n `Adding hashbang to binary executable output file: ${\n chunk.fileName\n }`\n );\n\n return `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n`;\n }\n return \"\";\n };\n }\n },\n async buildEnd() {\n if (!isSetObject(this.config.bin)) {\n this.warn(\n `No binaries were found for the ${\n this.config.name\n } application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`\n );\n } else {\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\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${path}`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Unable to locate the binary executable output file: ${path}. This may indicate either a misconfiguration in the package.json file or an issue with the build process.`\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 );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A,iBAAA,OAAA,GAAU,OAAV,CAAA,CAAA,OAAA,CAAA,EAC7B,OAD6B,EAAA,GAofjC,MApfiC,CAof1B,QApf0B,CAAA,EAAA"}
1
+ {"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAkFA;AAAwC,cAA3B,MAA2B,EAAA,CAAA,iBAAA,OAAA,GAAU,OAAV,CAAA,CAAA,OAAA,CAAA,EAC7B,OAD6B,EAAA,GA2fjC,MA3fiC,CA2f1B,QA3f0B,CAAA,EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAiFA;AAAwC,cAA3B,MAA2B,EAAA,CAAA,iBAAA,OAAA,GAAU,OAAV,CAAA,CAAA,OAAA,CAAA,EAC7B,OAD6B,EAAA,GAofjC,MApfiC,CAof1B,QApf0B,CAAA,EAAA"}
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAkFA;AAAwC,cAA3B,MAA2B,EAAA,CAAA,iBAAA,OAAA,GAAU,OAAV,CAAA,CAAA,OAAA,CAAA,EAC7B,OAD6B,EAAA,GA2fjC,MA3fiC,CA2f1B,QA3f0B,CAAA,EAAA"}
package/dist/plugin.mjs CHANGED
@@ -4,18 +4,18 @@ import { UtilsBuiltin } from "./components/utils-builtin.mjs";
4
4
  import { getCommandTree } from "./plugin-utils/get-command-tree.mjs";
5
5
  import { traverseCommands } from "./plugin-utils/traverse-command-tree.mjs";
6
6
  import { commands } from "./helpers/automd.mjs";
7
+ import { findCommandsRoot, resolveCommandId, resolveCommandName, resolveCommandPath } from "./helpers/paths.mjs";
7
8
  import { getCommandsPersistencePath, readCommandsPersistence, writeCommandsPersistence } from "./helpers/persistence.mjs";
8
- import { formatCommandTree, getDefaultOptions } from "./helpers/utilities.mjs";
9
- import { findCommandsRoot, reflectCommandTree, resolveCommandId, resolveCommandName, resolveCommandPath } from "./helpers/resolve-command.mjs";
10
9
  import { formatBinaryPath, updatePackageJsonBinary } from "./helpers/update-package-json.mjs";
10
+ import { formatCommandTree, getDefaultOptions } from "./helpers/utilities.mjs";
11
11
  import { validateCommand } from "./helpers/validations.mjs";
12
+ import { resolve } from "./resolver/resolve.mjs";
12
13
  import { createComponent } from "@alloy-js/core/jsx-runtime";
13
14
  import { For, Show } from "@alloy-js/core/components";
14
15
  import { render } from "@powerlines/plugin-alloy/render";
15
16
  import automd from "@powerlines/plugin-automd";
16
17
  import deepkit from "@powerlines/plugin-deepkit";
17
18
  import nodejs from "@powerlines/plugin-nodejs";
18
- import tsdown from "@powerlines/plugin-tsdown";
19
19
  import { toArray } from "@stryke/convert/to-array";
20
20
  import { chmodX } from "@stryke/fs/chmod-x";
21
21
  import { appendPath } from "@stryke/path/append";
@@ -27,10 +27,12 @@ import { resolveParentPath } from "@stryke/path/resolve-parent-path";
27
27
  import { camelCase } from "@stryke/string-format/camel-case";
28
28
  import { constantCase } from "@stryke/string-format/constant-case";
29
29
  import { kebabCase } from "@stryke/string-format/kebab-case";
30
+ import { isObject } from "@stryke/type-checks/is-object";
30
31
  import { isSetObject } from "@stryke/type-checks/is-set-object";
31
32
  import { isSetString } from "@stryke/type-checks/is-set-string";
32
- import { defu } from "defu";
33
- import { resolveEntries } from "powerlines/lib/entry";
33
+ import { defu as defu$1 } from "defu";
34
+ import { tsdown } from "powerlines/tsdown";
35
+ import { resolveInputs } from "powerlines/utils";
34
36
 
35
37
  //#region src/plugin.tsx
36
38
  const MAX_DEPTH = 50;
@@ -47,10 +49,12 @@ const plugin = (options = {}) => {
47
49
  async config() {
48
50
  this.debug("Resolving the Shell Shock configuration.");
49
51
  await updatePackageJsonBinary(this);
50
- const result = defu({ output: { buildPath: joinPaths(this.config.projectRoot, "dist") } }, options, {
52
+ const result = defu$1({ output: { buildPath: joinPaths(this.config.root, "dist") } }, options, {
51
53
  name: getAppName(this),
52
54
  title: getAppTitle(this),
53
55
  description: getAppDescription(this),
56
+ platform: "node",
57
+ projectType: "application",
54
58
  envPrefix: constantCase(getAppName(this)),
55
59
  env: { prefix: [] },
56
60
  isCaseSensitive: false,
@@ -58,16 +62,13 @@ const plugin = (options = {}) => {
58
62
  format: "esm",
59
63
  dts: true
60
64
  },
61
- entry: !this.config.entry || Array.isArray(this.config.entry) && this.config.entry.length === 0 ? [joinPaths(this.config.sourceRoot, "**/*.ts"), joinPaths(this.config.sourceRoot, "**/*.tsx")] : void 0,
62
- build: {
63
- dts: false,
64
- platform: "node",
65
+ input: !this.config.input || Array.isArray(this.config.input) && this.config.input.length === 0 || isObject(this.config.input) && Object.keys(this.config.input).length === 0 ? [joinPaths(this.config.root, "src/**/command.ts"), joinPaths(this.config.root, "src/**/command.tsx")] : void 0,
66
+ resolve: { external: ["@powerlines/deepkit"] },
67
+ tsdown: {
68
+ dts: true,
65
69
  nodeProtocol: true,
66
- unbundle: false,
67
- noExternal: ["@powerlines/deepkit"]
68
- },
69
- type: "application",
70
- framework: "shell-shock"
70
+ unbundle: false
71
+ }
71
72
  });
72
73
  if (!result.env.prefix || !Array.isArray(result.env.prefix)) result.env.prefix = toArray(result.env.prefix);
73
74
  if (!result.env.prefix.includes(result.envPrefix)) result.env.prefix.push(result.envPrefix);
@@ -92,7 +93,7 @@ const plugin = (options = {}) => {
92
93
  }
93
94
  }
94
95
  },
95
- ...nodejs(defu(options ?? {}, { env: {
96
+ ...nodejs(defu$1(options ?? {}, { env: {
96
97
  types: "@shell-shock/core/types/env#ShellShockEnv",
97
98
  validate: false
98
99
  } })),
@@ -101,10 +102,10 @@ const plugin = (options = {}) => {
101
102
  async configResolved() {
102
103
  this.debug("Finding command entry point files.");
103
104
  this.commandsPath = findCommandsRoot(this);
104
- const entries = await resolveEntries(this, toArray(this.config.entry || []));
105
- this.debug(`Found ${entries.length} entry points specified in the configuration options.`);
106
- this.inputs = entries.reduce((ret, entry) => {
107
- if (!isParentPath(entry.file, this.commandsPath)) throw new Error(`Command entry point "${entry.file}" is not located within the commands root "${this.commandsPath}". Please ensure that all command entry points are located within the current project.`);
105
+ const inputs = await resolveInputs(this, this.config.input);
106
+ this.debug(`Found ${inputs.length} entry points specified in the configuration options.`);
107
+ this.inputs = inputs.reduce((ret, entry) => {
108
+ if (entry.file !== this.commandsPath && !isParentPath(entry.file, this.commandsPath)) throw new Error(`Command entry point "${entry.file}" is not located within the commands root "${this.commandsPath}". Please ensure that all command entry points are located within the current project.`);
108
109
  const id = resolveCommandId(this, entry.file);
109
110
  if (!ret.some((existing) => existing.id === id)) {
110
111
  const name = resolveCommandName(entry.file);
@@ -187,17 +188,20 @@ const plugin = (options = {}) => {
187
188
  }
188
189
  },
189
190
  {
190
- name: "shell-shock:reflect-commands",
191
+ name: "shell-shock:resolve-commands",
191
192
  prepare: {
192
193
  order: "post",
193
194
  async handler() {
194
195
  this.debug("Initializing the CLI application's command tree.");
195
196
  this.commands = {};
196
197
  if (this.config.command !== "prepare" && this.config.skipCache !== true && this.persistedMeta?.checksum === this.meta.checksum && this.fs.existsSync(getCommandsPersistencePath(this))) {
197
- this.debug(`Skipping reflection initialization as the meta checksum has not changed.`);
198
+ this.debug(`Skipping command resolution as the meta checksum has not changed.`);
198
199
  await readCommandsPersistence(this);
199
200
  } else {
200
- for (const input of this.inputs.filter((input$1) => input$1.segments.filter((segment) => !isDynamicPathSegment(segment) && !isPathSegmentGroup(segment)).length === 1)) this.commands[input.name] = await reflectCommandTree(this, input);
201
+ for (const input of this.inputs.filter((input$1) => input$1.segments.filter((segment) => !isDynamicPathSegment(segment) && !isPathSegmentGroup(segment)).length === 1)) this.commands[input.name] = await resolve({
202
+ context: this,
203
+ command: input
204
+ });
201
205
  this.debug("Post-processing commands to ensure proper reflection.");
202
206
  this.options = this.options.map((option) => ({
203
207
  ...option,
@@ -232,8 +236,8 @@ const plugin = (options = {}) => {
232
236
  {
233
237
  name: "shell-shock:chmod+x",
234
238
  configResolved() {
235
- this.config.build.outputOptions ??= {};
236
- this.config.build.outputOptions.banner = (chunk) => {
239
+ this.config.tsdown.outputOptions ??= {};
240
+ if (isObject(this.config.tsdown.outputOptions)) this.config.tsdown.outputOptions.banner = (chunk) => {
237
241
  if (chunk.isEntry && joinPaths(this.entryPath, "bin.ts") === chunk.facadeModuleId) {
238
242
  this.debug(`Adding hashbang to binary executable output file: ${chunk.fileName}`);
239
243
  return `#!/usr/bin/env ${this.config.mode === "development" ? "-S NODE_OPTIONS=--enable-source-maps" : ""} node\n`;
@@ -244,7 +248,7 @@ const plugin = (options = {}) => {
244
248
  async buildEnd() {
245
249
  if (!isSetObject(this.config.bin)) this.warn(`No binaries were found for the ${this.config.name} application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`);
246
250
  else await Promise.all(Object.values(this.config.bin).map(async (bin) => {
247
- const path = appendPath(bin, joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot));
251
+ const path = appendPath(bin, joinPaths(this.workspaceConfig.workspaceRoot, this.config.root));
248
252
  if (this.fs.existsSync(path)) {
249
253
  this.debug(`Adding executable permissions (chmod+x) to binary executable output file: ${path}`);
250
254
  await chmodX(path);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","names":["For","Show","render","automd","deepkit","nodejs","tsdown","toArray","chmodX","appendPath","findFilePath","relativePath","isParentPath","joinPaths","replacePath","resolveParentPath","camelCase","constantCase","kebabCase","isSetObject","isSetString","defu","resolveEntries","CommandDocsFile","UtilsBuiltin","commands","getCommandsPersistencePath","readCommandsPersistence","writeCommandsPersistence","findCommandsRoot","reflectCommandTree","resolveCommandId","resolveCommandName","resolveCommandPath","formatBinaryPath","updatePackageJsonBinary","formatCommandTree","getDefaultOptions","validateCommand","getAppDescription","getAppName","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getCommandTree","traverseCommands","MAX_DEPTH","plugin","options","name","config","debug","result","output","buildPath","projectRoot","title","description","envPrefix","env","prefix","isCaseSensitive","format","dts","entry","Array","isArray","length","sourceRoot","undefined","build","platform","nodeProtocol","unbundle","noExternal","type","framework","includes","push","configResolved","order","handler","bin","packageJson","inputs","Object","values","id","path","segments","alias","isVirtual","types","validate","commandsPath","entries","reduce","ret","file","Error","some","existing","split","filter","Boolean","map","segment","index","found","findIndex","replace","join","input","command","prepare","_$createComponent","warn","cmd","depth","parentPath","sort","a","b","skipCache","persistedMeta","checksum","meta","fs","existsSync","option","optional","fromEntries","isValid","failures","error","failure","code","details","info","outputOptions","banner","chunk","isEntry","entryPath","facadeModuleId","fileName","mode","buildEnd","Promise","all","workspaceConfig","workspaceRoot","generators","docs","each","doubleHardline","children","child","when","shellShock"],"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 tsdown from \"@powerlines/plugin-tsdown\";\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 { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { resolveEntries } from \"powerlines/lib/entry\";\nimport type { OutputOptions, RenderedChunk } from \"rolldown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n findCommandsRoot,\n reflectCommandTree,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/resolve-command\";\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 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.projectRoot, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n envPrefix: constantCase(getAppName(this)),\n env: {\n prefix: [] as string[]\n },\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: true\n },\n entry:\n !this.config.entry ||\n (Array.isArray(this.config.entry) &&\n this.config.entry.length === 0)\n ? [\n joinPaths(this.config.sourceRoot, \"**/*.ts\"),\n joinPaths(this.config.sourceRoot, \"**/*.tsx\")\n ]\n : undefined,\n build: {\n dts: false,\n platform: \"node\",\n nodeProtocol: true,\n unbundle: false,\n noExternal: [\"@powerlines/deepkit\"]\n },\n type: \"application\",\n framework: \"shell-shock\"\n }\n );\n\n if (!result.env.prefix || !Array.isArray(result.env.prefix)) {\n result.env.prefix = toArray(result.env.prefix);\n }\n if (!result.env.prefix.includes(result.envPrefix)) {\n result.env.prefix.push(result.envPrefix);\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.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 entries = await resolveEntries(\n this,\n toArray(this.config.entry || [])\n );\n\n this.debug(\n `Found ${\n entries.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = entries.reduce((ret, entry) => {\n if (!isParentPath(entry.file, this.commandsPath)) {\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:reflect-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 reflection initialization 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 reflectCommandTree(this, input);\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.build.outputOptions ??= {} as OutputOptions;\n (this.config.build.outputOptions as OutputOptions).banner = (\n chunk: RenderedChunk\n ) => {\n if (\n chunk.isEntry &&\n joinPaths(this.entryPath, \"bin.ts\") === chunk.facadeModuleId\n ) {\n this.debug(\n `Adding hashbang to binary executable output file: ${chunk.fileName}`\n );\n\n return `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n`;\n }\n return \"\";\n };\n },\n async buildEnd() {\n if (!isSetObject(this.config.bin)) {\n this.warn(\n `No binaries were found for the ${\n this.config.name\n } application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`\n );\n } else {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(\n this.workspaceConfig.workspaceRoot,\n this.config.projectRoot\n )\n );\n\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${path}`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Unable to locate the binary executable output file: ${path}. This may indicate either a misconfiguration in the package.json file or an issue with the build process.`\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAM+C,YAAY;;;;AAKlB,MAAaC,UACXC,UAAmB,EAAE,KAClB;AACH,QAAO;EACL3C,QAAQ;EACRF,SAAS;EACTD,QAAQ;EACR;GACE+C,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MAAM,2CAA2C;AAEtD,UAAMjB,wBAAwB,KAAK;IAEnC,MAAMkB,SAAShC,KACb,EACEiC,QAAQ,EACNC,WAAW1C,UAAU,KAAKsC,OAAOK,aA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AE;AAC5B,WAAKrC,MACH,6EAA6EqC,OAC9E;AAED,YAAMjF,OAAOiF,KAAK;WAElB,MAAK4B,KACH,uDAAuD5B,KAAI,4GAC5D;MAGP,CAAC;;GAGN;EACD;GACEvC,MAAM;GACN8B,iBAAiB;AACf,SAAK7B,OAAOhD,WAAW,EAAE;AACzB,SAAKgD,OAAOhD,OAAOsJ,aAAa;KAC9B,GAAI,KAAKtG,OAAOhD,OAAOsJ,cAAc,EAAE;KACvChI,UAAUA,SAAS,KAAI;KACxB;;GAEH,MAAMiI,OAAO;AACX,SAAKtG,MACH,oEACD;IAED,MAAM3B,aAAW,KAAK4D,OACnBqB,KAAIO,UAASpE,eAAe,MAAMoE,MAAMvB,SAAS,CAAC,CAClDc,OAAOC,QAAyB;AAEnC,WAAOvG,OACL,MAAIkH,gBACHpH,KAAG;KAAA,IAAC2J,OAAI;AAAA,aAAErE,OAAOC,OAAO9D,WAAS;;KAAEmI,gBAAc;KAAAC,WAC/CC,UAAK1C,gBACHnH,MAAI;MAAA,IAAC8J,OAAI;AAAA,cAAE,CAACD,MAAMlE;;MAAS,IAAAiE,WAAA;AAAA,cAAAzC,gBACzB7F,iBAAe,EAAC2F,SAAS4C,OAAK,CAAA;;MAAA,CAAA;KAElC,CAEL,CAAC;;GAEJ;EACF;;AAIH,qBAAe9G"}
1
+ {"version":3,"file":"plugin.mjs","names":["For","Show","render","automd","deepkit","nodejs","toArray","chmodX","appendPath","findFilePath","relativePath","isParentPath","joinPaths","replacePath","resolveParentPath","camelCase","constantCase","kebabCase","isObject","isSetObject","isSetString","defu","tsdown","resolveInputs","CommandDocsFile","UtilsBuiltin","commands","findCommandsRoot","resolveCommandId","resolveCommandName","resolveCommandPath","getCommandsPersistencePath","readCommandsPersistence","writeCommandsPersistence","formatBinaryPath","updatePackageJsonBinary","formatCommandTree","getDefaultOptions","validateCommand","getAppDescription","getAppName","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getCommandTree","traverseCommands","resolve","MAX_DEPTH","plugin","options","name","config","debug","result","output","buildPath","root","title","description","platform","projectType","envPrefix","env","prefix","isCaseSensitive","format","dts","input","Array","isArray","length","Object","keys","undefined","external","nodeProtocol","unbundle","includes","push","configResolved","order","handler","bin","packageJson","inputs","values","id","path","segments","alias","isVirtual","types","validate","commandsPath","reduce","ret","entry","file","Error","some","existing","split","filter","Boolean","map","segment","index","found","findIndex","replace","join","command","prepare","_$createComponent","warn","cmd","depth","parentPath","sort","a","b","skipCache","persistedMeta","checksum","meta","fs","existsSync","context","option","optional","fromEntries","entries","isValid","failures","error","failure","code","details","info","outputOptions","banner","chunk","isEntry","entryPath","facadeModuleId","fileName","mode","buildEnd","Promise","all","workspaceConfig","workspaceRoot","generators","docs","each","doubleHardline","children","child","when","shellShock"],"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 { isSetObject } from \"@stryke/type-checks/is-set-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 { OutputOptions, RenderedChunk } from \"rolldown\";\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 envPrefix: constantCase(getAppName(this)),\n env: {\n prefix: [] as string[]\n },\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: true\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: true,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n if (!result.env.prefix || !Array.isArray(result.env.prefix)) {\n result.env.prefix = toArray(result.env.prefix);\n }\n if (!result.env.prefix.includes(result.envPrefix)) {\n result.env.prefix.push(result.envPrefix);\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.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.outputOptions ??= {} as any;\n if (isObject(this.config.tsdown.outputOptions)) {\n (\n this.config.tsdown.outputOptions as NonNullable<OutputOptions>\n ).banner = (chunk: RenderedChunk) => {\n if (\n chunk.isEntry &&\n joinPaths(this.entryPath, \"bin.ts\") === chunk.facadeModuleId\n ) {\n this.debug(\n `Adding hashbang to binary executable output file: ${\n chunk.fileName\n }`\n );\n\n return `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n`;\n }\n return \"\";\n };\n }\n },\n async buildEnd() {\n if (!isSetObject(this.config.bin)) {\n this.warn(\n `No binaries were found for the ${\n this.config.name\n } application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`\n );\n } else {\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\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${path}`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Unable to locate the binary executable output file: ${path}. This may indicate either a misconfiguration in the package.json file or an issue with the build process.`\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,MAAMgD,YAAY;;;;AAKlB,MAAaC,UACXC,UAAmB,EAAE,KAClB;AACH,QAAO;EACL5B,QAAQ;EACRlB,SAAS;EACTD,QAA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time.cjs');
2
+ const require_types_command = require('../types/command.cjs');
3
+ const require_helpers = require('./helpers.cjs');
4
+ let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
5
+ let __stryke_type_checks_is_bigint = require("@stryke/type-checks/is-bigint");
6
+ let __stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
7
+ let __stryke_type_checks_is_regexp = require("@stryke/type-checks/is-regexp");
8
+
9
+ //#region src/resolver/deepkit.ts
10
+ function __assignType(fn, args) {
11
+ fn.__type = args;
12
+ return fn;
13
+ }
14
+ function extractCommandParameterKind(type) {
15
+ if (type === __powerlines_deepkit_vendor_type.ReflectionKind.string) return require_types_command.CommandParameterKinds.string;
16
+ else if (type === __powerlines_deepkit_vendor_type.ReflectionKind.number || type === __powerlines_deepkit_vendor_type.ReflectionKind.bigint || type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, __stryke_type_checks_is_number.isNumber)(type.literal) || (0, __stryke_type_checks_is_bigint.isBigInt)(type.literal))) return require_types_command.CommandParameterKinds.number;
17
+ else if (type === __powerlines_deepkit_vendor_type.ReflectionKind.boolean) return require_types_command.CommandParameterKinds.boolean;
18
+ else return require_types_command.CommandParameterKinds.string;
19
+ }
20
+ extractCommandParameterKind.__type = [
21
+ "Type",
22
+ () => __powerlines_deepkit_vendor_type.__ΩReflectionKind,
23
+ "type",
24
+ "CommandParameterKind",
25
+ "extractCommandParameterKind",
26
+ "PP\"w!n\"J2#\"w$/%"
27
+ ];
28
+ function resolveCommandOption(ctx, reflection) {
29
+ const type = reflection.getType();
30
+ const existing = ctx.output.options[reflection.getNameAsString()] ?? {};
31
+ const option = {
32
+ name: reflection.getNameAsString(),
33
+ alias: reflection.getTags().alias ?? [],
34
+ title: reflection.getTags().title?.trim(),
35
+ description: reflection.getDescription(),
36
+ kind: extractCommandParameterKind(type),
37
+ optional: reflection.isOptional(),
38
+ default: reflection.getDefaultValue(),
39
+ variadic: reflection.isArray()
40
+ };
41
+ if (reflection.isArray()) if (type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
42
+ option.variadic = true;
43
+ option.kind = extractCommandParameterKind(type.type.kind);
44
+ } else throw new Error(`Unsupported array type for option "${reflection.getNameAsString()}" in command "${ctx.input.command.name}". Only string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
45
+ else if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.union) {
46
+ option.kind = type.types.every(__assignType((t) => t.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number || t.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, __stryke_type_checks_is_number.isNumber)(t.literal) || (0, __stryke_type_checks_is_bigint.isBigInt)(t.literal)), [
47
+ "t",
48
+ "",
49
+ "P\"2!\"/\""
50
+ ])) ? require_types_command.CommandParameterKinds.number : require_types_command.CommandParameterKinds.string;
51
+ option.choices = type.types.map(__assignType((t) => t.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal ? (0, __stryke_type_checks_is_number.isNumber)(t.literal) ? t.literal : (0, __stryke_type_checks_is_bigint.isBigInt)(t.literal) ? Number(t.literal) : (0, __stryke_type_checks_is_regexp.isRegExp)(t.literal) ? t.literal.source : String(t.literal) : null, [
52
+ "t",
53
+ "",
54
+ "P\"2!\"/\""
55
+ ])).filter(Boolean);
56
+ } else if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.literal) option.choices = [(0, __stryke_type_checks_is_number.isNumber)(type.literal) ? type.literal : (0, __stryke_type_checks_is_bigint.isBigInt)(type.literal) ? Number(type.literal) : (0, __stryke_type_checks_is_regexp.isRegExp)(type.literal) ? type.literal.source : String(type.literal)].filter(Boolean);
57
+ else if (!existing.kind && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${ctx.input.command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
58
+ return require_helpers.mergeCommandParameter(existing, option);
59
+ }
60
+ resolveCommandOption.__type = [
61
+ "ResolverContext",
62
+ "ctx",
63
+ "ReflectionProperty",
64
+ "reflection",
65
+ "CommandOption",
66
+ "resolveCommandOption",
67
+ "P\"w!2\"\"w#2$\"w%/&"
68
+ ];
69
+ function resolveCommandArgument(ctx, index, reflection) {
70
+ const type = reflection.getType();
71
+ const existing = ctx.output.args.length > index ? ctx.output.args[index] : {};
72
+ if (!existing.kind && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && !(type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array && (type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number))) throw new Error(`Unsupported type for argument "${reflection.getName()}" in command "${ctx.input.command.name}". Only string types (or an array of strings) are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
73
+ const argument = {
74
+ name: reflection.getName() || reflection.parameter.name,
75
+ alias: reflection.getAlias(),
76
+ kind: extractCommandParameterKind(type.kind),
77
+ title: reflection.getTitle() || reflection.parameter.tags?.title,
78
+ description: reflection.parameter.description,
79
+ optional: reflection.isOptional(),
80
+ default: reflection.getDefaultValue()
81
+ };
82
+ if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) {
83
+ if (type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
84
+ argument.variadic = true;
85
+ argument.kind = extractCommandParameterKind(type.type.kind);
86
+ } else if (!existing.kind) throw new Error(`Unsupported array type for argument "${reflection.getName()}" in command "${ctx.input.command.name}". Only string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
87
+ } else if (!existing.kind && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for argument "${reflection.getName()}" in command "${ctx.input.command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
88
+ return require_helpers.mergeCommandParameter(existing, argument, { name: `arg${index}` });
89
+ }
90
+ resolveCommandArgument.__type = [
91
+ "ResolverContext",
92
+ "ctx",
93
+ "index",
94
+ "ReflectionParameter",
95
+ "reflection",
96
+ "CommandArgument",
97
+ "resolveCommandArgument",
98
+ "P\"w!2\"'2#\"w$2%\"w&/'"
99
+ ];
100
+ function resolveFromBytecode(ctx) {
101
+ const { input, module: module$1 } = ctx;
102
+ const type = (0, __powerlines_deepkit_vendor_type.reflect)(module$1);
103
+ if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`The command entry file "${input.command.entry.input?.file || input.command.path}" does not export a valid function.`);
104
+ const reflection = new __powerlines_deepkit_vendor_type.ReflectionFunction(type);
105
+ ctx.output.description ??= ctx.input.command.description || reflection.getDescription() || type.description;
106
+ const parameters = reflection.getParameters();
107
+ if (parameters.length > 0 && parameters[0]) {
108
+ if (parameters[0].type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || parameters[0].type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) {
109
+ const optionsReflection = __powerlines_deepkit_vendor_type.ReflectionClass.from(parameters[0].type);
110
+ for (const propertyReflection of optionsReflection.getProperties()) ctx.output.options[propertyReflection.getNameAsString()] = resolveCommandOption(ctx, propertyReflection);
111
+ } else if (!ctx.module?.options) throw new Error(`The first parameter of the command handler function in "${ctx.input.command.entry.input?.file || ctx.input.command.path}" must be an object literal or class type representing the command options.`);
112
+ ctx.output.args = parameters.slice(1).map(__assignType((arg, index) => resolveCommandArgument(ctx, index, arg), [
113
+ "arg",
114
+ "index",
115
+ "",
116
+ "P\"2!\"2\"\"/#"
117
+ ]));
118
+ }
119
+ }
120
+ resolveFromBytecode.__type = [
121
+ "ResolverContext",
122
+ "ctx",
123
+ "resolveFromBytecode",
124
+ "P\"w!2\"\"/#"
125
+ ];
126
+
127
+ //#endregion
128
+ exports.resolveFromBytecode = resolveFromBytecode;
129
+ //# sourceMappingURL=deepkit.cjs.map