Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"gulp-markdown": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.6.0",
"gulp-transform": "^2.0.0",
"hammerjs": "^2.0.8",
"highlight.js": "^9.11.0",
Expand Down
1 change: 1 addition & 0 deletions tools/gulp/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ import './tasks/payload';
import './tasks/coverage';
import './tasks/material-release';
import './tasks/universal';
import './tasks/validate-release';
1 change: 1 addition & 0 deletions tools/gulp/tasks/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ task(':publish', async () => {
task('publish', sequenceTask(
':publish:whoami',
':publish:build-releases',
'validate-release:check-bundles',
':publish',
':publish:logout',
));
42 changes: 42 additions & 0 deletions tools/gulp/tasks/validate-release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {task} from 'gulp';
import {DIST_RELEASES, RELEASE_PACKAGES} from '../build-config';
import {readFileSync} from 'fs';
import {join} from 'path';
import {green, red} from 'chalk';
import {sequenceTask} from '../util/task_helpers';

/** RegExp that matches Angular component inline styles that contain a sourcemap reference. */
const inlineStylesSourcemapRegex = /styles: ?\[(?:"|').*sourceMappingURL=.*(?:"|')/;

task('validate-release', sequenceTask(':publish:build-releases', 'validate-release:check-bundles'));

/** Task that checks the release bundles for any common mistakes before releasing to the public. */
task('validate-release:check-bundles', () => {
const bundleFailures = RELEASE_PACKAGES
.map(packageName => join(DIST_RELEASES, packageName, '@angular', `${packageName}.js`))
.map(packageBundle => checkPackageBundle(packageBundle))
.map((failures, index) => ({failures, packageName: RELEASE_PACKAGES[index]}));

bundleFailures.forEach(({failures, packageName}) => {
failures.forEach(failure => console.error(red(`Failure (${packageName}): ${failure}`)));
});

if (bundleFailures.some(({failures}) => failures.length > 0)) {
// Throw an error to notify Gulp about the failures that have been detected.
throw 'Release bundles are not valid and ready for being released.';
} else {
console.log(green('Release bundles have been checked and are looking fine.'));
}
});

/** Task that checks the given release bundle for common mistakes. */
function checkPackageBundle(bundlePath: string): string[] {
const bundleContent = readFileSync(bundlePath, 'utf8');
const failures = [];

if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
failures.push('Bundles contain sourcemap references in component styles.');
}

return failures;
}
3 changes: 0 additions & 3 deletions tools/gulp/util/task_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {yellow} from 'chalk';
const gulpClean = require('gulp-clean');
const gulpRunSequence = require('run-sequence');
const gulpSass = require('gulp-sass');
const gulpSourcemaps = require('gulp-sourcemaps');
const gulpConnect = require('gulp-connect');
const gulpIf = require('gulp-if');
const gulpCleanCss = require('gulp-clean-css');
Expand Down Expand Up @@ -47,10 +46,8 @@ export function ngcBuildTask(tsConfigPath: string) {
export function sassBuildTask(dest: string, root: string, minify = false) {
return () => {
return gulp.src(_globify(root, '**/*.scss'))
.pipe(gulpSourcemaps.init({ loadMaps: true }))
.pipe(gulpSass().on('error', gulpSass.logError))
.pipe(gulpIf(minify, gulpCleanCss()))
.pipe(gulpSourcemaps.write('.'))
.pipe(gulp.dest(dest));
};
}
Expand Down