From 5d2ca34c0a8fe2cab849b12b3a0550d85628d4de Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 20 Nov 2025 13:18:49 +0800 Subject: [PATCH 1/3] feat: add placeholder replacement for package manager in markdown files --- src/index.ts | 29 ++++++++++++++++--- test/agents.test.ts | 2 +- .../agents-md/template-vanilla/AGENTS.md | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index fe0c749..e44f43f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -204,7 +204,7 @@ export async function create({ const cwd = process.cwd(); const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent); - const pkgManager = pkgInfo ? pkgInfo.name : 'npm'; + const packageManager = pkgInfo ? pkgInfo.name : 'npm'; // No version provided, read from package.json if (!version) { @@ -264,12 +264,14 @@ export async function create({ to: distFolder, version, skipFiles, + packageManager, }); copyFolder({ from: srcFolder, to: distFolder, version, packageName, + packageManager, skipFiles, }); @@ -294,6 +296,7 @@ export async function create({ to: distFolder, version, skipFiles, + packageManager, isMergePackageJson: true, }); @@ -307,6 +310,7 @@ export async function create({ to: distFolder, version, skipFiles, + packageManager, isMergePackageJson: true, }); @@ -324,7 +328,10 @@ export async function create({ if (agentsFiles.length > 0) { const mergedAgents = mergeAgentsFiles(agentsFiles); const agentsPath = path.join(distFolder, 'AGENTS.md'); - fs.writeFileSync(agentsPath, `${mergedAgents}\n`); + fs.writeFileSync( + agentsPath, + `${replacePlaceholder(mergedAgents, packageManager)}\n`, + ); } const nextSteps = noteInformation @@ -332,8 +339,8 @@ export async function create({ : [ `1. ${color.cyan(`cd ${targetDir}`)}`, `2. ${color.cyan('git init')} ${color.dim('(optional)')}`, - `3. ${color.cyan(`${pkgManager} install`)}`, - `4. ${color.cyan(`${pkgManager} run dev`)}`, + `3. ${color.cyan(`${packageManager} install`)}`, + `4. ${color.cyan(`${packageManager} run dev`)}`, ]; if (nextSteps.length) { @@ -382,6 +389,12 @@ export function mergePackageJson(targetPackage: string, extraPackage: string) { fs.writeFileSync(targetPackage, `${JSON.stringify(mergedJson, null, 2)}\n`); } +const isMarkdown = (file: string) => + file.endsWith('.md') || file.endsWith('.mdx'); + +const replacePlaceholder = (content: string, packageManager: string) => + content.replace(/{{ packageManager }}/g, packageManager); + /** * Copy files from one folder to another. * @param from Source folder @@ -396,6 +409,7 @@ export function copyFolder({ to, version, packageName, + packageManager, isMergePackageJson, skipFiles = [], }: { @@ -403,6 +417,7 @@ export function copyFolder({ to: string; version?: string | Record; packageName?: string; + packageManager: string; isMergePackageJson?: boolean; skipFiles?: string[]; }) { @@ -430,6 +445,7 @@ export function copyFolder({ copyFolder({ from: srcFile, to: distFile, + packageManager, version, skipFiles, }); @@ -444,6 +460,11 @@ export function copyFolder({ updatePackageJson(distFile, version, packageName); } else { fs.copyFileSync(srcFile, distFile); + + if (isMarkdown(distFile)) { + const content = fs.readFileSync(distFile, 'utf-8'); + fs.writeFileSync(distFile, replacePlaceholder(content, packageManager)); + } } } } diff --git a/test/agents.test.ts b/test/agents.test.ts index 66da09b..2c47ead 100644 --- a/test/agents.test.ts +++ b/test/agents.test.ts @@ -62,7 +62,7 @@ test('should generate AGENTS.md with no tools selected', async () => { ### Rstest - - Run \`npm run test\` to test your code + - Run \`pnpm run test\` to test your code ## Template Info diff --git a/test/fixtures/agents-md/template-vanilla/AGENTS.md b/test/fixtures/agents-md/template-vanilla/AGENTS.md index 7c49a5f..ba83971 100644 --- a/test/fixtures/agents-md/template-vanilla/AGENTS.md +++ b/test/fixtures/agents-md/template-vanilla/AGENTS.md @@ -9,4 +9,4 @@ ### Rstest -- Run `npm run test` to test your code +- Run `{{ packageManager }} run test` to test your code From 11d21196b7f4476503ef120802452d14c8a4e6aa Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 20 Nov 2025 13:21:20 +0800 Subject: [PATCH 2/3] fix --- test/agents.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/agents.test.ts b/test/agents.test.ts index 2c47ead..895c098 100644 --- a/test/agents.test.ts +++ b/test/agents.test.ts @@ -117,7 +117,7 @@ test('should generate AGENTS.md with single tool selected', async () => { ### Rstest - - Run \`npm run test\` to test your code + - Run \`pnpm run test\` to test your code ### Biome @@ -180,7 +180,7 @@ test('should generate AGENTS.md with eslint tool and template mapping', async () ### Rstest - - Run \`npm run test\` to test your code + - Run \`pnpm run test\` to test your code ### ESLint @@ -230,7 +230,7 @@ test('should merge top-level sections from AGENTS.md files', async () => { ### Rstest - - Run \`npm run test\` to test your code + - Run \`pnpm run test\` to test your code ## Template Info From 40c5b9c6f27edc18503ffa9a04f54282c2cc5bd2 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 20 Nov 2025 13:22:39 +0800 Subject: [PATCH 3/3] fix --- package.json | 2 +- template-biome/AGENTS.md | 4 ++-- template-eslint/AGENTS.md | 2 +- template-prettier/AGENTS.md | 2 +- test/agents.test.ts | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a78bc4b..e55b295 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "dev": "rslib build --watch", "lint": "biome check .", "lint:write": "biome check . --write", - "prepare": "simple-git-hooks && npm run build", + "prepare": "simple-git-hooks && pnpm run build", "test": "rstest run", "bump": "npx bumpp" }, diff --git a/template-biome/AGENTS.md b/template-biome/AGENTS.md index c26c433..a5be109 100644 --- a/template-biome/AGENTS.md +++ b/template-biome/AGENTS.md @@ -2,5 +2,5 @@ ### Biome -- Run `npm run lint` to lint your code -- Run `npm run format` to format your code +- Run `{{ packageManager }} run lint` to lint your code +- Run `{{ packageManager }} run format` to format your code diff --git a/template-eslint/AGENTS.md b/template-eslint/AGENTS.md index 2226fc4..209e9bc 100644 --- a/template-eslint/AGENTS.md +++ b/template-eslint/AGENTS.md @@ -2,4 +2,4 @@ ### ESLint -- Run `npm run lint` to lint your code +- Run `{{ packageManager }} run lint` to lint your code diff --git a/template-prettier/AGENTS.md b/template-prettier/AGENTS.md index 7b57953..ebc03f4 100644 --- a/template-prettier/AGENTS.md +++ b/template-prettier/AGENTS.md @@ -2,4 +2,4 @@ ### Prettier -- Run `npm run format` to format your code +- Run `{{ packageManager }} run format` to format your code diff --git a/test/agents.test.ts b/test/agents.test.ts index 895c098..b1c0b04 100644 --- a/test/agents.test.ts +++ b/test/agents.test.ts @@ -121,8 +121,8 @@ test('should generate AGENTS.md with single tool selected', async () => { ### Biome - - Run \`npm run lint\` to lint your code - - Run \`npm run format\` to format your code + - Run \`pnpm run lint\` to lint your code + - Run \`pnpm run format\` to format your code ## Template Info @@ -184,7 +184,7 @@ test('should generate AGENTS.md with eslint tool and template mapping', async () ### ESLint - - Run \`npm run lint\` to lint your code + - Run \`pnpm run lint\` to lint your code ## Template Info