Make template package version numbers more descriptive

This commit is contained in:
Steve Sanderson
2017-05-25 11:19:14 +01:00
parent 44512226c6
commit cc859306a3
3 changed files with 45 additions and 17 deletions

View File

@@ -56,18 +56,20 @@ function listFilesExcludingGitignored(root: string): string[] {
.filter(fn => gitignoreEvaluator.accepts(fn)); .filter(fn => gitignoreEvaluator.accepts(fn));
} }
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[]) { function applyContentReplacements(sourceContent: Buffer, contentReplacements: { from: RegExp, to: string }[]) {
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
let sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
// For text files, replace hardcoded values with template tags
if (isTextFile(fn)) {
let sourceText = sourceContent.toString('utf8'); let sourceText = sourceContent.toString('utf8');
contentReplacements.forEach(replacement => { contentReplacements.forEach(replacement => {
sourceText = sourceText.replace(replacement.from, replacement.to); sourceText = sourceText.replace(replacement.from, replacement.to);
}); });
sourceContent = new Buffer(sourceText, 'utf8'); return new Buffer(sourceText, 'utf8');
}
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[]) {
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
let sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
if (isTextFile(fn)) {
sourceContent = applyContentReplacements(sourceContent, contentReplacements);
} }
// Also apply replacements in filenames // Also apply replacements in filenames
@@ -87,6 +89,11 @@ function copyRecursive(sourceRoot: string, destRoot: string, matchGlob: string)
}); });
} }
function getBuildNumber() {
return process.env.APPVEYOR_BUILD_NUMBER
|| ('t-' + Math.floor((new Date().valueOf() - new Date(2017, 0, 1).valueOf()) / (60*1000)));
}
function buildYeomanNpmPackage(outputRoot: string) { function buildYeomanNpmPackage(outputRoot: string) {
const outputTemplatesRoot = path.join(outputRoot, 'app/templates'); const outputTemplatesRoot = path.join(outputRoot, 'app/templates');
rimraf.sync(outputTemplatesRoot); rimraf.sync(outputTemplatesRoot);
@@ -226,14 +233,18 @@ function buildDotNetNewNuGetPackage(packageId: string) {
}, null, 2)); }, null, 2));
}); });
// Invoke NuGet to create the final package // Create the .nuspec file
const yeomanPackageVersion = JSON.parse(fs.readFileSync(path.join(yeomanGeneratorSource, 'package.json'), 'utf8')).version; const yeomanPackageVersion = JSON.parse(fs.readFileSync(path.join(yeomanGeneratorSource, 'package.json'), 'utf8')).version;
writeTemplate('./src/dotnetnew', outputRoot, [ const nuspecContentTemplate = fs.readFileSync(`./src/dotnetnew/${ packageId }.nuspec`);
{ from: /\{packageId\}/g, to: packageId }, writeFileEnsuringDirExists(outputRoot,
{ from: /\{version\}/g, to: yeomanPackageVersion }, `${ packageId }.nuspec`,
], [ applyContentReplacements(nuspecContentTemplate, [
{ from: /.*\.nuspec$/, to: `${packageId}.nuspec` }, { from: /\{yeomanversion\}/g, to: yeomanPackageVersion },
]); { from: /\{buildnumber\}/g, to: getBuildNumber() },
])
);
// Invoke NuGet to create the final package
const nugetExe = path.join(process.cwd(), './bin/NuGet.exe'); const nugetExe = path.join(process.cwd(), './bin/NuGet.exe');
const nugetStartInfo = { cwd: outputRoot, stdio: 'inherit' }; const nugetStartInfo = { cwd: outputRoot, stdio: 'inherit' };
if (isWindows) { if (isWindows) {

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>{packageId}</id> <id>Microsoft.AspNetCore.SpaTemplates</id>
<version>{version}</version> <version>{yeomanversion}</version>
<description>Single Page Application templates for ASP.NET Core</description> <description>Single Page Application templates for ASP.NET Core</description>
<authors>Microsoft</authors> <authors>Microsoft</authors>
<language>en-US</language> <language>en-US</language>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Microsoft.DotNet.Web.Spa.ProjectTemplates</id>
<version>2.0.0-preview2-{buildnumber}</version>
<description>Single Page Application templates for ASP.NET Core</description>
<authors>Microsoft</authors>
<language>en-US</language>
<projectUrl>https://github.com/aspnet/javascriptservices</projectUrl>
<licenseUrl>https://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<packageTypes>
<packageType name="Template" />
</packageTypes>
</metadata>
</package>