@@ -6,7 +6,7 @@ import * as _ from 'lodash';
66import * as mkdirp from 'mkdirp' ;
77import * as rimraf from 'rimraf' ;
88
9- const textFileExtensions = [ '.gitignore' , '.config' , '.cs' , '.cshtml' , 'Dockerfile' , '.html' , '.js' , '.json' , '.jsx' , '.md' , '.ts' , '.tsx' , '.xproj' ] ;
9+ const textFileExtensions = [ '.gitignore' , 'template_gitignore' , ' .config', '.cs' , '.cshtml' , 'Dockerfile' , '.html' , '.js' , '.json' , '.jsx' , '.md' , '.ts' , '.tsx' , '.xproj' ] ;
1010
1111const templates = {
1212 'angular-2' : '../../templates/Angular2Spa/' ,
@@ -33,12 +33,15 @@ function isTextFile(filename: string): boolean {
3333
3434function writeFileEnsuringDirExists ( root : string , filename : string , contents : string | Buffer ) {
3535 let fullPath = path . join ( root , filename ) ;
36- mkdirp . sync ( path . dirname ( fullPath ) ) ;
36+ mkdirp . sync ( path . dirname ( fullPath ) ) ;
3737 fs . writeFileSync ( fullPath , contents ) ;
3838}
3939
40- function listFilesExcludingGitignored ( root : string ) : string [ ] {
41- let gitIgnorePath = path . join ( root , '.gitignore' ) ;
40+ function listFilesExcludingGitignored ( root : string ) : string [ ] {
41+ // Note that the gitignore files, prior to be written by the generator, are called 'template_gitignore'
42+ // instead of '.gitignore'. This is a workaround for Yeoman doing strange stuff with .gitignore files
43+ // (it renames them to .npmignore, which is not helpful).
44+ let gitIgnorePath = path . join ( root , 'template_gitignore' ) ;
4245 let gitignoreEvaluator = fs . existsSync ( gitIgnorePath )
4346 ? gitignore . compile ( fs . readFileSync ( gitIgnorePath , 'utf8' ) )
4447 : { accepts : ( ) => true } ;
@@ -49,36 +52,36 @@ function listFilesExcludingGitignored(root: string): string[] {
4952function writeTemplate ( sourceRoot : string , destRoot : string ) {
5053 listFilesExcludingGitignored ( sourceRoot ) . forEach ( fn => {
5154 let sourceContent = fs . readFileSync ( path . join ( sourceRoot , fn ) ) ;
52-
55+
5356 // For text files, replace hardcoded values with template tags
5457 if ( isTextFile ( fn ) ) {
5558 let sourceText = sourceContent . toString ( 'utf8' ) ;
5659 contentReplacements . forEach ( replacement => {
5760 sourceText = sourceText . replace ( replacement . from , replacement . to ) ;
5861 } ) ;
59-
62+
6063 sourceContent = new Buffer ( sourceText , 'utf8' ) ;
6164 }
62-
65+
6366 // Also apply replacements in filenames
6467 filenameReplacements . forEach ( replacement => {
6568 fn = fn . replace ( replacement . from , replacement . to ) ;
6669 } ) ;
67-
70+
6871 writeFileEnsuringDirExists ( destRoot , fn , sourceContent ) ;
69- } ) ;
72+ } ) ;
7073}
7174
7275function copyRecursive ( sourceRoot : string , destRoot : string , matchGlob : string ) {
7376 glob . sync ( matchGlob , { cwd : sourceRoot , dot : true , nodir : true } )
7477 . forEach ( fn => {
75- const sourceContent = fs . readFileSync ( path . join ( sourceRoot , fn ) ) ;
78+ const sourceContent = fs . readFileSync ( path . join ( sourceRoot , fn ) ) ;
7679 writeFileEnsuringDirExists ( destRoot , fn , sourceContent ) ;
7780 } ) ;
7881}
7982
8083const outputRoot = './generator-aspnetcore-spa' ;
81- const outputTemplatesRoot = path . join ( outputRoot , 'app/templates' ) ;
84+ const outputTemplatesRoot = path . join ( outputRoot , 'app/templates' ) ;
8285rimraf . sync ( outputTemplatesRoot ) ;
8386
8487// Copy template files
0 commit comments