| 671 | ) |
| 672 | |
| 673 | const write = (file: string, content?: string) => { |
| 674 | const targetPath = path.join(root, renameFiles[file] ?? file) |
| 675 | if (content) { |
| 676 | fs.writeFileSync(targetPath, content) |
| 677 | } else if (file === 'index.html') { |
| 678 | const templatePath = path.join(templateDir, file) |
| 679 | const templateContent = fs.readFileSync(templatePath, 'utf-8') |
| 680 | const updatedContent = templateContent.replace( |
| 681 | /<title>.*?<\/title>/, |
| 682 | `<title>${packageName}</title>`, |
| 683 | ) |
| 684 | fs.writeFileSync(targetPath, updatedContent) |
| 685 | } else { |
| 686 | copy(path.join(templateDir, file), targetPath) |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | const files = fs.readdirSync(templateDir) |
| 691 | for (const file of files.filter((f) => f !== 'package.json')) { |