Skip to content

Commit ea40615

Browse files
committed
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
1 parent b4e8c7d commit ea40615

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
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';
89

910
const appDir = join(SOURCE_ROOT, 'demo-app');
1011
const outDir = join(DIST_ROOT, 'packages', 'demo-app');
1112

13+
/** Array of vendors that are required to serve the demo-app. */
14+
const appVendors = [
15+
'@angular', 'systemjs', 'zone.js', 'rxjs', 'hammerjs', 'core-js', 'web-animations-js'
16+
];
17+
18+
/** Glob that matches all required vendors for the demo-app. */
19+
const vendorGlob = `+(${appVendors.join('|')})/**/*.+(html|css|js|map)`;
20+
1221
task(':watch:devapp', () => {
1322
watch(join(appDir, '**/*.ts'), [':build:devapp:ts', triggerLivereload]);
1423
watch(join(appDir, '**/*.scss'), [':build:devapp:scss', triggerLivereload]);
@@ -28,3 +37,10 @@ task(':serve:devapp', serverTask(outDir, true));
2837
task('serve:devapp', ['build:devapp'], sequenceTask(
2938
[':serve:devapp', 'material:watch', ':watch:devapp']
3039
));
40+
41+
/** Task that copies all vendors into the demo-app package. Allows hosting the app on firebase. */
42+
task('build-deploy:devapp', ['build:devapp'], () => {
43+
copyFiles(join(PROJECT_ROOT, 'node_modules'), vendorGlob, join(outDir, 'node_modules'));
44+
copyFiles(DIST_BUNDLES, '*.+(js|map)', join(outDir, 'dist/bundles'));
45+
copyFiles(DIST_MATERIAL, '**/prebuilt/*.+(css|map)', join(outDir, 'dist/packages/material'));
46+
});

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)