2015-10-23 07:56:53 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gulp = require('gulp');
|
|
|
|
var prettify = require('gulp-jsbeautifier');
|
2016-08-19 11:15:32 -07:00
|
|
|
var diff = require('gulp-diff');
|
2016-01-30 07:50:43 -08:00
|
|
|
var webpack = require('webpack-stream');
|
|
|
|
var named = require('vinyl-named');
|
2015-12-19 07:39:51 -08:00
|
|
|
var esformatter = require('gulp-esformatter');
|
2016-02-15 06:58:46 -08:00
|
|
|
var esformatter_origin = require('esformatter');
|
|
|
|
var through = require('through2');
|
2015-10-24 02:47:37 -07:00
|
|
|
var electron = require('electron-connect').server.create({
|
2016-01-30 07:50:43 -08:00
|
|
|
path: './dist'
|
2015-10-24 02:47:37 -07:00
|
|
|
});
|
2015-10-24 01:44:47 -07:00
|
|
|
var packager = require('electron-packager');
|
2016-06-14 08:19:41 -07:00
|
|
|
const fs = require('fs');
|
2015-10-23 07:56:53 -07:00
|
|
|
|
2016-08-29 14:40:11 -07:00
|
|
|
const distPackageAuthor = 'Mattermost, Inc.';
|
2016-06-17 06:02:14 -07:00
|
|
|
|
2016-05-16 07:01:26 -07:00
|
|
|
var sources = ['**/*.js', '**/*.json', '**/*.css', '**/*.html', '!**/node_modules/**', '!dist/**', '!release/**', '!**/test_config.json'];
|
2015-10-23 07:56:53 -07:00
|
|
|
|
2015-12-19 07:39:51 -08:00
|
|
|
gulp.task('prettify', ['prettify:sources', 'prettify:jsx']);
|
2016-08-29 14:40:11 -07:00
|
|
|
gulp.task('prettify:verify', ['prettify:sources:verify', 'prettify:jsx:verify']);
|
2016-02-15 06:58:46 -08:00
|
|
|
|
|
|
|
var prettify_options = {
|
|
|
|
html: {
|
2016-08-19 11:15:32 -07:00
|
|
|
indent_size: 2,
|
|
|
|
end_with_newline: true
|
2016-02-15 06:58:46 -08:00
|
|
|
},
|
|
|
|
css: {
|
2016-08-19 11:15:32 -07:00
|
|
|
indent_size: 2,
|
|
|
|
end_with_newline: true
|
2016-02-15 06:58:46 -08:00
|
|
|
},
|
|
|
|
js: {
|
2016-08-19 11:15:32 -07:00
|
|
|
indent_size: 2,
|
|
|
|
brace_style: "end-expand",
|
|
|
|
end_with_newline: true
|
2016-02-15 06:58:46 -08:00
|
|
|
}
|
|
|
|
};
|
2015-12-19 07:39:51 -08:00
|
|
|
|
|
|
|
gulp.task('prettify:sources', ['sync-meta'], function() {
|
2015-12-19 02:43:57 -08:00
|
|
|
return gulp.src(sources)
|
2016-02-15 06:58:46 -08:00
|
|
|
.pipe(prettify(prettify_options))
|
2016-08-19 11:15:32 -07:00
|
|
|
.pipe(prettify.reporter())
|
|
|
|
.pipe(diff())
|
|
|
|
.pipe(diff.reporter({
|
|
|
|
quiet: true,
|
|
|
|
fail: false
|
|
|
|
}))
|
2015-10-23 07:56:53 -07:00
|
|
|
.pipe(gulp.dest('.'));
|
|
|
|
});
|
2015-10-24 01:44:47 -07:00
|
|
|
|
2016-02-15 06:58:46 -08:00
|
|
|
gulp.task('prettify:sources:verify', function() {
|
|
|
|
return gulp.src(sources)
|
2016-08-19 11:15:32 -07:00
|
|
|
.pipe(prettify(prettify_options))
|
|
|
|
.pipe(prettify.reporter())
|
|
|
|
.pipe(diff())
|
|
|
|
.pipe(diff.reporter({
|
|
|
|
quiet: true,
|
|
|
|
fail: true
|
|
|
|
}));
|
2016-02-15 06:58:46 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var esformatter_jsx_options = {
|
|
|
|
indent: {
|
|
|
|
value: ' '
|
|
|
|
},
|
|
|
|
plugins: ['esformatter-jsx']
|
|
|
|
};
|
|
|
|
|
2015-12-19 07:39:51 -08:00
|
|
|
gulp.task('prettify:jsx', function() {
|
2016-01-30 07:50:43 -08:00
|
|
|
return gulp.src('src/browser/**/*.jsx')
|
2016-02-15 06:58:46 -08:00
|
|
|
.pipe(esformatter(esformatter_jsx_options))
|
2016-02-11 08:12:28 -08:00
|
|
|
.pipe(gulp.dest('src/browser'));
|
2015-12-23 05:04:21 -08:00
|
|
|
});
|
2015-12-19 07:39:51 -08:00
|
|
|
|
2016-02-15 06:58:46 -08:00
|
|
|
gulp.task('prettify:jsx:verify', function() {
|
|
|
|
return gulp.src('src/browser/**/*.jsx')
|
|
|
|
.pipe(through.obj(function(file, enc, cb) {
|
|
|
|
var result = esformatter_origin.diff.unified(file.contents.toString(), esformatter_origin.rc(file.path, esformatter_jsx_options));
|
|
|
|
if (result !== "") {
|
|
|
|
console.log('Error: ' + file.path + ' must be formatted');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-06-14 08:19:41 -07:00
|
|
|
gulp.task('build', ['sync-meta', 'webpack', 'copy'], function(cb) {
|
|
|
|
const appPackageJson = require('./src/package.json');
|
|
|
|
const distPackageJson = Object.assign({}, appPackageJson, {
|
|
|
|
author: {
|
2016-06-17 06:02:14 -07:00
|
|
|
name: distPackageAuthor,
|
2016-06-14 08:19:41 -07:00
|
|
|
email: 'noreply'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fs.writeFile('./dist/package.json', JSON.stringify(distPackageJson, null, ' '), cb);
|
2016-01-30 07:50:43 -08:00
|
|
|
});
|
|
|
|
|
2016-02-13 03:12:57 -08:00
|
|
|
gulp.task('webpack', ['webpack:main', 'webpack:browser', 'webpack:webview']);
|
2015-12-19 02:52:29 -08:00
|
|
|
|
2016-01-30 07:50:43 -08:00
|
|
|
gulp.task('webpack:browser', function() {
|
2016-04-22 08:50:57 -07:00
|
|
|
return gulp.src('src/browser/*.jsx')
|
2016-01-30 07:50:43 -08:00
|
|
|
.pipe(named())
|
|
|
|
.pipe(webpack({
|
|
|
|
module: {
|
|
|
|
loaders: [{
|
|
|
|
test: /\.json$/,
|
|
|
|
loader: 'json'
|
|
|
|
}, {
|
|
|
|
test: /\.jsx$/,
|
|
|
|
loader: 'babel',
|
|
|
|
query: {
|
|
|
|
presets: ['react']
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js'
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__filename: false,
|
|
|
|
__dirname: false
|
|
|
|
},
|
2016-04-13 07:34:50 -07:00
|
|
|
target: 'electron-renderer'
|
2015-12-19 02:52:29 -08:00
|
|
|
}))
|
2016-01-30 07:50:43 -08:00
|
|
|
.pipe(gulp.dest('dist/browser/'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('webpack:main', function() {
|
|
|
|
return gulp.src('src/main.js')
|
|
|
|
.pipe(webpack({
|
|
|
|
module: {
|
|
|
|
loaders: [{
|
|
|
|
test: /\.json$/,
|
|
|
|
loader: 'json'
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js'
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__filename: false,
|
|
|
|
__dirname: false
|
|
|
|
},
|
2016-04-13 07:34:50 -07:00
|
|
|
target: 'electron-main',
|
|
|
|
externals: {
|
|
|
|
remote: true // for electron-connect
|
|
|
|
}
|
2015-12-19 02:52:29 -08:00
|
|
|
}))
|
2016-01-30 07:50:43 -08:00
|
|
|
.pipe(gulp.dest('dist/'));
|
|
|
|
});
|
|
|
|
|
2016-02-13 03:12:57 -08:00
|
|
|
gulp.task('webpack:webview', function() {
|
|
|
|
return gulp.src('src/browser/webview/mattermost.js')
|
|
|
|
.pipe(named())
|
|
|
|
.pipe(webpack({
|
|
|
|
output: {
|
|
|
|
filename: '[name].js'
|
|
|
|
},
|
|
|
|
target: 'electron'
|
|
|
|
}))
|
2016-08-29 14:40:11 -07:00
|
|
|
.pipe(gulp.dest('dist/browser/webview'));
|
2016-02-13 03:12:57 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('copy', ['copy:resources', 'copy:html/css', 'copy:modules']);
|
2016-01-30 07:50:43 -08:00
|
|
|
|
|
|
|
gulp.task('copy:resources', function() {
|
|
|
|
return gulp.src('src/resources/**')
|
|
|
|
.pipe(gulp.dest('dist/resources'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('copy:html/css', function() {
|
|
|
|
return gulp.src(['src/browser/**/*.html', 'src/browser/**/*.css'])
|
|
|
|
.pipe(gulp.dest('dist/browser'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('copy:modules', function() {
|
|
|
|
return gulp.src(['src/node_modules/bootstrap/dist/**'])
|
2016-08-29 14:40:11 -07:00
|
|
|
.pipe(gulp.dest('dist/browser/modules/bootstrap'));
|
2015-12-19 02:52:29 -08:00
|
|
|
});
|
|
|
|
|
2016-02-09 03:59:52 -08:00
|
|
|
gulp.task('watch', ['build'], function() {
|
2015-10-24 02:47:37 -07:00
|
|
|
var options = ['--livereload'];
|
|
|
|
electron.start(options);
|
2016-02-09 03:59:52 -08:00
|
|
|
|
|
|
|
gulp.watch(['src/main.js', 'src/main/**/*.js', 'src/common/**/*.js'], ['webpack:main']);
|
2016-02-13 03:12:57 -08:00
|
|
|
gulp.watch(['src/browser/**/*.js', 'src/browser/**/*.jsx'], ['webpack:browser', 'webpack:webview']);
|
2016-02-09 03:59:52 -08:00
|
|
|
gulp.watch(['src/browser/**/*.css', 'src/browser/**/*.html', 'src/resources/**/*.png'], ['copy']);
|
|
|
|
|
|
|
|
gulp.watch(['dist/main.js', 'dist/resources/**'], function() {
|
2015-10-24 02:47:37 -07:00
|
|
|
electron.restart(options);
|
|
|
|
});
|
2016-02-09 03:59:52 -08:00
|
|
|
gulp.watch(['dist/browser/*.js'], electron.reload);
|
2015-10-24 02:47:37 -07:00
|
|
|
});
|
|
|
|
|
2015-12-19 02:43:57 -08:00
|
|
|
function makePackage(platform, arch, callback) {
|
2015-10-24 05:35:10 -07:00
|
|
|
var packageJson = require('./src/package.json');
|
2015-10-24 01:44:47 -07:00
|
|
|
packager({
|
2016-02-11 08:12:28 -08:00
|
|
|
dir: './dist',
|
2015-11-01 08:02:56 -08:00
|
|
|
platform: platform,
|
|
|
|
arch: arch,
|
2015-12-24 07:24:10 -08:00
|
|
|
version: require('./package.json').devDependencies['electron-prebuilt'],
|
2015-10-24 01:44:47 -07:00
|
|
|
out: './release',
|
2015-10-24 02:47:37 -07:00
|
|
|
prune: true,
|
2015-10-24 04:12:22 -07:00
|
|
|
overwrite: true,
|
2015-11-01 08:02:56 -08:00
|
|
|
"app-version": packageJson.version,
|
2016-04-26 05:53:59 -07:00
|
|
|
icon: 'resources/icon',
|
2015-12-04 08:04:37 -08:00
|
|
|
"version-string": {
|
2016-06-17 06:02:14 -07:00
|
|
|
CompanyName: distPackageAuthor,
|
2016-06-17 07:39:45 -07:00
|
|
|
LegalCopyright: `Copyright (c) 2015 - ${new Date().getFullYear()} ${packageJson.author.name}`,
|
2016-06-27 07:09:42 -07:00
|
|
|
FileDescription: packageJson.productName,
|
2016-03-13 06:55:08 -07:00
|
|
|
OriginalFilename: packageJson.productName + '.exe',
|
2015-12-04 08:04:37 -08:00
|
|
|
ProductVersion: packageJson.version,
|
2016-03-13 06:55:08 -07:00
|
|
|
ProductName: packageJson.productName,
|
2015-12-04 08:04:37 -08:00
|
|
|
InternalName: packageJson.name
|
|
|
|
}
|
2015-10-24 01:44:47 -07:00
|
|
|
}, function(err, appPath) {
|
|
|
|
if (err) {
|
2015-12-19 02:43:57 -08:00
|
|
|
callback(err);
|
2015-10-24 01:44:47 -07:00
|
|
|
}
|
|
|
|
else {
|
2016-09-16 04:24:27 -07:00
|
|
|
if (platform === 'linux' || platform === 'all') {
|
2016-08-24 08:20:07 -07:00
|
|
|
const dest_32 = 'release/Mattermost-linux-ia32';
|
|
|
|
const dest_64 = 'release/Mattermost-linux-x64';
|
|
|
|
fs.createReadStream('resources/icon.png').pipe(fs.createWriteStream(`${dest_32}/icon.png`));
|
|
|
|
fs.createReadStream('resources/icon.png').pipe(fs.createWriteStream(`${dest_64}/icon.png`));
|
|
|
|
fs.createReadStream('resources/linux/create_desktop_file.sh')
|
|
|
|
.pipe(fs.createWriteStream(`${dest_32}/create_desktop_file.sh`))
|
|
|
|
.on('finish', () => {
|
|
|
|
fs.chmodSync(`${dest_32}/create_desktop_file.sh`, '755');
|
|
|
|
});
|
|
|
|
fs.createReadStream('resources/linux/create_desktop_file.sh')
|
|
|
|
.pipe(fs.createWriteStream(`${dest_64}/create_desktop_file.sh`))
|
|
|
|
.on('finish', () => {
|
|
|
|
fs.chmodSync(`${dest_64}/create_desktop_file.sh`, '755');
|
|
|
|
});
|
|
|
|
setTimeout(() => {
|
|
|
|
callback();
|
|
|
|
}, 1000); // should wait all pipes
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callback();
|
|
|
|
}
|
2015-10-24 01:44:47 -07:00
|
|
|
}
|
|
|
|
});
|
2016-08-29 14:40:11 -07:00
|
|
|
}
|
2015-11-01 08:02:56 -08:00
|
|
|
|
2015-12-24 06:33:39 -08:00
|
|
|
gulp.task('package', ['build'], function(cb) {
|
2015-12-19 02:43:57 -08:00
|
|
|
makePackage(process.platform, 'all', cb);
|
2015-12-11 04:40:25 -08:00
|
|
|
});
|
|
|
|
|
2015-12-24 06:33:39 -08:00
|
|
|
gulp.task('package:all', ['build'], function(cb) {
|
2015-12-19 02:43:57 -08:00
|
|
|
makePackage('all', 'all', cb);
|
2015-11-01 08:02:56 -08:00
|
|
|
});
|
|
|
|
|
2015-12-24 06:33:39 -08:00
|
|
|
gulp.task('package:windows', ['build'], function(cb) {
|
2015-12-19 02:43:57 -08:00
|
|
|
makePackage('win32', 'all', cb);
|
2015-11-01 08:02:56 -08:00
|
|
|
});
|
|
|
|
|
2015-12-24 06:33:39 -08:00
|
|
|
gulp.task('package:osx', ['build'], function(cb) {
|
2015-12-19 02:43:57 -08:00
|
|
|
makePackage('darwin', 'all', cb);
|
2015-11-01 08:02:56 -08:00
|
|
|
});
|
|
|
|
|
2015-12-24 06:33:39 -08:00
|
|
|
gulp.task('package:linux', ['build'], function(cb) {
|
2015-12-19 02:43:57 -08:00
|
|
|
makePackage('linux', 'all', cb);
|
2015-10-24 01:44:47 -07:00
|
|
|
});
|
2015-10-24 05:35:10 -07:00
|
|
|
|
|
|
|
gulp.task('sync-meta', function() {
|
|
|
|
var appPackageJson = require('./src/package.json');
|
|
|
|
var packageJson = require('./package.json');
|
|
|
|
appPackageJson.name = packageJson.name;
|
2016-03-13 06:55:08 -07:00
|
|
|
appPackageJson.productName = packageJson.productName;
|
2015-10-24 05:35:10 -07:00
|
|
|
appPackageJson.version = packageJson.version;
|
|
|
|
appPackageJson.description = packageJson.description;
|
|
|
|
appPackageJson.author = packageJson.author;
|
|
|
|
appPackageJson.license = packageJson.license;
|
|
|
|
fs.writeFileSync('./src/package.json', JSON.stringify(appPackageJson, null, ' ') + '\n');
|
|
|
|
});
|