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

Update code style of gulp tasks

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