Skip to content

Commit e8b9bc3

Browse files
authored
chore: Bundling improvements (#1507)
* Move i18n files * Copy assets with rollup * Call electron-builder CLI
1 parent 8f142ab commit e8b9bc3

14 files changed

Lines changed: 168 additions & 64 deletions

gulpfile.js

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const { promisify } = require('util');
33

44
const { convert: convertToIcns } = require('@fiahfy/icns-convert');
55
const { convert: convertSvgToPng } = require('convert-svg-to-png');
6-
const { build } = require('electron-builder');
7-
const { dest, parallel, series, src, task, watch } = require('gulp');
6+
const { parallel, series, task } = require('gulp');
87
const execa = require('gulp-execa');
98
const toIco = require('to-ico');
109
const rimraf = require('rimraf');
@@ -14,59 +13,19 @@ const NODE_ENV = process.env.NODE_ENV || 'development';
1413

1514
task('clean', () => promisify(rimraf)('app'));
1615

17-
task('build:public', () => src('src/public/**/*')
18-
.pipe(dest('app/public')));
19-
20-
task('build:i18n', () => src('src/i18n/lang/**/*')
21-
.pipe(dest('app/i18n/lang')));
22-
23-
task('build:bundle', execa.task('rollup -c', { env: { NODE_ENV } }));
24-
25-
task('build', parallel('build:public', 'build:i18n', 'build:bundle'));
26-
27-
task('watch', () => {
28-
watch('src/public/**/*', task('build:public'));
29-
watch('src/i18n/lang/**/*', task('build:i18n'));
30-
watch('src/**/*.js', task('build:bundle'));
31-
});
16+
task('build', execa.task('rollup -c', { env: { NODE_ENV } }));
17+
task('watch', execa.task('rollup -c -w', { env: { NODE_ENV } }));
3218

3319
task('test:build', execa.task('rollup -c', { env: { NODE_ENV: 'test' } }));
34-
35-
task('test:renderer',
36-
execa.task('xvfb-maybe electron-mocha --require source-map-support/register --renderer app/renderer.specs/*.js'));
20+
task('test:renderer', execa.task('xvfb-maybe electron-mocha --require source-map-support/register --renderer app/renderer.specs/*.js'));
3721

3822
task('test', series('clean', 'test:build', 'test:renderer'));
39-
4023
task('start:electron', execa.task('electron .'));
41-
4224
task('start', series('build', parallel('watch', 'start:electron')));
4325

44-
task('release:darwin', async () => {
45-
// Workaround for https://github.com/electron-userland/electron-builder/issues/4204
46-
for (const target of ['dmg', 'pkg', 'zip', 'mas']) {
47-
// eslint-disable-next-line no-await-in-loop
48-
await build({
49-
publish: NODE_ENV === 'production' ? 'onTagOrDraft' : 'never',
50-
x64: true,
51-
mac: [target],
52-
});
53-
}
54-
});
55-
56-
task('release:linux', () => build({
57-
publish: NODE_ENV === 'production' ? 'onTagOrDraft' : 'never',
58-
x64: true,
59-
linux: [],
60-
c: { productName: 'rocketchat' },
61-
}));
62-
63-
task('release:win32', () => build({
64-
publish: NODE_ENV === 'production' ? 'onTagOrDraft' : 'never',
65-
x64: true,
66-
ia32: true,
67-
win: [],
68-
}));
69-
26+
task('release:darwin', execa.task(`electron-builder --publish ${ NODE_ENV === 'production' ? 'onTagOrDraft' : 'never' } --x64 --mac`));
27+
task('release:linux', execa.task(`electron-builder --publish ${ NODE_ENV === 'production' ? 'onTagOrDraft' : 'never' } --x64 --linux --c.productName=rocketchat`));
28+
task('release:win32', execa.task(`electron-builder --publish ${ NODE_ENV === 'production' ? 'onTagOrDraft' : 'never' } --x64 --ia32 --win`));
7029
task('release', series('build', `release:${ process.platform }`));
7130

7231
task('icons:clean', async () => {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"rollup": "^1.1.0",
8080
"rollup-plugin-babel": "^4.3.3",
8181
"rollup-plugin-commonjs": "^10.1.0",
82+
"rollup-plugin-copy": "^3.3.0",
8283
"rollup-plugin-json": "^4.0.0",
8384
"rollup-plugin-node-resolve": "^5.2.0",
8485
"rollup-plugin-replace": "^2.1.0",

rollup.config.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import builtinModules from 'builtin-modules';
22
import glob from 'glob';
33
import babel from 'rollup-plugin-babel';
44
import commonjs from 'rollup-plugin-commonjs';
5+
import copy from 'rollup-plugin-copy';
56
import json from 'rollup-plugin-json';
67
import nodeResolve from 'rollup-plugin-node-resolve';
78
import replace from 'rollup-plugin-replace';
@@ -17,6 +18,12 @@ const bundleOptions = {
1718
...Object.keys(appManifest.devDependencies),
1819
],
1920
plugins: [
21+
copy({
22+
targets: [
23+
{ src: 'src/i18n/*.i18n.json', dest: 'app/i18n' },
24+
{ src: 'src/public/*', dest: 'app/public' },
25+
],
26+
}),
2027
json(),
2128
replace({
2229
'process.env.BUGSNAG_API_KEY': JSON.stringify(process.env.BUGSNAG_API_KEY),
@@ -72,19 +79,6 @@ export default [
7279
},
7380
],
7481
},
75-
{
76-
input: 'src/i18n/index.js',
77-
...bundleOptions,
78-
output: [
79-
{
80-
file: 'app/i18n/index.js',
81-
format: 'cjs',
82-
intro: '(function () {',
83-
outro: '})()',
84-
sourcemap: true,
85-
},
86-
],
87-
},
8882
{
8983
input: 'src/preload.js',
9084
...bundleOptions,

src/i18n/index.js renamed to src/i18n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import i18nextNodeFileSystemBackend from 'i18next-node-fs-backend';
66
import { initReactI18next } from 'react-i18next';
77

88
const app = mainApp || remote.app;
9-
const languagesDirPath = `${ app.getAppPath() }/app/i18n/lang`;
9+
const languagesDirPath = `${ app.getAppPath() }/app/i18n`;
1010
const defaultLocale = 'en';
1111
let globalLocale = defaultLocale;
1212

0 commit comments

Comments
 (0)