|
| 1 | +import {task} from 'gulp'; |
| 2 | +import {DIST_RELEASES, RELEASE_PACKAGES} from '../build-config'; |
| 3 | +import {readFileSync} from 'fs'; |
| 4 | +import {join} from 'path'; |
| 5 | +import {green, red} from 'chalk'; |
| 6 | +import {sequenceTask} from '../util/task_helpers'; |
| 7 | + |
| 8 | +/** RegExp that matches Angular component inline styles that contain a sourcemap reference. */ |
| 9 | +const inlineStylesSourcemapRegex = /styles: ?\[(?:"|').*sourceMappingURL=.*(?:"|')/; |
| 10 | + |
| 11 | +task('validate-release', sequenceTask(':publish:build-releases', 'validate-release:check-bundles')); |
| 12 | + |
| 13 | +/** Task that checks the release bundles for any common mistakes before releasing to the public. */ |
| 14 | +task('validate-release:check-bundles', () => { |
| 15 | + const bundleFailures = RELEASE_PACKAGES |
| 16 | + .map(packageName => join(DIST_RELEASES, packageName, '@angular', `${packageName}.js`)) |
| 17 | + .map(packageBundle => checkPackageBundle(packageBundle)) |
| 18 | + .map((failures, index) => ({failures, packageName: RELEASE_PACKAGES[index]})); |
| 19 | + |
| 20 | + bundleFailures.forEach(({failures, packageName}) => { |
| 21 | + failures.forEach(failure => console.error(red(`Failure (${packageName}): ${failure}`))); |
| 22 | + }); |
| 23 | + |
| 24 | + if (bundleFailures.some(({failures}) => failures.length > 0)) { |
| 25 | + // Throw an error to notify Gulp about the failures that have been detected. |
| 26 | + throw 'Release bundles are not valid and ready for being released.'; |
| 27 | + } else { |
| 28 | + console.log(green('Release bundles have been checked and are looking fine.')); |
| 29 | + } |
| 30 | +}); |
| 31 | + |
| 32 | +/** Task that checks the given release bundle for common mistakes. */ |
| 33 | +function checkPackageBundle(bundlePath: string): string[] { |
| 34 | + const bundleContent = readFileSync(bundlePath, 'utf8'); |
| 35 | + const failures = []; |
| 36 | + |
| 37 | + if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) { |
| 38 | + failures.push('Bundles contain sourcemap references in component styles.'); |
| 39 | + } |
| 40 | + |
| 41 | + return failures; |
| 42 | +} |
0 commit comments