3 var gulp
= require('gulp');
4 var path
= require('path');
5 var gzip
= require('gulp-gzip');
6 var tar
= require('gulp-tar');
7 var git
= require('gulp-git');
8 var fs
= require('fs');
9 var mkdirp
= require('mkdirp');
10 var childProcessPromise
= require('./child-process-promise');
12 var argv
= require('yargs')
13 .option('inspect-node', {
16 'Remotely inspect the Node.js instance with Chrome devtools (adds the `--inspect` flag to the Node.js process)'
18 .option('trace-warnings-node', {
21 'Give stack traces when a console warning happens (adds the `--trace-warnings` flag to the Node.js process)'
26 * Hook into the package stage
28 gulp
.task('process:assemble', ['process:assemble:copy-app']);
31 * Hook into the post-package stage
33 gulp
.task('process:package', ['process:package:tarball']);
35 gulp
.task('process:assemble:copy-app', [
36 'process:assemble:copy-app:files',
37 'process:assemble:copy-app:version'
40 gulp
.task('process:assemble:copy-app:files', function() {
49 'npm-shrinkwrap.json',
52 'output/assets/js/webpack-manifest.json',
53 'output/assets/js/vue-ssr-server-bundle.json',
54 'public/templates/**',
62 { base
: '.', nodir
: true }
64 .pipe(gulp
.dest('output/app'));
67 gulp
.task('process:assemble:copy-app:version', function(done
) {
68 git
.revParse({ args
: 'HEAD' }, function(err
, commit
) {
69 if (err
) return done(err
);
71 git
.revParse({ args
: '--short HEAD' }, function(err
, hash
) {
72 if (err
) return done(err
);
74 git
.revParse({ args
: '--abbrev-ref HEAD' }, function(err
, branch
) {
75 if (err
) return done(err
);
77 // Prefix the asset tag with an S
78 if (process
.env
.STAGED_ENVIRONMENT
=== 'true') {
82 // Use jenkins variables
83 if (branch
=== 'HEAD' && process
.env
.CI_COMMIT_REF_SLUG
) {
84 branch
= process
.env
.CI_COMMIT_REF_SLUG
;
87 mkdirp
.sync('output/app/');
89 fs
.writeFileSync('output/app/ASSET_TAG', hash
);
90 fs
.writeFileSync('output/app/GIT_COMMIT', commit
);
91 fs
.writeFileSync('output/app/VERSION', branch
);
98 gulp
.task('process:package:tarball', function() {
100 .src(['output/app/**'], { stat
: true })
101 .pipe(tar('app.tar'))
102 .pipe(gzip({ append
: true, gzipOptions
: { level
: 9 } }))
103 .pipe(gulp
.dest('output'));
106 gulp
.task('process:watch:server', function() {
107 var nodemon
= require('gulp-nodemon');
110 if (argv
.inspectNode
) {
111 nodeArgs
.push('--inspect');
113 if (argv
.traceWarningsNode
) {
114 nodeArgs
.push('--trace-warnings');
121 path
.resolve(__dirname
, '../modules/api-client'),
122 path
.resolve(__dirname
, '../modules/web-push/browser'),
123 path
.resolve(__dirname
, '../modules/web-push/service-worker'),
126 args
: ['--cdn:use', 'true'],
131 gulp
.task('process:watch:static', function() {
132 return childProcessPromise
.fork('./server/static', [], {
133 SERVE_STATIC_ASSETS
: 1,
138 gulp
.task('process:watch', ['process:watch:server', 'process:watch:static'], function() {});