@@ -4,6 +4,7 @@ const sass = require('node-sass');
44const browserify = require ( 'browserify' ) ;
55const coffeeify = require ( 'coffeeify' ) ;
66const babelify = require ( 'babelify' ) ;
7+ const uglifyify = require ( 'uglifyify' ) ;
78const tildeImporter = require ( 'node-sass-tilde-importer' ) ;
89
910const paths = {
@@ -13,19 +14,35 @@ const paths = {
1314 } ,
1415 output : {
1516 styles : 'build' ,
16- scripts : 'build'
17+ scripts : 'build' ,
18+ fonts : 'build'
1719 }
1820} ;
1921
20- function walkDir ( dir , callback ) {
21- fs . readdirSync ( dir ) . forEach ( f => {
22- let dirPath = path . join ( dir , f ) ;
23- let isDirectory = fs . statSync ( dirPath ) . isDirectory ( ) ;
24- isDirectory
25- ? walkDir ( dirPath , callback )
26- : callback ( path . join ( dir , f ) ) ;
27- } ) ;
28- }
22+ const staticDeps = [
23+ [ 'node_modules/bootstrap-table/dist/bootstrap-table.min.css' , paths . output . styles ] ,
24+ [ 'node_modules/chosen-js/chosen.min.css' , paths . output . styles ] ,
25+ [ 'node_modules/@devhau/md-editor/dist/md-editor.min.css' , paths . output . styles ] ,
26+
27+ [ 'node_modules/jquery/dist/jquery.min.js' , paths . output . scripts ] ,
28+ [ 'node_modules/bootstrap-sass/assets/javascripts/bootstrap.min.js' , paths . output . scripts ] ,
29+ [ 'node_modules/bootstrap-table/dist/bootstrap-table.min.js' , paths . output . scripts ] ,
30+ [ 'node_modules/bootstrap-table/dist/extensions/editable/bootstrap-table-editable.min.js' , paths . output . scripts ] ,
31+ [ 'node_modules/bootstrap-table/dist/locale/bootstrap-table-en-US.min.js' , paths . output . scripts ] ,
32+ [ 'node_modules/underscore/underscore-min.js' , paths . output . scripts ] ,
33+ [ 'node_modules/jscroll/dist/jquery.jscroll.min.js' , paths . output . scripts ] ,
34+ [ 'node_modules/chosen-js/chosen.jquery.min.js' , paths . output . scripts ] ,
35+ [ 'node_modules/@devhau/md-editor/dist/md-editor.min.js' , paths . output . scripts ] ,
36+ [ 'node_modules/typeahead.js/dist/typeahead.bundle.min.js' , paths . output . scripts ] ,
37+
38+ [ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot' , paths . output . fonts ] ,
39+ [ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.svg' , paths . output . fonts ] ,
40+ [ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf' , paths . output . fonts ] ,
41+ [ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff' , paths . output . fonts ] ,
42+ [ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2' , paths . output . fonts ] ,
43+ [ 'node_modules/font-awesome/fonts/fontawesome-webfont.ttf' , paths . output . fonts ] ,
44+ [ 'node_modules/font-awesome/fonts/fontawesome-webfont.woff2' , paths . output . fonts ]
45+ ] ;
2946
3047for ( let path in paths . output ) {
3148 if ( paths . output . hasOwnProperty ( path ) ) {
@@ -37,6 +54,24 @@ for (let path in paths.output) {
3754 }
3855}
3956
57+ for ( const [ fromFile , toDir ] of staticDeps ) {
58+ const toFile = fs . statSync ( toDir ) . isDirectory ( )
59+ ? path . join ( toDir , path . basename ( fromFile ) )
60+ : toDir ;
61+ fs . copyFileSync ( fromFile , toFile ) ;
62+ console . log ( `Copied ${ fromFile } to ${ toFile } ` ) ;
63+ }
64+
65+ function walkDir ( dir , callback ) {
66+ fs . readdirSync ( dir ) . forEach ( f => {
67+ let dirPath = path . join ( dir , f ) ;
68+ let isDirectory = fs . statSync ( dirPath ) . isDirectory ( ) ;
69+ isDirectory
70+ ? walkDir ( dirPath , callback )
71+ : callback ( path . join ( dir , f ) ) ;
72+ } ) ;
73+ }
74+
4075walkDir ( paths . input . styles , inputFile => {
4176 if ( ! inputFile . endsWith ( '.scss' ) )
4277 return ;
@@ -46,19 +81,20 @@ walkDir(paths.input.styles, inputFile => {
4681 sass . render ( {
4782 file : inputFile ,
4883 outfile : outFile ,
84+ outputStyle : 'compressed' ,
4985 importer : tildeImporter ,
5086 } , ( err , result ) => {
51- if ( err )
87+ if ( err ) {
5288 console . log ( err ) ;
53- else fs . writeFile ( outFile ,
54- result . css ,
55- 'utf8' ,
56- err => {
57- if ( err )
89+ } else {
90+ fs . writeFile ( outFile , result . css , 'utf8' , err => {
91+ if ( err ) {
5892 console . log ( err ) ;
59- else
93+ } else {
6094 console . log ( `Rendered ${ inputFile } to ${ outFile } ` ) ;
95+ }
6196 } ) ;
97+ }
6298 } ) ;
6399} ) ;
64100
@@ -70,7 +106,7 @@ walkDir(paths.input.scripts, inputFile => {
70106 const outFile = path . join ( paths . output . scripts , `${ basename } .js` ) ;
71107 browserify ( [ inputFile ] , {
72108 extensions : [ '.js' , '.coffee' ] ,
73- transform : [ coffeeify , babelify ] ,
109+ transform : [ coffeeify , babelify , [ uglifyify , { global : true } ] ] ,
74110 } ) . bundle ( ( err , result ) => {
75111 if ( err ) {
76112 console . log ( err ) ;
0 commit comments