@@ -4,26 +4,62 @@ var http = require('http-get');
44var rjs = require ( 'requirejs' ) ;
55var knox = require ( 'knox' ) ;
66var glob = require ( "glob" )
7+ var clc = require ( 'cli-color' ) ;
8+
9+ // CONFIG
10+
11+ var cloudfront_production = 'https://d3oqwi49u9bqjg.cloudfront.net' ;
12+ var cloudfront_stage = 'https://d51ivijxlr7mx.cloudfront.net' ;
13+
14+ // Logging helpers
15+
16+ var types = {
17+ default : clc . black ,
18+ error : clc . red . bold ,
19+ warn : clc . yellow ,
20+ heading : clc . blue . bold . underline ,
21+ label : clc . blue . bold ,
22+ action : clc . xterm ( 8 ) . italic
23+ } ;
24+
25+ var log = function ( message , _type ) {
26+ var type = _type || types . default ;
27+ console . log ( type ( message ) + '\n' ) ;
28+ }
29+
30+ // Start build
31+
32+ log ( 'Api Engine Client Builder' , types . heading )
33+
734
8- console . log ( process . argv ) ;
935
10- var cloudfront = 'https://d3oqwi49u9bqjg.cloudfront.net' ;
1136
1237if ( process . argv [ 2 ] === 'stage' ) {
13- var cloudfront = 'https://d51ivijxlr7mx.cloudfront.net' ;
38+ var cloudfront = cloudfront_stage ;
39+ log ( 'Staging enviroment selected' , types . label )
40+ } else {
41+ var cloudfront = cloudfront_production ;
42+ log ( 'Production enviroment selected' , types . label )
1443}
1544
1645
46+
1747var version = Date . now ( ) ;
1848var outputFolder = 'output/version/' + version
19- console . log ( 'Building client ' ) ;
49+ log ( 'Starting build ' ) ;
2050var startTime = Date . now ( ) ;
2151
52+ log ( 'Create output folders' , types . action ) ;
53+
2254fs . removeSync ( 'output' ) ;
2355fs . mkdirSync ( 'output' ) ;
2456fs . mkdirSync ( 'output/version' ) ;
2557fs . mkdirSync ( outputFolder ) ;
58+
59+
2660var rootPath = '..' ;
61+ log ( 'Running require.js optimizer' , types . action )
62+
2763 rjs . optimize ( {
2864 dir : outputFolder + '/js' ,
2965 mainConfigFile : rootPath + '/js/main.js' ,
@@ -60,10 +96,16 @@ var rootPath = '..';
6096 }
6197 ]
6298} ) ;
99+ log ( 'Optimization finished' , types . action )
100+ log ( 'Editing index.html to contain new enviroment variables' , types . action )
101+
63102var index = fs . readFileSync ( rootPath + '/index.html' , 'ascii' ) ;
64103index = index . replace ( 'css/styles.css' , cloudfront + '/version/' + version + '/css/styles.css' ) ;
65104index = index . replace ( '<base href="/repos/apiengine-client/" />' , '' ) ;
66105index = index . replace ( ' data-main="js/main"' , ' data-main="' + cloudfront + '/version/' + version + '/js/main"' ) ;
106+
107+ log ( 'Optimization css with require.js' , types . action )
108+
67109fs . writeFileSync ( 'output/index.html' , index ) ;
68110 rjs . optimize ( {
69111 cssIn : rootPath + '/css/styles.css' ,
@@ -88,6 +130,7 @@ function cssIncImages(cssFile) {
88130 fs . writeFileSync ( cssFile , css , 'utf-8' ) ; // you can overwrite the original file with this line
89131 return css ;
90132}
133+ log ( 'Copying accross more needed files' , types . action )
91134
92135 fs . copy ( rootPath + '/googleaa49fe030680ef6c.html' , 'output/googleaa49fe030680ef6c.html' , function ( ) {
93136 fs . copy ( rootPath + '/site.xml' , 'output/site.xml' , function ( ) {
@@ -96,11 +139,14 @@ function cssIncImages(cssFile) {
96139 fs . copy ( rootPath + '/css/img' , outputFolder + '/css/img' , function ( ) {
97140 fs . copy ( rootPath + '/img' , outputFolder + '/img' , function ( ) {
98141 fs . copy ( rootPath + '/css/fonts' , outputFolder + '/css/fonts' , function ( ) {
142+ log ( 'Embedding images into CSS' , types . action )
99143
100144cssIncImages ( outputFolder + '/css/styles.css' ) ;
101145 fs . copy ( 'output' , 'relic' , function ( ) {
102-
103146 var endTime = ( Date . now ( ) - startTime ) / 1000 ;
147+ log ( 'Build finished!' , types . heading )
148+ log ( 'Finished in ' + endTime + ' seconds' , types . label )
149+
104150} ) ;
105151 } ) ;
106152 } ) ;
0 commit comments