mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Split out built-in templates into new package Microsoft.DotNet.Web.Spa.ProjectTemplates
This commit is contained in:
@@ -12,25 +12,28 @@ const isWindows = /^win/.test(process.platform);
|
|||||||
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx'];
|
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx'];
|
||||||
const yeomanGeneratorSource = './src/yeoman';
|
const yeomanGeneratorSource = './src/yeoman';
|
||||||
|
|
||||||
// To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
|
const dotNetPackages = {
|
||||||
// webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
|
builtIn: 'Microsoft.DotNet.Web.Spa.ProjectTemplates',
|
||||||
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
|
extra: 'Microsoft.AspNetCore.SpaTemplates'
|
||||||
const commonTemplatePrepublishSteps = [
|
|
||||||
'npm install',
|
|
||||||
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
|
|
||||||
'node node_modules/webpack/bin/webpack.js'
|
|
||||||
];
|
|
||||||
const commonForceInclusionRegex = /^(wwwroot|ClientApp)\/dist\//; // Files to be included in template, even though gitignored
|
|
||||||
|
|
||||||
const templates: { [key: string]: { dir: string, dotNetNewId: string, displayName: string, prepublish?: string[], forceInclusion?: RegExp } } = {
|
|
||||||
'angular': { dir: '../../templates/AngularSpa/', dotNetNewId: 'Angular', displayName: 'Angular' },
|
|
||||||
'aurelia': { dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia' },
|
|
||||||
'knockout': { dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
|
|
||||||
'react-redux': { dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
|
|
||||||
'react': { dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js' },
|
|
||||||
'vue': { dir: '../../templates/VueSpa/', dotNetNewId: 'Vue', displayName: 'Vue.js' }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const commonForceInclusionRegex = /^(wwwroot|ClientApp)\/dist\//; // Files to be included in template, even though gitignored
|
||||||
|
|
||||||
|
interface TemplateConfig {
|
||||||
|
dir: string;
|
||||||
|
dotNetNewId: string;
|
||||||
|
dotNetPackageId: string;
|
||||||
|
displayName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const templates: { [key: string]: TemplateConfig } = {
|
||||||
|
'angular': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/AngularSpa/', dotNetNewId: 'Angular', displayName: 'Angular' },
|
||||||
|
'aurelia': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia' },
|
||||||
|
'knockout': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
|
||||||
|
'react-redux': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
|
||||||
|
'react': { dotNetPackageId: dotNetPackages.builtIn, dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js' },
|
||||||
|
'vue': { dotNetPackageId: dotNetPackages.extra, dir: '../../templates/VueSpa/', dotNetNewId: 'Vue', displayName: 'Vue.js' }
|
||||||
|
};
|
||||||
|
|
||||||
function isTextFile(filename: string): boolean {
|
function isTextFile(filename: string): boolean {
|
||||||
return textFileExtensions.indexOf(path.extname(filename).toLowerCase()) >= 0
|
return textFileExtensions.indexOf(path.extname(filename).toLowerCase()) >= 0
|
||||||
@@ -111,7 +114,17 @@ function buildYeomanNpmPackage(outputRoot: string) {
|
|||||||
rimraf.sync(tempRoot);
|
rimraf.sync(tempRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildDotNetNewNuGetPackage() {
|
function buildDotNetNewNuGetPackages(outputDir: string) {
|
||||||
|
const dotNetPackageIds = _.values(dotNetPackages);
|
||||||
|
dotNetPackageIds.forEach(packageId => {
|
||||||
|
const dotNetNewNupkgPath = buildDotNetNewNuGetPackage(packageId);
|
||||||
|
|
||||||
|
// Move the .nupkg file to the output dir
|
||||||
|
fs.renameSync(dotNetNewNupkgPath, path.join(outputDir, path.basename(dotNetNewNupkgPath)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildDotNetNewNuGetPackage(packageId: string) {
|
||||||
const outputRoot = './dist/dotnetnew';
|
const outputRoot = './dist/dotnetnew';
|
||||||
rimraf.sync(outputRoot);
|
rimraf.sync(outputRoot);
|
||||||
|
|
||||||
@@ -124,6 +137,11 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
];
|
];
|
||||||
const contentReplacements = [];
|
const contentReplacements = [];
|
||||||
_.forEach(templates, (templateConfig, templateName) => {
|
_.forEach(templates, (templateConfig, templateName) => {
|
||||||
|
// Only include templates matching the output package ID
|
||||||
|
if (templateConfig.dotNetPackageId !== packageId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
|
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
|
||||||
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
|
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
|
||||||
|
|
||||||
@@ -134,8 +152,8 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
fs.writeFileSync(path.join(templateConfigDir, 'template.json'), JSON.stringify({
|
fs.writeFileSync(path.join(templateConfigDir, 'template.json'), JSON.stringify({
|
||||||
author: 'Microsoft',
|
author: 'Microsoft',
|
||||||
classifications: ['Web', 'MVC', 'SPA'],
|
classifications: ['Web', 'MVC', 'SPA'],
|
||||||
groupIdentity: `Microsoft.AspNetCore.SpaTemplates.${templateConfig.dotNetNewId}`,
|
groupIdentity: `${packageId}.${templateConfig.dotNetNewId}`,
|
||||||
identity: `Microsoft.AspNetCore.SpaTemplates.${templateConfig.dotNetNewId}.CSharp`,
|
identity: `${packageId}.${templateConfig.dotNetNewId}.CSharp`,
|
||||||
name: `MVC ASP.NET Core with ${templateConfig.displayName}`,
|
name: `MVC ASP.NET Core with ${templateConfig.displayName}`,
|
||||||
preferNameDirectory: true,
|
preferNameDirectory: true,
|
||||||
primaryOutputs: [{ path: `${sourceProjectName}.csproj` }],
|
primaryOutputs: [{ path: `${sourceProjectName}.csproj` }],
|
||||||
@@ -213,8 +231,11 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
// Invoke NuGet to create the final package
|
// Invoke NuGet to create the final package
|
||||||
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, [
|
writeTemplate('./src/dotnetnew', outputRoot, [
|
||||||
|
{ from: /\{packageId\}/g, to: packageId },
|
||||||
{ from: /\{version\}/g, to: yeomanPackageVersion },
|
{ from: /\{version\}/g, to: yeomanPackageVersion },
|
||||||
], [], null);
|
], [
|
||||||
|
{ from: /.*\.nuspec$/, to: `${packageId}.nuspec` },
|
||||||
|
], null);
|
||||||
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) {
|
||||||
@@ -233,19 +254,18 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
|
|
||||||
function runAllPrepublishScripts() {
|
function runAllPrepublishScripts() {
|
||||||
Object.getOwnPropertyNames(templates).forEach(templateKey => {
|
Object.getOwnPropertyNames(templates).forEach(templateKey => {
|
||||||
const templateInfo = templates[templateKey];
|
// To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
|
||||||
|
// webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
|
||||||
// First run standard prepublish steps
|
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
|
||||||
runScripts(templateInfo.dir, commonTemplatePrepublishSteps);
|
runPrepublishScripts(templates[templateKey].dir, [
|
||||||
|
'npm install',
|
||||||
// Second, run any template-specific prepublish steps
|
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
|
||||||
if (templateInfo.prepublish) {
|
'node node_modules/webpack/bin/webpack.js'
|
||||||
runScripts(templateInfo.dir, templateInfo.prepublish);
|
]);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function runScripts(rootDir: string, scripts: string[]) {
|
function runPrepublishScripts(rootDir: string, scripts: string[]) {
|
||||||
console.log(`[Prepublish] In directory: ${ rootDir }`);
|
console.log(`[Prepublish] In directory: ${ rootDir }`);
|
||||||
scripts.forEach(script => {
|
scripts.forEach(script => {
|
||||||
console.log(`[Prepublish] Running: ${ script }`);
|
console.log(`[Prepublish] Running: ${ script }`);
|
||||||
@@ -262,10 +282,7 @@ rimraf.sync(distDir);
|
|||||||
mkdirp.sync(artifactsDir);
|
mkdirp.sync(artifactsDir);
|
||||||
runAllPrepublishScripts();
|
runAllPrepublishScripts();
|
||||||
buildYeomanNpmPackage(yeomanOutputRoot);
|
buildYeomanNpmPackage(yeomanOutputRoot);
|
||||||
const dotNetNewNupkgPath = buildDotNetNewNuGetPackage();
|
buildDotNetNewNuGetPackages(artifactsDir);
|
||||||
|
|
||||||
// Move the .nupkg file to the artifacts dir
|
|
||||||
fs.renameSync(dotNetNewNupkgPath, path.join(artifactsDir, path.basename(dotNetNewNupkgPath)));
|
|
||||||
|
|
||||||
// Finally, create a .tar.gz file containing the built generator-aspnetcore-spa.
|
// Finally, create a .tar.gz file containing the built generator-aspnetcore-spa.
|
||||||
// The CI system can treat this as the final built artifact.
|
// The CI system can treat this as the final built artifact.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?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>Microsoft.AspNetCore.SpaTemplates</id>
|
<id>{packageId}</id>
|
||||||
<version>{version}</version>
|
<version>{version}</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>
|
||||||
Reference in New Issue
Block a user