Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / build-scripts / gulpfile-process.js
blobbf966a1be8df6570c3f86ec863dde4b64aef87d0
1 'use strict';
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', {
14 type: 'boolean',
15 describe:
16 'Remotely inspect the Node.js instance with Chrome devtools (adds the `--inspect` flag to the Node.js process)'
18 .option('trace-warnings-node', {
19 type: 'boolean',
20 describe:
21 'Give stack traces when a console warning happens (adds the `--trace-warnings` flag to the Node.js process)'
23 .help('help').argv;
25 /**
26 * Hook into the package stage
28 gulp.task('process:assemble', ['process:assemble:copy-app']);
30 /**
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'
38 ]);
40 gulp.task('process:assemble:copy-app:files', function() {
41 return gulp
42 .src(
44 '.npmrc',
45 'api.js',
46 'web.js',
47 'websockets.js',
48 'package.json',
49 'npm-shrinkwrap.json',
50 'preinstall.sh',
51 'config/**',
52 'output/assets/js/webpack-manifest.json',
53 'output/assets/js/vue-ssr-server-bundle.json',
54 'public/templates/**',
55 'public/layouts/**',
56 'public/js/**',
57 'scripts/**',
58 'server/**',
59 'shared/**',
60 'modules/**'
62 { base: '.', nodir: true }
64 .pipe(gulp.dest('output/app'));
65 });
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') {
79 hash = 'S' + hash;
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);
92 done();
93 });
94 });
95 });
96 });
98 gulp.task('process:package:tarball', function() {
99 return gulp
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');
109 const nodeArgs = [];
110 if (argv.inspectNode) {
111 nodeArgs.push('--inspect');
113 if (argv.traceWarningsNode) {
114 nodeArgs.push('--trace-warnings');
117 nodemon({
118 debug: true,
119 script: 'web.js',
120 ignore: [
121 path.resolve(__dirname, '../modules/api-client'),
122 path.resolve(__dirname, '../modules/web-push/browser'),
123 path.resolve(__dirname, '../modules/web-push/service-worker'),
124 '**/test/**'
126 args: ['--cdn:use', 'true'],
127 nodeArgs
131 gulp.task('process:watch:static', function() {
132 return childProcessPromise.fork('./server/static', [], {
133 SERVE_STATIC_ASSETS: 1,
134 PORT: 5001
138 gulp.task('process:watch', ['process:watch:server', 'process:watch:static'], function() {});