-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
executable file
·141 lines (120 loc) · 3.42 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const autoprefixer = require( 'gulp-autoprefixer' );
const browserify = require( 'browserify' );
const babelify = require( 'babelify' );
const buffer = require( 'vinyl-buffer' );
const glob = require( 'glob' );
const gulp = require( 'gulp' );
const sass = require( 'gulp-sass' )( require('sass') );
const source = require( 'vinyl-source-stream' );
const sourcemaps = require( 'gulp-sourcemaps' );
const uglify = require( 'gulp-uglify-es' ).default;
const package = require( './package.json' );
let scssOverridePath
if ( process.argv.length > 3 && parseInt( process.argv[3] ) ) {
/// 2DO: fucken fix this!
scssOverridePath = '../../uploads/sites/' + process.argv[3] - '/scss/';
} else {
scssOverridePath = 'src/scss-override/';
}
const config = {
sass : {
precision: 8,
stopOnError: false,
functions: {
},
includePaths:[
'./src/scss/',
],
watchPaths: './src/scss/**/*.scss',
// importers:[]
},
js: {
exclude:[
'./src/js/lib/'
]
},
destPath: e => {
let ext = e.extname, next
if ( '.map' === ext ) {
ext = e.basename.replace( ext, '' ).match(/\.\w+$/)[0]
}
return ext.replace( /^\./, './' );
}
}
function js_task(debug) {
return cb => {
let tasks = glob.sync("./src/js/**/index.js")
.filter( p => ! config.js.exclude.find( ex => p.indexOf(ex) !== -1 ) )
.map( entry => {
let target = entry.replace(/(\.\/src\/js\/|\/index)/g,'');
const bundler = browserify({
entries: [entry],
debug: true, // keep always true
paths:['./src/js/lib']
})
.transform( babelify.configure({}) )
.transform( 'browserify-shim' );
return bundler
.bundle()
.pipe(source(target))
.pipe(buffer())
.pipe(sourcemaps.init( { loadMaps: true } ) )
.pipe( uglify() )
.on('error', function (error) {
console.error(error.message);
// this.emit('end');
})
.pipe(sourcemaps.write( './' ) )
.pipe( gulp.dest( config.destPath ) );
} );
return Promise.all(tasks)
}
}
function scss_task(debug) {
const conf = config.sass
conf.outputStyle = debug ? 'expanded' : 'compressed'
return cb => {
return gulp.src( config.sass.watchPaths )
.pipe( sourcemaps.init( ) )
.pipe( sass( conf ) )
.pipe(autoprefixer({}))
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( config.destPath ) );
// let g = gulp.src( config.sass.watchPaths ); // fuck gulp 4 sourcemaps!
// if ( debug ) { // lets keep ye olde traditions
// g = g.pipe( sourcemaps.init( ) )
// }
// g = g.pipe(
// sass( conf )
// )
// ;
// if ( debug ) {
// g = g.pipe( sourcemaps.write( '.' ) )
// }
//
// return g.pipe( gulp.dest( config.destPath ) );
}
}
gulp.task('build:js', js_task( false ) );
gulp.task('build:scss', scss_task( false ) );
gulp.task('dev:js', js_task( true ) );
gulp.task('dev:scss', scss_task( true ) );
gulp.task('watch:scss',cb => {
cb()
})
gulp.task('watch', cb => {
gulp.watch( config.sass.watchPaths, gulp.parallel('dev:scss','watch:scss'));
gulp.watch('./src/js/**/*.js',gulp.parallel('dev:js'));
});
gulp.task('dev',gulp.series('dev:scss','dev:js','watch'));
gulp.task('build', gulp.series('build:js','build:scss'));
gulp.task('default',cb => {
console.log('run either `gulp build` or `gulp dev`');
cb();
});
if ( process.argv.length > 3 && parseInt( process.argv[3] ) ) {
gulp.task( process.argv[3], gulp.series('dev'));
}
module.exports = {
build:gulp.series('build')
}