2017-07-17 19:55:49 +02:00
|
|
|
import {task} from 'gulp';
|
2017-09-29 00:30:38 +02:00
|
|
|
import {tsBuildTask, copyTask, serverTask} from '../util/task_helpers';
|
2017-03-24 14:06:45 -07:00
|
|
|
import {join} from 'path';
|
2017-06-16 19:58:34 +02:00
|
|
|
import {
|
2017-07-17 19:55:49 +02:00
|
|
|
buildConfig, copyFiles, buildScssTask, sequenceTask, watchFiles
|
2017-06-16 19:58:34 +02:00
|
|
|
} from 'material2-build-tools';
|
2017-12-19 16:45:54 -08:00
|
|
|
import {
|
|
|
|
|
cdkPackage,
|
|
|
|
|
materialExperimentalPackage,
|
|
|
|
|
cdkExperimentalPackage,
|
|
|
|
|
materialPackage,
|
2018-04-27 18:43:36 -07:00
|
|
|
momentAdapterPackage,
|
|
|
|
|
examplesPackage,
|
2017-12-19 16:45:54 -08:00
|
|
|
} from '../packages';
|
2017-05-04 23:47:37 +02:00
|
|
|
|
|
|
|
|
// These imports don't have any typings provided.
|
|
|
|
|
const firebaseTools = require('firebase-tools');
|
2016-08-19 10:59:45 -07:00
|
|
|
|
2017-06-08 20:24:58 +02:00
|
|
|
const {outputDir, packagesDir, projectDir} = buildConfig;
|
|
|
|
|
|
|
|
|
|
/** Path to the directory where all bundles live. */
|
|
|
|
|
const bundlesDir = join(outputDir, 'bundles');
|
|
|
|
|
|
|
|
|
|
const appDir = join(packagesDir, 'demo-app');
|
|
|
|
|
const outDir = join(outputDir, 'packages', 'demo-app');
|
|
|
|
|
|
2017-05-04 23:47:37 +02:00
|
|
|
/** Array of vendors that are required to serve the demo-app. */
|
|
|
|
|
const appVendors = [
|
2017-11-06 14:17:35 -08:00
|
|
|
'@angular',
|
|
|
|
|
'systemjs',
|
|
|
|
|
'zone.js',
|
|
|
|
|
'rxjs',
|
|
|
|
|
'hammerjs',
|
|
|
|
|
'core-js',
|
|
|
|
|
'moment',
|
|
|
|
|
'tslib',
|
2018-04-27 18:43:36 -07:00
|
|
|
'@webcomponents',
|
2017-05-04 23:47:37 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** Glob that matches all required vendors for the demo-app. */
|
|
|
|
|
const vendorGlob = `+(${appVendors.join('|')})/**/*.+(html|css|js|map)`;
|
|
|
|
|
|
2017-09-29 22:23:14 +02:00
|
|
|
/** Glob that matches all assets that need to be copied to the output. */
|
2018-01-31 19:24:47 +01:00
|
|
|
const assetsGlob = join(appDir, `**/*.+(html|css|svg|ico)`);
|
2017-09-29 22:23:14 +02:00
|
|
|
|
2016-08-19 10:59:45 -07:00
|
|
|
task(':watch:devapp', () => {
|
2017-07-17 19:55:49 +02:00
|
|
|
watchFiles(join(appDir, '**/*.ts'), [':build:devapp:ts']);
|
|
|
|
|
watchFiles(join(appDir, '**/*.scss'), [':build:devapp:scss']);
|
|
|
|
|
watchFiles(join(appDir, '**/*.html'), [':build:devapp:assets']);
|
2017-05-30 18:27:31 +02:00
|
|
|
|
2017-11-29 22:46:04 +01:00
|
|
|
// Custom watchers for all packages that are used inside of the demo-app. This is necessary
|
|
|
|
|
// because we only want to build the changed package (using the build-no-bundles task).
|
2017-09-29 00:30:38 +02:00
|
|
|
watchFiles(join(cdkPackage.sourceDir, '**/*'), ['cdk:build-no-bundles']);
|
|
|
|
|
watchFiles(join(materialPackage.sourceDir, '**/!(*.scss)'), ['material:build-no-bundles']);
|
|
|
|
|
watchFiles(join(materialPackage.sourceDir, '**/*.scss'), [':build:devapp:material-with-styles']);
|
|
|
|
|
watchFiles(join(momentAdapterPackage.sourceDir, '**/*'),
|
|
|
|
|
['material-moment-adapter:build-no-bundles']);
|
2017-12-19 16:45:54 -08:00
|
|
|
watchFiles(join(materialExperimentalPackage.sourceDir, '**/*'),
|
2017-11-29 22:46:04 +01:00
|
|
|
['material-experimental:build-no-bundles']);
|
2017-12-19 16:45:54 -08:00
|
|
|
watchFiles(join(cdkExperimentalPackage.sourceDir, '**/*'),
|
|
|
|
|
['cdk-experimental:build-no-bundles']);
|
2018-04-27 18:43:36 -07:00
|
|
|
watchFiles(join(examplesPackage.sourceDir, '**/*'), ['material-examples:build-no-bundles']);
|
2016-08-19 10:59:45 -07:00
|
|
|
});
|
|
|
|
|
|
2017-03-17 21:25:01 +01:00
|
|
|
/** Path to the demo-app tsconfig file. */
|
2017-03-29 20:13:33 +02:00
|
|
|
const tsconfigPath = join(appDir, 'tsconfig-build.json');
|
2016-08-19 10:59:45 -07:00
|
|
|
|
2017-03-17 21:25:01 +01:00
|
|
|
task(':build:devapp:ts', tsBuildTask(tsconfigPath));
|
2017-06-16 19:58:34 +02:00
|
|
|
task(':build:devapp:scss', buildScssTask(outDir, appDir));
|
2017-09-29 22:23:14 +02:00
|
|
|
task(':build:devapp:assets', copyTask(assetsGlob, outDir));
|
|
|
|
|
|
2017-03-24 14:06:45 -07:00
|
|
|
task(':serve:devapp', serverTask(outDir, true));
|
2016-11-09 02:26:29 +01:00
|
|
|
|
2017-09-29 00:30:38 +02:00
|
|
|
// The themes for the demo-app are built by using the SCSS mixins from Material.
|
|
|
|
|
// Therefore when SCSS files have been changed, the custom theme needs to be rebuilt.
|
|
|
|
|
task(':build:devapp:material-with-styles', sequenceTask(
|
|
|
|
|
'material:build-no-bundles', ':build:devapp:scss'
|
2016-08-19 10:59:45 -07:00
|
|
|
));
|
2017-05-04 23:47:37 +02:00
|
|
|
|
2017-09-29 00:30:38 +02:00
|
|
|
task('build:devapp', sequenceTask(
|
2017-11-29 22:46:04 +01:00
|
|
|
'cdk:build-no-bundles',
|
|
|
|
|
'material:build-no-bundles',
|
2017-12-20 09:59:31 -08:00
|
|
|
'cdk-experimental:build-no-bundles',
|
2017-11-29 22:46:04 +01:00
|
|
|
'material-experimental:build-no-bundles',
|
|
|
|
|
'material-moment-adapter:build-no-bundles',
|
2018-04-27 18:43:36 -07:00
|
|
|
'build-examples-module', // The examples module needs to be built before building examples package
|
|
|
|
|
'material-examples:build-no-bundles',
|
2017-11-29 22:46:04 +01:00
|
|
|
[':build:devapp:assets', ':build:devapp:scss', ':build:devapp:ts']
|
2017-09-29 00:30:38 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
|
|
task('serve:devapp', ['build:devapp'], sequenceTask([':serve:devapp', ':watch:devapp']));
|
|
|
|
|
|
2017-05-04 23:47:37 +02:00
|
|
|
/** Task that copies all vendors into the demo-app package. Allows hosting the app on firebase. */
|
|
|
|
|
task('stage-deploy:devapp', ['build:devapp'], () => {
|
2017-06-08 20:24:58 +02:00
|
|
|
copyFiles(join(projectDir, 'node_modules'), vendorGlob, join(outDir, 'node_modules'));
|
|
|
|
|
copyFiles(bundlesDir, '*.+(js|map)', join(outDir, 'dist/bundles'));
|
2017-10-04 17:24:49 -07:00
|
|
|
copyFiles(cdkPackage.outputDir, '**/*.+(js|map)', join(outDir, 'dist/packages/cdk'));
|
|
|
|
|
copyFiles(materialPackage.outputDir, '**/*.+(js|map)', join(outDir, 'dist/packages/material'));
|
2017-12-19 16:45:54 -08:00
|
|
|
copyFiles(materialExperimentalPackage.outputDir, '**/*.+(js|map)',
|
2017-11-29 22:46:04 +01:00
|
|
|
join(outDir, 'dist/packages/material-experimental'));
|
2017-12-19 16:45:54 -08:00
|
|
|
copyFiles(cdkExperimentalPackage.outputDir, '**/*.+(js|map)',
|
|
|
|
|
join(outDir, 'dist/packages/cdk-experimental'));
|
2017-09-29 00:30:38 +02:00
|
|
|
copyFiles(materialPackage.outputDir, '**/prebuilt/*.+(css|map)',
|
|
|
|
|
join(outDir, 'dist/packages/material'));
|
2018-04-27 18:43:36 -07:00
|
|
|
copyFiles(examplesPackage.outputDir, '**/*.+(js|map)',
|
|
|
|
|
join(outDir, 'dist/packages/material-examples'));
|
|
|
|
|
copyFiles(momentAdapterPackage.outputDir, '**/*.+(js|map)',
|
|
|
|
|
join(outDir, 'dist/packages/material-moment-adapter'));
|
2017-05-04 23:47:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Task that deploys the demo-app to Firebase. Firebase project will be the one that is
|
|
|
|
|
* set for project directory using the Firebase CLI.
|
|
|
|
|
*/
|
|
|
|
|
task('deploy:devapp', ['stage-deploy:devapp'], () => {
|
2017-06-08 20:24:58 +02:00
|
|
|
return firebaseTools.deploy({cwd: projectDir, only: 'hosting'})
|
2017-05-04 23:47:37 +02:00
|
|
|
// Firebase tools opens a persistent websocket connection and the process will never exit.
|
|
|
|
|
.then(() => { console.log('Successfully deployed the demo-app to firebase'); process.exit(0); })
|
|
|
|
|
.catch((err: any) => { console.log(err); process.exit(1); });
|
|
|
|
|
});
|