Stop generating .template.config files dynamically. Convert them to plain files on disk.

This commit is contained in:
Steve Sanderson
2017-08-22 18:06:48 -07:00
parent 900e9ca835
commit 7c52be5e42
19 changed files with 750 additions and 136 deletions

View File

@@ -10,7 +10,6 @@ import * as targz from 'tar.gz';
const isWindows = /^win/.test(process.platform);
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx'];
const webToolsVSPackageGuid = '{0CD94836-1526-4E85-87D3-FB5274C5AFC9}';
const dotNetPackages = {
builtIn: 'Microsoft.DotNet.Web.Spa.ProjectTemplates',
@@ -19,19 +18,16 @@ const dotNetPackages = {
interface TemplateConfig {
dir: string;
dotNetNewId: string;
dotNetPackageId: string;
displayName: string;
localizationIdStart: number;
}
const templates: { [key: string]: TemplateConfig } = {
'angular': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/AngularSpa/', dotNetNewId: 'Angular', displayName: 'Angular', localizationIdStart: 1100 },
'aurelia': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia', localizationIdStart: 1200 },
'knockout': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js', localizationIdStart: 1300 },
'react-redux': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux', localizationIdStart: 1400 },
'react': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js', localizationIdStart: 1500 },
'vue': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/VueSpa/', dotNetNewId: 'Vue', displayName: 'Vue.js', localizationIdStart: 1600 }
'angular': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/AngularSpa/' },
'aurelia': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/AureliaSpa/' },
'knockout': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/KnockoutSpa/' },
'react-redux': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactReduxSpa/' },
'react': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactSpa/' },
'vue': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/VueSpa/' }
};
function isTextFile(filename: string): boolean {
@@ -129,123 +125,6 @@ function buildDotNetNewNuGetPackage(packageId: string) {
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements);
// Add the .template.config dir and its contents
const templateConfigDir = path.join(templateOutputDir, '.template.config');
mkdirp.sync(templateConfigDir);
fs.writeFileSync(path.join(templateConfigDir, 'template.json'), JSON.stringify({
author: 'Microsoft',
classifications: ['Web', 'MVC', 'SPA'],
groupIdentity: `${packageId}.${templateConfig.dotNetNewId}`,
identity: `${packageId}.${templateConfig.dotNetNewId}.CSharp`,
name: `ASP.NET Core with ${templateConfig.displayName}`,
preferNameDirectory: true,
primaryOutputs: [{ path: `${sourceProjectName}.csproj` }],
shortName: `${templateConfig.dotNetNewId.toLowerCase()}`,
sourceName: sourceProjectName,
sources: [{
source: './',
target: './',
exclude: ['.template.config/**']
}],
symbols: {
TargetFrameworkOverride: {
type: 'parameter',
description: 'Overrides the target framework',
replaces: 'TargetFrameworkOverride',
datatype: 'string',
defaultValue: ''
},
Framework: {
type: 'parameter',
description: 'The target framework for the project.',
datatype: 'choice',
choices: [
{
choice: 'netcoreapp2.0',
description: 'Target netcoreapp2.0'
}
],
replaces: 'netcoreapp2.0',
defaultValue: 'netcoreapp2.0'
},
HostIdentifier: {
type: 'bind',
binding: 'HostIdentifier'
},
skipRestore: {
type: 'parameter',
datatype: 'bool',
description: 'If specified, skips the automatic restore of the project on create.',
defaultValue: 'false'
}
},
tags: { language: 'C#', type: 'project' },
postActions: [
{
condition: '(!skipRestore)',
description: 'Restore NuGet packages required by this project.',
manualInstructions: [{ text: 'Run \'dotnet restore\'' }],
actionId: '210D431B-A78B-4D2F-B762-4ED3E3EA9025',
continueOnError: true
},
/*
// Currently it doesn't appear to be possible to run `npm install` from a
// postAction, due to https://github.com/dotnet/templating/issues/849
// We will re-enable this when that bug is fixed.
{
condition: '(!skipRestore)',
description: 'Restores NPM packages required by this project.',
manualInstructions: [{ text: 'Run \'npm install\'' }],
actionId: '3A7C4B45-1F5D-4A30-959A-51B88E82B5D2',
args: { executable: 'npm', args: 'install' },
continueOnError: false
}
*/
{
// For the preview2 release, just display manual instructions instead.
// This is only applicable on the command line, because VS will restore
// NPM packages automatically by default.
condition: '(HostIdentifier == "dotnetcli" || HostIdentifier == "dotnetcli-preview")',
actionId: 'AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C',
description: '\n\n-------------------------------------------------------------------\nIMPORTANT: Before running this project on the command line,\n you must restore NPM packages by running "npm install"\n-------------------------------------------------------------------\n',
manualInstructions: [{ text: 'Run "npm install"' }]
}
],
}, null, 2));
fs.writeFileSync(path.join(templateConfigDir, 'dotnetcli.host.json'), JSON.stringify({
$schema: 'http://json.schemastore.org/dotnetcli.host',
symbolInfo: {
TargetFrameworkOverride: {
isHidden: 'true',
longName: 'target-framework-override',
shortName: ''
},
Framework: {
longName: 'framework'
},
skipRestore: {
longName: 'no-restore',
shortName: ''
},
}
}, null, 2));
const localisedNameId = templateConfig.localizationIdStart + 0;
const localisedDescId = templateConfig.localizationIdStart + 1;
fs.writeFileSync(path.join(templateConfigDir, 'vs-2017.3.host.json'), JSON.stringify({
$schema: 'http://json.schemastore.org/vs-2017.3.host',
name: { text: templateConfig.displayName, package: webToolsVSPackageGuid, id: localisedNameId.toString() },
description: { text: `A project template for creating an ASP.NET Core application with ${templateConfig.displayName}`, package: webToolsVSPackageGuid, id: localisedDescId.toString() },
order: 301,
icon: 'icon.png',
learnMoreLink: 'https://github.com/aspnet/JavaScriptServices',
uiFilters: [ 'oneaspnet' ],
minFullFrameworkVersion: '4.6.1'
}, null, 2));
});
// Create the .nuspec file
@@ -274,15 +153,6 @@ function buildDotNetNewNuGetPackage(packageId: string) {
return glob.sync(path.join(outputRoot, './*.nupkg'))[0];
}
function runPrepublishScripts(rootDir: string, scripts: string[]) {
console.log(`[Prepublish] In directory: ${ rootDir }`);
scripts.forEach(script => {
console.log(`[Prepublish] Running: ${ script }`);
childProcess.execSync(script, { cwd: rootDir, stdio: 'inherit' });
});
console.log(`[Prepublish] Done`)
}
const distDir = './dist';
const artifactsDir = path.join(distDir, 'artifacts');