@shell-shock/core 0.13.2 → 0.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/plugin.cjs +4 -0
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +4 -0
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.cts +2 -2
- package/dist/types/config.d.mts +2 -2
- package/dist/types/config.mjs.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ This package is part of the ⚡<b>Shell Shock</b> monorepo. The Shell Shock pack
|
|
|
27
27
|
|
|
28
28
|
<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
|
|
29
29
|
|
|
30
|
-
[](https://stormsoftware.com/projects/shell-shock/) [](http://commitizen.github.io/cz-cli/)  
|
|
31
31
|
|
|
32
32
|
<!-- prettier-ignore-start -->
|
|
33
33
|
<!-- markdownlint-disable -->
|
package/dist/plugin.cjs
CHANGED
|
@@ -108,6 +108,10 @@ const plugin = (options = {}) => {
|
|
|
108
108
|
app: this.config.reference.substring(0, this.config.reference.indexOf("{command}")).replace(/\/?$/, "/"),
|
|
109
109
|
commands: this.config.reference
|
|
110
110
|
};
|
|
111
|
+
else if (this.config.reference.includes("{commands}")) this.config.reference = {
|
|
112
|
+
app: this.config.reference.substring(0, this.config.reference.indexOf("{commands}")).replace(/\/?$/, "/"),
|
|
113
|
+
commands: this.config.reference
|
|
114
|
+
};
|
|
111
115
|
else this.config.reference = { app: this.config.reference };
|
|
112
116
|
this.commandsPath = require_paths.findCommandsRoot(this);
|
|
113
117
|
const inputs = await (0, powerlines_utils.resolveInputs)(this, this.config.input);
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath, relativePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { tsdown } from \"powerlines/tsdown\";\nimport { resolveInputs } from \"powerlines/utils\";\nimport type { BuildContext, RolldownChunk, TsdownHooks } from \"tsdown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n findCommandsRoot,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/paths\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getGlobalOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport { resolve } from \"./resolver/resolve\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport { CommandParameterKinds } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n path: joinPaths(this.config.root, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n platform: \"node\",\n projectType: \"application\",\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: false\n },\n input:\n !this.config.input ||\n (Array.isArray(this.config.input) &&\n this.config.input.length === 0) ||\n (isObject(this.config.input) &&\n Object.keys(this.config.input).length === 0)\n ? [\n joinPaths(this.config.root, \"src/**/command.ts\"),\n joinPaths(this.config.root, \"src/**/command.tsx\")\n ]\n : undefined,\n resolve: {\n external: [\"@powerlines/deepkit\"]\n },\n tsdown: {\n dts: false,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getGlobalOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n if (isSetString(this.config.reference)) {\n if (this.config.reference.includes(\"{command}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{command}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else {\n this.config.reference = {\n app: this.config.reference\n };\n }\n }\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n typegen(code: string) {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `${code}\n\n/**\n * The global options available for every command in the ${getAppTitle(\n this,\n true\n )} command-line application.\n */\nexport interface GlobalOptions {\n ${this.options\n .map(\n option =>\n `${\n option.description\n ? `\n/**\n * ${option.description}${\n option.default\n ? `\n *\n * @defaultValue ${\n option.kind === CommandParameterKinds.string\n ? `\"${option.default}\"`\n : option.default\n }`\n : \"\"\n }\n */\n`\n : \"\"\n }${option.name}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };${\n option.alias && option.alias.length > 0\n ? option.alias\n .map(\n alias =>\n `${alias}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };`\n )\n .join(\"\\n\\n\")\n : \"\"\n }`\n )\n .join(\"\\n\\n\")}\n}\n`;\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.hooks ??= {} as TsdownHooks;\n (this.config.tsdown.hooks as TsdownHooks)[\"build:done\"] = async (\n _: BuildContext & {\n chunks: RolldownChunk[];\n }\n ) => {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(this.workspaceConfig.workspaceRoot, this.config.root)\n );\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding hashbang to binary executable output file: ${path}`\n );\n\n const content = await this.fs.read(path);\n if (content && !content.startsWith(\"#!\")) {\n await this.fs.write(\n path,\n `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n\\n${content}`\n );\n }\n\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${\n path\n }`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Expected binary output file not found at path: ${\n path\n }. Skipping adding hashbang and executable permissions (chmod+x).`\n );\n }\n })\n );\n };\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,YAAY;;;;AAKlB,MAAY,UAAA,UAAA,EAAA,KAAA;AACV,QAAA;iCAAW;2CAAA;0CAAA;EAAA;GACX,MAAA;GACA,MAAA,SAAA;AACA,SAAA,MAAA,2CAAA;AACI,UAAI,oDAAqB,KAAQ;AA0BjC,0BAzBoB,EAClB,QAAC,EACA,6CAAiB,KAAC,OAAS,MAAQ,OAAA,EACrC,EACA,EAAE,SAAA;KACF,MAAO,mCAAU,KAAM;KACvB,OAAO,oCAAU,KAAQ;;KAE1B,UAAY;;KAEhB,iBAAA;KACK,QAAK;MACV,QAAA;MACK,KAAM;MACJ;KACJ,OAAA,CAAA,KAAA,OAAA,SAAA,MAAA,QAAA,KAAA,OAAA,MAAA,IAAA,KAAA,OAAA,MAAA,WAAA,iDAAA,KAAA,OAAA,MAAA,IAAA,OAAA,KAAA,KAAA,OAAA,MAAA,CAAA,WAAA,IAAA,wCAAA,KAAA,OAAA,MAAA,oBAAA,yCAAA,KAAA,OAAA,MAAA,qBAAA,CAAA,GAAA;KACG,SAAC,EACC,UAAE,CAAA,sBAAA,EACR;KACA,QAAQ;MACR,KAAA;MACM,cAAc;MAClB,UAAc;M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QAAA,IAAa,OAAA,OAAA,KAAA,OAAA,IAAA,CAAA,IAAA,OAAA,QAAA;MACf,MAAA,2CAAA,4CAAA,KAAA,gBAAA,eAAA,KAAA,OAAA,KAAA,CAAA;AACH,UAAA,KAAA,GAAA,WAAA,KAAA,EAAA;AACN,YAAA,MAAA,qDAAA,OAAA;OACG,MAAc,UAAA,MAAA,KAAA,GAAA,KAAA,KAAA;AACR,WAAM,WAAG,CAAA,QAAA,WAAsB,KAAA,CAC9B,OAAO,KAAO,GAAE,MAAA,MAAA,kBAAA,KAAA,OAAA,SAAA,gBAAA,yCAAA,GAAA,WAAA,UAAA;AAEzB,YAAA,MAAA,6EAAA,OAAA;AACM,4CAAA,KAAA;YAEN,MAAA,KAAA,kDAAA,KAAA,kEAAA;OAEQ,CAAC;;;GAGR;EAAE;GACD,MAAM;GACN,iBAAY;AACV,SAAK,OAAO,WAAS,EAAA;AACrB,SAAK,OAAO,OAAK,aAAY;KAC3B,GAAI,KAAK,OAAO,OAAO,cAAS,EAAA;KAChC,UAAU,wBAAS,KAAI;KACxB;;GAEH,MAAM,OAAO;AACX,SAAK,MAAM,oEAAyC;IACpD,MAAM,WAAW,KAAA,OAAM,KAAA,UAAA,wCAAA,MAAA,MAAA,SAAA,CAAA,CAAA,OAAA,QAAA;AACvB,uDAAc,sDAAS,+BAAA;KACrB,IAAI,OAAK;AACP,aAAC,OAAA,OAAA,SAAA;;KAEH,gBAAa;KACb,WAAS,0DAAG,gCAAA;MACV,IAAI,OAAI;AACN,cAAO,CAAC,MAAG;;MAEb,IAAI,WAAW;AACb,8DAAwB,yCAAkB,EACxC,SAAS,OACV,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath, relativePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { tsdown } from \"powerlines/tsdown\";\nimport { resolveInputs } from \"powerlines/utils\";\nimport type { BuildContext, RolldownChunk, TsdownHooks } from \"tsdown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n findCommandsRoot,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/paths\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getGlobalOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport { resolve } from \"./resolver/resolve\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport { CommandParameterKinds } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n path: joinPaths(this.config.root, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n platform: \"node\",\n projectType: \"application\",\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: false\n },\n input:\n !this.config.input ||\n (Array.isArray(this.config.input) &&\n this.config.input.length === 0) ||\n (isObject(this.config.input) &&\n Object.keys(this.config.input).length === 0)\n ? [\n joinPaths(this.config.root, \"src/**/command.ts\"),\n joinPaths(this.config.root, \"src/**/command.tsx\")\n ]\n : undefined,\n resolve: {\n external: [\"@powerlines/deepkit\"]\n },\n tsdown: {\n dts: false,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getGlobalOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n if (isSetString(this.config.reference)) {\n if (this.config.reference.includes(\"{command}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{command}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else if (this.config.reference.includes(\"{commands}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{commands}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else {\n this.config.reference = {\n app: this.config.reference\n };\n }\n }\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n typegen(code: string) {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `${code}\n\n/**\n * The global options available for every command in the ${getAppTitle(\n this,\n true\n )} command-line application.\n */\nexport interface GlobalOptions {\n ${this.options\n .map(\n option =>\n `${\n option.description\n ? `\n/**\n * ${option.description}${\n option.default\n ? `\n *\n * @defaultValue ${\n option.kind === CommandParameterKinds.string\n ? `\"${option.default}\"`\n : option.default\n }`\n : \"\"\n }\n */\n`\n : \"\"\n }${option.name}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };${\n option.alias && option.alias.length > 0\n ? option.alias\n .map(\n alias =>\n `${alias}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };`\n )\n .join(\"\\n\\n\")\n : \"\"\n }`\n )\n .join(\"\\n\\n\")}\n}\n`;\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.hooks ??= {} as TsdownHooks;\n (this.config.tsdown.hooks as TsdownHooks)[\"build:done\"] = async (\n _: BuildContext & {\n chunks: RolldownChunk[];\n }\n ) => {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(this.workspaceConfig.workspaceRoot, this.config.root)\n );\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding hashbang to binary executable output file: ${path}`\n );\n\n const content = await this.fs.read(path);\n if (content && !content.startsWith(\"#!\")) {\n await this.fs.write(\n path,\n `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n\\n${content}`\n );\n }\n\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${\n path\n }`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Expected binary output file not found at path: ${\n path\n }. Skipping adding hashbang and executable permissions (chmod+x).`\n );\n }\n })\n );\n };\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,YAAY;;;;AAKlB,MAAY,UAAA,UAAA,EAAA,KAAA;AACV,QAAA;iCAAW;2CAAA;0CAAA;EAAA;GACX,MAAA;GACA,MAAA,SAAA;AACA,SAAA,MAAA,2CAAA;AACI,UAAI,oDAAqB,KAAQ;AA0BjC,0BAzBoB,EAClB,QAAC,EACA,6CAAiB,KAAC,OAAS,MAAQ,OAAA,EACrC,EACA,EAAE,SAAA;KACF,MAAO,mCAAU,KAAM;KACvB,OAAO,oCAAU,KAAQ;;KAE1B,UAAY;;KAEhB,iBAAA;KACK,QAAK;MACV,QAAA;MACK,KAAM;MACJ;KACJ,OAAA,CAAA,KAAA,OAAA,SAAA,MAAA,QAAA,KAAA,OAAA,MAAA,IAAA,KAAA,OAAA,MAAA,WAAA,iDAAA,KAAA,OAAA,MAAA,IAAA,OAAA,KAAA,KAAA,OAAA,MAAA,CAAA,WAAA,IAAA,wCAAA,KAAA,OAAA,MAAA,oBAAA,yCAAA,KAAA,OAAA,MAAA,qBAAA,CAAA,GAAA;KACG,SAAC,EACC,UAAE,CAAA,sBAAA,EACR;KACA,QAAQ;MACR,KAAA;MACM,cAAc;MAClB,UAAc;MACZ;;;GAIJ,gBAAgB;IACd,OA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CAAG;MACtC,IAAI,OAAO;AACT,cAAK,CAAG,MAAA;;MAEV,IAAI,WAAS;AACX,8DAAyB,yCAAC,EACxB,SAAS,OACV,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.tsx"],"mappings":";;;;;;;AAkFA;cAAa,MAAA,oBAA2B,OAAA,GAAU,OAAA,EAChD,OAAA,GAAS,OAAA,
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.tsx"],"mappings":";;;;;;;AAkFA;cAAa,MAAA,oBAA2B,OAAA,GAAU,OAAA,EAChD,OAAA,GAAS,OAAA,KAimBJ,MAAA,CAAO,QAAA"}
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.tsx"],"mappings":";;;;;;;AAkFA;cAAa,MAAA,oBAA2B,OAAA,GAAU,OAAA,EAChD,OAAA,GAAS,OAAA,
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.tsx"],"mappings":";;;;;;;AAkFA;cAAa,MAAA,oBAA2B,OAAA,GAAU,OAAA,EAChD,OAAA,GAAS,OAAA,KAimBJ,MAAA,CAAO,QAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -103,6 +103,10 @@ const plugin = (options = {}) => {
|
|
|
103
103
|
app: this.config.reference.substring(0, this.config.reference.indexOf("{command}")).replace(/\/?$/, "/"),
|
|
104
104
|
commands: this.config.reference
|
|
105
105
|
};
|
|
106
|
+
else if (this.config.reference.includes("{commands}")) this.config.reference = {
|
|
107
|
+
app: this.config.reference.substring(0, this.config.reference.indexOf("{commands}")).replace(/\/?$/, "/"),
|
|
108
|
+
commands: this.config.reference
|
|
109
|
+
};
|
|
106
110
|
else this.config.reference = { app: this.config.reference };
|
|
107
111
|
this.commandsPath = findCommandsRoot(this);
|
|
108
112
|
const inputs = await resolveInputs(this, this.config.input);
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath, relativePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { tsdown } from \"powerlines/tsdown\";\nimport { resolveInputs } from \"powerlines/utils\";\nimport type { BuildContext, RolldownChunk, TsdownHooks } from \"tsdown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n findCommandsRoot,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/paths\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getGlobalOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport { resolve } from \"./resolver/resolve\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport { CommandParameterKinds } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n path: joinPaths(this.config.root, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n platform: \"node\",\n projectType: \"application\",\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: false\n },\n input:\n !this.config.input ||\n (Array.isArray(this.config.input) &&\n this.config.input.length === 0) ||\n (isObject(this.config.input) &&\n Object.keys(this.config.input).length === 0)\n ? [\n joinPaths(this.config.root, \"src/**/command.ts\"),\n joinPaths(this.config.root, \"src/**/command.tsx\")\n ]\n : undefined,\n resolve: {\n external: [\"@powerlines/deepkit\"]\n },\n tsdown: {\n dts: false,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getGlobalOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n if (isSetString(this.config.reference)) {\n if (this.config.reference.includes(\"{command}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{command}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else {\n this.config.reference = {\n app: this.config.reference\n };\n }\n }\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n typegen(code: string) {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `${code}\n\n/**\n * The global options available for every command in the ${getAppTitle(\n this,\n true\n )} command-line application.\n */\nexport interface GlobalOptions {\n ${this.options\n .map(\n option =>\n `${\n option.description\n ? `\n/**\n * ${option.description}${\n option.default\n ? `\n *\n * @defaultValue ${\n option.kind === CommandParameterKinds.string\n ? `\"${option.default}\"`\n : option.default\n }`\n : \"\"\n }\n */\n`\n : \"\"\n }${option.name}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };${\n option.alias && option.alias.length > 0\n ? option.alias\n .map(\n alias =>\n `${alias}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };`\n )\n .join(\"\\n\\n\")\n : \"\"\n }`\n )\n .join(\"\\n\\n\")}\n}\n`;\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.hooks ??= {} as TsdownHooks;\n (this.config.tsdown.hooks as TsdownHooks)[\"build:done\"] = async (\n _: BuildContext & {\n chunks: RolldownChunk[];\n }\n ) => {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(this.workspaceConfig.workspaceRoot, this.config.root)\n );\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding hashbang to binary executable output file: ${path}`\n );\n\n const content = await this.fs.read(path);\n if (content && !content.startsWith(\"#!\")) {\n await this.fs.write(\n path,\n `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n\\n${content}`\n );\n }\n\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${\n path\n }`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Expected binary output file not found at path: ${\n path\n }. Skipping adding hashbang and executable permissions (chmod+x).`\n );\n }\n })\n );\n };\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,YAAY;;;;AAKlB,MAAY,UAAA,UAAA,EAAA,KAAA;AACV,QAAA;EAAA,QAAW;EAAA,SAAA;EAAA,QAAA;EAAA;GACX,MAAA;GACA,MAAA,SAAA;AACA,SAAA,MAAA,2CAAA;AACI,UAAI,wBAAqB,KAAQ;AA0BjC,WAzBG,KAAiB,EAClB,QAAC,EACA,MAAO,UAAU,KAAC,OAAS,MAAQ,OAAA,EACrC,EACA,EAAE,SAAA;KACF,MAAO,WAAU,KAAM;KACvB,OAAO,YAAU,KAAQ;;KAE1B,UAAY;;KAEhB,iBAAA;KACK,QAAK;MACV,QAAA;MACK,KAAM;MACJ;KACJ,OAAA,CAAA,KAAA,OAAA,SAAA,MAAA,QAAA,KAAA,OAAA,MAAA,IAAA,KAAA,OAAA,MAAA,WAAA,KAAA,SAAA,KAAA,OAAA,MAAA,IAAA,OAAA,KAAA,KAAA,OAAA,MAAA,CAAA,WAAA,IAA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AAA,MAAA;MACV,IAAI,OAAI;AACN,cAAO,CAAC,MAAG;;MAEb,IAAI,WAAW;AACb,cAAO,gBAAiB,iBAAkB,EACxC,SAAS,OACV,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath, relativePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { tsdown } from \"powerlines/tsdown\";\nimport { resolveInputs } from \"powerlines/utils\";\nimport type { BuildContext, RolldownChunk, TsdownHooks } from \"tsdown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { UtilsBuiltin } from \"./components/utils-builtin\";\nimport { commands } from \"./helpers/automd\";\nimport {\n findCommandsRoot,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/paths\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getGlobalOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport { resolve } from \"./resolver/resolve\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport { CommandParameterKinds } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n path: joinPaths(this.config.root, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n platform: \"node\",\n projectType: \"application\",\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: false\n },\n input:\n !this.config.input ||\n (Array.isArray(this.config.input) &&\n this.config.input.length === 0) ||\n (isObject(this.config.input) &&\n Object.keys(this.config.input).length === 0)\n ? [\n joinPaths(this.config.root, \"src/**/command.ts\"),\n joinPaths(this.config.root, \"src/**/command.tsx\")\n ]\n : undefined,\n resolve: {\n external: [\"@powerlines/deepkit\"]\n },\n tsdown: {\n dts: false,\n nodeProtocol: true,\n unbundle: false\n }\n }\n );\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.appSpecificEnvPrefix = isSetString(\n this.config.autoAssignEnv\n )\n ? this.config.autoAssignEnv\n : constantCase(getAppName(this));\n if (\n !this.config.env.prefix ||\n !Array.isArray(this.config.env.prefix)\n ) {\n this.config.env.prefix = toArray(this.config.env.prefix);\n }\n\n if (\n !this.config.env.prefix.includes(this.config.appSpecificEnvPrefix)\n ) {\n this.config.env.prefix.push(this.config.appSpecificEnvPrefix);\n }\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getGlobalOptions(this, {\n id: null,\n name: this.config.name,\n path: null,\n segments: [],\n title: this.config.title,\n description: this.config.description,\n alias: [],\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(\n defu(options ?? {}, {\n env: {\n types: \"@shell-shock/core/types/env#ShellShockEnv\",\n validate: false\n }\n })\n ),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n if (isSetString(this.config.reference)) {\n if (this.config.reference.includes(\"{command}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{command}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else if (this.config.reference.includes(\"{commands}\")) {\n this.config.reference = {\n app: this.config.reference\n .substring(0, this.config.reference.indexOf(\"{commands}\"))\n .replace(/\\/?$/, \"/\"),\n commands: this.config.reference\n };\n } else {\n this.config.reference = {\n app: this.config.reference\n };\n }\n }\n\n this.commandsPath = findCommandsRoot(this);\n const inputs = await resolveInputs(this, this.config.input);\n\n this.debug(\n `Found ${\n inputs.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = inputs.reduce((ret, entry) => {\n if (\n entry.file !== this.commandsPath &&\n !isParentPath(entry.file, this.commandsPath)\n ) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(entry.file);\n let segments = resolveCommandPath(this, entry.file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n },\n typegen(code: string) {\n this.debug(\n \"Generating type definitions for the Shell Shock application.\"\n );\n\n return `${code}\n\n/**\n * The global options available for every command in the ${getAppTitle(\n this,\n true\n )} command-line application.\n */\nexport interface GlobalOptions {\n ${this.options\n .map(\n option =>\n `${\n option.description\n ? `\n/**\n * ${option.description}${\n option.default\n ? `\n *\n * @defaultValue ${\n option.kind === CommandParameterKinds.string\n ? `\"${option.default}\"`\n : option.default\n }`\n : \"\"\n }\n */\n`\n : \"\"\n }${option.name}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };${\n option.alias && option.alias.length > 0\n ? option.alias\n .map(\n alias =>\n `${alias}${option.optional ? \"?\" : \"\"}: ${\n option.kind === CommandParameterKinds.boolean\n ? \"boolean\"\n : `${option.variadic ? \"(\" : \"\"}${\n option.choices\n ? option.choices\n .map(choice =>\n option.kind === CommandParameterKinds.number\n ? `${choice}`\n : `\"${choice}\"`\n )\n .join(\" | \")\n : option.kind === CommandParameterKinds.number\n ? \"number\"\n : \"string\"\n }${option.variadic ? \")[]\" : \"\"}`\n };`\n )\n .join(\"\\n\\n\")\n : \"\"\n }`\n )\n .join(\"\\n\\n\")}\n}\n`;\n },\n async prepare() {\n this.debug(\n \"Rendering base built-in modules for the Shell Shock application.\"\n );\n\n return render(\n this,\n <>\n <UtilsBuiltin />\n </>\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${\n isParentPath(command.entry.file, this.commandsPath)\n ? replacePath(command.entry.file, this.commandsPath)\n : relativePath(command.entry.file, this.commandsPath)\n }${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n if (isParentPath(parentPath, this.commandsPath)) {\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Unable to process virtual commands for ${command.name} \\n\\nPlease ensure ${command.entry.file} is a valid command entry file and does not have an invalid path.`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n\n let segments = resolveCommandPath(this, file)\n .split(\"/\")\n .filter(Boolean);\n\n // Ensure unique segment names by appending an index suffix to duplicates\n segments = segments.map((segment, index) => {\n const found = segments.findIndex(\n existing => existing === segment\n );\n if (found !== -1 && found !== index) {\n segment += `_${\n segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(\n /_\\d+$/,\n \"\"\n ) === segment\n ).length\n }`;\n }\n\n return segment;\n });\n\n ret.push({\n id,\n path: segments.join(\"/\"),\n segments,\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.segments.length - b.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:resolve-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n\n this.commands = {};\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping command resolution as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.segments.filter(\n segment =>\n !isDynamicPathSegment(segment) &&\n !isPathSegmentGroup(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await resolve({\n context: this,\n command: input\n });\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.tsdown.hooks ??= {} as TsdownHooks;\n (this.config.tsdown.hooks as TsdownHooks)[\"build:done\"] = async (\n _: BuildContext & {\n chunks: RolldownChunk[];\n }\n ) => {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(this.workspaceConfig.workspaceRoot, this.config.root)\n );\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding hashbang to binary executable output file: ${path}`\n );\n\n const content = await this.fs.read(path);\n if (content && !content.startsWith(\"#!\")) {\n await this.fs.write(\n path,\n `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n\\n${content}`\n );\n }\n\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${\n path\n }`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Expected binary output file not found at path: ${\n path\n }. Skipping adding hashbang and executable permissions (chmod+x).`\n );\n }\n })\n );\n };\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,YAAY;;;;AAKlB,MAAY,UAAA,UAAA,EAAA,KAAA;AACV,QAAA;EAAA,QAAW;EAAA,SAAA;EAAA,QAAA;EAAA;GACX,MAAA;GACA,MAAA,SAAA;AACA,SAAA,MAAA,2CAAA;AACI,UAAI,wBAAqB,KAAQ;AA0BjC,WAzBG,KAAiB,EAClB,QAAC,EACA,MAAO,UAAU,KAAC,OAAS,MAAQ,OAAA,EACrC,EACA,EAAE,SAAA;KACF,MAAO,WAAU,KAAM;KACvB,OAAO,YAAU,KAAQ;;KAE1B,UAAY;;KAEhB,iBAAA;KACK,QAAK;MACV,QAAA;MACK,KAAM;MACJ;KACJ,OAAA,CAAA,K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C,6EAAS,OAAA;AACpB,aAAO,OAAA,KAAA;YAEN,MAAA,KAAA,kDAAA,KAAA,kEAAA;OAEN,CAAA;;;GAGC;EAAE;GACD,MAAM;GACN,iBAAW;AACT,SAAK,OAAM,WAAO,EAAA;AAClB,SAAK,OAAK,OAAO,aAAA;KACf,GAAI,KAAK,OAAG,OAAO,cAAA,EAAA;KACnB,UAAU,SAAS,KAAA;KACpB;;GAEH,MAAM,OAAO;AACX,SAAK,MAAM,oEAAK;IAChB,MAAM,WAAW,KAAK,OAAK,KAAA,UAAA,eAAA,MAAA,MAAA,SAAA,CAAA,CAAA,OAAA,QAAA;AAC3B,WAAO,OAAO,MAAM,gBAAU,KAAA;KAC5B,IAAI,OAAO;AACT,aAAO,OAAM,OAAM,SAAA;;KAErB,gBAAG;KACH,WAAS,UAAS,gBAAmB,MAAG;MACtC,IAAI,OAAO;AACT,cAAK,CAAG,MAAA;;MAEV,IAAI,WAAS;AACX,cAAO,gBAAkB,iBAAC,EACxB,SAAS,OACV,CAAC;;MAEL,CAAC;KACH,CAAC,CAAC;;GAEN;EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","names":[],"sources":["../../src/types/config.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 { AutoMDPluginResolvedConfig } from \"@powerlines/plugin-automd/types/plugin\";\nimport type {\n NodeJsPluginOptions,\n NodeJsPluginResolvedConfig,\n NodeJsPluginUserConfig\n} from \"@powerlines/plugin-nodejs/types/plugin\";\nimport type {\n TsdownPluginResolvedConfig,\n TsdownPluginUserConfig\n} from \"@powerlines/plugin-tsdown/types/plugin\";\nimport type { OutputConfig as PowerlinesOutputConfig } from \"powerlines\";\nimport type { CommandBase, CommandOption } from \"./command\";\nimport type { Context } from \"./context\";\n\ntype BuildOptions = Pick<\n TsdownPluginUserConfig,\n | \"root\"\n | \"name\"\n | \"title\"\n | \"description\"\n | \"logLevel\"\n | \"mode\"\n | \"skipCache\"\n | \"autoInstall\"\n | \"plugins\"\n | \"tsconfig\"\n | \"tsconfigRaw\"\n>;\n\nexport interface ReferenceOptions {\n /**\n * A URL to the application documentation or reference.\n */\n app: string;\n\n /**\n * A URL to the application command specific documentation or reference.\n *\n * @remarks\n * This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{
|
|
1
|
+
{"version":3,"file":"config.cjs","names":[],"sources":["../../src/types/config.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 { AutoMDPluginResolvedConfig } from \"@powerlines/plugin-automd/types/plugin\";\nimport type {\n NodeJsPluginOptions,\n NodeJsPluginResolvedConfig,\n NodeJsPluginUserConfig\n} from \"@powerlines/plugin-nodejs/types/plugin\";\nimport type {\n TsdownPluginResolvedConfig,\n TsdownPluginUserConfig\n} from \"@powerlines/plugin-tsdown/types/plugin\";\nimport type { OutputConfig as PowerlinesOutputConfig } from \"powerlines\";\nimport type { CommandBase, CommandOption } from \"./command\";\nimport type { Context } from \"./context\";\n\ntype BuildOptions = Pick<\n TsdownPluginUserConfig,\n | \"root\"\n | \"name\"\n | \"title\"\n | \"description\"\n | \"logLevel\"\n | \"mode\"\n | \"skipCache\"\n | \"autoInstall\"\n | \"plugins\"\n | \"tsconfig\"\n | \"tsconfigRaw\"\n>;\n\nexport interface ReferenceOptions {\n /**\n * A URL to the application documentation or reference.\n */\n app: string;\n\n /**\n * A URL to the application command specific documentation or reference.\n *\n * @remarks\n * This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.\n */\n commands?: string;\n}\n\ntype BaseOptions = Partial<BuildOptions> & {\n /**\n * A set of global command options to apply to each command.\n *\n * @remarks\n * Each command will inherit these global options. To disable the addition of these global options, set this property to `false`, or provide a custom set of options/a function that returns them. A `GlobalOptions` interface will be created by the `shell-shock typegen` command and added to the generated `shell-shock.d.ts` file.\n */\n globalOptions?:\n | CommandOption[]\n | ((context: Context, input: CommandBase) => CommandOption[])\n | false;\n\n /**\n * Determines whether commands and option names are treated as case-sensitive.\n *\n * @defaultValue `false`\n */\n isCaseSensitive?: boolean;\n\n /**\n * The name of the binary (the {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | \"bin\" field} in package.json) that will be used to run the application through NodeJs package managers (e.g., npm, yarn, pnpm).\n *\n * @remarks\n * If an array is provided, each binary will be linked to the same compiled output file. If not provided, the {@link Options.name | name} option will be used.\n *\n * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin\n * @see https://yarnpkg.com/cli/bin\n * @see https://pnpm.io/package_json#bin\n */\n bin?: string | string[];\n\n /**\n * Should Shell Shock attempt to automatically assign environment variables to manipulate default values for command options based on the option name?\n *\n * @remarks\n * If set to a string, Shell Shock will use the provided string as an application specific environment variable prefix, convert the option name to {@link https://stringcase.org/cases/constant/ | constant case}, and prepend the provided `string` value to determine the corresponding environment variable name. For example, if an option is named `\"configPath\"` and the `autoAssignEnv` is `\"MY_APP_\"`, Shell Shock will look for an environment variable named `\"MY_APP_CONFIG_PATH\"` and assign its value to the option if it exists. If set to `true`, Shell Shock will use a default environment variable prefix derived from the {@link Options.name | application name}.\n *\n * @see https://medium.com/chingu/an-introduction-to-environment-variables-and-how-to-use-them-f602f66d15fa\n * @see https://stringcase.org/cases/constant/\n */\n autoAssignEnv?: true | string;\n\n /**\n * A URL to the application documentation or reference.\n *\n * @remarks\n * This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.\n */\n reference?: ReferenceOptions | string;\n};\n\n/**\n * The plugin options for Shell Shock.\n */\nexport type Options = BaseOptions & Partial<NodeJsPluginOptions>;\n\n/**\n * The output configuration options for Shell Shock.\n */\nexport type OutputConfig = Pick<\n PowerlinesOutputConfig,\n \"path\" | \"copy\" | \"storage\"\n> & {\n /**\n * An indicator specifying whether to generate TypeScript declaration files (.d.ts) during the build process.\n */\n dts?: false;\n};\n\n/**\n * The user configuration options for Shell Shock.\n */\nexport type UserConfig = BaseOptions &\n Partial<NodeJsPluginUserConfig> & {\n /**\n * Configuration for the output of the build process\n */\n output?: OutputConfig;\n };\n\n/**\n * The resolved configuration options for Shell Shock.\n */\nexport type ResolvedConfig = TsdownPluginResolvedConfig &\n AutoMDPluginResolvedConfig &\n NodeJsPluginResolvedConfig &\n Required<Omit<Options, \"bin\" | \"reference\">> & {\n /**\n * The name of the binary (the {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | \"bin\" field} in package.json) that will be used to run the application through NodeJs package managers (e.g., npm, yarn, pnpm).\n *\n * @remarks\n * If an array is provided, each binary will be linked to the same compiled output file. If not provided, the {@link Options.name | name} option will be used.\n *\n * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin\n * @see https://yarnpkg.com/cli/bin\n * @see https://pnpm.io/package_json#bin\n */\n bin: Record<string, string>;\n\n /**\n * The URL(s) to the application documentation or reference.\n */\n reference: ReferenceOptions;\n\n /**\n * The command-line application specific environment variable prefix used for automatically assigning environment variables to command options.\n */\n appSpecificEnvPrefix: string;\n\n /**\n * The user configuration for the Shell Shock process.\n */\n userConfig: UserConfig;\n };\n"],"mappings":";;;AAAA,MAAM,UAAU;CAAC;CAAK;CAAK;CAAQ;CAA4B;;;;;;AAE/D,MAAM,cAAc;CAAA;CAAM;CAAW;CAAM;;;;;;;;;AAE3C,MAAM,YAAS;CAAA;CAAS;CAAG;CAAY;CAAqB;AAC5D,MAAI,aAAc;CAAA;CAAM;CAAA;CAAe;CAA4B;AACnE,MAAM,kBAAkB;OAAC;CAAa;CAAS;CAAA;CAAa;CAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACnE,MAAK,sBAAuB;CAAC;CAAE;CAAiB;CAAmB;CAAW;AAE9E,MAAC,iBAAsB;OAAI;OAAqB;CAAC;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;AACjD,MAAC,aAAkB;OAAO;OAAoB;CAAc;CAAO;CAAA;AAEnE,MAAC,kBAAuB;OAAG;CAAQ;CAAa;CAAK;CAAA;CAAA;CAAA;CAAA;CAAA;AAErD,MAAM,gBAAQ;OAAa;OAAS;OAAA;CAAA;CAAA;CAAA;CAAA;AAEpC,MAAM,oBAAoB;OAAO;OAAmB;OAAe;CAAG;CAAA;OAAA;CAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/dist/types/config.d.cts
CHANGED
|
@@ -16,7 +16,7 @@ interface ReferenceOptions {
|
|
|
16
16
|
* A URL to the application command specific documentation or reference.
|
|
17
17
|
*
|
|
18
18
|
* @remarks
|
|
19
|
-
* This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{
|
|
19
|
+
* This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.
|
|
20
20
|
*/
|
|
21
21
|
commands?: string;
|
|
22
22
|
}
|
|
@@ -59,7 +59,7 @@ type BaseOptions = Partial<BuildOptions> & {
|
|
|
59
59
|
* A URL to the application documentation or reference.
|
|
60
60
|
*
|
|
61
61
|
* @remarks
|
|
62
|
-
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{
|
|
62
|
+
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.
|
|
63
63
|
*/
|
|
64
64
|
reference?: ReferenceOptions | string;
|
|
65
65
|
};
|
package/dist/types/config.d.mts
CHANGED
|
@@ -16,7 +16,7 @@ interface ReferenceOptions {
|
|
|
16
16
|
* A URL to the application command specific documentation or reference.
|
|
17
17
|
*
|
|
18
18
|
* @remarks
|
|
19
|
-
* This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{
|
|
19
|
+
* This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.
|
|
20
20
|
*/
|
|
21
21
|
commands?: string;
|
|
22
22
|
}
|
|
@@ -59,7 +59,7 @@ type BaseOptions = Partial<BuildOptions> & {
|
|
|
59
59
|
* A URL to the application documentation or reference.
|
|
60
60
|
*
|
|
61
61
|
* @remarks
|
|
62
|
-
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{
|
|
62
|
+
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.
|
|
63
63
|
*/
|
|
64
64
|
reference?: ReferenceOptions | string;
|
|
65
65
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/types/config.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 { AutoMDPluginResolvedConfig } from \"@powerlines/plugin-automd/types/plugin\";\nimport type {\n NodeJsPluginOptions,\n NodeJsPluginResolvedConfig,\n NodeJsPluginUserConfig\n} from \"@powerlines/plugin-nodejs/types/plugin\";\nimport type {\n TsdownPluginResolvedConfig,\n TsdownPluginUserConfig\n} from \"@powerlines/plugin-tsdown/types/plugin\";\nimport type { OutputConfig as PowerlinesOutputConfig } from \"powerlines\";\nimport type { CommandBase, CommandOption } from \"./command\";\nimport type { Context } from \"./context\";\n\ntype BuildOptions = Pick<\n TsdownPluginUserConfig,\n | \"root\"\n | \"name\"\n | \"title\"\n | \"description\"\n | \"logLevel\"\n | \"mode\"\n | \"skipCache\"\n | \"autoInstall\"\n | \"plugins\"\n | \"tsconfig\"\n | \"tsconfigRaw\"\n>;\n\nexport interface ReferenceOptions {\n /**\n * A URL to the application documentation or reference.\n */\n app: string;\n\n /**\n * A URL to the application command specific documentation or reference.\n *\n * @remarks\n * This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/types/config.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 { AutoMDPluginResolvedConfig } from \"@powerlines/plugin-automd/types/plugin\";\nimport type {\n NodeJsPluginOptions,\n NodeJsPluginResolvedConfig,\n NodeJsPluginUserConfig\n} from \"@powerlines/plugin-nodejs/types/plugin\";\nimport type {\n TsdownPluginResolvedConfig,\n TsdownPluginUserConfig\n} from \"@powerlines/plugin-tsdown/types/plugin\";\nimport type { OutputConfig as PowerlinesOutputConfig } from \"powerlines\";\nimport type { CommandBase, CommandOption } from \"./command\";\nimport type { Context } from \"./context\";\n\ntype BuildOptions = Pick<\n TsdownPluginUserConfig,\n | \"root\"\n | \"name\"\n | \"title\"\n | \"description\"\n | \"logLevel\"\n | \"mode\"\n | \"skipCache\"\n | \"autoInstall\"\n | \"plugins\"\n | \"tsconfig\"\n | \"tsconfigRaw\"\n>;\n\nexport interface ReferenceOptions {\n /**\n * A URL to the application documentation or reference.\n */\n app: string;\n\n /**\n * A URL to the application command specific documentation or reference.\n *\n * @remarks\n * This URL is expected to contain the token `{command}`, which will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.\n */\n commands?: string;\n}\n\ntype BaseOptions = Partial<BuildOptions> & {\n /**\n * A set of global command options to apply to each command.\n *\n * @remarks\n * Each command will inherit these global options. To disable the addition of these global options, set this property to `false`, or provide a custom set of options/a function that returns them. A `GlobalOptions` interface will be created by the `shell-shock typegen` command and added to the generated `shell-shock.d.ts` file.\n */\n globalOptions?:\n | CommandOption[]\n | ((context: Context, input: CommandBase) => CommandOption[])\n | false;\n\n /**\n * Determines whether commands and option names are treated as case-sensitive.\n *\n * @defaultValue `false`\n */\n isCaseSensitive?: boolean;\n\n /**\n * The name of the binary (the {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | \"bin\" field} in package.json) that will be used to run the application through NodeJs package managers (e.g., npm, yarn, pnpm).\n *\n * @remarks\n * If an array is provided, each binary will be linked to the same compiled output file. If not provided, the {@link Options.name | name} option will be used.\n *\n * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin\n * @see https://yarnpkg.com/cli/bin\n * @see https://pnpm.io/package_json#bin\n */\n bin?: string | string[];\n\n /**\n * Should Shell Shock attempt to automatically assign environment variables to manipulate default values for command options based on the option name?\n *\n * @remarks\n * If set to a string, Shell Shock will use the provided string as an application specific environment variable prefix, convert the option name to {@link https://stringcase.org/cases/constant/ | constant case}, and prepend the provided `string` value to determine the corresponding environment variable name. For example, if an option is named `\"configPath\"` and the `autoAssignEnv` is `\"MY_APP_\"`, Shell Shock will look for an environment variable named `\"MY_APP_CONFIG_PATH\"` and assign its value to the option if it exists. If set to `true`, Shell Shock will use a default environment variable prefix derived from the {@link Options.name | application name}.\n *\n * @see https://medium.com/chingu/an-introduction-to-environment-variables-and-how-to-use-them-f602f66d15fa\n * @see https://stringcase.org/cases/constant/\n */\n autoAssignEnv?: true | string;\n\n /**\n * A URL to the application documentation or reference.\n *\n * @remarks\n * This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.\n */\n reference?: ReferenceOptions | string;\n};\n\n/**\n * The plugin options for Shell Shock.\n */\nexport type Options = BaseOptions & Partial<NodeJsPluginOptions>;\n\n/**\n * The output configuration options for Shell Shock.\n */\nexport type OutputConfig = Pick<\n PowerlinesOutputConfig,\n \"path\" | \"copy\" | \"storage\"\n> & {\n /**\n * An indicator specifying whether to generate TypeScript declaration files (.d.ts) during the build process.\n */\n dts?: false;\n};\n\n/**\n * The user configuration options for Shell Shock.\n */\nexport type UserConfig = BaseOptions &\n Partial<NodeJsPluginUserConfig> & {\n /**\n * Configuration for the output of the build process\n */\n output?: OutputConfig;\n };\n\n/**\n * The resolved configuration options for Shell Shock.\n */\nexport type ResolvedConfig = TsdownPluginResolvedConfig &\n AutoMDPluginResolvedConfig &\n NodeJsPluginResolvedConfig &\n Required<Omit<Options, \"bin\" | \"reference\">> & {\n /**\n * The name of the binary (the {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | \"bin\" field} in package.json) that will be used to run the application through NodeJs package managers (e.g., npm, yarn, pnpm).\n *\n * @remarks\n * If an array is provided, each binary will be linked to the same compiled output file. If not provided, the {@link Options.name | name} option will be used.\n *\n * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin\n * @see https://yarnpkg.com/cli/bin\n * @see https://pnpm.io/package_json#bin\n */\n bin: Record<string, string>;\n\n /**\n * The URL(s) to the application documentation or reference.\n */\n reference: ReferenceOptions;\n\n /**\n * The command-line application specific environment variable prefix used for automatically assigning environment variables to command options.\n */\n appSpecificEnvPrefix: string;\n\n /**\n * The user configuration for the Shell Shock process.\n */\n userConfig: UserConfig;\n };\n"],"mappings":";AAAA,MAAM,UAAU;CAAC;CAAK;CAAK;CAAQ;CAA4B;;;;;;AAE/D,MAAM,cAAc;CAAA;CAAM;CAAW;CAAM;;;;;;;;;AAE3C,MAAM,YAAS;CAAA;CAAS;CAAG;CAAY;CAAqB;AAC5D,MAAI,aAAc;CAAA;CAAM;CAAA;CAAe;CAA4B;AACnE,MAAM,kBAAkB;OAAC;CAAa;CAAS;CAAA;CAAa;CAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACnE,MAAK,sBAAuB;CAAC;CAAE;CAAiB;CAAmB;CAAW;AAE9E,MAAC,iBAAsB;OAAI;OAAqB;CAAC;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;AACjD,MAAC,aAAkB;OAAO;OAAoB;CAAc;CAAO;CAAA;AAEnE,MAAC,kBAAuB;OAAG;CAAQ;CAAa;CAAK;CAAA;CAAA;CAAA;CAAA;CAAA;AAErD,MAAM,gBAAQ;OAAa;OAAS;OAAA;CAAA;CAAA;CAAA;CAAA;AAEpC,MAAM,oBAAoB;OAAO;OAAmB;OAAe;CAAG;CAAA;OAAA;CAAA;OAAA;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shell-shock/core",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing the core Shell Shock functionality used to build and manage a command-line application.",
|
|
6
6
|
"repository": {
|
|
@@ -352,12 +352,12 @@
|
|
|
352
352
|
"@alloy-js/core": "0.23.0-dev.8",
|
|
353
353
|
"@alloy-js/markdown": "0.23.0-dev.1",
|
|
354
354
|
"@alloy-js/typescript": "0.23.0-dev.4",
|
|
355
|
-
"@powerlines/deepkit": "^0.6.
|
|
356
|
-
"@powerlines/plugin-alloy": "^0.25.
|
|
357
|
-
"@powerlines/plugin-automd": "^0.1.
|
|
358
|
-
"@powerlines/plugin-deepkit": "^0.11.
|
|
359
|
-
"@powerlines/plugin-nodejs": "^0.1.
|
|
360
|
-
"@powerlines/plugin-tsdown": "^0.1.
|
|
355
|
+
"@powerlines/deepkit": "^0.6.147",
|
|
356
|
+
"@powerlines/plugin-alloy": "^0.25.54",
|
|
357
|
+
"@powerlines/plugin-automd": "^0.1.368",
|
|
358
|
+
"@powerlines/plugin-deepkit": "^0.11.247",
|
|
359
|
+
"@powerlines/plugin-nodejs": "^0.1.290",
|
|
360
|
+
"@powerlines/plugin-tsdown": "^0.1.316",
|
|
361
361
|
"@standard-schema/spec": "^1.1.0",
|
|
362
362
|
"@standard-schema/utils": "^0.3.0",
|
|
363
363
|
"@stryke/cli": "^0.13.35",
|
|
@@ -373,16 +373,16 @@
|
|
|
373
373
|
"automd": "^0.4.3",
|
|
374
374
|
"defu": "^6.1.4",
|
|
375
375
|
"json-schema": "^0.4.0",
|
|
376
|
-
"powerlines": "^0.42.
|
|
376
|
+
"powerlines": "^0.42.9",
|
|
377
377
|
"tsdown": "^0.21.4"
|
|
378
378
|
},
|
|
379
379
|
"devDependencies": {
|
|
380
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
380
|
+
"@powerlines/plugin-plugin": "^0.12.319",
|
|
381
381
|
"@types/json-schema": "^7.0.15",
|
|
382
382
|
"@types/node": "^25.5.0",
|
|
383
383
|
"typescript": "^5.9.3",
|
|
384
384
|
"zod": "^4.3.6"
|
|
385
385
|
},
|
|
386
386
|
"publishConfig": { "access": "public" },
|
|
387
|
-
"gitHead": "
|
|
387
|
+
"gitHead": "bb9aa600d0f9effbd29eabb7bb096267a461059e"
|
|
388
388
|
}
|