Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ const main = defineCommand({
const project = createDefaultTemplate(
Object.fromEntries(deps.entries()),
isCommentWithDev,
selectedPackageManager,
);

for (const filePath of Object.keys(project)) {
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { installCommands } from "@pkg-pr-new/utils";

function generateShellCommand(
url: string,
isCommentWithDev: boolean,
selectedPackageManager: ("npm" | "yarn" | "pnpm" | "bun")[],
) {
return selectedPackageManager
.map(
(pm) =>
`\`\`\`sh\n${installCommands[pm]} ${url + (isCommentWithDev ? " -D" : "")}\n\`\`\``,
)
.join("\n");
}

export const createDefaultTemplate = (
dependencies: Record<string, string>,
isCommentWithDev: boolean,
selectedPackageManager: ("npm" | "yarn" | "pnpm" | "bun")[],
) => ({
"index.js": "",
"README.md": `
Expand All @@ -15,12 +31,8 @@ Templates are particularly useful for creating live, interactive examples of you
As a user, you can check the package.json file and see the new generated packages! You can just copy those and put them in your package.json or install them with your favorite package manager.

${Object.values(dependencies)
.map(
(url) => `
\`\`\`sh
npm i ${url + (isCommentWithDev ? " -D" : "")}
\`\`\`
`,
.map((url) =>
generateShellCommand(url, isCommentWithDev, selectedPackageManager),
)
.join("")}

Expand Down
Loading