Merge static refactor
This commit is contained in:
parent
5976870d38
commit
3045702a1e
158 changed files with 549 additions and 757 deletions
|
|
@ -1,26 +1,70 @@
|
|||
import { parallel, series, watch as _watch } from 'gulp';
|
||||
|
||||
import path from 'path';
|
||||
import del from 'del';
|
||||
|
||||
import { ACCOUNTS_DIR, CORE_DIR, sassTask } from './gulp/sass';
|
||||
import babelTask from './gulp/babel';
|
||||
import { dest, parallel, series, src, watch as _watch } from 'gulp';
|
||||
import concat from 'gulp-concat';
|
||||
import globby from 'globby';
|
||||
import sass from 'gulp-sass';
|
||||
import babelify from 'babelify';
|
||||
import browserify from 'browserify';
|
||||
import source from 'vinyl-source-stream';
|
||||
import buffer from 'vinyl-buffer';
|
||||
|
||||
const PROJECT_DIR = path.join('src', 'newsreader');
|
||||
const STATIC_DIR = path.join(PROJECT_DIR, 'static');
|
||||
const CSS_SUFFIX = 'css/';
|
||||
const JS_SUFFIX = 'js/';
|
||||
|
||||
const SASS_DEST_DIR = path.join(STATIC_DIR, CSS_SUFFIX);
|
||||
const JS_DEST_DIR = path.join(STATIC_DIR, JS_SUFFIX);
|
||||
|
||||
const SASS_DIR = path.join(PROJECT_DIR, 'scss');
|
||||
const JS_DIR = path.join(PROJECT_DIR, 'js');
|
||||
|
||||
const clean = () => {
|
||||
return del([
|
||||
`${ACCOUNTS_DIR}/accounts/dist/css/*`,
|
||||
return del([`${STATIC_DIR}/${CSS_SUFFIX}/*.css`, `${STATIC_DIR}/${JS_SUFFIX}/*.js`]);
|
||||
};
|
||||
|
||||
`${CORE_DIR}/core/dist/css/*`,
|
||||
`${CORE_DIR}/core/dist/js/*`,
|
||||
]);
|
||||
const sassTask = () => {
|
||||
return src(`${SASS_DIR}/index.scss`)
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(concat(`main.css`))
|
||||
.pipe(dest(SASS_DEST_DIR));
|
||||
};
|
||||
|
||||
const babelTask = () => {
|
||||
const getDirName = filename => {
|
||||
const fragments = filename.split('/');
|
||||
|
||||
return fragments[fragments.length - 2];
|
||||
};
|
||||
|
||||
const promise = globby([`${JS_DIR}/pages/**/index.js`]).then(entries => {
|
||||
entries.forEach(entry => {
|
||||
const bundle = browserify({ entries: entry, debug: true });
|
||||
const transpiledBundle = bundle.transform(babelify);
|
||||
const bundleName = getDirName(entry);
|
||||
|
||||
return transpiledBundle
|
||||
.bundle()
|
||||
.pipe(source('index.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(concat(`${bundleName}.js`))
|
||||
.pipe(dest(JS_DEST_DIR));
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.resolve(promise);
|
||||
};
|
||||
|
||||
export const watch = () => {
|
||||
return _watch([`${PROJECT_DIR}/scss/**/*.scss`, `${PROJECT_DIR}/js/**/*.js`], done => {
|
||||
series(clean, sassTask, babelTask)(done);
|
||||
});
|
||||
return _watch(
|
||||
[`${PROJECT_DIR}/scss/**/*.scss`, `${PROJECT_DIR}/js/**/*.js`],
|
||||
{ ignoreInitial: false },
|
||||
done => {
|
||||
series(clean, parallel(sassTask, babelTask))(done);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default series(clean, sassTask, babelTask);
|
||||
export default series(clean, parallel(babelTask, sassTask));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue