forked from HeratPatel/hnpwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (59 loc) · 1.93 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const gulp = require('gulp');
const del = require('del');
const dotenv = require('dotenv');
const replace = require('gulp-replace');
function changeEnvironments(envFile) {
const envPattern = /\.env ?= ?{([^;]+)/g;
// clear env
gulp
.src('index.html')
.pipe(replace(envPattern, '.env = {}'))
.pipe(gulp.dest('.'));
// check for the errors
if (envFile.error) {
throw envFile.error;
}
const replacement = `.env = ${JSON.stringify(envFile.parsed)}`;
return gulp
.src('index.html')
.pipe(replace(envPattern, replacement))
.pipe(gulp.dest('.'));
}
// development
gulp.task('env-dev', () => {
const envFile = dotenv.config({ path: '.env.dev' });
return changeEnvironments(envFile);
});
// production
gulp.task('env-prod', () => {
const envFile = dotenv.config({ path: '.env.prod' });
return changeEnvironments(envFile);
});
/**
* Builds the Firebase-ready version of the PWA, moving the necessary
* files to the functions folder to be used by PRPL Server
*/
gulp.task('firebase', () => {
// These are the files needed by PRPL Server, that are going to be moved to the functions folder
const filesToMove = [
'build/polymer.json',
'build/**/index.html',
'build/**/push-manifest.json'
];
// Delete the build folder inside the functions folder
return (
del('functions/build')
.then(
() =>
// Copy the files needed by PRPL Server
new Promise(resolve =>
gulp
.src(filesToMove, { base: '.' })
.pipe(gulp.dest('functions'))
.on('end', resolve)
)
)
// Delete them from the original build
.then(() => del(filesToMove))
);
});