@@ -56,18 +56,20 @@ function listFilesExcludingGitignored(root: string): string[] {
5656 . filter ( fn => gitignoreEvaluator . accepts ( fn ) ) ;
5757}
5858
59+ function applyContentReplacements ( sourceContent : Buffer , contentReplacements : { from : RegExp , to : string } [ ] ) {
60+ let sourceText = sourceContent . toString ( 'utf8' ) ;
61+ contentReplacements . forEach ( replacement => {
62+ sourceText = sourceText . replace ( replacement . from , replacement . to ) ;
63+ } ) ;
64+
65+ return new Buffer ( sourceText , 'utf8' ) ;
66+ }
67+
5968function writeTemplate ( sourceRoot : string , destRoot : string , contentReplacements : { from : RegExp , to : string } [ ] , filenameReplacements : { from : RegExp , to : string } [ ] ) {
6069 listFilesExcludingGitignored ( sourceRoot ) . forEach ( fn => {
6170 let sourceContent = fs . readFileSync ( path . join ( sourceRoot , fn ) ) ;
62-
63- // For text files, replace hardcoded values with template tags
6471 if ( isTextFile ( fn ) ) {
65- let sourceText = sourceContent . toString ( 'utf8' ) ;
66- contentReplacements . forEach ( replacement => {
67- sourceText = sourceText . replace ( replacement . from , replacement . to ) ;
68- } ) ;
69-
70- sourceContent = new Buffer ( sourceText , 'utf8' ) ;
72+ sourceContent = applyContentReplacements ( sourceContent , contentReplacements ) ;
7173 }
7274
7375 // Also apply replacements in filenames
@@ -87,6 +89,11 @@ function copyRecursive(sourceRoot: string, destRoot: string, matchGlob: string)
8789 } ) ;
8890}
8991
92+ function getBuildNumber ( ) {
93+ return process . env . APPVEYOR_BUILD_NUMBER
94+ || ( 't-' + Math . floor ( ( new Date ( ) . valueOf ( ) - new Date ( 2017 , 0 , 1 ) . valueOf ( ) ) / ( 60 * 1000 ) ) ) ;
95+ }
96+
9097function buildYeomanNpmPackage ( outputRoot : string ) {
9198 const outputTemplatesRoot = path . join ( outputRoot , 'app/templates' ) ;
9299 rimraf . sync ( outputTemplatesRoot ) ;
@@ -226,14 +233,18 @@ function buildDotNetNewNuGetPackage(packageId: string) {
226233 } , null , 2 ) ) ;
227234 } ) ;
228235
229- // Invoke NuGet to create the final package
236+ // Create the .nuspec file
230237 const yeomanPackageVersion = JSON . parse ( fs . readFileSync ( path . join ( yeomanGeneratorSource , 'package.json' ) , 'utf8' ) ) . version ;
231- writeTemplate ( './src/dotnetnew' , outputRoot , [
232- { from : / \{ p a c k a g e I d \} / g, to : packageId } ,
233- { from : / \{ v e r s i o n \} / g, to : yeomanPackageVersion } ,
234- ] , [
235- { from : / .* \. n u s p e c $ / , to : `${ packageId } .nuspec` } ,
236- ] ) ;
238+ const nuspecContentTemplate = fs . readFileSync ( `./src/dotnetnew/${ packageId } .nuspec` ) ;
239+ writeFileEnsuringDirExists ( outputRoot ,
240+ `${ packageId } .nuspec` ,
241+ applyContentReplacements ( nuspecContentTemplate , [
242+ { from : / \{ y e o m a n v e r s i o n \} / g, to : yeomanPackageVersion } ,
243+ { from : / \{ b u i l d n u m b e r \} / g, to : getBuildNumber ( ) } ,
244+ ] )
245+ ) ;
246+
247+ // Invoke NuGet to create the final package
237248 const nugetExe = path . join ( process . cwd ( ) , './bin/NuGet.exe' ) ;
238249 const nugetStartInfo = { cwd : outputRoot , stdio : 'inherit' } ;
239250 if ( isWindows ) {
0 commit comments