11var fs = require ( "fs" ) ,
2- uglify = {
3- parser : require ( "./lib/parse-js.js" ) ,
4- processor : require ( "./lib/process.js" )
5- } ,
6-
7- // Set the config filename
8- configfile = "config" ,
9-
10- config , version , source_dir , output_full , output_min , head , filenames , foot , i ,
11- ast , minified_source ,
12-
13- files = [ ] ,
14- numFiles = 0 ,
15-
16- source = "" ;
2+ uglify = {
3+ parser : require ( "./lib/parse-js.js" ) ,
4+ processor : require ( "./lib/process.js" )
5+ } ,
6+
7+ // Set the config filename
8+ configfile = "config" ,
9+
10+ config , version , source_dir , output_full , output_min , head , umd , filenames , foot , i ,
11+ ast , minified_source ,
12+
13+ files = [ ] ,
14+ numFiles = 0 ,
15+
16+ source = "" ;
1717
1818// Get config file
1919console . log ( "Reading config file..." ) ;
2020config = fs . readFileSync ( configfile , "UTF-8" ) ;
2121
2222// Get variables from config file
2323version = / ^ v e r s i o n = ( .* ) $ / m. exec ( config ) [ 1 ] ,
24- source_dir = / ^ s o u r c e _ d i r = ( .* ) $ / m. exec ( config ) [ 1 ] ,
25- output_full = / ^ o u t p u t _ f u l l = ( .* ) $ / m. exec ( config ) [ 1 ] . replace ( "{version}" , version ) ,
26- output_min = / ^ o u t p u t _ m i n = ( .* ) $ / m. exec ( config ) [ 1 ] . replace ( "{version}" , version ) ,
27- head = / h e a d \s - - - - - \s ( [ \s \S ] * ?) - - - - - \s / g. exec ( config ) [ 1 ] . replace ( "{version}" , version ) . replace ( "{year}" , "2011-" + ( new Date ( ) ) . getFullYear ( ) ) ,
28- filenames = / f i l e s \s - - - - - \s ( [ \s \S ] * ?) \s - - - - - / g. exec ( config ) [ 1 ] . split ( / \s / ) ;
29- foot = / f o o t \s - - - - - \s ( [ \s \S ] * ?) \s - - - - - / g. exec ( config ) [ 1 ] . split ( / \s / ) ;
24+ source_dir = / ^ s o u r c e _ d i r = ( .* ) $ / m. exec ( config ) [ 1 ] ,
25+ output_full = / ^ o u t p u t _ f u l l = ( .* ) $ / m. exec ( config ) [ 1 ] . replace ( "{version}" , version ) ,
26+ output_min = / ^ o u t p u t _ m i n = ( .* ) $ / m. exec ( config ) [ 1 ] . replace ( "{version}" , version ) ,
27+ head = / h e a d \s - - - - - \s ( [ \s \S ] * ?) - - - - - \s / g. exec ( config ) [ 1 ] . replace ( "{version}" , version ) . replace ( "{year}" , "2011-" + ( new Date ( ) ) . getFullYear ( ) ) ,
28+ umd = / u m d \s - - - - - \s ( [ \s \S ] * ?) - - - - - \s / g. exec ( config ) [ 1 ] ,
29+ filenames = / f i l e s \s - - - - - \s ( [ \s \S ] * ?) \s - - - - - / g. exec ( config ) [ 1 ] . split ( / \s / ) ;
30+
3031numFiles = filenames . length ;
31- filenames = filenames . concat ( foot ) ;
3232
3333// Get all the source files
3434for ( i = 0 ; i < filenames . length ; i ++ ) {
35- console . log ( "Reading file: " + filenames [ i ] ) ;
36-
37- // Add current file
38- files . push ( {
39- name : filenames [ i ] ,
40- content : fs . readFileSync ( source_dir + filenames [ i ] , "UTF-8" )
41- } ) ;
35+ console . log ( "Reading file: " + filenames [ i ] ) ;
36+
37+ // Add current file
38+ files . push ( {
39+ name : filenames [ i ] ,
40+ content : fs . readFileSync ( source_dir + filenames [ i ] , "UTF-8" )
41+ } ) ;
4242}
43-
43+
4444// Start the building process
4545console . log ( "Building source file..." ) ;
4646
47- // Add the head code to the top of the file
48- source = head ;
49-
50- // Loop through all files and append the source
47+ source = head + umd ;
5148for ( i = 0 ; i < numFiles ; i ++ ) {
5249
53- // Replace the self executing anonymous functions that wrap each file
54- // Only the end of core will be removed, and added to the end of the new file
55- if ( files [ i ] . name === "core/Proton.js" ) {
56- files [ i ] . content = files [ i ] . content . replace ( / \} ( \s | ) \) ( \s | ) \( w i n d o w ( \s | ) \) ; / , "" ) ;
57- } else {
58- files [ i ] . content = files [ i ] . content . replace ( / \( f u n c t i o n ( \s | ) \( ( \s | ) P r o t o n , ( \s | ) u n d e f i n e d ( \s | ) \) ( \s | ) \{ / , "" ) ;
59- files [ i ] . content = files [ i ] . content . replace ( / \} ( \s | ) \) ( \s | ) \( ( \s | ) P r o t o n ( \s | ) \) ; / , "" ) ;
60- }
61-
62- // Append the file to the full source
63- source += "\n" + files [ i ] . content ;
64-
65- // Append the end of the core wrapper
66- if ( i === numFiles - 1 ) {
67- source += "\n})(window);" ;
68- }
69- }
50+ if ( files [ i ] . name === "core/Proton.js" ) {
51+ files [ i ] . content = files [ i ] . content . replace ( / \} ( \s | ) \) ( \s | ) \( w i n d o w ( \s | ) \) ; / , "" ) ;
52+ files [ i ] . content = files [ i ] . content . replace ( / \( f u n c t i o n \( w i n d o w \, \s u n d e f i n e d \) \s \{ / , "" ) ;
53+ files [ i ] . content = files [ i ] . content . replace ( / w i n d o w \. P r o t o n \s \= \s P r o t o n \; / , "" ) ;
54+ } else {
55+ files [ i ] . content = files [ i ] . content . replace ( / \( f u n c t i o n ( \s | ) \( ( \s | ) P r o t o n , ( \s | ) u n d e f i n e d ( \s | ) \) ( \s | ) \{ / , "" ) ;
56+ files [ i ] . content = files [ i ] . content . replace ( / \} ( \s | ) \) ( \s | ) \( ( \s | ) P r o t o n ( \s | ) \) ; / , "" ) ;
57+ }
7058
71- // Loop through all foot files
72- for ( i = numFiles ; i < numFiles + foot . length ; i ++ ) {
59+ // Append the file to the full source
60+ source += "\n" + files [ i ] . content ;
7361
74- // Append the file to the full source
75- source += "\n" + files [ i ] . content ;
62+ // Append the end of the core wrapper
63+ if ( i === numFiles - 1 ) {
64+ //source += "\n })(window);";
65+ source += "\n\n return Proton;\n}));" ;
66+ }
7667}
77-
68+ ///console.log(umd);
7869// Save source to output file
7970fs . writeFile ( output_full , source , "UTF-8" ) ;
8071console . log ( "Source file saved as: " + output_full ) ;
@@ -89,4 +80,4 @@ minified_source = uglify.processor.gen_code(ast);
8980
9081// Save minified source file
9182fs . writeFile ( output_min , head + minified_source , "UTF-8" ) ;
92- console . log ( "Minified source file saved as: " + output_min ) ;
83+ console . log ( "Minified source file saved as: " + output_min ) ;
0 commit comments