@shell-shock/core 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/components/docs.d.mts +5 -5
  2. package/dist/components/helpers.cjs +9 -0
  3. package/dist/components/helpers.cjs.map +1 -1
  4. package/dist/components/helpers.d.cts +15 -7
  5. package/dist/components/helpers.d.cts.map +1 -1
  6. package/dist/components/helpers.d.mts +15 -7
  7. package/dist/components/helpers.d.mts.map +1 -1
  8. package/dist/components/helpers.mjs +9 -1
  9. package/dist/components/helpers.mjs.map +1 -1
  10. package/dist/components/index.cjs +1 -0
  11. package/dist/components/index.d.cts +2 -2
  12. package/dist/components/index.d.mts +2 -2
  13. package/dist/components/index.mjs +2 -2
  14. package/dist/components/options-parser-logic.cjs +142 -62
  15. package/dist/components/options-parser-logic.cjs.map +1 -1
  16. package/dist/components/options-parser-logic.d.cts +17 -17
  17. package/dist/components/options-parser-logic.d.cts.map +1 -1
  18. package/dist/components/options-parser-logic.d.mts +17 -17
  19. package/dist/components/options-parser-logic.d.mts.map +1 -1
  20. package/dist/components/options-parser-logic.mjs +143 -63
  21. package/dist/components/options-parser-logic.mjs.map +1 -1
  22. package/dist/components/usage.d.cts +2 -2
  23. package/dist/components/usage.d.mts +2 -2
  24. package/dist/components/usage.d.mts.map +1 -1
  25. package/dist/components/utils-builtin.cjs +5 -9
  26. package/dist/components/utils-builtin.cjs.map +1 -1
  27. package/dist/components/utils-builtin.d.cts.map +1 -1
  28. package/dist/components/utils-builtin.d.mts.map +1 -1
  29. package/dist/components/utils-builtin.mjs +5 -9
  30. package/dist/components/utils-builtin.mjs.map +1 -1
  31. package/dist/helpers/automd.cjs +1 -1
  32. package/dist/helpers/automd.cjs.map +1 -1
  33. package/dist/helpers/automd.mjs +1 -1
  34. package/dist/helpers/automd.mjs.map +1 -1
  35. package/dist/plugin-utils/description-helpers.cjs +105 -0
  36. package/dist/plugin-utils/description-helpers.cjs.map +1 -0
  37. package/dist/plugin-utils/description-helpers.d.cts +44 -0
  38. package/dist/plugin-utils/description-helpers.d.cts.map +1 -0
  39. package/dist/plugin-utils/description-helpers.d.mts +44 -0
  40. package/dist/plugin-utils/description-helpers.d.mts.map +1 -0
  41. package/dist/plugin-utils/description-helpers.mjs +101 -0
  42. package/dist/plugin-utils/description-helpers.mjs.map +1 -0
  43. package/dist/plugin-utils/get-command-tree.cjs +26 -0
  44. package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
  45. package/dist/plugin-utils/get-command-tree.d.cts +8 -1
  46. package/dist/plugin-utils/get-command-tree.d.cts.map +1 -1
  47. package/dist/plugin-utils/get-command-tree.d.mts +8 -1
  48. package/dist/plugin-utils/get-command-tree.d.mts.map +1 -1
  49. package/dist/plugin-utils/get-command-tree.mjs +26 -1
  50. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  51. package/dist/plugin-utils/index.cjs +7 -1
  52. package/dist/plugin-utils/index.d.cts +3 -2
  53. package/dist/plugin-utils/index.d.mts +3 -2
  54. package/dist/plugin-utils/index.mjs +3 -2
  55. package/dist/plugin-utils/type-checks.d.cts.map +1 -1
  56. package/dist/plugin.cjs +5 -7
  57. package/dist/plugin.cjs.map +1 -1
  58. package/dist/plugin.d.cts.map +1 -1
  59. package/dist/plugin.d.mts.map +1 -1
  60. package/dist/plugin.mjs +5 -7
  61. package/dist/plugin.mjs.map +1 -1
  62. package/dist/resolver/deepkit.cjs +6 -3
  63. package/dist/resolver/deepkit.cjs.map +1 -1
  64. package/dist/resolver/deepkit.mjs +6 -3
  65. package/dist/resolver/deepkit.mjs.map +1 -1
  66. package/dist/resolver/helpers.cjs +16 -22
  67. package/dist/resolver/helpers.cjs.map +1 -1
  68. package/dist/resolver/helpers.mjs +16 -22
  69. package/dist/resolver/helpers.mjs.map +1 -1
  70. package/dist/resolver/module.cjs +2 -2
  71. package/dist/resolver/module.cjs.map +1 -1
  72. package/dist/resolver/module.mjs +2 -2
  73. package/dist/resolver/module.mjs.map +1 -1
  74. package/dist/resolver/resolve.cjs +13 -13
  75. package/dist/resolver/resolve.cjs.map +1 -1
  76. package/dist/resolver/resolve.mjs +13 -13
  77. package/dist/resolver/resolve.mjs.map +1 -1
  78. package/dist/types/config.cjs +5 -3
  79. package/dist/types/config.cjs.map +1 -1
  80. package/dist/types/config.d.cts +7 -3
  81. package/dist/types/config.d.cts.map +1 -1
  82. package/dist/types/config.d.mts +7 -3
  83. package/dist/types/config.d.mts.map +1 -1
  84. package/dist/types/config.mjs +5 -3
  85. package/dist/types/config.mjs.map +1 -1
  86. package/package.json +11 -11
package/dist/plugin.cjs CHANGED
@@ -3,8 +3,8 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
3
  const require_context_helpers = require('./plugin-utils/context-helpers.cjs');
4
4
  const require_components_docs = require('./components/docs.cjs');
5
5
  const require_components_utils_builtin = require('./components/utils-builtin.cjs');
6
- const require_get_command_tree = require('./plugin-utils/get-command-tree.cjs');
7
6
  const require_traverse_command_tree = require('./plugin-utils/traverse-command-tree.cjs');
7
+ const require_get_command_tree = require('./plugin-utils/get-command-tree.cjs');
8
8
  const require_automd = require('./helpers/automd.cjs');
9
9
  const require_paths = require('./helpers/paths.cjs');
10
10
  const require_persistence = require('./helpers/persistence.cjs');
@@ -54,14 +54,12 @@ const plugin = (options = {}) => {
54
54
  async config() {
55
55
  this.debug("Resolving the Shell Shock configuration.");
56
56
  await require_update_package_json.updatePackageJsonBinary(this);
57
- const result = (0, defu.defu)({ output: { buildPath: (0, __stryke_path_join_paths.joinPaths)(this.config.root, "dist") } }, options, {
57
+ return (0, defu.defu)({ output: { buildPath: (0, __stryke_path_join_paths.joinPaths)(this.config.root, "dist") } }, options, {
58
58
  name: require_context_helpers.getAppName(this),
59
59
  title: require_context_helpers.getAppTitle(this),
60
60
  description: require_context_helpers.getAppDescription(this),
61
61
  platform: "node",
62
62
  projectType: "application",
63
- envPrefix: (0, __stryke_string_format_constant_case.constantCase)(require_context_helpers.getAppName(this)),
64
- env: { prefix: [] },
65
63
  isCaseSensitive: false,
66
64
  output: {
67
65
  format: "esm",
@@ -75,14 +73,14 @@ const plugin = (options = {}) => {
75
73
  unbundle: false
76
74
  }
77
75
  });
78
- if (!result.env.prefix || !Array.isArray(result.env.prefix)) result.env.prefix = (0, __stryke_convert_to_array.toArray)(result.env.prefix);
79
- if (!result.env.prefix.includes(result.envPrefix)) result.env.prefix.push(result.envPrefix);
80
- return result;
81
76
  },
82
77
  configResolved: {
83
78
  order: "pre",
84
79
  async handler() {
85
80
  this.debug("Shell Shock configuration has been resolved.");
81
+ this.config.appSpecificEnvPrefix = (0, __stryke_type_checks_is_set_string.isSetString)(this.config.autoAssignEnv) ? this.config.autoAssignEnv : (0, __stryke_string_format_constant_case.constantCase)(require_context_helpers.getAppName(this));
82
+ if (!this.config.env.prefix || !Array.isArray(this.config.env.prefix)) this.config.env.prefix = (0, __stryke_convert_to_array.toArray)(this.config.env.prefix);
83
+ if (!this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)) this.config.env.prefix.push(this.config.appSpecificEnvPrefix);
86
84
  this.config.bin = ((0, __stryke_type_checks_is_set_string.isSetString)(this.packageJson.bin) ? { [(0, __stryke_string_format_kebab_case.kebabCase)(this.config.name)]: this.packageJson.bin } : this.packageJson.bin) ?? { [(0, __stryke_string_format_kebab_case.kebabCase)(this.config.name)]: require_update_package_json.formatBinaryPath(this.config.output.format) };
87
85
  this.inputs ??= [];
88
86
  this.options = Object.values(require_utilities.getDefaultOptions(this, {
@@ -1 +1 @@
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 );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;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I,sHAEnB;QAED,OAAMkG,QAAQC,IACZ9E,OAAOc,OAAO,KAAKlC,OAAO+B,IAAI,CAACsB,IAAI,OAAMtB,QAAO;KAC9C,MAAMK,4CACJL,6CACU,KAAKoE,gBAAgBC,eAAe,KAAKpG,OAAOK,KAC5D,CAAC;AAED,SAAI,KAAKqE,GAAGC,WAAWvC,KAAK,EAAE;AAC5B,WAAKnC,MACH,6EAA6EmC,OAC9E;AAED,4CAAaA,KAAK;WAElB,MAAK2B,KACH,uDAAuD3B,KAAI,4GAC5D;MAGP,CAAC;;GAGN;EACD;GACErC,MAAM;GACN6B,iBAAiB;AACf,SAAK5B,OAAOjD,WAAW,EAAE;AACzB,SAAKiD,OAAOjD,OAAOsJ,aAAa;KAC9B,GAAI,KAAKrG,OAAOjD,OAAOsJ,cAAc,EAAE;KACvC/H,UAAUA,wBAAS,KAAI;KACxB;;GAEH,MAAMgI,OAAO;AACX,SAAKrG,MACH,oEACD;IAED,MAAM3B,aAAW,KAAK2D,OACnBoB,KAAIrC,UAASvB,wCAAe,MAAMuB,MAAMqB,SAAS,CAAC,CAClDc,OAAOC,QAAyB;AAEnC,wDACE,uDACCxG,gCAAG;KAAA,IAAC2J,OAAI;AAAA,aAAEnF,OAAOc,OAAO5D,WAAS;;KAAEkI,gBAAc;KAAAC,WAC/CC,2DACE7J,iCAAI;MAAA,IAAC8J,OAAI;AAAA,cAAE,CAACD,MAAMnE;;MAAS,IAAAkE,WAAA;AAAA,+DACzBrI,yCAAe,EAACwF,SAAS8C,OAAK,CAAA;;MAAA,CAAA;KAElC,CAEL,CAAC;;GAEJ;EACF;;AAIH,qBAAe7G"}
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","isCaseSensitive","format","dts","input","Array","isArray","length","Object","keys","undefined","external","nodeProtocol","unbundle","configResolved","order","handler","appSpecificEnvPrefix","autoAssignEnv","env","prefix","includes","push","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 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 return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getDefaultOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.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;iCACG;4CACC;2CACD;EACR;GACEC,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MAAM,2CAA2C;AAEtD,UAAMlB,oDAAwB,KAAK;AA0CnC,0BAvCE,EACEoB,QAAQ,EACNC,mDAAqB,KAAKJ,OAAOK,MAAM,OAAM,EAC/C,EACD,EACDP,SACA;KACEC,MAAMX,mCAAW,KAAK;KACtBkB,OAAOjB,oCAAY,KAAK;KACxBkB,aAAapB,0CAAkB,KAAK;KACpCqB,UAAU;KACVC,aAAa;KACbC,iBAAiB;KACjBP,QAAQ;MACNQ,QAAQ;MACRC,KAAK;MACN;KACDC,OACE,CAAC,KAAKb,OAAOa,SACZC,MAAMC,QAAQ,KAAKf,OAAOa,MAAM,IAC/B,KAAKb,OAAOa,MAAMG,WAAW,kDACrB,KAAKhB,OAAOa,MAAM,IAC1BI,OAAOC,KAAK,KAAKlB,OAAOa,MAAM,CAACG,WAAW,IACxC,yCACY,KAAKhB,OAAOK,MAAM,oBAAoB,0CACtC,KAAKL,OAAOK,MAAM,qBAAqB,CAClD,GACDc;KACNxB,SAAS,EACPyB,UAAU,CAAC,sBAAqB,EACjC;KACDlD,QAAQ;MACN0C,KAAK;MACLS,cAAc;MACdC,UAAU;MACZ;KAEJ,CAAC;;GAIHC,gBAAgB;IACdC,OAAO;IACP,MAAMC,UAAU;AACd,UAAKxB,MAAM,+CAA+C;AAE1D,UAAKD,OAAO0B,2EACV,KAAK1B,OAAO2B,cACb,GACG,KAAK3B,OAAO2B,uEACCvC,mCAAW,KAAK,CAAC;AAClC,S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1 +1 @@
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
+ {"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,GAkgBjC,MAlgBiC,CAkgB1B,QAlgB0B,CAAA,EAAA"}
@@ -1 +1 @@
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"}
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,GAkgBjC,MAlgBiC,CAkgB1B,QAlgB0B,CAAA,EAAA"}
package/dist/plugin.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getAppDescription, getAppName, getAppTitle, getDynamicPathSegmentName, isDynamicPathSegment, isPathSegmentGroup } from "./plugin-utils/context-helpers.mjs";
2
2
  import { CommandDocsFile } from "./components/docs.mjs";
3
3
  import { UtilsBuiltin } from "./components/utils-builtin.mjs";
4
- import { getCommandTree } from "./plugin-utils/get-command-tree.mjs";
5
4
  import { traverseCommands } from "./plugin-utils/traverse-command-tree.mjs";
5
+ import { getCommandTree } from "./plugin-utils/get-command-tree.mjs";
6
6
  import { commands } from "./helpers/automd.mjs";
7
7
  import { findCommandsRoot, resolveCommandId, resolveCommandName, resolveCommandPath } from "./helpers/paths.mjs";
8
8
  import { getCommandsPersistencePath, readCommandsPersistence, writeCommandsPersistence } from "./helpers/persistence.mjs";
@@ -49,14 +49,12 @@ const plugin = (options = {}) => {
49
49
  async config() {
50
50
  this.debug("Resolving the Shell Shock configuration.");
51
51
  await updatePackageJsonBinary(this);
52
- const result = defu$1({ output: { buildPath: joinPaths(this.config.root, "dist") } }, options, {
52
+ return defu$1({ output: { buildPath: joinPaths(this.config.root, "dist") } }, options, {
53
53
  name: getAppName(this),
54
54
  title: getAppTitle(this),
55
55
  description: getAppDescription(this),
56
56
  platform: "node",
57
57
  projectType: "application",
58
- envPrefix: constantCase(getAppName(this)),
59
- env: { prefix: [] },
60
58
  isCaseSensitive: false,
61
59
  output: {
62
60
  format: "esm",
@@ -70,14 +68,14 @@ const plugin = (options = {}) => {
70
68
  unbundle: false
71
69
  }
72
70
  });
73
- if (!result.env.prefix || !Array.isArray(result.env.prefix)) result.env.prefix = toArray(result.env.prefix);
74
- if (!result.env.prefix.includes(result.envPrefix)) result.env.prefix.push(result.envPrefix);
75
- return result;
76
71
  },
77
72
  configResolved: {
78
73
  order: "pre",
79
74
  async handler() {
80
75
  this.debug("Shell Shock configuration has been resolved.");
76
+ this.config.appSpecificEnvPrefix = isSetString(this.config.autoAssignEnv) ? this.config.autoAssignEnv : constantCase(getAppName(this));
77
+ if (!this.config.env.prefix || !Array.isArray(this.config.env.prefix)) this.config.env.prefix = toArray(this.config.env.prefix);
78
+ if (!this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)) this.config.env.prefix.push(this.config.appSpecificEnvPrefix);
81
79
  this.config.bin = (isSetString(this.packageJson.bin) ? { [kebabCase(this.config.name)]: this.packageJson.bin } : this.packageJson.bin) ?? { [kebabCase(this.config.name)]: formatBinaryPath(this.config.output.format) };
82
80
  this.inputs ??= [];
83
81
  this.options = Object.values(getDefaultOptions(this, {
@@ -1 +1 @@
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,QAAQ;EACR;GACEgD,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MAAM,2CAA2C;AAEtD,UAAMlB,wBAAwB,KAAK;IAEnC,MAAMmB,SAASjC,OACb,EACEkC,QAAQ,EACNC,WAAW5C,UAAU,KAAKwC,OAAOK,MAAM,OAAM,EAC/C,EACD,EACDP,SACA;KACEC,MAAMX,WAAW,KAAK;KACtBkB,OAAOjB,YAAY,KAAK;KACxBkB,aAAapB,kBAAkB,KAAK;KACpCqB,UAAU;KACVC,aAAa;KACbC,WAAW9C,aAAawB,WAAW,KAAK,CAAC;KACzCuB,KAAK,EACHC,QAAQ,EAAA,EACT;KACDC,iBAAiB;KACjBV,QAAQ;MACNW,QAAQ;MACRC,KAAK;MACN;KACDC,OACE,CAAC,KAAKhB,OAAOgB,SACZC,MAAMC,QAAQ,KAAKlB,OAAOgB,MAAM,IAC/B,KAAKhB,OAAOgB,MAAMG,WAAW,KAC9BrD,SAAS,KAAKkC,OAAOgB,MAAM,IAC1BI,OAAOC,KAAK,KAAKrB,OAAOgB,MAAM,CAACG,WAAW,IACxC,CACE3D,UAAU,KAAKwC,OAAO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ACX,SAAKrG,MACH,oEACD;IAED,MAAM3B,aAAW,KAAK2D,OACnBoB,KAAIrC,UAASvB,eAAe,MAAMuB,MAAMqB,SAAS,CAAC,CAClDc,OAAOC,QAAyB;AAEnC,WAAOtG,OACL,MAAIgH,gBACHlH,KAAG;KAAA,IAAC2J,OAAI;AAAA,aAAEnF,OAAOc,OAAO5D,WAAS;;KAAEkI,gBAAc;KAAAC,WAC/CC,UAAK5C,gBACHjH,MAAI;MAAA,IAAC8J,OAAI;AAAA,cAAE,CAACD,MAAMnE;;MAAS,IAAAkE,WAAA;AAAA,cAAA3C,gBACzB1F,iBAAe,EAACwF,SAAS8C,OAAK,CAAA;;MAAA,CAAA;KAElC,CAEL,CAAC;;GAEJ;EACF;;AAIH,qBAAe7G"}
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","isCaseSensitive","format","dts","input","Array","isArray","length","Object","keys","undefined","external","nodeProtocol","unbundle","configResolved","order","handler","appSpecificEnvPrefix","autoAssignEnv","env","prefix","includes","push","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 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 return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getDefaultOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.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,QAAQ;EACR;GACEgD,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MAAM,2CAA2C;AAEtD,UAAMlB,wBAAwB,KAAK;AA0CnC,WAxCed,OACb,EACEkC,QAAQ,EACNC,WAAW5C,UAAU,KAAKwC,OAAOK,MAAM,OAAM,EAC/C,EACD,EACDP,SACA;KACEC,MAAMX,WAAW,KAAK;KACtBkB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,IAAI,CAACsB,IAAI,OAAMtB,QAAO;KAC9C,MAAMK,OAAOjF,WACX4E,KACAxE,UAAU,KAAK4I,gBAAgBC,eAAe,KAAKrG,OAAOK,KAC5D,CAAC;AAED,SAAI,KAAKsE,GAAGC,WAAWvC,KAAK,EAAE;AAC5B,WAAKpC,MACH,6EAA6EoC,OAC9E;AAED,YAAMlF,OAAOkF,KAAK;WAElB,MAAK2B,KACH,uDAAuD3B,KAAI,4GAC5D;MAGP,CAAC;;GAGN;EACD;GACEtC,MAAM;GACNwB,iBAAiB;AACf,SAAKvB,OAAOjD,WAAW,EAAE;AACzB,SAAKiD,OAAOjD,OAAOuJ,aAAa;KAC9B,GAAI,KAAKtG,OAAOjD,OAAOuJ,cAAc,EAAE;KACvChI,UAAUA,SAAS,KAAI;KACxB;;GAEH,MAAMiI,OAAO;AACX,SAAKtG,MACH,oEACD;IAED,MAAM3B,aAAW,KAAK4D,OACnBoB,KAAIzC,UAASpB,eAAe,MAAMoB,MAAMyB,SAAS,CAAC,CAClDc,OAAOC,QAAyB;AAEnC,WAAOvG,OACL,MAAIiH,gBACHnH,KAAG;KAAA,IAAC4J,OAAI;AAAA,aAAEvF,OAAOkB,OAAO7D,WAAS;;KAAEmI,gBAAc;KAAAC,WAC/CC,UAAK5C,gBACHlH,MAAI;MAAA,IAAC+J,OAAI;AAAA,cAAE,CAACD,MAAMnE;;MAAS,IAAAkE,WAAA;AAAA,cAAA3C,gBACzB3F,iBAAe,EAACyF,SAAS8C,OAAK,CAAA;;MAAA,CAAA;KAElC,CAEL,CAAC;;GAEJ;EACF;;AAIH,qBAAe9G"}
@@ -1,6 +1,7 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_types_command = require('../types/command.cjs');
3
3
  const require_helpers = require('./helpers.cjs');
4
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
4
5
  let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
5
6
  let __stryke_type_checks_is_bigint = require("@stryke/type-checks/is-bigint");
6
7
  let __stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
@@ -12,9 +13,11 @@ function __assignType(fn, args) {
12
13
  return fn;
13
14
  }
14
15
  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;
16
+ const isKind = !((0, __stryke_type_checks_is_set_object.isSetObject)(type) && "kind" in type);
17
+ const kind = !isKind ? type.kind : type;
18
+ if (kind === __powerlines_deepkit_vendor_type.ReflectionKind.string) return require_types_command.CommandParameterKinds.string;
19
+ else if (kind === __powerlines_deepkit_vendor_type.ReflectionKind.number || kind === __powerlines_deepkit_vendor_type.ReflectionKind.bigint || !isKind && 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;
20
+ else if (kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean) return require_types_command.CommandParameterKinds.boolean;
18
21
  else return require_types_command.CommandParameterKinds.string;
19
22
  }
20
23
  extractCommandParameterKind.__type = [
@@ -1 +1 @@
1
- {"version":3,"file":"deepkit.cjs","names":[],"sources":["../../src/resolver/deepkit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n Type,\n TypeArray,\n TypeLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isBigInt } from \"@stryke/type-checks/is-bigint\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind,\n Context,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport { mergeCommandParameter } from \"./helpers\";\nimport type { ResolverContext } from \"./types\";\n\nfunction extractCommandParameterKind(\n type: Type | ReflectionKind\n): CommandParameterKind {\n if (type === ReflectionKind.string) {\n return CommandParameterKinds.string;\n } else if (\n type === ReflectionKind.number ||\n type === ReflectionKind.bigint ||\n ((type as Type).kind === ReflectionKind.literal &&\n (isNumber((type as TypeLiteral).literal) ||\n isBigInt((type as TypeLiteral).literal)))\n ) {\n return CommandParameterKinds.number;\n } else if (type === ReflectionKind.boolean) {\n return CommandParameterKinds.boolean;\n } else {\n return CommandParameterKinds.string;\n }\n}\n\nfunction resolveCommandOption(\n ctx: ResolverContext,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n const existing = (ctx.output.options[reflection.getNameAsString()] ??\n {}) as Partial<CommandOption>;\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title: reflection.getTags().title?.trim(),\n description: reflection.getDescription(),\n kind: extractCommandParameterKind(type),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray()\n };\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind((type as TypeArray).type.kind) as\n | \"string\"\n | \"number\";\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (type.kind === ReflectionKind.union) {\n option.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (option as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (option as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, option) as CommandOption;\n}\n\nfunction resolveCommandArgument(\n ctx: ResolverContext,\n index: number,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n const existing = (\n ctx.output.args.length > index ? ctx.output.args[index] : {}\n ) as Partial<CommandArgument>;\n\n if (\n !existing.kind &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName() || reflection.parameter.name,\n alias: reflection.getAlias(),\n kind: extractCommandParameterKind(type.kind),\n title: reflection.getTitle() || reflection.parameter.tags?.title,\n description: reflection.parameter.description,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue()\n };\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (argument as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind(type.type.kind) as \"string\" | \"number\";\n } else if (!existing.kind) {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, argument, {\n name: `arg${index}`\n }) as CommandArgument;\n}\n\nexport function resolveFromBytecode<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n const { input, module } = ctx;\n\n const type = reflect(module);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${\n input.command.entry.input?.file || input.command.path\n }\" does not export a valid function.`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n ctx.output.description ??= (ctx.input.command.description ||\n reflection.getDescription() ||\n type.description)!;\n\n const parameters = reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n ctx.output.options[propertyReflection.getNameAsString()] =\n resolveCommandOption(ctx, propertyReflection);\n }\n } else if (!ctx.module?.options) {\n throw new Error(\n `The first parameter of the command handler function in \"${\n ctx.input.command.entry.input?.file || ctx.input.command.path\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n ctx.output.args = parameters\n .slice(1)\n .map((arg, index) => resolveCommandArgument(ctx, index, arg));\n }\n}\n"],"mappings":";;;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AAQX,SAAS,4BAA4B,MAAM;qEAEnC,QAAO,4CAAqB;UAEvB,SAAS,gDAAe,6EAE5B,KAAG,SAAA,gDAAA,yDACS,KAAA,QAAA,iDACD,KAAA,QAAA,EACd,QAAA,4CAAA;UAEM,SAAA,gDAAA,QACJ,QAAO,4CAAsB;KAG7B,QAAO,4CAAE;;AAGjB,4BAAc,SAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACd,SAAS,qBAAqB,KAAK,YAAK;CACpC,MAAM,OAAO,WAAW,SAAS;CACjC,MAAM,WAAY,IAAI,OAAO,QAAQ,WAAW,iBAA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AY;CAAA;CAAA;CAAA"}
1
+ {"version":3,"file":"deepkit.cjs","names":[],"sources":["../../src/resolver/deepkit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n Type,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isBigInt } from \"@stryke/type-checks/is-bigint\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind,\n Context,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport { mergeCommandParameter } from \"./helpers\";\nimport type { ResolverContext } from \"./types\";\n\nfunction extractCommandParameterKind(\n type: Type | ReflectionKind\n): CommandParameterKind {\n const isKind = !(isSetObject(type) && \"kind\" in type);\n const kind = !isKind ? type.kind : type;\n if (kind === ReflectionKind.string) {\n return CommandParameterKinds.string;\n } else if (\n kind === ReflectionKind.number ||\n kind === ReflectionKind.bigint ||\n (!isKind &&\n type.kind === ReflectionKind.literal &&\n (isNumber(type.literal) || isBigInt(type.literal)))\n ) {\n return CommandParameterKinds.number;\n } else if (kind === ReflectionKind.boolean) {\n return CommandParameterKinds.boolean;\n } else {\n return CommandParameterKinds.string;\n }\n}\n\nfunction resolveCommandOption(\n ctx: ResolverContext,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n const existing = (ctx.output.options[reflection.getNameAsString()] ??\n {}) as Partial<CommandOption>;\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title: reflection.getTags().title?.trim(),\n description: reflection.getDescription(),\n kind: extractCommandParameterKind(type),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray()\n };\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind((type as TypeArray).type.kind) as\n | \"string\"\n | \"number\";\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (type.kind === ReflectionKind.union) {\n option.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (option as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (option as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, option) as CommandOption;\n}\n\nfunction resolveCommandArgument(\n ctx: ResolverContext,\n index: number,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n const existing = (\n ctx.output.args.length > index ? ctx.output.args[index] : {}\n ) as Partial<CommandArgument>;\n\n if (\n !existing.kind &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName() || reflection.parameter.name,\n alias: reflection.getAlias(),\n kind: extractCommandParameterKind(type.kind),\n title: reflection.getTitle() || reflection.parameter.tags?.title,\n description: reflection.parameter.description,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue()\n };\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (argument as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind(type.type.kind) as \"string\" | \"number\";\n } else if (!existing.kind) {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, argument, {\n name: `arg${index}`\n }) as CommandArgument;\n}\n\nexport function resolveFromBytecode<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n const { input, module } = ctx;\n\n const type = reflect(module);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${\n input.command.entry.input?.file || input.command.path\n }\" does not export a valid function.`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n ctx.output.description ??= (ctx.input.command.description ||\n reflection.getDescription() ||\n type.description)!;\n\n const parameters = reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n ctx.output.options[propertyReflection.getNameAsString()] =\n resolveCommandOption(ctx, propertyReflection);\n }\n } else if (!ctx.module?.options) {\n throw new Error(\n `The first parameter of the command handler function in \"${\n ctx.input.command.entry.input?.file || ctx.input.command.path\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n ctx.output.args = parameters\n .slice(1)\n .map((arg, index) => resolveCommandArgument(ctx, index, arg));\n }\n}\n"],"mappings":";;;;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;CAUP,MAAM,SAAS,sDAAc,KAAG,IAAA,UAAA;;AAEhC,KAAI,SAAS,gDAAe;UAGnB,SAAQ,gDAAA,UACb,SAAS,gDAA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,iDAAA,KAAA,WAAA,GAAA,KAAA;AACpB,QAAK,MAAE,sBAAA,kBAAA,eAAA,CACH,KAAI,OAAO,QAAQ,mBAAA,iBAAA,IAChB,qBAAA,KAAA,mBAAA;kCAId,OAAA,IAAA,MAAA,2DAAA,IAAA,MAAA,QAAA,MAAA,OAAA,QAAA,IAAA,MAAA,QAAA,KAAA,6EAAA;AAEG,MAAI,OAAO,OAAO,WACb,MAAM,EAAE,CACR,IAAI,cAAc,KAAK,UAAM,uBAAA,KAAA,OAAA,IAAA,EAAA;GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;;AAG1C,oBAAoB,SAAS;CAAC;CAAmB;CAAA;CAAA;CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { CommandParameterKinds } from "../types/command.mjs";
2
2
  import { mergeCommandParameter } from "./helpers.mjs";
3
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
3
4
  import { ReflectionClass, ReflectionFunction, ReflectionKind, __ΩReflectionKind, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
4
5
  import { isBigInt } from "@stryke/type-checks/is-bigint";
5
6
  import { isNumber } from "@stryke/type-checks/is-number";
@@ -11,9 +12,11 @@ function __assignType(fn, args) {
11
12
  return fn;
12
13
  }
13
14
  function extractCommandParameterKind(type) {
14
- if (type === ReflectionKind.string) return CommandParameterKinds.string;
15
- else if (type === ReflectionKind.number || type === ReflectionKind.bigint || type.kind === ReflectionKind.literal && (isNumber(type.literal) || isBigInt(type.literal))) return CommandParameterKinds.number;
16
- else if (type === ReflectionKind.boolean) return CommandParameterKinds.boolean;
15
+ const isKind = !(isSetObject(type) && "kind" in type);
16
+ const kind = !isKind ? type.kind : type;
17
+ if (kind === ReflectionKind.string) return CommandParameterKinds.string;
18
+ else if (kind === ReflectionKind.number || kind === ReflectionKind.bigint || !isKind && type.kind === ReflectionKind.literal && (isNumber(type.literal) || isBigInt(type.literal))) return CommandParameterKinds.number;
19
+ else if (kind === ReflectionKind.boolean) return CommandParameterKinds.boolean;
17
20
  else return CommandParameterKinds.string;
18
21
  }
19
22
  extractCommandParameterKind.__type = [