Skip to content

Commit 3a23d31

Browse files
devversionandrewseguin
authored andcommitted
build: fix missing prebuilt themes (#5042)
* build: fix missing prebuilt themes * Fixes that the prebuilt themes are not copied over to the release output. * Introduces two more checks (specifc for material) in the validate-release task * Fixes that the generation of the theming SCSS bundle happens outside of gulp. Fixes #5038 * Logic improvements.
1 parent 79092bd commit 3a23d31

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

tools/gulp/tasks/material-release.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {task, src, dest} from 'gulp';
22
import {join} from 'path';
3-
import {writeFileSync} from 'fs';
3+
import {writeFileSync, mkdirpSync} from 'fs-extra';
44
import {Bundler} from 'scss-bundle';
55
import {sequenceTask} from '../util/task_helpers';
66
import {composeRelease} from '../packaging/build-release';
@@ -14,6 +14,9 @@ const {packagesDir, outputDir} = buildConfig;
1414
/** Path to the directory where all releases are created. */
1515
const releasesDir = join(outputDir, 'releases');
1616

17+
/** Path to the output of the Material package. */
18+
const materialOutputPath = join(outputDir, 'packages', 'material');
19+
1720
// Path to the sources of the Material package.
1821
const materialPath = join(packagesDir, 'lib');
1922
// Path to the release output of material.
@@ -23,7 +26,7 @@ const themingEntryPointPath = join(materialPath, 'core', 'theming', '_all-theme.
2326
// Output path for the scss theming bundle.
2427
const themingBundlePath = join(releasePath, '_theming.scss');
2528
// Matches all pre-built theme css files
26-
const prebuiltThemeGlob = join(materialPath, '**/theming/prebuilt/*.css?(.map)');
29+
const prebuiltThemeGlob = join(materialOutputPath, '**/theming/prebuilt/*.css?(.map)');
2730
// Matches all SCSS files in the library.
2831
const allScssGlob = join(materialPath, '**/*.scss');
2932

@@ -54,7 +57,10 @@ task('material:bundle-theming-scss', () => {
5457
// Instantiates the SCSS bundler and bundles all imports of the specified entry point SCSS file.
5558
// A glob of all SCSS files in the library will be passed to the bundler. The bundler takes an
5659
// array of globs, which will match SCSS files that will be only included once in the bundle.
57-
new Bundler().Bundle(themingEntryPointPath, [allScssGlob]).then(result => {
60+
return new Bundler().Bundle(themingEntryPointPath, [allScssGlob]).then(result => {
61+
// The release directory is not created yet because the composing of the release happens when
62+
// this task finishes.
63+
mkdirpSync(releasePath);
5864
writeFileSync(themingBundlePath, result.bundledContent);
5965
});
6066
});

tools/gulp/tasks/validate-release.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {task} from 'gulp';
2-
import {readFileSync} from 'fs';
2+
import {readFileSync, existsSync} from 'fs';
33
import {join} from 'path';
44
import {green, red} from 'chalk';
55
import {sequenceTask} from '../util/task_helpers';
66
import {releasePackages} from './publish';
7+
import {sync as glob} from 'glob';
78
import {buildConfig} from '../packaging/build-config';
89

910
/** Path to the directory where all releases are created. */
@@ -19,27 +20,27 @@ task('validate-release', sequenceTask(':publish:build-releases', 'validate-relea
1920

2021
/** Task that checks the release bundles for any common mistakes before releasing to the public. */
2122
task('validate-release:check-bundles', () => {
22-
const bundleFailures = releasePackages
23-
.map(packageName => join(releasesDir, packageName, '@angular', `${packageName}.js`))
24-
.map(packageBundle => checkPackageBundle(packageBundle))
23+
const releaseFailures = releasePackages
24+
.map(packageName => checkReleasePackage(packageName))
2525
.map((failures, index) => ({failures, packageName: releasePackages[index]}));
2626

27-
bundleFailures.forEach(({failures, packageName}) => {
27+
releaseFailures.forEach(({failures, packageName}) => {
2828
failures.forEach(failure => console.error(red(`Failure (${packageName}): ${failure}`)));
2929
});
3030

31-
if (bundleFailures.some(({failures}) => failures.length > 0)) {
31+
if (releaseFailures.some(({failures}) => failures.length > 0)) {
3232
// Throw an error to notify Gulp about the failures that have been detected.
33-
throw 'Release bundles are not valid and ready for being released.';
33+
throw 'Release output is not valid and not ready for being released.';
3434
} else {
35-
console.log(green('Release bundles have been checked and are looking fine.'));
35+
console.log(green('Release output has been checked and everything looks fine.'));
3636
}
3737
});
3838

39-
/** Task that checks the given release bundle for common mistakes. */
40-
function checkPackageBundle(bundlePath: string): string[] {
39+
/** Task that validates the given release package before releasing. */
40+
function checkReleasePackage(packageName: string): string[] {
41+
const bundlePath = join(releasesDir, packageName, '@angular', `${packageName}.js`);
4142
const bundleContent = readFileSync(bundlePath, 'utf8');
42-
const failures = [];
43+
let failures = [];
4344

4445
if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
4546
failures.push('Bundles contain sourcemap references in component styles.');
@@ -49,5 +50,27 @@ function checkPackageBundle(bundlePath: string): string[] {
4950
failures.push('Bundles are including references to external resources (templates or styles)');
5051
}
5152

53+
if (packageName === 'material') {
54+
failures = failures.concat(checkMaterialPackage());
55+
}
56+
57+
return failures;
58+
}
59+
60+
/** Function that includes special checks for the Material package. */
61+
function checkMaterialPackage(): string[] {
62+
const packagePath = join(releasesDir, 'material');
63+
const prebuiltThemesPath = join(packagePath, 'prebuilt-themes');
64+
const themingFilePath = join(packagePath, '_theming.scss');
65+
const failures = [];
66+
67+
if (glob('*.css', {cwd: prebuiltThemesPath}).length === 0) {
68+
failures.push('Prebuilt themes are not present in the Material release output.');
69+
}
70+
71+
if (!existsSync(themingFilePath)) {
72+
failures.push('The theming SCSS file is not present in the Material release output.');
73+
}
74+
5275
return failures;
5376
}

0 commit comments

Comments
 (0)