mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Build templates nupkgs directly from source without copying to staging location
This commit is contained in:
@@ -18,7 +18,7 @@ build_script:
|
|||||||
- npm run build
|
- npm run build
|
||||||
- ps: Pop-Location
|
- ps: Pop-Location
|
||||||
artifacts:
|
artifacts:
|
||||||
- path: templates\package-builder\dist\artifacts\*.nupkg
|
- path: templates\package-builder\artifacts\*.nupkg
|
||||||
name: Microsoft.AspNetCore.SpaTemplates
|
name: Microsoft.AspNetCore.SpaTemplates
|
||||||
type: NuGetPackage
|
type: NuGetPackage
|
||||||
# - ps: .\build.ps1
|
# - ps: .\build.ps1
|
||||||
|
|||||||
@@ -14,4 +14,10 @@
|
|||||||
<packageType name="Template" />
|
<packageType name="Template" />
|
||||||
</packageTypes>
|
</packageTypes>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<files>
|
||||||
|
<file
|
||||||
|
src="**/*"
|
||||||
|
exclude="*/node_modules/**;*/bin/**;*/obj/**;*/ClientApp/dist/**;*/wwwroot/dist/**"
|
||||||
|
target="Content" />
|
||||||
|
</files>
|
||||||
</package>
|
</package>
|
||||||
|
|||||||
@@ -14,4 +14,10 @@
|
|||||||
<packageType name="Template" />
|
<packageType name="Template" />
|
||||||
</packageTypes>
|
</packageTypes>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<files>
|
||||||
|
<file
|
||||||
|
src="**/*"
|
||||||
|
exclude="*/node_modules/**;*/bin/**;*/obj/**;*/.vs/**;*/.vscode/**;*/ClientApp/dist/**;*/wwwroot/dist/**"
|
||||||
|
target="Content" />
|
||||||
|
</files>
|
||||||
</package>
|
</package>
|
||||||
|
|||||||
3
templates/package-builder/.gitignore
vendored
3
templates/package-builder/.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/node_modules/
|
/node_modules/
|
||||||
/built/
|
/built/
|
||||||
/dist/
|
/artifacts/
|
||||||
|
/tmp/
|
||||||
|
|||||||
@@ -15,28 +15,6 @@ const dotNetPackages = [
|
|||||||
'Microsoft.AspNetCore.SpaTemplates'
|
'Microsoft.AspNetCore.SpaTemplates'
|
||||||
];
|
];
|
||||||
|
|
||||||
function writeFileEnsuringDirExists(root: string, filename: string, contents: string | Buffer) {
|
|
||||||
let fullPath = path.join(root, filename);
|
|
||||||
mkdirp.sync(path.dirname(fullPath));
|
|
||||||
fs.writeFileSync(fullPath, contents);
|
|
||||||
}
|
|
||||||
|
|
||||||
function listFilesExcludingGitignored(root: string): string[] {
|
|
||||||
let gitIgnorePath = path.join(root, '.gitignore');
|
|
||||||
let gitignoreEvaluator = fs.existsSync(gitIgnorePath)
|
|
||||||
? gitignore.compile(fs.readFileSync(gitIgnorePath, 'utf8'))
|
|
||||||
: { accepts: () => true };
|
|
||||||
return glob.sync('**/*', { cwd: root, dot: true, nodir: true })
|
|
||||||
.filter(fn => gitignoreEvaluator.accepts(fn));
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeTemplate(sourceRoot: string, destRoot: string) {
|
|
||||||
listFilesExcludingGitignored(sourceRoot).forEach(fn => {
|
|
||||||
let sourceContent = fs.readFileSync(path.join(sourceRoot, fn));
|
|
||||||
writeFileEnsuringDirExists(destRoot, fn, sourceContent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBuildNumber(): string {
|
function getBuildNumber(): string {
|
||||||
if (process.env.APPVEYOR_BUILD_NUMBER) {
|
if (process.env.APPVEYOR_BUILD_NUMBER) {
|
||||||
return process.env.APPVEYOR_BUILD_NUMBER;
|
return process.env.APPVEYOR_BUILD_NUMBER;
|
||||||
@@ -52,35 +30,17 @@ function buildDotNetNewNuGetPackages(outputDir: string) {
|
|||||||
const dotNetNewNupkgPath = buildDotNetNewNuGetPackage(packageId);
|
const dotNetNewNupkgPath = buildDotNetNewNuGetPackage(packageId);
|
||||||
|
|
||||||
// Move the .nupkg file to the output dir
|
// Move the .nupkg file to the output dir
|
||||||
|
mkdirp.sync(outputDir);
|
||||||
fs.renameSync(dotNetNewNupkgPath, path.join(outputDir, path.basename(dotNetNewNupkgPath)));
|
fs.renameSync(dotNetNewNupkgPath, path.join(outputDir, path.basename(dotNetNewNupkgPath)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildDotNetNewNuGetPackage(packageId: string) {
|
function buildDotNetNewNuGetPackage(packageId: string) {
|
||||||
const outputRoot = './dist/dotnetnew';
|
|
||||||
rimraf.sync(outputRoot);
|
|
||||||
|
|
||||||
// Copy template files
|
|
||||||
const packageSourceRootDir = path.join('../', packageId);
|
|
||||||
const templatesInPackage = fs.readdirSync(path.join(packageSourceRootDir, 'Content'));
|
|
||||||
|
|
||||||
_.forEach(templatesInPackage, templateName => {
|
|
||||||
const templateSourceDir = path.join(packageSourceRootDir, 'Content', templateName);
|
|
||||||
const templateOutputDir = path.join(outputRoot, 'Content', templateName);
|
|
||||||
writeTemplate(templateSourceDir, templateOutputDir);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create the .nuspec file
|
|
||||||
const nuspecFilename = `${ packageId }.nuspec`;
|
|
||||||
const nuspecContentTemplate = fs.readFileSync(path.join(packageSourceRootDir, nuspecFilename));
|
|
||||||
writeFileEnsuringDirExists(outputRoot,
|
|
||||||
nuspecFilename,
|
|
||||||
nuspecContentTemplate
|
|
||||||
);
|
|
||||||
|
|
||||||
// Invoke NuGet to create the final package
|
// Invoke NuGet to create the final package
|
||||||
|
const packageSourceRootDir = path.join('../', packageId);
|
||||||
|
const nuspecFilename = `${ packageId }.nuspec`;
|
||||||
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: packageSourceRootDir, stdio: 'inherit' };
|
||||||
const packageVersion = `1.0.${ getBuildNumber() }`;
|
const packageVersion = `1.0.${ getBuildNumber() }`;
|
||||||
const nugetArgs = ['pack', nuspecFilename, '-Version', packageVersion];
|
const nugetArgs = ['pack', nuspecFilename, '-Version', packageVersion];
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
@@ -92,15 +52,7 @@ function buildDotNetNewNuGetPackage(packageId: string) {
|
|||||||
childProcess.spawnSync('mono', nugetArgs, nugetStartInfo);
|
childProcess.spawnSync('mono', nugetArgs, nugetStartInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
return glob.sync(path.join(packageSourceRootDir, './*.nupkg'))[0];
|
||||||
rimraf.sync('./tmp');
|
|
||||||
|
|
||||||
return glob.sync(path.join(outputRoot, './*.nupkg'))[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const distDir = './dist';
|
buildDotNetNewNuGetPackages('./artifacts');
|
||||||
const artifactsDir = path.join(distDir, 'artifacts');
|
|
||||||
|
|
||||||
rimraf.sync(distDir);
|
|
||||||
mkdirp.sync(artifactsDir);
|
|
||||||
buildDotNetNewNuGetPackages(artifactsDir);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user