3 const Promise = require('bluebird');
4 const path = require('path');
5 const gulp = require('gulp');
7 const postcss = require('gulp-postcss');
8 const autoprefixer = require('autoprefixer-core');
9 const mqpacker = require('css-mqpacker');
10 const csswring = require('csswring');
11 const styleBuilder = require('./style-builder');
12 const getSourceMapOptions = require('./get-sourcemap-options');
13 const uglify = require('gulp-uglify');
14 const childProcessPromise = require('./child-process-promise');
15 const extractUrls = require('./extract-urls');
16 const bootScriptUtils = require('gitter-web-templates/lib/boot-script-utils');
18 // We need access to the `clientapp:compile:webpack` task
19 require('./gulpfile-clientapp');
21 var opts = require('yargs')
33 .alias('help', 'h').argv;
37 buildPath = 'output/android/www/';
38 } else if (opts.ios) {
39 buildPath = 'output/ios/www/';
41 throw new Error('Please define the --android of --ios args when running the embedded build');
45 * Hook into the compile stage
47 gulp.task('embedded:compile', [
48 'embedded:compile:copy-files',
49 'embedded:compile:markup',
50 'embedded:compile:css',
51 'embedded:compile:copy-webpack-builds'
54 // We also copy files after the CSS is compiled in `embedded:post-compile:copy-linked-assets`
55 gulp.task('embedded:compile:copy-files', function() {
59 'public/images/emoji/*',
60 // these icons are for thread message indicator
61 // inline-threads-for-mobile-embedded
62 'public/images/svg/corner-up-left.svg',
63 'public/images/svg/corner-down-right.svg',
65 'public/repo/katex/**'
72 .pipe(gulp.dest(buildPath));
75 gulp.task('embedded:compile:markup', ['clientapp:compile:webpack'], function() {
77 path.join(__dirname, './render-embedded-chat.js'),
79 path.join(buildPath, 'mobile/embedded-chat.html')
82 args.push('--android');
88 return childProcessPromise.spawn(
91 Object.assign({}, process.env, {
92 // Default to prod config
93 NODE_ENV: process.env.NODE_ENV || 'prod'
98 const cssIosStyleBuilder = styleBuilder(['public/less/mobile-native-chat.less'], {
99 dest: path.join(buildPath, 'styles'),
100 watchGlob: 'public/**/*.less',
101 sourceMapOptions: getSourceMapOptions(),
103 paths: ['public/less'],
105 'target-env': '"mobile"'
108 streamTransform: function(stream) {
112 browsers: ['ios_saf >= 6'],
122 gulp.task('embedded:compile:css', function() {
123 return cssIosStyleBuilder.build();
126 /* Generate embedded native */
127 gulp.task('embedded:compile:copy-webpack-builds', ['clientapp:compile:webpack'], function() {
128 const assets = bootScriptUtils.generateAssetsForChunks(['mobile-native-embedded-chat']);
131 .src(assets.map(asset => path.join('output/assets/js/', asset)), {
132 base: './output/assets/js/',
135 .pipe(gulp.dest(path.join(buildPath, 'js')));
138 gulp.task('embedded:post-compile', [
139 'embedded:post-compile:uglify',
140 'embedded:post-compile:copy-linked-assets'
143 gulp.task('embedded:post-compile:uglify', function() {
145 .src(path.join(buildPath, 'js/*.js'))
147 .pipe(gulp.dest(path.join(buildPath, 'js')));
150 gulp.task('embedded:post-compile:copy-linked-assets', function() {
152 extractUrls(path.join(buildPath, 'styles/mobile-native-chat.css'), buildPath)
153 ]).then(resourceLists => {
154 const resourceList = resourceLists.reduce((list, resultantList) => {
155 return resultantList.concat(list);
163 .pipe(gulp.dest(buildPath));