newsreader/gulp/babel.js
2019-12-31 14:33:14 +01:00

52 lines
1.3 KiB
JavaScript

import path from 'path';
import { dest, series } from 'gulp';
import babelify from 'babelify';
import browserify from 'browserify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import concat from 'gulp-concat';
const PROJECT_DIR = path.join('src', 'newsreader');
const SRC_DIR = path.join(PROJECT_DIR, 'js');
const STATIC_SUFFIX = 'dist/js/';
const CORE_DIR = path.join(PROJECT_DIR, 'news', 'core', 'static', 'core');
const COLLECTION_DIR = path.join(
PROJECT_DIR,
'news',
'collection',
'static',
'collection'
);
const taskMappings = [
{ name: 'homepage', destDir: `${CORE_DIR}/${STATIC_SUFFIX}` },
{ name: 'categories', destDir: `${CORE_DIR}/${STATIC_SUFFIX}` },
{ name: 'rules', destDir: `${COLLECTION_DIR}/${STATIC_SUFFIX}` },
];
const babelTask = done => {
const tasks = taskMappings.map(taskMapping => {
const { name, destDir } = taskMapping;
const bundle = browserify({
entries: `${SRC_DIR}/pages/${name}/index.js`,
debug: true,
});
const transpiledBundle = bundle.transform(babelify);
return () =>
transpiledBundle
.bundle()
.pipe(source('index.js'))
.pipe(buffer())
.pipe(concat(`${name}.js`))
.pipe(dest(destDir));
});
return series(...tasks)(done);
};
export default babelTask;