-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
48 lines (40 loc) · 1.43 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
'use strict';
const gulp = require('gulp');
const gulpCopy = require('gulp-copy');
const replace = require('gulp-string-replace');
const exec = require('child_process').exec;
const zip = require('gulp-zip');
const fs = require('fs');
const repo_root = __dirname + '/';
gulp.task('copyjquery', function(){
gulp.src('node_modules/jquery/dist/jquery.min.js')
.pipe(gulp.dest('build/extern/'))
});
gulp.task('copy', ['copyjquery'], function(){
return gulp.src(['js/*', 'extern/*', 'manifest.json', 'icons/*', 'assets/*'])
.pipe(gulpCopy('./build/'));
});
gulp.task('webpack', function(cb){
exec('webpack', function(err, stdout, stderr){
console.log(stdout);
console.log(stderr);
cb(err);
})
});
gulp.task('build', ['copy', 'webpack'], function(){
let raw_creds = fs.readFileSync(process.env.KEY_LOCATION).toString();
let creds = raw_creds.replace(/\"/g, '\\"').replace(/\n/g, '\\n');
return gulp.src(['build/**/*.js', 'build/manifest.json'])
.pipe(replace(/\{\{ crm_location \}\}/g, process.env.CRM_LOCATION))
.pipe(replace(/{{ credentials }}/g, raw_creds))
.pipe(replace(/{ credentials }/g, creds))
.pipe(gulp.dest('build/'));
});
gulp.task('watch', ['build'], function(){
gulp.watch('./js/*', ['build']);
});
gulp.task('zip', ['build'], function(){
return gulp.src('build/**/*')
.pipe(zip('extension.zip'))
.pipe(gulp.dest('dist'));
});