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/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/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 66da09b..b1c0b04 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 @@ -117,12 +117,12 @@ 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 - - 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 @@ -180,11 +180,11 @@ 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 - - Run \`npm run lint\` to lint your code + - Run \`pnpm run lint\` to lint your code ## Template Info @@ -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 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