1
1
import { task } from 'gulp' ;
2
- import { readFileSync } from 'fs' ;
2
+ import { readFileSync , existsSync } from 'fs' ;
3
3
import { join } from 'path' ;
4
4
import { green , red } from 'chalk' ;
5
5
import { sequenceTask } from '../util/task_helpers' ;
6
6
import { releasePackages } from './publish' ;
7
+ import { sync as glob } from 'glob' ;
7
8
import { buildConfig } from '../packaging/build-config' ;
8
9
9
10
/** Path to the directory where all releases are created. */
@@ -19,27 +20,27 @@ task('validate-release', sequenceTask(':publish:build-releases', 'validate-relea
19
20
20
21
/** Task that checks the release bundles for any common mistakes before releasing to the public. */
21
22
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 ) )
25
25
. map ( ( failures , index ) => ( { failures, packageName : releasePackages [ index ] } ) ) ;
26
26
27
- bundleFailures . forEach ( ( { failures, packageName} ) => {
27
+ releaseFailures . forEach ( ( { failures, packageName} ) => {
28
28
failures . forEach ( failure => console . error ( red ( `Failure (${ packageName } ): ${ failure } ` ) ) ) ;
29
29
} ) ;
30
30
31
- if ( bundleFailures . some ( ( { failures} ) => failures . length > 0 ) ) {
31
+ if ( releaseFailures . some ( ( { failures} ) => failures . length > 0 ) ) {
32
32
// 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.' ;
34
34
} 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.' ) ) ;
36
36
}
37
37
} ) ;
38
38
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` ) ;
41
42
const bundleContent = readFileSync ( bundlePath , 'utf8' ) ;
42
- const failures = [ ] ;
43
+ let failures = [ ] ;
43
44
44
45
if ( inlineStylesSourcemapRegex . exec ( bundleContent ) !== null ) {
45
46
failures . push ( 'Bundles contain sourcemap references in component styles.' ) ;
@@ -49,5 +50,27 @@ function checkPackageBundle(bundlePath: string): string[] {
49
50
failures . push ( 'Bundles are including references to external resources (templates or styles)' ) ;
50
51
}
51
52
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
+
52
75
return failures ;
53
76
}
0 commit comments