@@ -3,9 +3,9 @@ import * as path from 'node:path';
33import { renameFile , walkDirectory } from './fs.js' ;
44
55/**
6- * Placeholder name used in template, that should be replaced with project name.
6+ * Placeholder name used in template, that should be replaced with normalized project name.
77 */
8- const DEFAULT_PLACEHOLDER_NAME = 'HelloWorld' ;
8+ const PLACEHOLDER_NAME = 'HelloWorld' ;
99
1010/**
1111 * Rename common files that cannot be put into template literaly, e.g. .gitignore.
@@ -24,38 +24,41 @@ export function renameCommonFiles(projectPath: string) {
2424 * - Rename paths containing placeholder
2525 * - Replace placeholder in text files
2626 */
27- export function replacePlaceholder ( projectPath : string , projectName : string ) {
28- if ( projectName === DEFAULT_PLACEHOLDER_NAME ) {
27+ export function replacePlaceholder (
28+ projectPath : string ,
29+ normalizedName : string
30+ ) {
31+ if ( normalizedName === PLACEHOLDER_NAME ) {
2932 return ;
3033 }
3134
3235 for ( const filePath of walkDirectory ( projectPath ) . reverse ( ) ) {
3336 if ( ! fs . statSync ( filePath ) . isDirectory ( ) ) {
34- replacePlaceholderInTextFile ( filePath , projectName ) ;
37+ replacePlaceholderInTextFile ( filePath , normalizedName ) ;
3538 }
3639
37- if ( path . basename ( filePath ) . includes ( DEFAULT_PLACEHOLDER_NAME ) ) {
38- renameFile ( filePath , DEFAULT_PLACEHOLDER_NAME , projectName ) ;
40+ if ( path . basename ( filePath ) . includes ( PLACEHOLDER_NAME ) ) {
41+ renameFile ( filePath , PLACEHOLDER_NAME , normalizedName ) ;
3942 } else if (
40- path . basename ( filePath ) . includes ( DEFAULT_PLACEHOLDER_NAME . toLowerCase ( ) )
43+ path . basename ( filePath ) . includes ( PLACEHOLDER_NAME . toLowerCase ( ) )
4144 ) {
4245 renameFile (
4346 filePath ,
44- DEFAULT_PLACEHOLDER_NAME . toLowerCase ( ) ,
45- projectName . toLowerCase ( )
47+ PLACEHOLDER_NAME . toLowerCase ( ) ,
48+ normalizedName . toLowerCase ( )
4649 ) ;
4750 }
4851 }
4952}
5053
51- function replacePlaceholderInTextFile ( filePath : string , projectName : string ) {
54+ function replacePlaceholderInTextFile (
55+ filePath : string ,
56+ normalizedName : string
57+ ) {
5258 const fileContent = fs . readFileSync ( filePath , 'utf8' ) ;
5359 const replacedFileContent = fileContent
54- . replaceAll ( DEFAULT_PLACEHOLDER_NAME , projectName )
55- . replaceAll (
56- DEFAULT_PLACEHOLDER_NAME . toLowerCase ( ) ,
57- projectName . toLowerCase ( )
58- ) ;
60+ . replaceAll ( PLACEHOLDER_NAME , normalizedName )
61+ . replaceAll ( PLACEHOLDER_NAME . toLowerCase ( ) , normalizedName . toLowerCase ( ) ) ;
5962
6063 if ( fileContent !== replacedFileContent ) {
6164 fs . writeFileSync ( filePath , replacedFileContent , 'utf8' ) ;
0 commit comments