Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 4451222

Browse files
Stop including prebuilt .js bundles with template packages, since they are now generated on first build
1 parent a2bde75 commit 4451222

File tree

1 file changed

+7
-23
lines changed
  • templates/package-builder/src/build

1 file changed

+7
-23
lines changed

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const dotNetPackages = {
1717
extra: 'Microsoft.AspNetCore.SpaTemplates'
1818
};
1919

20-
const commonForceInclusionRegex = /^(wwwroot|ClientApp)\/dist\//; // Files to be included in template, even though gitignored
21-
2220
interface TemplateConfig {
2321
dir: string;
2422
dotNetNewId: string;
@@ -46,7 +44,7 @@ function writeFileEnsuringDirExists(root: string, filename: string, contents: st
4644
fs.writeFileSync(fullPath, contents);
4745
}
4846

49-
function listFilesExcludingGitignored(root: string, forceInclusion: RegExp): string[] {
47+
function listFilesExcludingGitignored(root: string): string[] {
5048
// Note that the gitignore files, prior to be written by the generator, are called 'template_gitignore'
5149
// instead of '.gitignore'. This is a workaround for Yeoman doing strange stuff with .gitignore files
5250
// (it renames them to .npmignore, which is not helpful).
@@ -55,11 +53,11 @@ function listFilesExcludingGitignored(root: string, forceInclusion: RegExp): str
5553
? gitignore.compile(fs.readFileSync(gitIgnorePath, 'utf8'))
5654
: { accepts: () => true };
5755
return glob.sync('**/*', { cwd: root, dot: true, nodir: true })
58-
.filter(fn => gitignoreEvaluator.accepts(fn) || (forceInclusion && forceInclusion.test(fn)));
56+
.filter(fn => gitignoreEvaluator.accepts(fn));
5957
}
6058

61-
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[], forceInclusion: RegExp) {
62-
listFilesExcludingGitignored(sourceRoot, forceInclusion).forEach(fn => {
59+
function writeTemplate(sourceRoot: string, destRoot: string, contentReplacements: { from: RegExp, to: string }[], filenameReplacements: { from: RegExp, to: string }[]) {
60+
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
6361
let sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
6462

6563
// For text files, replace hardcoded values with template tags
@@ -102,7 +100,7 @@ function buildYeomanNpmPackage(outputRoot: string) {
102100
];
103101
_.forEach(templates, (templateConfig, templateName) => {
104102
const outputDir = path.join(outputTemplatesRoot, templateName);
105-
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
103+
writeTemplate(templateConfig.dir, outputDir, contentReplacements, filenameReplacements);
106104
});
107105

108106
// Also copy the generator files (that's the compiled .js files, plus all other non-.ts files)
@@ -143,7 +141,7 @@ function buildDotNetNewNuGetPackage(packageId: string) {
143141
}
144142

145143
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
146-
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements, commonForceInclusionRegex);
144+
writeTemplate(templateConfig.dir, templateOutputDir, contentReplacements, filenameReplacements);
147145

148146
// Add the .template.config dir and its contents
149147
const templateConfigDir = path.join(templateOutputDir, '.template.config');
@@ -235,7 +233,7 @@ function buildDotNetNewNuGetPackage(packageId: string) {
235233
{ from: /\{version\}/g, to: yeomanPackageVersion },
236234
], [
237235
{ from: /.*\.nuspec$/, to: `${packageId}.nuspec` },
238-
], null);
236+
]);
239237
const nugetExe = path.join(process.cwd(), './bin/NuGet.exe');
240238
const nugetStartInfo = { cwd: outputRoot, stdio: 'inherit' };
241239
if (isWindows) {
@@ -252,19 +250,6 @@ function buildDotNetNewNuGetPackage(packageId: string) {
252250
return glob.sync(path.join(outputRoot, './*.nupkg'))[0];
253251
}
254252

255-
function runAllPrepublishScripts() {
256-
Object.getOwnPropertyNames(templates).forEach(templateKey => {
257-
// To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
258-
// webpack on project creation. Note that these script entries are *not* the same as the project's usual prepublish
259-
// scripts, because here we want dev-mode builds (e.g., to support HMR), not prod-mode builds.
260-
runPrepublishScripts(templates[templateKey].dir, [
261-
'npm install',
262-
'node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js',
263-
'node node_modules/webpack/bin/webpack.js'
264-
]);
265-
});
266-
}
267-
268253
function runPrepublishScripts(rootDir: string, scripts: string[]) {
269254
console.log(`[Prepublish] In directory: ${ rootDir }`);
270255
scripts.forEach(script => {
@@ -280,7 +265,6 @@ const yeomanOutputRoot = path.join(distDir, 'generator-aspnetcore-spa');
280265

281266
rimraf.sync(distDir);
282267
mkdirp.sync(artifactsDir);
283-
runAllPrepublishScripts();
284268
buildYeomanNpmPackage(yeomanOutputRoot);
285269
buildDotNetNewNuGetPackages(artifactsDir);
286270

0 commit comments

Comments
 (0)