Skip to content

Commit f8a2860

Browse files
devversionandrewseguin
authored andcommitted
build: script to build demo-app for firebase (#4330)
* build: script to build demo-app for firebase * Adds a new gulp task that can be used to build the devapp in "deploy"-mode. This allows us to deploy the demo-app on firebase. Fixes #3857 * Add firebase deploy task
1 parent 7884b09 commit f8a2860

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

firebase.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"source": "tools/screenshot-test/functions"
44
},
55
"hosting": {
6-
"public": "dist",
6+
"public": "dist/packages/demo-app",
77
"rewrites": [
88
{
99
"source": "/**/!(*.@(js|ts|html|css|json|svg|png|jpg|jpeg))",
@@ -22,11 +22,7 @@
2222
}
2323
],
2424
"ignore": [
25-
"firebase.json",
26-
"**/.*",
27-
"**/node_modules/**",
28-
"tmp",
29-
"deploy"
25+
"firebase.json"
3026
]
3127
}
3228
}

tools/gulp/tasks/development.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import {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';
33
import {
44
sassBuildTask, tsBuildTask, copyTask, buildAppTask, sequenceTask, triggerLivereload,
55
serverTask
66
} from '../util/task_helpers';
77
import {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

913
const appDir = join(SOURCE_ROOT, 'demo-app');
1014
const 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+
1224
task(':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));
2840
task('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+
});

tools/gulp/util/copy-files.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {sync as glob} from 'glob';
2+
import {mkdirpSync, copySync} from 'fs-extra';
3+
import {join, dirname} from 'path';
4+
5+
/** Function to copy files that match a glob to another directory. */
6+
export function copyFiles(fromPath: string, fileGlob: string, outDir: string) {
7+
glob(fileGlob, {cwd: fromPath}).forEach(filePath => {
8+
let fileDestPath = join(outDir, filePath);
9+
mkdirpSync(dirname(fileDestPath));
10+
copySync(join(fromPath, filePath), fileDestPath);
11+
});
12+
}

tools/gulp/util/package-build.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import {inlineMetadataResources} from './inline-resources';
44
import {transpileFile} from './ts-compiler';
55
import {ScriptTarget, ModuleKind} from 'typescript';
66
import {sync as glob} from 'glob';
7-
import {
8-
writeFileSync, copySync, mkdirpSync, readFileSync
9-
} from 'fs-extra';
7+
import {writeFileSync, readFileSync} from 'fs-extra';
108
import {
119
DIST_BUNDLES, DIST_ROOT, SOURCE_ROOT, PROJECT_ROOT, LICENSE_BANNER, MATERIAL_VERSION
1210
} from '../constants';
1311
import {addPureAnnotations} from './annotate-pure';
12+
import {copyFiles} from './copy-files';
1413

1514
// There are no type definitions available for these imports.
1615
const uglify = require('uglify-js');
@@ -107,14 +106,6 @@ function uglifyFile(inputPath: string, outputPath: string) {
107106
writeFileSync(sourcemapOut, result.map);
108107
}
109108

110-
function copyFiles(fromPath: string, fileGlob: string, outDir: string) {
111-
glob(fileGlob, {cwd: fromPath}).forEach(filePath => {
112-
let fileDestPath = join(outDir, filePath);
113-
mkdirpSync(dirname(fileDestPath));
114-
copySync(join(fromPath, filePath), fileDestPath);
115-
});
116-
}
117-
118109
/** Updates the `package.json` file of the specified package. Replaces the version placeholder. */
119110
function updatePackageVersion(packageDir: string) {
120111
let packagePath = join(packageDir, 'package.json');

0 commit comments

Comments
 (0)