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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
29 changes: 25 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -264,12 +264,14 @@ export async function create({
to: distFolder,
version,
skipFiles,
packageManager,
});
copyFolder({
from: srcFolder,
to: distFolder,
version,
packageName,
packageManager,
skipFiles,
});

Expand All @@ -294,6 +296,7 @@ export async function create({
to: distFolder,
version,
skipFiles,
packageManager,
isMergePackageJson: true,
});

Expand All @@ -307,6 +310,7 @@ export async function create({
to: distFolder,
version,
skipFiles,
packageManager,
isMergePackageJson: true,
});

Expand All @@ -324,16 +328,19 @@ 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
? noteInformation
: [
`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) {
Expand Down Expand Up @@ -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
Expand All @@ -396,13 +409,15 @@ export function copyFolder({
to,
version,
packageName,
packageManager,
isMergePackageJson,
skipFiles = [],
}: {
from: string;
to: string;
version?: string | Record<string, string>;
packageName?: string;
packageManager: string;
isMergePackageJson?: boolean;
skipFiles?: string[];
}) {
Expand Down Expand Up @@ -430,6 +445,7 @@ export function copyFolder({
copyFolder({
from: srcFile,
to: distFile,
packageManager,
version,
skipFiles,
});
Expand All @@ -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));
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions template-biome/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion template-eslint/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

### ESLint

- Run `npm run lint` to lint your code
- Run `{{ packageManager }} run lint` to lint your code
2 changes: 1 addition & 1 deletion template-prettier/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

### Prettier

- Run `npm run format` to format your code
- Run `{{ packageManager }} run format` to format your code
14 changes: 7 additions & 7 deletions test/agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/agents-md/template-vanilla/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

### Rstest

- Run `npm run test` to test your code
- Run `{{ packageManager }} run test` to test your code
Loading