Skip to content

Commit ee847e1

Browse files
author
Samson
committed
updated build
1 parent 1f664c4 commit ee847e1

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

build/build.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,62 @@ var http = require('http-get');
44
var rjs = require('requirejs');
55
var knox = require('knox');
66
var 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

1237
if(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+
1747
var version = Date.now();
1848
var outputFolder = 'output/version/' + version
19-
console.log('Building client');
49+
log('Starting build');
2050
var startTime = Date.now();
2151

52+
log('Create output folders', types.action);
53+
2254
fs.removeSync('output');
2355
fs.mkdirSync('output');
2456
fs.mkdirSync('output/version');
2557
fs.mkdirSync(outputFolder);
58+
59+
2660
var 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+
63102
var index = fs.readFileSync(rootPath + '/index.html', 'ascii');
64103
index = index.replace('css/styles.css', cloudfront + '/version/' + version + '/css/styles.css');
65104
index = index.replace('<base href="/repos/apiengine-client/" />', '');
66105
index = index.replace(' data-main="js/main"', ' data-main="' + cloudfront + '/version/' + version + '/js/main"');
106+
107+
log('Optimization css with require.js', types.action)
108+
67109
fs.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

100144
cssIncImages(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
});

build/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"knox": "~0.3.0",
99
"http-get": "~0.4.2",
1010
"glob": "~3.1.12",
11-
"chimney": "~0.2.0"
11+
"chimney": "~0.2.0",
12+
"cli-color": "~0.2.2",
1213
}
1314
}

0 commit comments

Comments
 (0)