1
- var fs = require ( 'fs' ) ;
2
- var path = require ( 'path' ) ;
3
-
4
- var browserify = require ( 'browserify' ) ;
5
- var UglifyJS = require ( 'uglify-js' ) ;
6
-
7
1
var constants = require ( './util/constants' ) ;
8
2
var common = require ( './util/common' ) ;
9
- var compressAttributes = require ( './util/compress_attributes' ) ;
10
- var patchMinified = require ( './util/patch_minified' ) ;
11
- var doesFileExist = common . doesFileExist ;
3
+ var _bundle = require ( './util/browserify_wrapper' ) ;
12
4
13
5
/*
14
6
* This script takes one argument
@@ -26,6 +18,7 @@ var DEV = (arg === 'dev') || (arg === '--dev');
26
18
27
19
28
20
// Check if style and font build files are there
21
+ var doesFileExist = common . doesFileExist ;
29
22
if ( ! doesFileExist ( constants . pathToCSSBuild ) || ! doesFileExist ( constants . pathToFontSVG ) ) {
30
23
throw new Error ( [
31
24
'build/ is missing one or more files' ,
@@ -59,45 +52,3 @@ constants.partialBundlePaths.forEach(function(pathObj) {
59
52
pathToMinBundle : pathObj . distMin
60
53
} ) ;
61
54
} ) ;
62
-
63
- function _bundle ( pathToIndex , pathToBundle , opts ) {
64
- opts = opts || { } ;
65
-
66
- // do we output a minified file?
67
- var pathToMinBundle = opts . pathToMinBundle ,
68
- outputMinified = ! ! pathToMinBundle && ! opts . debug ;
69
-
70
- var browserifyOpts = { } ;
71
- browserifyOpts . standalone = opts . standalone ;
72
- browserifyOpts . debug = opts . debug ;
73
- browserifyOpts . transform = outputMinified ? [ compressAttributes ] : [ ] ;
74
-
75
- var b = browserify ( pathToIndex , browserifyOpts ) ,
76
- bundleWriteStream = fs . createWriteStream ( pathToBundle ) ;
77
-
78
- bundleWriteStream . on ( 'finish' , function ( ) {
79
- logger ( pathToBundle ) ;
80
- } ) ;
81
-
82
- b . bundle ( function ( err , buf ) {
83
- if ( err ) throw err ;
84
-
85
- if ( outputMinified ) {
86
- var minifiedCode = UglifyJS . minify ( buf . toString ( ) , constants . uglifyOptions ) . code ;
87
- minifiedCode = patchMinified ( minifiedCode ) ;
88
-
89
- fs . writeFile ( pathToMinBundle , minifiedCode , function ( err ) {
90
- if ( err ) throw err ;
91
-
92
- logger ( pathToMinBundle ) ;
93
- } ) ;
94
- }
95
- } )
96
- . pipe ( bundleWriteStream ) ;
97
- }
98
-
99
- function logger ( pathToOutput ) {
100
- var log = 'ok ' + path . basename ( pathToOutput ) ;
101
-
102
- console . log ( log ) ;
103
- }
0 commit comments