@@ -56,18 +56,20 @@ function listFilesExcludingGitignored(root: string): string[] {
56
56
. filter ( fn => gitignoreEvaluator . accepts ( fn ) ) ;
57
57
}
58
58
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
+
59
68
function writeTemplate ( sourceRoot : string , destRoot : string , contentReplacements : { from : RegExp , to : string } [ ] , filenameReplacements : { from : RegExp , to : string } [ ] ) {
60
69
listFilesExcludingGitignored ( sourceRoot ) . forEach ( fn => {
61
70
let sourceContent = fs . readFileSync ( path . join ( sourceRoot , fn ) ) ;
62
-
63
- // For text files, replace hardcoded values with template tags
64
71
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 ) ;
71
73
}
72
74
73
75
// Also apply replacements in filenames
@@ -87,6 +89,11 @@ function copyRecursive(sourceRoot: string, destRoot: string, matchGlob: string)
87
89
} ) ;
88
90
}
89
91
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
+
90
97
function buildYeomanNpmPackage ( outputRoot : string ) {
91
98
const outputTemplatesRoot = path . join ( outputRoot , 'app/templates' ) ;
92
99
rimraf . sync ( outputTemplatesRoot ) ;
@@ -226,14 +233,18 @@ function buildDotNetNewNuGetPackage(packageId: string) {
226
233
} , null , 2 ) ) ;
227
234
} ) ;
228
235
229
- // Invoke NuGet to create the final package
236
+ // Create the .nuspec file
230
237
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
237
248
const nugetExe = path . join ( process . cwd ( ) , './bin/NuGet.exe' ) ;
238
249
const nugetStartInfo = { cwd : outputRoot , stdio : 'inherit' } ;
239
250
if ( isWindows ) {
0 commit comments