1- var fs = require ( 'fs' ) ;
2- var gulp = require ( 'gulp' ) ;
3- var gutil = require ( 'gulp-util' ) ;
4- var coffee = require ( 'gulp-coffee' ) ;
5- var stripDebug = require ( 'gulp-strip-debug' ) ;
6- var mergeStream = require ( 'merge-stream' ) ;
7- var mergeJSON = require ( 'gulp-merge-json' ) ;
8- var zip = require ( 'gulp-zip' ) ;
9- var jeditor = require ( "gulp-json-editor" ) ;
10- var rename = require ( 'gulp-rename' )
1+ const fs = require ( 'fs' ) ;
2+ const gulp = require ( 'gulp' ) ;
3+ const stripDebug = require ( 'gulp-strip-debug' ) ;
4+ const mergeStream = require ( 'merge-stream' ) ;
5+ const mergeJSON = require ( 'gulp-merge-json' ) ;
6+ const zip = require ( 'gulp-zip' ) ;
7+ const jeditor = require ( "gulp-json-editor" ) ;
8+ const rename = require ( 'gulp-rename' )
9+ const headerComment = require ( 'gulp-header-comment' ) ;
1110
1211// Settings for building packages
13- var settings = {
12+ const settings = {
1413 name : 'codesy' ,
15- version : '0.0.0.5 ' ,
14+ version : '0.0.0.6 ' ,
1615 source : './src' ,
17- destination : './build ' ,
16+ destination : './dist ' ,
1817 static_files : {
1918 source : './static' ,
2019 glob : [ 'css/*' , 'js/*.js' , 'img/*.png' ]
@@ -26,12 +25,12 @@ var settings = {
2625 firefox : {
2726 source : './src/firefox' ,
2827 destination : 'firefox' ,
29- extension : '. xpi'
28+ extension : 'xpi'
3029 } ,
3130 chrome : {
3231 source : './src/chrome' ,
3332 destination : 'chrome' ,
34- extension : '. zip'
33+ extension : 'zip'
3534
3635 }
3736}
@@ -42,112 +41,104 @@ var settings = {
4241// destination: (optional) path where files will go. If destination is not included,
4342// the functions will return a stream of files.
4443
45- compile_coffee = function ( options ) {
46- this . source = options . source
47- this . destination = options . destination
44+ javascript_src = function ( options ) {
4845 return (
49- function ( _this ) {
46+ function ( { source , destination } ) {
5047 return function ( ) {
51- console . log ( "compile " + _this . source + "/*.coffee files" )
52- // next line compile coffee files in source directory and ./src root
53- var compiled_stream = gulp . src ( [ _this . source + '/*.coffee' , settings . source + '/*.coffee' ] )
54- . pipe ( coffee ( { bare : true } ) . on ( 'error' , gutil . log ) )
55- if ( _this . destination ) {
56- return compiled_stream . pipe ( gulp . dest ( _this . destination + '/js' ) )
48+ console . log ( `gather src ${ source } /*.js files` )
49+ console . log ( `gather src ${ settings . source } /*.js files` )
50+
51+ const js_files = gulp . src ( [ `${ source } /*.js` , `${ settings . source } /*.js` ] )
52+ . pipe ( headerComment ( `codesy widget version ${ settings . version } ` ) )
53+
54+ if ( destination ) {
55+ console . log ( ` destination ${ destination } /js` ) ;
56+ return js_files . pipe ( gulp . dest ( `${ destination } /js` ) )
5757 } else {
58- return compiled_stream
58+ return js_files
5959 }
6060 }
6161 }
62- ) ( this )
62+ ) ( options )
6363}
6464
6565static_files = function ( destination ) {
66- this . destination = destination
67- return (
68- function ( _this ) {
69- return function ( ) {
70- var 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
66+ return (
67+ function ( destination , { glob, source} ) {
68+ return function ( ) {
69+ const static_stream = gulp . src ( glob , { base : source , cwd : source } )
70+ if ( destination ) {
71+ return static_stream . pipe ( gulp . dest ( destination ) )
72+ } else {
73+ return static_stream
74+ }
75+ }
7876 }
79- }
80- }
81- ) ( this )
77+ ) ( destination , settings . static_files )
8278}
8379
8480// this function needs to include dev server details in the options object:
8581// dev_server: object with domain and port
8682
87- var manifest = function ( options ) {
88- this . options = options
83+ const manifest = function ( options ) {
8984 return (
90- function ( _this ) {
85+ function ( { source , destination } ) {
9186 return function ( ) {
92- var common = gulp . src ( settings . source + ' /manifest.json' )
93- var additions = gulp . src ( _this . options . source + ' /manifest_additions.json' )
87+ const common = gulp . src ( ` ${ settings . source } /manifest.json` )
88+ const additions = gulp . src ( ` ${ source } /manifest_additions.json` )
9489 manifest_stream = mergeStream ( additions , common )
9590 . pipe ( mergeJSON ( 'manifest.json' ) )
9691 . pipe ( jeditor ( function ( json ) {
9792 json . version = settings . version
9893 return json
9994 } ) )
100- if ( _this . destination ) {
101- return manifest_stream . pipe ( gulp . dest ( _this . destination ) ) ;
95+ if ( destination ) {
96+ return manifest_stream . pipe ( gulp . dest ( destination ) ) ;
10297 } else {
10398 return manifest_stream
10499 }
105100 }
106- } ) ( this )
101+ } ) ( options )
107102}
108103
109- var add_dev_server = function ( manifest_stream ) {
110- var 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 , "/" ]
104+ const add_dev_server = function ( manifest_stream ) {
105+ ( { domain, port} = settings . dev_server )
106+ const warning = 'THIS IS NOT the production manifest.' ,
107+ dev_permission = `https://${ domain } :${ port } /` ,
108+ dev_match = `https://${ domain } /`
113109 return manifest_stream
114110 . 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 ( "" ) )
111+ json . DEV_WARNING = warning
112+ json . permissions . push ( dev_permission )
113+ json . content_scripts [ 1 ] . matches . push ( dev_match )
118114 return json
119115 } ) )
120116}
121117
122- var package = function ( options , zipped , for_dev ) {
123- this . options = options
124- this . zipped = zipped
125- this . for_dev = for_dev
118+ const package = function ( options , zipped , for_dev ) {
126119 return (
127- function ( _this ) {
120+ function ( { source , destination : dest , extension : ext } , zipped , for_dev ) {
128121 return function ( ) {
129- var package_name , destination , package_stream
130- var static_stream = ( new static_files ( ) ) ( )
131- var manifest_stream = ( new manifest ( { source :_this . options . source } ) ) ( )
132- var js_stream = ( new compile_coffee ( { source :_this . options . source } ) ) ( )
133- . pipe ( rename ( function ( path ) {
134- path . dirname += "/js" ;
135- } ) )
136-
137- if ( _this . for_dev ) {
122+ console . log ( `package source: ${ source } ` ) ;
123+ let package_name , destination , package_stream ;
124+ let static_stream = ( new static_files ( ) ) ( )
125+ let manifest_stream = ( new manifest ( { source} ) ) ( )
126+ const js_stream = ( new javascript_src ( { source} ) ) ( )
127+ . pipe ( rename ( ( path ) => path . dirname += "/js" ) )
128+
129+ if ( for_dev ) {
138130 manifest_stream = add_dev_server ( manifest_stream )
139- package_name = settings . name + '-dev' + _this . options . extension
140- destination = _this . options . destination
141-
131+ package_name = `${ settings . name } -${ settings . version } .dev.${ ext } `
142132 } else {
143133 js_stream . pipe ( stripDebug ( ) )
144- package_name = settings . name + '-' + settings . version + _this . options . extension
145- destination = settings . destination
134+ package_name = `${ settings . name } -${ settings . version } .${ ext } `
146135 }
136+ destination = for_dev ? dest : settings . destination
137+ console . log ( `package dest: ${ destination } ` ) ;
147138
148139 package_stream = mergeStream ( manifest_stream , js_stream , static_stream )
149140
150- if ( _this . zipped ) {
141+ if ( zipped ) {
151142 package_stream
152143 . pipe ( zip ( package_name ) )
153144 . pipe ( gulp . dest ( destination ) )
@@ -157,22 +148,19 @@ var package = function (options, zipped, for_dev){
157148 }
158149 }
159150 }
160- ) ( this )
151+ ) ( options , zipped , for_dev )
161152}
162153
163- var watch_dev = function ( options , task ) {
154+ const watch_dev = function ( { source } , task ) {
164155 console . log ( "start watching" ) ;
165- var manifest_files = [ settings . source + '/manifest.json' , options . source + '/manifest_additions.json' ]
166- var coffee_files = [ options . source + '/*.coffee' , settings . source + '/*.coffee' ]
167- // watch static files
168- gulp . watch ( settings . static_files . source + '/**' , task )
169- // watch manifest files
156+ const manifest_files = [ `${ settings . source } /manifest.json` , `${ source } /manifest_additions.json` ]
157+ const js_files = [ `${ source } /*.js` , `${ settings . source } /*.js` ]
158+ gulp . watch ( `${ settings . static_files . source } /**` , task )
170159 gulp . watch ( manifest_files , task )
171- gulp . watch ( coffee_files , task )
160+ gulp . watch ( js_files , task )
172161}
173162
174163// DEV TASKS
175-
176164gulp . task ( 'dev-chrome-unpacked' , [ 'chrome-unpacked' ] , function ( ) {
177165 watch_dev ( settings . chrome , [ 'chrome-unpacked' ] )
178166} )
@@ -182,16 +170,18 @@ gulp.task('dev-chrome-packed', ['chrome-dev-zip'], function() {
182170} )
183171
184172gulp . task ( 'dev-firefox-unpacked' , [ 'firefox-unpacked' ] , function ( ) {
185- watch_dev ( settings . chrome , [ 'firefox-unpacked' ] )
173+ watch_dev ( settings . firefox , [ 'firefox-unpacked' ] )
186174} )
187175
188176gulp . task ( 'dev-firefox-packed' , [ 'firefox-dev-xpi' ] , function ( ) {
189- watch_dev ( settings . chrome , [ 'firefox-dev-xpi' ] )
177+ watch_dev ( settings . firefox , [ 'firefox-dev-xpi' ] )
190178} )
191179
192180gulp . task ( 'dev-unpacked' , [ 'dev-chrome-unpacked' , 'dev-firefox-unpacked' ] )
193181gulp . task ( 'dev-packed' , [ 'dev-chrome-packed' , 'dev-firefox-packed' ] )
194182
183+ // FF dev must use file
184+ gulp . task ( 'dev-mixed' , [ 'dev-chrome-unpacked' , 'dev-firefox-packed' ] )
195185
196186
197187// FILE BUILDING TASKS
@@ -208,11 +198,10 @@ gulp.task('chrome-dev-zip', (new package(settings.chrome, true, true)))
208198// create chrome dev directroy in the chrome.source directory with dev settings
209199gulp . task ( 'chrome-unpacked' , ( new package ( settings . chrome , false , true ) ) )
210200
211-
212201// create xpi for FF prod
213202gulp . task ( 'publish-firefox' , ( new package ( settings . firefox , true , false ) ) )
214203
215- // create zip for chrome
204+ // create zip for chrome and opera
216205gulp . task ( 'publish-chrome' , ( new package ( settings . chrome , true , false ) ) )
217206
218207gulp . task ( 'publish-all' , [ 'publish-firefox' , 'publish-chrome' ] )
0 commit comments