1+ import gulp from "gulp" ;
2+ import rimraf from "gulp-rimraf" ;
3+ import preprocess from "gulp-preprocess" ;
4+ import cssMin from "gulp-cssmin" ;
5+ import browserify from "browserify" ;
6+ import to5ify from "6to5ify" ;
7+ import streamify from "gulp-streamify" ;
8+ import source from "vinyl-source-stream" ;
9+ import scss from "gulp-sass" ;
10+ import pkg from "./package.json" ;
11+
12+ const
13+ SOURCE_DIR = `${ __dirname } /src` ,
14+ BUILD_DIR = `${ __dirname } /build` ,
15+ context = {
16+ package : pkg
17+ } ;
18+
19+ gulp . task ( "clean" , ( ) => {
20+ return gulp . src ( BUILD_DIR , { read : false } )
21+ . pipe ( rimraf ( ) ) ;
22+ } ) ;
23+
24+ gulp . task ( "cls" , [ "clean" ] , ( ) => {
25+ return gulp . src ( SOURCE_DIR + "/cls/**/*.cls" )
26+ . pipe ( preprocess ( { context : context } ) )
27+ . pipe ( gulp . dest ( BUILD_DIR + "/cls" ) ) ;
28+ } ) ;
29+
30+ gulp . task ( "html" , [ "clean" ] , ( ) => {
31+ return gulp . src ( SOURCE_DIR + "/static/**/*.html" )
32+ . pipe ( preprocess ( { context : context } ) )
33+ . pipe ( gulp . dest ( BUILD_DIR + "/static" ) ) ;
34+ } ) ;
35+
36+ gulp . task ( "js" , [ "clean" ] , ( ) => {
37+ return browserify ( `${ SOURCE_DIR } /static/js/index.js` , { debug : true } )
38+ . transform ( to5ify )
39+ . bundle ( )
40+ . on ( `error` , ( err ) => { console . error ( err ) ; } )
41+ . pipe ( source ( "index.js" ) )
42+ . pipe ( streamify ( preprocess ( { context : context } ) ) )
43+ . pipe ( gulp . dest ( `${ BUILD_DIR } /static/js` ) ) ;
44+ } ) ;
45+
46+ gulp . task ( "css" , [ "clean" ] , ( ) => {
47+ return gulp . src ( `${ SOURCE_DIR } /static/scss/index.scss` )
48+ . pipe ( scss ( ) . on ( "error" , scss . logError ) )
49+ . pipe ( cssMin ( ) )
50+ . pipe ( gulp . dest ( `${ BUILD_DIR } /static/css` ) ) ;
51+ } ) ;
52+
53+ gulp . task ( "default" , [ "cls" , "html" , "js" , "css" ] ) ;
0 commit comments