mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
When building "dotnet new" templates, always prebuild and include client-side 'dist' files for all templates, because dotnet new can't run arbitrary post-generation steps
This commit is contained in:
@@ -12,23 +12,25 @@ const isWindows = /^win/.test(process.platform);
|
|||||||
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx', '.xproj'];
|
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx', '.xproj'];
|
||||||
const yeomanGeneratorSource = './src/yeoman';
|
const yeomanGeneratorSource = './src/yeoman';
|
||||||
|
|
||||||
// For the Angular 2 template, we want to bundle prebuilt dist dev-mode files, because the VS template can't auto-run
|
// 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
|
// webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
|
||||||
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
|
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
|
||||||
const runWebpackInDevModeScripts = [
|
const commonTemplatePrepublishSteps = [
|
||||||
'npm install',
|
'npm install',
|
||||||
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
|
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
|
||||||
'node node_modules/webpack/bin/webpack.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 } } = {
|
const templates: { [key: string]: { dir: string, dotNetNewId: string, displayName: string, prepublish?: string[], forceInclusion?: RegExp } } = {
|
||||||
'angular': { dir: '../../templates/Angular2Spa/', dotNetNewId: 'Angular', displayName: 'Angular', prepublish: runWebpackInDevModeScripts, forceInclusion: /^(wwwroot|ClientApp)\/dist\// },
|
'angular': { dir: '../../templates/Angular2Spa/', dotNetNewId: 'Angular', displayName: 'Angular' },
|
||||||
'aurelia': { dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia' },
|
'aurelia': { dir: '../../templates/AureliaSpa/', dotNetNewId: 'Aurelia', displayName: 'Aurelia' },
|
||||||
'knockout': { dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
|
'knockout': { dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
|
||||||
'react-redux': { dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
|
'react-redux': { dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
|
||||||
'react': { dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js' }
|
'react': { dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.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
|
||||||
|| textFileExtensions.indexOf(path.basename(filename)) >= 0;
|
|| textFileExtensions.indexOf(path.basename(filename)) >= 0;
|
||||||
@@ -108,7 +110,7 @@ function buildYeomanNpmPackage(outputRoot: string) {
|
|||||||
];
|
];
|
||||||
_.forEach(templates, (templateConfig, templateName) => {
|
_.forEach(templates, (templateConfig, templateName) => {
|
||||||
const outputDir = path.join(outputTemplatesRoot, templateName);
|
const outputDir = path.join(outputTemplatesRoot, templateName);
|
||||||
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, templateConfig.forceInclusion);
|
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Also copy the generator files (that's the compiled .js files, plus all other non-.ts files)
|
// Also copy the generator files (that's the compiled .js files, plus all other non-.ts files)
|
||||||
@@ -134,7 +136,7 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
const contentReplacements = [];
|
const contentReplacements = [];
|
||||||
_.forEach(templates, (templateConfig, templateName) => {
|
_.forEach(templates, (templateConfig, templateName) => {
|
||||||
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
|
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
|
||||||
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, templateConfig.forceInclusion);
|
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
|
||||||
|
|
||||||
// Add the .template.config dir and its contents
|
// Add the .template.config dir and its contents
|
||||||
const templateConfigDir = path.join(templateOutputDir, '.template.config');
|
const templateConfigDir = path.join(templateOutputDir, '.template.config');
|
||||||
@@ -152,7 +154,7 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
sources: [{
|
sources: [{
|
||||||
source: './',
|
source: './',
|
||||||
target: './',
|
target: './',
|
||||||
exclude: ['.deployment', '.template.config/**', 'project.json', '*.xproj']
|
exclude: ['.deployment', '.template.config/**', 'project.json', '*.xproj', '**/_placeholder.txt']
|
||||||
}],
|
}],
|
||||||
symbols: {
|
symbols: {
|
||||||
sdkVersion: {
|
sdkVersion: {
|
||||||
@@ -196,6 +198,11 @@ function buildDotNetNewNuGetPackage() {
|
|||||||
function runAllPrepublishScripts() {
|
function runAllPrepublishScripts() {
|
||||||
Object.getOwnPropertyNames(templates).forEach(templateKey => {
|
Object.getOwnPropertyNames(templates).forEach(templateKey => {
|
||||||
const templateInfo = templates[templateKey];
|
const templateInfo = templates[templateKey];
|
||||||
|
|
||||||
|
// First run standard prepublish steps
|
||||||
|
runScripts(templateInfo.dir, commonTemplatePrepublishSteps);
|
||||||
|
|
||||||
|
// Second, run any template-specific prepublish steps
|
||||||
if (templateInfo.prepublish) {
|
if (templateInfo.prepublish) {
|
||||||
runScripts(templateInfo.dir, templateInfo.prepublish);
|
runScripts(templateInfo.dir, templateInfo.prepublish);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user