Skip to content

Commit 2b8f753

Browse files
devversionmmalerba
authored andcommitted
build: use shared logic to build packages (#4202)
* build: use shared logic to build packages * No longer creates the whole set of gulp tasks just to build a single package. * Makes the package building & releasing more consistent. No extra `build:release` just for the `lib` package. References #4108 * Address feedback
1 parent 14b330e commit 2b8f753

20 files changed

+164
-232
lines changed

DEV_ENVIRONMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
5. From the root of the project, run `npm install`.
1010

1111

12-
To build the components in dev mode, run `gulp build:components`.
13-
To build the components in release mode, run `gulp build:release`
12+
To build Material in dev mode, run `gulp material:build`.
13+
To build Material in release mode, run `gulp material:build-release`
1414

1515
To bring up a local server, run `gulp serve:devapp`. This will automatically watch for changes
1616
and rebuild. The browser should refresh automatically when changes are made.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/angular/material2.git"
99
},
1010
"scripts": {
11-
"build": "gulp build:release",
11+
"build": "gulp material:build-release:clean",
1212
"demo-app": "gulp serve:devapp",
1313
"test": "gulp test",
1414
"tslint": "gulp lint",

scripts/closure-compiler/build-devapp-bundle.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ set -e -o pipefail
99
cd $(dirname $0)/../..
1010

1111

12-
# Build a release of the library and of the CDK package.
13-
$(npm bin)/gulp build:release
12+
# Build a release of material and of the CDK package.
13+
$(npm bin)/gulp material:build-release:clean
1414
$(npm bin)/gulp cdk:build-release
1515

1616
# Build demo-app with ES2015 modules. Closure compiler is then able to parse imports.

scripts/release/publish-build-artifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repoUrl="https://github.com/angular/material2-builds.git"
2121
repoDir="tmp/$repoName"
2222

2323
# Create a release of the current repository.
24-
$(npm bin)/gulp build:release
24+
$(npm bin)/gulp material:build-release:clean
2525

2626
# Prepare cloning the builds repository
2727
rm -rf $repoDir

src/material-examples/tsconfig-build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"experimentalDecorators": true,
88
"module": "es2015",
99
"moduleResolution": "node",
10-
"outDir": "../../dist/packages/examples",
10+
"outDir": "../../dist/packages/material-examples",
1111
"rootDir": ".",
1212
"sourceMap": true,
1313
"inlineSources": true,

tools/gulp/gulpfile.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
import {createPackageBuildTasks} from './util/package-tasks';
2+
3+
/** Create gulp tasks to build the different packages in the project. */
4+
createPackageBuildTasks('cdk');
5+
createPackageBuildTasks('material', ['cdk']);
6+
createPackageBuildTasks('material-examples', ['material']);
7+
18
import './tasks/ci';
29
import './tasks/clean';
310
import './tasks/default';
411
import './tasks/development';
512
import './tasks/docs';
613
import './tasks/e2e';
714
import './tasks/lint';
8-
import './tasks/release';
15+
import './tasks/publish';
916
import './tasks/screenshots';
1017
import './tasks/unit-test';
1118
import './tasks/aot';
1219
import './tasks/payload';
1320
import './tasks/coverage';
14-
import './tasks/library';
15-
import './tasks/examples';
16-
import './tasks/cdk';
21+
import './tasks/material-release';

tools/gulp/tasks/aot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {join} from 'path';
66

77
const tsconfigFile = join(DIST_DEMOAPP, 'tsconfig-aot.json');
88

9-
/** Builds the demo-app and library. To be able to run NGC, apply the metadata workaround. */
9+
/** Builds the demo-app and material. To be able to run NGC, apply the metadata workaround. */
1010
task('aot:deps', sequenceTask(
1111
'build:devapp',
12-
[':package:release', 'cdk:build-release'],
12+
['material:build-release', 'cdk:build-release'],
1313
'aot:copy-release'
1414
));
1515

tools/gulp/tasks/cdk.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

tools/gulp/tasks/development.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ task('build:devapp', buildAppTask('devapp'));
2626
task(':serve:devapp', serverTask(outDir, true));
2727

2828
task('serve:devapp', ['build:devapp'], sequenceTask(
29-
[':serve:devapp', 'library:watch', ':watch:devapp']
29+
[':serve:devapp', 'material:watch', ':watch:devapp']
3030
));

tools/gulp/tasks/e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ task('serve:e2eapp', sequenceTask('build:e2eapp', ':serve:e2eapp'));
4848
* [Watch task] Builds and serves e2e app, rebuilding whenever the sources change.
4949
* This should only be used when running e2e tests locally.
5050
*/
51-
task('serve:e2eapp:watch', ['serve:e2eapp', 'library:watch', ':watch:e2eapp']);
51+
task('serve:e2eapp:watch', ['serve:e2eapp', 'material:watch', ':watch:e2eapp']);
5252

5353
/**
5454
* Builds and serves the e2e-app and runs protractor once the e2e-app is ready.

tools/gulp/tasks/examples.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

tools/gulp/tasks/library.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

tools/gulp/tasks/lint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {DIST_MATERIAL} from '../constants';
55
gulp.task('lint', ['tslint', 'stylelint', 'madge', 'dashboardlint']);
66

77
/** Task that runs madge to detect circular dependencies. */
8-
gulp.task('madge', ['library:clean-build'], execNodeTask('madge', ['--circular', DIST_MATERIAL]));
8+
gulp.task('madge', ['material:clean-build'], execNodeTask('madge', ['--circular', DIST_MATERIAL]));
99

1010
/** Task to lint Angular Material's scss stylesheets. */
1111
gulp.task('stylelint', execNodeTask(

tools/gulp/tasks/material-release.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {task, src, dest} from 'gulp';
2+
import {join} from 'path';
3+
import {writeFileSync} from 'fs';
4+
import {Bundler} from 'scss-bundle';
5+
import {execNodeTask, sequenceTask} from '../util/task_helpers';
6+
import {composeRelease} from '../util/package-build';
7+
import {COMPONENTS_DIR, DIST_MATERIAL, DIST_RELEASES} from '../constants';
8+
9+
// There are no type definitions available for these imports.
10+
const gulpRename = require('gulp-rename');
11+
12+
// Path to the release output of material.
13+
const releasePath = join(DIST_RELEASES, 'material');
14+
// The entry-point for the scss theming bundle.
15+
const themingEntryPointPath = join(COMPONENTS_DIR, 'core', 'theming', '_all-theme.scss');
16+
// Output path for the scss theming bundle.
17+
const themingBundlePath = join(releasePath, '_theming.scss');
18+
// Matches all pre-built theme css files
19+
const prebuiltThemeGlob = join(DIST_MATERIAL, '**/theming/prebuilt/*.css');
20+
// Matches all SCSS files in the library.
21+
const allScssGlob = join(COMPONENTS_DIR, '**/*.scss');
22+
23+
/**
24+
* Overwrite the release task for the material package. The material release will include special
25+
* files, like a bundled theming SCSS file or all prebuilt themes.
26+
*/
27+
task('material:build-release', ['material:prepare-release'], () => composeRelease('material'));
28+
29+
/**
30+
* Task that will build the material package. It will also copy all prebuilt themes and build
31+
* a bundled SCSS file for theming
32+
*/
33+
task('material:prepare-release', sequenceTask(
34+
'material:build',
35+
['material:copy-prebuilt-themes', 'material:bundle-theming-scss']
36+
));
37+
38+
/** Copies all prebuilt themes into the release package under `prebuilt-themes/` */
39+
task('material:copy-prebuilt-themes', () => {
40+
src(prebuiltThemeGlob)
41+
.pipe(gulpRename({dirname: ''}))
42+
.pipe(dest(join(releasePath, 'prebuilt-themes')));
43+
});
44+
45+
/** Bundles all scss requires for theming into a single scss file in the root of the package. */
46+
task('material:bundle-theming-scss', () => {
47+
// Instantiates the SCSS bundler and bundles all imports of the specified entry point SCSS file.
48+
// A glob of all SCSS files in the library will be passed to the bundler. The bundler takes an
49+
// array of globs, which will match SCSS files that will be only included once in the bundle.
50+
new Bundler().Bundle(themingEntryPointPath, [allScssGlob]).then(result => {
51+
writeFileSync(themingBundlePath, result.bundledContent);
52+
});
53+
});

tools/gulp/tasks/payload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {openFirebaseDashboardDatabase} from '../util/firebase';
88

99
const bundlesDir = join(DIST_ROOT, 'bundles');
1010

11-
/** Task which runs test against the size of whole library. */
12-
task('payload', ['library:clean-build'], () => {
11+
/** Task which runs test against the size of material. */
12+
task('payload', ['material:clean-build'], () => {
1313

1414
let results = {
1515
umd_kb: getBundleSize('material.umd.js'),

0 commit comments

Comments
 (0)