Skip to content

Commit

Permalink
fix(pm-x): make version optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 22, 2024
1 parent 5fe253e commit ffada82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/2.generators/pm-x.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ The `pm-x` generator generates commands for running/executing a package through
- `name`: The package name (by default tries to read from the `name` field in `package.json`).
- `separate`: Separate code blocks for each package manager (defaults to `false`).
- `args`: An additional string appended at the end of each command suggesting arguments to be used with the program. (defaults to `""`).
- `version`: Show version in exec command
8 changes: 7 additions & 1 deletion src/generators/pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ export const pmX = defineGenerator({
};
}

let versionSuffix = "";
if (args.version) {
versionSuffix =
typeof args.version === "string" ? `@${args.version}` : `@${version}`;
}

const contents = RUN_COMMANDS.map(
([pm, cmd]) =>
`# ${pm}\n${cmd} ${name}@${version ? `${version}` : ""}${args.args ? ` ${args.args}` : ""}`,
`# ${pm}\n${cmd} ${name}${versionSuffix}${args.args ? ` ${args.args}` : ""}`,
);

if ((args.separate ?? false) === false) {
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

```sh
# npm
npx automd@0.3.4 .
npx automd .

# pnpm
pnpm dlx automd@0.3.4 .
pnpm dlx automd .

# bun
bunx automd@0.3.4 .
bunx automd .
```

<!-- /automd -->
Expand Down

0 comments on commit ffada82

Please sign in to comment.