Skip to content

Commit 06ad36f

Browse files
In Angular 2 template, include prebuilt wwwroot/dist/* files to support VS and "dotnet new" templates (which can't run post-project-creation actions)
1 parent 7a80d90 commit 06ad36f

File tree

1 file changed

+25
-9
lines changed
  • templates/package-builder/src/build

1 file changed

+25
-9
lines changed

templates/package-builder/src/build/build.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const isWindows = /^win/.test(process.platform);
1111
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx', '.xproj'];
1212
const yeomanGeneratorSource = './src/yeoman';
1313

14-
const templates: { [key: string]: { dir: string, dotNetNewId: string, displayName: string } } = {
15-
'angular-2': { dir: '../../templates/Angular2Spa/', dotNetNewId: 'Angular', displayName: 'Angular 2' },
14+
const templates: { [key: string]: { dir: string, dotNetNewId: string, displayName: string, forceInclusion?: RegExp } } = {
15+
'angular-2': { dir: '../../templates/Angular2Spa/', dotNetNewId: 'Angular', displayName: 'Angular 2', forceInclusion: /^wwwroot\/dist\// },
1616
'knockout': { dir: '../../templates/KnockoutSpa/', dotNetNewId: 'Knockout', displayName: 'Knockout.js' },
1717
'react-redux': { dir: '../../templates/ReactReduxSpa/', dotNetNewId: 'ReactRedux', displayName: 'React.js and Redux' },
1818
'react': { dir: '../../templates/ReactSpa/', dotNetNewId: 'React', displayName: 'React.js' }
@@ -28,7 +28,7 @@ function writeFileEnsuringDirExists(root: string, filename: string, contents: st
2828
fs.writeFileSync(fullPath, contents);
2929
}
3030

31-
function listFilesExcludingGitignored(root: string): string[] {
31+
function listFilesExcludingGitignored(root: string, forceInclusion: RegExp): string[] {
3232
// Note that the gitignore files, prior to be written by the generator, are called 'template_gitignore'
3333
// instead of '.gitignore'. This is a workaround for Yeoman doing strange stuff with .gitignore files
3434
// (it renames them to .npmignore, which is not helpful).
@@ -37,11 +37,11 @@ function listFilesExcludingGitignored(root: string): string[] {
3737
? gitignore.compile(fs.readFileSync(gitIgnorePath, 'utf8'))
3838
: { accepts: () => true };
3939
return glob.sync('**/*', { cwd: root, dot: true, nodir: true })
40-
.filter(fn => gitignoreEvaluator.accepts(fn));
40+
.filter(fn => gitignoreEvaluator.accepts(fn) || (forceInclusion && forceInclusion.test(fn)));
4141
}
4242

43-
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[]) {
44-
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
43+
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[], forceInclusion: RegExp) {
44+
listFilesExcludingGitignored(sourceRoot, forceInclusion).forEach(fn => {
4545
let sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
4646

4747
// For text files, replace hardcoded values with template tags
@@ -89,7 +89,7 @@ function buildYeomanNpmPackage() {
8989
];
9090
_.forEach(templates, (templateConfig, templateName) => {
9191
const outputDir = path.join(outputTemplatesRoot, templateName);
92-
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements);
92+
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, templateConfig.forceInclusion);
9393
});
9494

9595
// Also copy the generator files (that's the compiled .js files, plus all other non-.ts files)
@@ -125,7 +125,7 @@ function buildDotNetNewNuGetPackage() {
125125
_.forEach(templates, (templateConfig, templateName) => {
126126
const templateOutputDir = path.join(outputRoot, 'templates', templateName);
127127
const templateOutputProjectDir = path.join(templateOutputDir, sourceProjectName);
128-
writeTemplate(templateConfig.dir, templateOutputProjectDir, contentReplacements, filenameReplacements);
128+
writeTemplate(templateConfig.dir, templateOutputProjectDir, contentReplacements, filenameReplacements, templateConfig.forceInclusion);
129129

130130
// Add a .netnew.json file
131131
fs.writeFileSync(path.join(templateOutputDir, '.netnew.json'), JSON.stringify({
@@ -145,7 +145,7 @@ function buildDotNetNewNuGetPackage() {
145145
const yeomanPackageVersion = JSON.parse(fs.readFileSync(path.join(yeomanGeneratorSource, 'package.json'), 'utf8')).version;
146146
writeTemplate('./src/dotnetnew', outputRoot, [
147147
{ from: /\{version\}/g, to: yeomanPackageVersion },
148-
], []);
148+
], [], null);
149149
const nugetExe = path.join(process.cwd(), './bin/NuGet.exe');
150150
const nugetStartInfo = { cwd: outputRoot, stdio: 'inherit' };
151151
if (isWindows) {
@@ -160,5 +160,21 @@ function buildDotNetNewNuGetPackage() {
160160
rimraf.sync('./tmp');
161161
}
162162

163+
// TODO: Instead of just showing this warning, improve build script so it actually does build them
164+
// in the correct format. Can do this once we've moved away from using ASPNETCORE_ENVIRONMENT to
165+
// control the build output mode. The templates we warn about here are the ones where we ship some
166+
// files that wouldn't normally be under source control (e.g., /wwwroot/dist/*).
167+
const templatesWithForceIncludes = Object.getOwnPropertyNames(templates)
168+
.filter(templateName => !!templates[templateName].forceInclusion);
169+
if (templatesWithForceIncludes.length > 0) {
170+
console.warn(`
171+
---
172+
WARNING: Ensure that the following templates are already built in the configuration desired for publishing.
173+
For example, build the dist files in debug mode.
174+
TEMPLATES: ${templatesWithForceIncludes.join(', ')}
175+
---
176+
`);
177+
}
178+
163179
buildYeomanNpmPackage();
164180
buildDotNetNewNuGetPackage();

0 commit comments

Comments
 (0)