1
+ // ----------------------------------------------------------------------
2
+ // This Source Code Form is subject to the terms of the Mozilla Public
3
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ // --
6
+ // Copyright 2016-2018 Andi Dittrich <https://andidittrich.de>
7
+ // ----------------------------------------------------------------------
8
+
9
+
10
+ // --------------------------------------------------------------------------
11
+ // EnlighterJS Syntax Highlighter - https://enlighterjs.org
12
+ // --------------------------------------------------------------------------
13
+
14
+ const _package = require ( './package.json' ) ;
15
+ const _path = require ( 'path' ) ;
16
+ const _gulp = require ( 'gulp' ) ;
17
+ const _log = require ( 'fancy-log' ) ;
18
+
19
+ const _gulp_less = require ( 'gulp-less' ) ;
20
+ const _gulp_replace = require ( 'gulp-replace' ) ;
21
+ const _prettyError = require ( 'gulp-prettyerror' ) ;
22
+ const _concat = require ( 'gulp-concat-util' ) ;
23
+ const _gulp_cleancss = require ( 'gulp-clean-css' ) ;
24
+ const _wrapper = require ( 'gulp-wrapper' ) ;
25
+ const _uglify = require ( 'gulp-uglify' ) ;
26
+ const _rollup = require ( 'rollup' ) ;
27
+ const _rollup_babel = require ( 'rollup-plugin-babel' ) ;
28
+
29
+ // default task
30
+ _gulp . task ( 'default' , [ 'library' ] ) ;
31
+
32
+ // license header prepended to builds
33
+ const licenseHeader = `/*! EnlighterJS Syntax Highlighter Gutenberg Plugin ${ _package . version } | Mozilla Public License 2.0 | https://enlighterjs.org */\n` ;
34
+
35
+ // transpile ES6 and write to tmp file
36
+ _gulp . task ( 'es6-transpile' , async function ( ) {
37
+ const bundle = await _rollup . rollup ( {
38
+ input : './src/EnlighterJS.Gutenberg.js' ,
39
+ plugins : [
40
+ _rollup_babel ( )
41
+ ]
42
+ } ) ;
43
+
44
+ // write the bundle to disk
45
+ await bundle . write ( {
46
+ format : 'iife' ,
47
+ name : 'EnlighterJS_Gutenberg' ,
48
+ file : './.tmp/enlighterjs.gutenberg.js'
49
+ } ) ;
50
+ } ) ;
51
+
52
+ // compress
53
+ _gulp . task ( 'library' , [ 'es6-transpile' ] , function ( ) {
54
+
55
+ // add jquery addon and minify it
56
+ return _gulp . src ( [ '.tmp/enlighterjs.gutenberg.js' ] )
57
+
58
+ // minify
59
+ //.pipe(_uglify())
60
+ . pipe ( _concat ( 'enlighterjs.gutenberg.min.js' ) )
61
+
62
+ // add license header
63
+ . pipe ( _wrapper ( {
64
+ header : licenseHeader
65
+ } ) )
66
+
67
+ // add version string
68
+ . pipe ( _gulp_replace ( / \[ \[ V E R S I O N ] ] / g, _package . version ) )
69
+
70
+ . pipe ( _gulp . dest ( './dist/' ) ) ;
71
+ } ) ;
72
+
73
+ // generator to transpile less->css
74
+ function less2css ( themes , outputFilename ) {
75
+ const themesources = themes . map ( function ( l ) {
76
+ return 'src/themes/' + l + '.less' ;
77
+ } ) ;
78
+
79
+ // base is always required!
80
+ return _gulp . src ( [ 'src/themes/base.less' ] . concat ( themesources ) )
81
+ . pipe ( _prettyError ( ) )
82
+
83
+ . pipe ( _gulp_less ( ) )
84
+ . pipe ( _gulp_cleancss ( ) )
85
+ . pipe ( _concat ( outputFilename + '.min.css' ) )
86
+
87
+ // add license header
88
+ . pipe ( _wrapper ( {
89
+ header : licenseHeader
90
+ } ) )
91
+
92
+ . pipe ( _gulp . dest ( 'dist' ) ) ;
93
+ }
94
+
95
+ // LESS to CSS (Base + Themes)- FULL Bundle
96
+ _gulp . task ( 'less-themes-full' , function ( ) {
97
+ return less2css ( themelist , 'enlighterjs' ) ;
98
+ } ) ;
99
+
100
+ // Single Theme export
101
+ _gulp . task ( 'less-themes-single' , function ( ) {
102
+ return themelist . map ( name => less2css ( [ name ] , 'enlighterjs.' + name ) ) ;
103
+ } ) ;
104
+
105
+ _gulp . task ( 'watch' , [ 'library' , 'less-themes-full' , 'webserver' ] , function ( ) {
106
+ // js, jsx files
107
+ _gulp . watch ( [ 'src/**/*.js' , 'src/**/*.jsx' ] , [ 'library' ] ) . on ( 'change' , function ( event ) {
108
+ _log ( 'File ' + event . path + ' was ' + event . type + ', running tasks...' ) ;
109
+ } ) ;
110
+
111
+ // less files
112
+ _gulp . watch ( 'src/themes/*.less' , [ 'less-themes-full' ] ) . on ( 'change' , function ( event ) {
113
+ _log ( 'File ' + event . path + ' was ' + event . type + ', running tasks...' ) ;
114
+ } ) ;
115
+ } ) ;
116
+
117
+ // development webserver
118
+ _gulp . task ( 'webserver' , function ( ) {
119
+ // start development webserver
120
+ const webapp = _express ( ) ;
121
+ webapp . get ( '/' , function ( req , res ) {
122
+ res . sendFile ( _path . join ( __dirname , 'Development.html' ) ) ;
123
+ } ) ;
124
+ webapp . use ( _express . static ( _path . join ( __dirname , 'dist' ) ) ) ;
125
+ webapp . listen ( 8888 , ( ) => _log ( 'DEV Webserver Online - localhost:8888' ) ) ;
126
+ } ) ;
0 commit comments