diff --git a/docs/2.generators/pm-install.md b/docs/2.generators/pm-install.md index e495113..0371f16 100644 --- a/docs/2.generators/pm-install.md +++ b/docs/2.generators/pm-install.md @@ -4,16 +4,16 @@ The `pm-install` or `pm-i` generator generates installation commands for several ## Example - + ### Input - + ### Output - + ```sh # ✨ Auto-detect @@ -42,3 +42,4 @@ The `pm-install` or `pm-i` generator generates installation commands for several - `dev`: Install as a dev dependency (defaults to `false`). - `separate`: Separate code blocks for each package manager (defaults to `false`). - `auto`: Auto-detect package manager using [unjs/nypm](https://github.com/unjs/nypm#-nypm) (defaults to `true`). +- `version`: Show version in install command diff --git a/src/generators/pm.ts b/src/generators/pm.ts index 30fbee6..ff32481 100644 --- a/src/generators/pm.ts +++ b/src/generators/pm.ts @@ -30,9 +30,15 @@ export const pmInstall = defineGenerator({ INSTALL_COMMANDS.unshift(["npx nypm", "i"]); } + let versionSuffix = ""; + if (args.version) { + versionSuffix = + typeof args.version === "string" ? `@${args.version}` : `@^${version}`; + } + const contents = INSTALL_COMMANDS.map( ([cmd, install]) => - `# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? " -D" : ""} ${name}${version ? `@^${version}` : ""}`, + `# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? " -D" : ""} ${name}${versionSuffix}`, ); if ((args.separate ?? false) === false) { diff --git a/test/fixture/INPUT.md b/test/fixture/INPUT.md index 281264d..ac559c7 100644 --- a/test/fixture/INPUT.md +++ b/test/fixture/INPUT.md @@ -12,7 +12,7 @@ ## `pm-install` - + ## `jsdocs` diff --git a/test/fixture/OUTPUT.md b/test/fixture/OUTPUT.md index 05ca579..0a8c13f 100644 --- a/test/fixture/OUTPUT.md +++ b/test/fixture/OUTPUT.md @@ -30,7 +30,7 @@ bunx automd@0.3.3 . ## `pm-install` - + ```sh # ✨ Auto-detect