11import { task , watch } from 'gulp' ;
2- import { DIST_ROOT , SOURCE_ROOT } from '../constants' ;
2+ import { DIST_ROOT , SOURCE_ROOT , PROJECT_ROOT , DIST_BUNDLES , DIST_MATERIAL } from '../constants' ;
33import {
44 sassBuildTask , tsBuildTask , copyTask , buildAppTask , sequenceTask , triggerLivereload ,
55 serverTask
66} from '../util/task_helpers' ;
77import { join } from 'path' ;
8+ import { copyFiles } from '../util/copy-files' ;
9+
10+ // These imports don't have any typings provided.
11+ const firebaseTools = require ( 'firebase-tools' ) ;
812
913const appDir = join ( SOURCE_ROOT , 'demo-app' ) ;
1014const outDir = join ( DIST_ROOT , 'packages' , 'demo-app' ) ;
1115
16+ /** Array of vendors that are required to serve the demo-app. */
17+ const appVendors = [
18+ '@angular' , 'systemjs' , 'zone.js' , 'rxjs' , 'hammerjs' , 'core-js' , 'web-animations-js'
19+ ] ;
20+
21+ /** Glob that matches all required vendors for the demo-app. */
22+ const vendorGlob = `+(${ appVendors . join ( '|' ) } )/**/*.+(html|css|js|map)` ;
23+
1224task ( ':watch:devapp' , ( ) => {
1325 watch ( join ( appDir , '**/*.ts' ) , [ ':build:devapp:ts' , triggerLivereload ] ) ;
1426 watch ( join ( appDir , '**/*.scss' ) , [ ':build:devapp:scss' , triggerLivereload ] ) ;
@@ -28,3 +40,21 @@ task(':serve:devapp', serverTask(outDir, true));
2840task ( 'serve:devapp' , [ 'build:devapp' ] , sequenceTask (
2941 [ ':serve:devapp' , 'material:watch' , ':watch:devapp' ]
3042) ) ;
43+
44+ /** Task that copies all vendors into the demo-app package. Allows hosting the app on firebase. */
45+ task ( 'stage-deploy:devapp' , [ 'build:devapp' ] , ( ) => {
46+ copyFiles ( join ( PROJECT_ROOT , 'node_modules' ) , vendorGlob , join ( outDir , 'node_modules' ) ) ;
47+ copyFiles ( DIST_BUNDLES , '*.+(js|map)' , join ( outDir , 'dist/bundles' ) ) ;
48+ copyFiles ( DIST_MATERIAL , '**/prebuilt/*.+(css|map)' , join ( outDir , 'dist/packages/material' ) ) ;
49+ } ) ;
50+
51+ /**
52+ * Task that deploys the demo-app to Firebase. Firebase project will be the one that is
53+ * set for project directory using the Firebase CLI.
54+ */
55+ task ( 'deploy:devapp' , [ 'stage-deploy:devapp' ] , ( ) => {
56+ return firebaseTools . deploy ( { cwd : PROJECT_ROOT , only : 'hosting' } )
57+ // Firebase tools opens a persistent websocket connection and the process will never exit.
58+ . then ( ( ) => { console . log ( 'Successfully deployed the demo-app to firebase' ) ; process . exit ( 0 ) ; } )
59+ . catch ( ( err : any ) => { console . log ( err ) ; process . exit ( 1 ) ; } ) ;
60+ } ) ;
0 commit comments