Commit 086393e6 authored by Tasso Evangelista's avatar Tasso Evangelista
Browse files

Update code style of gulp tasks

parent 921969c9
...@@ -10,55 +10,45 @@ const bundle = require('./bundle'); ...@@ -10,55 +10,45 @@ const bundle = require('./bundle');
const utils = require('./utils'); const utils = require('./utils');
const { beepSound, srcDir, configDir, appDir } = require('./utils'); const { beepSound, srcDir, configDir, appDir } = require('./utils');
gulp.task('public', () => { gulp.task('public', () => gulp.src(srcDir.path('public/**/*'))
return gulp.src(srcDir.path('public/**/*')) .pipe(plumber())
.pipe(plumber()) .pipe(gulp.dest(appDir.path('public'))));
.pipe(gulp.dest(appDir.path('public')));
});
gulp.task('i18n', () => { gulp.task('i18n', () => gulp.src(srcDir.path('i18n/lang/**/*'))
return gulp.src(srcDir.path('i18n/lang/**/*')) .pipe(plumber())
.pipe(plumber()) .pipe(gulp.dest(appDir.path('i18n/lang'))));
.pipe(gulp.dest(appDir.path('i18n/lang')));
});
gulp.task('bundle', () => { gulp.task('bundle', () => Promise.all([
return Promise.all([ bundle(srcDir.path('background.js'), appDir.path('background.js')),
bundle(srcDir.path('background.js'), appDir.path('background.js')), bundle(srcDir.path('app.js'), appDir.path('app.js')),
bundle(srcDir.path('app.js'), appDir.path('app.js')), bundle(srcDir.path('i18n/index.js'), appDir.path('i18n/index.js')),
bundle(srcDir.path('i18n/index.js'), appDir.path('i18n/index.js')) ]));
]);
});
gulp.task('less', () => { gulp.task('less', () => gulp.src(srcDir.path('stylesheets/main.less'))
return gulp.src(srcDir.path('stylesheets/main.less')) .pipe(plumber())
.pipe(plumber()) .pipe(less())
.pipe(less()) .pipe(gulp.dest(appDir.path('stylesheets'))));
.pipe(gulp.dest(appDir.path('stylesheets')));
});
gulp.task('environment', () => { gulp.task('environment', () => gulp.src(configDir.path(`env_${ utils.getEnvName() }.json`))
return gulp.src(configDir.path(`env_${ utils.getEnvName() }.json`)) .pipe(plumber())
.pipe(plumber()) .pipe(rename('env.json'))
.pipe(rename('env.json')) .pipe(gulp.dest(appDir.path('.'))));
.pipe(gulp.dest(appDir.path('.')));
});
gulp.task('build-app', [ 'public', 'i18n', 'bundle', 'less', 'environment' ]); gulp.task('build-app', ['public', 'i18n', 'bundle', 'less', 'environment']);
gulp.task('watch', () => { gulp.task('watch', () => {
const runOnChanges = taskName => batch((event, done) => { const runOnChanges = (taskName) => batch((event, done) => {
gulp.start(taskName, err => { gulp.start(taskName, (err) => {
if (err) { if (err) {
beepSound(); beepSound();
} }
done(err); done(err);
}); });
}); });
watch(srcDir.path('public/**/*'), runOnChanges('public')); watch(srcDir.path('public/**/*'), runOnChanges('public'));
watch(srcDir.path('i18n/lang/**/*'), runOnChanges('i18n')); watch(srcDir.path('i18n/lang/**/*'), runOnChanges('i18n'));
watch(srcDir.path('**/*.js'), runOnChanges('bundle')); watch(srcDir.path('**/*.js'), runOnChanges('bundle'));
watch(srcDir.path('**/*.less'), runOnChanges('less')); watch(srcDir.path('**/*.less'), runOnChanges('less'));
watch(configDir.path('**/*'), runOnChanges('environment')); watch(configDir.path('**/*'), runOnChanges('environment'));
}); });
...@@ -5,30 +5,32 @@ const jetpack = require('fs-jetpack'); ...@@ -5,30 +5,32 @@ const jetpack = require('fs-jetpack');
const bundle = require('./bundle'); const bundle = require('./bundle');
const istanbul = require('rollup-plugin-istanbul'); const istanbul = require('rollup-plugin-istanbul');
const createEntryFile = (srcDir, matching, outputDir, entryFileName, rollupOptions) => { const createEntryFile = async(srcDir, matching, outputDir, entryFileName, rollupOptions) => {
return srcDir.findAsync('.', { matching }) const entryFileContent = srcDir.find('.', { matching })
.then(specPaths => specPaths.map(path => `import './${ path.replace(/\\/g, '/') }';`)) .map((path) => `import './${ path.replace(/\\/g, '/') }';`)
.then(imports => ( .join('\n');
"// This file is generated automatically.\n" +
"// All modifications will be lost.\n" + srcDir.write(entryFileName, entryFileContent);
imports.join('\n')
)) await bundle(srcDir.path(entryFileName), outputDir.path(entryFileName), rollupOptions);
.then(entryFileContent => srcDir.writeAsync(entryFileName, entryFileContent))
.then(() => bundle(srcDir.path(entryFileName), outputDir.path(entryFileName), rollupOptions)) srcDir.remove(entryFileName);
.then(() => srcDir.remove(entryFileName));
}; };
gulp.task('build-unit-tests', [ 'environment' ], () => { gulp.task('build-unit-tests', ['environment'], () => createEntryFile(
return createEntryFile(jetpack.cwd('src'), '*.spec.js', jetpack.cwd('app'), 'specs.js.autogenerated', { jetpack.cwd('src'), '*.spec.js',
rollupPlugins: [ jetpack.cwd('app'), 'specs.js.autogenerated',
istanbul({ {
exclude: ['**/*.spec.js', '**/specs.js.autogenerated'], rollupPlugins: [
sourcemap: true istanbul({
}) exclude: ['**/*.spec.js', '**/specs.js.autogenerated'],
] sourcemap: true,
}); }),
}); ],
}
));
gulp.task('build-e2e-tests', [ 'build-app' ], () => { gulp.task('build-e2e-tests', ['build-app'], () => createEntryFile(
return createEntryFile(jetpack.cwd('e2e'), '*.e2e.js', jetpack.cwd('app'), 'e2e.js.autogenerated'); jetpack.cwd('e2e'), '*.e2e.js',
}); jetpack.cwd('app'), 'e2e.js.autogenerated'
));
...@@ -2,59 +2,46 @@ ...@@ -2,59 +2,46 @@
const path = require('path'); const path = require('path');
const jetpack = require('fs-jetpack'); const jetpack = require('fs-jetpack');
const rollup = require('rollup').rollup; const { rollup } = require('rollup');
const rollupJson = require('rollup-plugin-json'); const rollupJson = require('rollup-plugin-json');
const appManifest = require('../package.json');
const nodeBuiltInModules = ['assert', 'buffer', 'child_process', 'cluster', const nodeBuiltInModules = ['assert', 'buffer', 'child_process', 'cluster', 'console', 'constants', 'crypto', 'dgram',
'console', 'constants', 'crypto', 'dgram', 'dns', 'domain', 'events', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path', 'process', 'punycode', 'querystring',
'fs', 'http', 'https', 'module', 'net', 'os', 'path', 'process', 'punycode', 'readline', 'repl', 'stream', 'string_decoder', 'timers', 'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib'];
'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'timers',
'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib'];
const electronBuiltInModules = ['electron']; const electronBuiltInModules = ['electron'];
const generateExternalModulesList = function () { const externalModulesList = [
const appManifest = jetpack.read('./package.json', 'json'); ...nodeBuiltInModules,
return [].concat( ...electronBuiltInModules,
nodeBuiltInModules, ...Object.keys(appManifest.dependencies),
electronBuiltInModules, ...Object.keys(appManifest.devDependencies),
Object.keys(appManifest.dependencies), ];
Object.keys(appManifest.devDependencies)
);
};
const cached = {}; const cached = {};
module.exports = function (src, dest, opts) { module.exports = async(src, dest, opts = {}) => {
opts = opts || {}; const inputOptions = {
opts.rollupPlugins = opts.rollupPlugins || []; input: src,
return rollup({ external: externalModulesList,
input: src, cache: cached[src],
external: generateExternalModulesList(), plugins: [
cache: cached[src], ...(opts.rollupPlugins || []),
plugins: [].concat( rollupJson(),
opts.rollupPlugins, ],
rollupJson() };
),
}) const outputOptions = {
.then(function (bundle) { format: 'cjs',
cached[src] = bundle; file: dest,
intro: '(function () {',
const jsFile = path.basename(dest); outro: '})()',
return bundle.generate({ sourcemap: true,
format: 'cjs', sourcemapFile: path.basename(dest),
sourcemap: true, };
sourcemapFile: jsFile,
}); const bundle = await rollup(inputOptions);
}) cached[src] = bundle;
.then(function (result) { await bundle.write(outputOptions);
// Wrap code in self invoking function so the variables don't
// pollute the global namespace.
const isolatedCode = '(function () {' + result.code + '\n}());';
const jsFile = path.basename(dest);
return Promise.all([
jetpack.writeAsync(dest, isolatedCode + '\n//# sourcemappingURL=' + jsFile + '.map'),
jetpack.writeAsync(dest + '.map', result.map.toString()),
]);
});
}; };
...@@ -8,16 +8,11 @@ const { getEnvName } = require('./utils'); ...@@ -8,16 +8,11 @@ const { getEnvName } = require('./utils');
const publish = getEnvName() !== 'production' ? 'never' : 'onTagOrDraft'; const publish = getEnvName() !== 'production' ? 'never' : 'onTagOrDraft';
gulp.task('release:darwin', () => build({ publish, x64: true, mac: [] })); gulp.task('release:darwin', () => build({ publish, x64: true, mac: [] }));
gulp.task('release:win32', () => build({ publish, x64: true, ia32: true, win: [ 'nsis', 'appx' ] })); gulp.task('release:win32', () => build({ publish, x64: true, ia32: true, win: ['nsis', 'appx'] }));
gulp.task('release:linux', (cb) => { gulp.task('release:linux', async() => {
build({ publish, x64: true, linux: [], c: { productName: 'rocketchat' } }) const allLinuxTargetsButSnap = config.linux.target.filter((target) => target !== 'snap');
.then(() => build({ await build({ publish, x64: true, linux: [], c: { productName: 'rocketchat' } });
publish, await build({ publish, ia32: true, linux: allLinuxTargetsButSnap, c: { productName: 'rocketchat' } });
ia32: true,
linux: config.linux.target.filter(target => target !== 'snap'),
c: { productName: 'rocketchat' }
}))
.then(() => cb(), (error) => cb(error));
}); });
gulp.task('release', (cb) => runSequence('build-app', `release:${ process.platform }`, cb)); gulp.task('release', (cb) => runSequence('build-app', `release:${ process.platform }`, cb));
...@@ -4,7 +4,7 @@ const gulp = require('gulp'); ...@@ -4,7 +4,7 @@ const gulp = require('gulp');
const childProcess = require('child_process'); const childProcess = require('child_process');
const electron = require('electron'); const electron = require('electron');
gulp.task('start', [ 'build-app', 'watch' ], () => { gulp.task('start', ['build-app', 'watch'], () => {
childProcess.spawn(electron, [ '.' ], { stdio: 'inherit' }) childProcess.spawn(electron, ['.'], { stdio: 'inherit' })
.on('close', () => process.exit()); .on('close', () => process.exit());
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment