Skip to content

Commit

Permalink
fix(create-mud): ensure gitignore is copied (#3492)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Jan 23, 2025
1 parent ffefc8f commit 923ab7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/create-mud/scripts/copy-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const __dirname = path.dirname(__filename);

if (/package\.json$/.test(destPath)) {
let source = await fs.readFile(sourcePath, "utf-8");
// Replace all MUD package links with mustache placeholder used by create-create-app
// that will be replaced with the latest MUD version number when the template is used.
// Replace all MUD package links with placeholder that we can use to later replace
// with the latest MUD version number when the template is used.
source = source.replace(/"([^"]+)":\s*"(link|file):[^"]+"/g, (match, packageName) =>
mudPackageNames.includes(packageName) ? `"${packageName}": "{{mud-version}}"` : match,
);
Expand All @@ -51,8 +51,13 @@ const __dirname = path.dirname(__filename);
}
// Replace template workspace root `tsconfig.json` files (which have paths relative to monorepo)
// with one that inherits our base tsconfig.
else if (/templates\/[^/]+\/tsconfig\.json/.test(destPath)) {
else if (/templates\/[^/]+\/tsconfig\.json$/.test(destPath)) {
await fs.copyFile(path.join(__dirname, "tsconfig.base.json"), destPath);
}
// npm excludes .gitignore files during packaging/publishing, so we move this aside for now.
// When creating a project from the template, we'll move this back.
else if (/\.gitignore$/.test(destPath)) {
await fs.copyFile(sourcePath, destPath.replace(/\.gitignore$/, ".gitignore_"));
} else {
await fs.copyFile(sourcePath, destPath);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/create-mud/src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function run() {
if (/package\.json$/.test(sourceFile)) {
const source = await fs.readFile(sourceFile, "utf-8");
await fs.writeFile(destFile, source.replaceAll(/{{mud-version}}/g, args.mudVersion), "utf-8");
} else if (/\.gitignore_$/.test(sourceFile)) {
await fs.copyFile(sourceFile, destFile.replace(/_$/, ""));
} else {
await fs.copyFile(sourceFile, destFile);
}
Expand Down

0 comments on commit 923ab7f

Please sign in to comment.