Skip to content

Commit 412ec1b

Browse files
Build templates nupkgs directly from source without copying to staging location
1 parent c62a3b4 commit 412ec1b

File tree

5 files changed

+20
-55
lines changed

5 files changed

+20
-55
lines changed

‎appveyor.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ build_script:
1818
- npm run build
1919
- ps: Pop-Location
2020
artifacts:
21-
- path: templates\package-builder\dist\artifacts\*.nupkg
21+
- path: templates\package-builder\artifacts\*.nupkg
2222
name: Microsoft.AspNetCore.SpaTemplates
2323
type: NuGetPackage
2424
# - ps: .\build.ps1

‎templates/Microsoft.AspNetCore.SpaTemplates/Microsoft.AspNetCore.SpaTemplates.nuspec‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
<packageTypename="Template" />
1515
</packageTypes>
1616
</metadata>
17+
<files>
18+
<file
19+
src="**/*"
20+
exclude="*/node_modules/**;*/bin/**;*/obj/**;*/ClientApp/dist/**;*/wwwroot/dist/**"
21+
target="Content" />
22+
</files>
1723
</package>

‎templates/Microsoft.DotNet.Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.nuspec‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
<packageTypename="Template" />
1515
</packageTypes>
1616
</metadata>
17+
<files>
18+
<file
19+
src="**/*"
20+
exclude="*/node_modules/**;*/bin/**;*/obj/**;*/.vs/**;*/.vscode/**;*/ClientApp/dist/**;*/wwwroot/dist/**"
21+
target="Content" />
22+
</files>
1723
</package>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/node_modules/
22
/built/
3-
/dist/
3+
/artifacts/
4+
/tmp/

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

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,6 @@ const dotNetPackages = [
1515
'Microsoft.AspNetCore.SpaTemplates'
1616
];
1717

18-
functionwriteFileEnsuringDirExists(root: string,filename: string,contents: string|Buffer){
19-
letfullPath=path.join(root,filename);
20-
mkdirp.sync(path.dirname(fullPath));
21-
fs.writeFileSync(fullPath,contents);
22-
}
23-
24-
functionlistFilesExcludingGitignored(root: string): string[]{
25-
letgitIgnorePath=path.join(root,'.gitignore');
26-
letgitignoreEvaluator=fs.existsSync(gitIgnorePath)
27-
? gitignore.compile(fs.readFileSync(gitIgnorePath,'utf8'))
28-
: {accepts: ()=>true};
29-
returnglob.sync('**/*',{cwd: root,dot: true,nodir: true})
30-
.filter(fn=>gitignoreEvaluator.accepts(fn));
31-
}
32-
33-
functionwriteTemplate(sourceRoot: string,destRoot: string){
34-
listFilesExcludingGitignored(sourceRoot).forEach(fn=>{
35-
letsourceContent=fs.readFileSync(path.join(sourceRoot,fn));
36-
writeFileEnsuringDirExists(destRoot,fn,sourceContent);
37-
});
38-
}
39-
4018
functiongetBuildNumber(): string{
4119
if(process.env.APPVEYOR_BUILD_NUMBER){
4220
returnprocess.env.APPVEYOR_BUILD_NUMBER;
@@ -52,35 +30,17 @@ function buildDotNetNewNuGetPackages(outputDir: string){
5230
constdotNetNewNupkgPath=buildDotNetNewNuGetPackage(packageId);
5331

5432
// Move the .nupkg file to the output dir
33+
mkdirp.sync(outputDir);
5534
fs.renameSync(dotNetNewNupkgPath,path.join(outputDir,path.basename(dotNetNewNupkgPath)));
5635
});
5736
}
5837

5938
functionbuildDotNetNewNuGetPackage(packageId: string){
60-
constoutputRoot='./dist/dotnetnew';
61-
rimraf.sync(outputRoot);
62-
63-
// Copy template files
39+
// Invoke NuGet to create the final package
6440
constpackageSourceRootDir=path.join('../',packageId);
65-
consttemplatesInPackage=fs.readdirSync(path.join(packageSourceRootDir,'Content'));
66-
67-
_.forEach(templatesInPackage,templateName=>{
68-
consttemplateSourceDir=path.join(packageSourceRootDir,'Content',templateName);
69-
consttemplateOutputDir=path.join(outputRoot,'Content',templateName);
70-
writeTemplate(templateSourceDir,templateOutputDir);
71-
});
72-
73-
// Create the .nuspec file
7441
constnuspecFilename=`${packageId}.nuspec`;
75-
constnuspecContentTemplate=fs.readFileSync(path.join(packageSourceRootDir,nuspecFilename));
76-
writeFileEnsuringDirExists(outputRoot,
77-
nuspecFilename,
78-
nuspecContentTemplate
79-
);
80-
81-
// Invoke NuGet to create the final package
8242
constnugetExe=path.join(process.cwd(),'./bin/NuGet.exe');
83-
constnugetStartInfo={cwd: outputRoot,stdio: 'inherit'};
43+
constnugetStartInfo={cwd: packageSourceRootDir,stdio: 'inherit'};
8444
constpackageVersion=`1.0.${getBuildNumber()}`;
8545
constnugetArgs=['pack',nuspecFilename,'-Version',packageVersion];
8646
if(isWindows){
@@ -92,15 +52,7 @@ function buildDotNetNewNuGetPackage(packageId: string){
9252
childProcess.spawnSync('mono',nugetArgs,nugetStartInfo);
9353
}
9454

95-
// Clean up
96-
rimraf.sync('./tmp');
97-
98-
returnglob.sync(path.join(outputRoot,'./*.nupkg'))[0];
55+
returnglob.sync(path.join(packageSourceRootDir,'./*.nupkg'))[0];
9956
}
10057

101-
constdistDir='./dist';
102-
constartifactsDir=path.join(distDir,'artifacts');
103-
104-
rimraf.sync(distDir);
105-
mkdirp.sync(artifactsDir);
106-
buildDotNetNewNuGetPackages(artifactsDir);
58+
buildDotNetNewNuGetPackages('./artifacts');

0 commit comments

Comments
(0)