@@ -13,7 +13,7 @@ const settings = {
1313 name : 'codesy' ,
1414 version : '0.0.0.6' ,
1515 source : './src' ,
16- destination : './build ' ,
16+ destination : './dist ' ,
1717 static_files : {
1818 source : './static' ,
1919 glob : [ 'css/*' , 'js/*.js' , 'img/*.png' ]
@@ -42,112 +42,100 @@ const settings = {
4242// the functions will return a stream of files.
4343
4444javascript_src = function ( options ) {
45- this . source = options . source
46- this . destination = options . destination
4745 return (
48- function ( _this ) {
46+ function ( { source , destination } ) {
4947 return function ( ) {
50- console . log ( "gather src " + _this . source + "/*.js files" )
51-
52- const js_files = gulp . src ( [ _this . source + '/*.js' , settings . source + '/*.js' ] )
48+ console . log ( `gather src ${ source } /*.js files` )
49+ const js_files = gulp . src ( [ `${ source } /*.js` , `${ source } /*.js` ] )
5350 . pipe ( headerComment ( `codesy widget version ${ settings . version } ` ) )
54- if ( _this . destination ) {
55- return js_files . pipe ( gulp . dest ( _this . destination + ' /js' ) )
51+ if ( destination ) {
52+ return js_files . pipe ( gulp . dest ( ` ${ destination } /js` ) )
5653 } else {
5754 return js_files
5855 }
5956 }
6057 }
61- ) ( this )
58+ ) ( options )
6259}
6360
6461
6562static_files = function ( destination ) {
66- this . destination = destination
67- return (
68- function ( _this ) {
69- return function ( ) {
70- const static_stream = gulp . src ( settings . static_files . glob ,
71- { base : settings . static_files . source ,
72- cwd : settings . static_files . source
73- } )
74- if ( _this . destination ) {
75- return static_stream . pipe ( gulp . dest ( _this . destination ) )
76- } else {
77- return static_stream
63+ return (
64+ function ( destination , { glob, source} ) {
65+ return function ( ) {
66+ const static_stream = gulp . src ( glob , { base : source , cwd : source } )
67+ if ( destination ) {
68+ return static_stream . pipe ( gulp . dest ( destination ) )
69+ } else {
70+ return static_stream
71+ }
72+ }
7873 }
79- }
80- }
81- ) ( this )
74+ ) ( destination , settings . static_files )
8275}
8376
8477// this function needs to include dev server details in the options object:
8578// dev_server: object with domain and port
8679
8780const manifest = function ( options ) {
88- this . options = options
8981 return (
90- function ( _this ) {
82+ function ( { source , destination } ) {
9183 return function ( ) {
92- const common = gulp . src ( settings . source + ' /manifest.json' )
93- const additions = gulp . src ( _this . options . source + ' /manifest_additions.json' )
84+ const common = gulp . src ( ` ${ settings . source } /manifest.json` )
85+ const additions = gulp . src ( ` ${ source } /manifest_additions.json` )
9486 manifest_stream = mergeStream ( additions , common )
9587 . pipe ( mergeJSON ( 'manifest.json' ) )
9688 . pipe ( jeditor ( function ( json ) {
9789 json . version = settings . version
9890 return json
9991 } ) )
100- if ( _this . destination ) {
101- return manifest_stream . pipe ( gulp . dest ( _this . destination ) ) ;
92+ if ( destination ) {
93+ return manifest_stream . pipe ( gulp . dest ( destination ) ) ;
10294 } else {
10395 return manifest_stream
10496 }
10597 }
106- } ) ( this )
98+ } ) ( options )
10799}
108100
109101const add_dev_server = function ( manifest_stream ) {
110- const warning = [ 'THIS IS NOT the production manifest.' ] ,
111- dev_permission = [ "https://" , settings . dev_server . domain , ":" , settings . dev_server . port , "/" ] ,
112- dev_match = [ "https://" , settings . dev_server . domain , "/" ]
102+ ( { domain, port} = settings . dev_server )
103+ const warning = 'THIS IS NOT the production manifest.' ,
104+ dev_permission = `https://${ domain } :${ port } /` ,
105+ dev_match = `https://${ domain } /`
113106 return manifest_stream
114107 . pipe ( jeditor ( function ( json ) {
115- json . DEV_WARNING = warning . join ( "" )
116- json . permissions . push ( dev_permission . join ( "" ) )
117- json . content_scripts [ 1 ] . matches . push ( dev_match . join ( "" ) )
108+ json . DEV_WARNING = warning
109+ json . permissions . push ( dev_permission )
110+ json . content_scripts [ 1 ] . matches . push ( dev_match )
118111 return json
119112 } ) )
120113}
121114
122115const package = function ( options , zipped , for_dev ) {
123- this . options = options
124- this . zipped = zipped
125- this . for_dev = for_dev
126116 return (
127- function ( _this ) {
117+ function ( { source , destination : dest , extension } , zipped , for_dev ) {
128118 return function ( ) {
129119 let package_name , destination , package_stream ;
130120 let static_stream = ( new static_files ( ) ) ( )
131- let manifest_stream = ( new manifest ( { source : _this . options . source } ) ) ( )
132- const js_stream = ( new javascript_src ( { source : _this . options . source } ) ) ( )
121+ let manifest_stream = ( new manifest ( { source} ) ) ( )
122+ const js_stream = ( new javascript_src ( { source} ) ) ( )
133123 . pipe ( rename ( function ( path ) {
134124 path . dirname += "/js" ;
135125 } ) )
136126
137- if ( _this . for_dev ) {
127+ if ( for_dev ) {
138128 manifest_stream = add_dev_server ( manifest_stream )
139- package_name = settings . name + '-dev' + _this . options . extension
140- destination = _this . options . destination
141-
129+ package_name = `${ settings . name } -dev${ extension } `
142130 } else {
143131 js_stream . pipe ( stripDebug ( ) )
144- package_name = settings . name + '-' + settings . version + _this . options . extension
145- destination = settings . destination
132+ package_name = `${ settings . name } -${ settings . version } ${ extension } `
146133 }
147134
135+ destination = for_dev ? dest : settings . destination
148136 package_stream = mergeStream ( manifest_stream , js_stream , static_stream )
149137
150- if ( _this . zipped ) {
138+ if ( zipped ) {
151139 package_stream
152140 . pipe ( zip ( package_name ) )
153141 . pipe ( gulp . dest ( destination ) )
@@ -157,22 +145,19 @@ const package = function (options, zipped, for_dev){
157145 }
158146 }
159147 }
160- ) ( this )
148+ ) ( options , zipped , for_dev )
161149}
162150
163- const watch_dev = function ( options , task ) {
151+ const watch_dev = function ( { source } , task ) {
164152 console . log ( "start watching" ) ;
165- const manifest_files = [ settings . source + '/manifest.json' , options . source + '/manifest_additions.json' ]
166- const js_files = [ options . source + '/*.js' , settings . source + '/*.js' ]
167- // watch static files
168- gulp . watch ( settings . static_files . source + '/**' , task )
169- // watch manifest files
153+ const manifest_files = [ `${ settings . source } /manifest.json` , `${ source } /manifest_additions.json` ]
154+ const js_files = [ `${ source } /*.js` , `${ settings . source } /*.js` ]
155+ gulp . watch ( `${ settings . static_files . source } /**` , task )
170156 gulp . watch ( manifest_files , task )
171157 gulp . watch ( js_files , task )
172158}
173159
174160// DEV TASKS
175-
176161gulp . task ( 'dev-chrome-unpacked' , [ 'chrome-unpacked' ] , function ( ) {
177162 watch_dev ( settings . chrome , [ 'chrome-unpacked' ] )
178163} )
@@ -192,6 +177,8 @@ gulp.task('dev-firefox-packed', ['firefox-dev-xpi'], function() {
192177gulp . task ( 'dev-unpacked' , [ 'dev-chrome-unpacked' , 'dev-firefox-unpacked' ] )
193178gulp . task ( 'dev-packed' , [ 'dev-chrome-packed' , 'dev-firefox-packed' ] )
194179
180+ // FF dev must use file
181+ gulp . task ( 'dev-mixed' , [ 'dev-chrome-unpacked' , 'dev-firefox-packed' ] )
195182
196183
197184// FILE BUILDING TASKS
@@ -208,11 +195,10 @@ gulp.task('chrome-dev-zip', (new package(settings.chrome, true, true)))
208195// create chrome dev directroy in the chrome.source directory with dev settings
209196gulp . task ( 'chrome-unpacked' , ( new package ( settings . chrome , false , true ) ) )
210197
211-
212198// create xpi for FF prod
213199gulp . task ( 'publish-firefox' , ( new package ( settings . firefox , true , false ) ) )
214200
215- // create zip for chrome and opera
201+ // create zip for chrome and opera
216202gulp . task ( 'publish-chrome' , ( new package ( settings . chrome , true , false ) ) )
217203
218204gulp . task ( 'publish-all' , [ 'publish-firefox' , 'publish-chrome' ] )
0 commit comments