Skip to content

Commit f45f61e

Browse files
jelbourndevversion
authored andcommitted
Package intermediate build artifacts into desired npm package structure
1 parent 13e8066 commit f45f61e

File tree

8 files changed

+78
-11
lines changed

8 files changed

+78
-11
lines changed

src/demo-app/tsconfig-aot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"extends": "./tsconfig",
44
"compilerOptions": {
5+
"experimentalDecorators": true,
56
"paths": {
67
"@angular/material": ["../material"]
78
}

src/lib/tsconfig-specs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"compilerOptions": {
44
"module": "commonjs",
55
"target": "es5",
6-
"types": ["jasmine"]
6+
"types": ["jasmine"],
7+
"experimentalDecorators": true
78
},
89
"include": [
910
"system-config-spec.ts",

tools/gulp/constants.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ export const MATERIAL_VERSION = require('../../package.json').version;
55
export const PROJECT_ROOT = join(__dirname, '../..');
66
export const SOURCE_ROOT = join(PROJECT_ROOT, 'src');
77

8+
/** Root build output directory */
89
export const DIST_ROOT = join(PROJECT_ROOT, 'dist');
10+
11+
/** Output subdirectory where all bundles will be written (flat ES modules and UMD) */
912
export const DIST_BUNDLES = join(DIST_ROOT, 'bundles');
10-
export const DIST_RELEASE = join(DIST_ROOT, 'release');
1113

14+
/** Output subdirectory where all library artifacts will be written (compiled JS, CSS, etc.) */
1215
export const DIST_MATERIAL = join(DIST_ROOT, 'packages', 'material');
16+
17+
/** Output subdirectory where the npm package will be staged for publish */
18+
export const DIST_RELEASE = join(DIST_ROOT, 'release');
19+
1320
export const DIST_DEMOAPP = join(DIST_ROOT, 'packages', 'demo-app');
1421
export const DIST_E2EAPP = join(DIST_ROOT, 'packages', 'e2e-app');
1522

tools/gulp/gulpfile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ import './tasks/aot';
1212
import './tasks/payload';
1313
import './tasks/coverage';
1414
import './tasks/library';
15+
16+
import './tasks/packaging';

tools/gulp/tasks/clean.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {task} from 'gulp';
22
import {DIST_ROOT} from '../constants';
3-
import {cleanTask} from '../util/task_helpers';
3+
import {cleanTask, sequenceTask} from '../util/task_helpers';
44

55

6+
/** Deletes the dist/ directory. */
67
task('clean', cleanTask(DIST_ROOT));

tools/gulp/tasks/packaging.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {join} from 'path';
2+
import {task, watch} from 'gulp';
3+
import {main as ngc} from '@angular/compiler-cli';
4+
import {PROJECT_ROOT, COMPONENTS_DIR} from '../constants';
5+
import {SOURCE_ROOT, DIST_BUNDLES, DIST_MATERIAL, UGLIFYJS_OPTIONS} from '../constants';
6+
import {sequenceTask} from '../util/task_helpers';
7+
8+
// There are no type definitions available for these imports.
9+
const runSequence = require('run-sequence');
10+
11+
12+
const libraryRoot = join(SOURCE_ROOT, 'lib');
13+
const tsconfigPath = join(libraryRoot, 'tsconfig.json');
14+
15+
task('build:package', sequenceTask(
16+
'clean',
17+
['build:package:ngc', 'library:assets'],
18+
// Inline assets into ESM output.
19+
'library:assets:inline',
20+
));
21+
22+
23+
task('build:package:ngc', () => ngc(tsconfigPath, {basePath: libraryRoot}));

tools/gulp/tasks/release.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,63 @@
11
import {spawn} from 'child_process';
22
import {existsSync, statSync, copySync} from 'fs-extra';
33
import {join} from 'path';
4-
import {task} from 'gulp';
4+
import {task, src, dest} from 'gulp';
55
import {execTask} from '../util/task_helpers';
6-
import {DIST_RELEASE, DIST_BUNDLES} from '../constants';
6+
import {DIST_RELEASE, DIST_BUNDLES, DIST_MATERIAL} from '../constants';
77

88
// There are no type definitions available for these imports.
99
import gulpRunSequence = require('run-sequence');
1010
import minimist = require('minimist');
1111

1212
const argv = minimist(process.argv.slice(3));
1313

14+
// Capture all d.ts files output by typescript compilation except for the special files
15+
// generated by ngc.
16+
const typingsGlob = [
17+
join(DIST_MATERIAL, '**', '*.d.ts'),
18+
`!${join(DIST_MATERIAL, 'index.d.ts')}`,
19+
`!${join(DIST_MATERIAL, 'public_api.d.ts')}`,
20+
];
21+
22+
// Capture all UMD bundles.
23+
const umdGlob = join(DIST_BUNDLES, '*.umd.*');
24+
25+
// Capture all flat ESM bunldes (e.g., "material.js" and "material.es5.js")
26+
const fesmGlob = [join(DIST_BUNDLES, "*.js"), `!${umdGlob}`];
27+
1428
task('build:release', function(done: () => void) {
1529
gulpRunSequence(
1630
'library:build',
17-
':build:release:copy',
31+
':package:release',
1832
done
1933
);
2034
});
2135

22-
/** Task that merges the different bundles and outputs into the release folder. */
23-
task(':build:release:copy', () => {
36+
/** Task that combines intermediate build artifacts into the release package structure. */
37+
task(':package:release', [
38+
':package:metadata',
39+
':package:typings',
40+
':package:umd',
41+
':package:fesm',
42+
]);
43+
44+
/** Copy metatadata.json and associated d.ts files to the root of the package structure. */
45+
task(':package:metadata', () => {
2446
// https://github.com/angular/angular/blob/master/build.sh#L293-L294
25-
copySync(join(DIST_BUNDLES, 'index.d.ts'), join(DIST_RELEASE, 'material.d.ts'));
26-
copySync(join(DIST_BUNDLES, 'index.metadata.json'), join(DIST_RELEASE, 'material.metadata.json'));
47+
copySync(join(DIST_MATERIAL, 'public_api.d.ts'), join(DIST_RELEASE, 'public_api.d.ts'));
48+
copySync(join(DIST_MATERIAL, 'index.d.ts'), join(DIST_RELEASE, 'material.d.ts'));
49+
copySync(join(DIST_MATERIAL, 'index.metadata.json'),
50+
join(DIST_RELEASE, 'material.metadata.json'));
51+
});
2752

53+
/** Copy all d.ts except the special flat typings from ngc to typings/ in the release package. */
54+
task(':package:typings', () => src(typingsGlob).pipe(dest(join(DIST_RELEASE, 'typings'))));
2855

29-
});
56+
/** Copy umd bundles to the root of the release package. */
57+
task(':package:umd', () => src(umdGlob).pipe((dest(join(DIST_RELEASE, 'bundles')))));
58+
59+
/** Copy fesm bundles to @angular/material in the release package */
60+
task(':package:fesm', () => src(fesmGlob).pipe(dest(join(DIST_RELEASE, '@angular', 'material'))));
3061

3162
/** Make sure we're logged in. */
3263
task(':publish:whoami', execTask('npm', ['whoami'], {

tools/gulp/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"experimentalDecorators": true,
34
"lib": ["es2015", "dom"],
45
"module": "commonjs",
56
"moduleResolution": "node",

0 commit comments

Comments
 (0)