-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
81 lines (64 loc) · 2.22 KB
/
build.js
File metadata and controls
81 lines (64 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Creates the att.js source and att.min.js
/*global __dirname*/
var fileName = 'att.js',
minFileName = 'att.min.js',
src = __dirname + '/src',
vendor = __dirname + '/vendor',
outputPath = __dirname + '/' + fileName,
minifiedPath = __dirname + '/' + minFileName;
var fs = require('fs'),
mustache = require('mustache'),
uglify = require('uglify-js'),
colors = require('colors');
var template = fs.readFileSync(src + '/template.js', 'utf-8'),
socketIO = fs.readFileSync(vendor + '/socket.io.js', 'utf-8'),
emitter = fs.readFileSync(src + '/wildemitter.js', 'utf-8'),
phoneNumber = fs.readFileSync(src + '/phoneNumber.js', 'utf-8'),
phone = fs.readFileSync(src + '/att.core.js', 'utf-8');
// indents each line in a file by 4 spaces or whatever you pass into it
function indent(file, indentAmount) {
var split = file.split('\n'),
actualIndent = indentAmount || ' ',
i = 0,
l = split.length;
for (; i < l; i++) {
split[i] = actualIndent + split[i];
}
return split.join('\n');
}
// build our concatenated code
var context = {
emitter: indent(emitter),
phone: indent(phone),
phoneNumber: indent(phoneNumber),
socket: socketIO
};
// some flair
console.log('\nAT&T'.bold + ' FOUNDRY'.blue.bold);
console.log('~~~~~~~~~~~~');
var file = 'att.js';
function clone(obj) {
var res = {};
for (var i in obj) {
res[i] = obj[i];
}
return res;
}
function writeFiles(name, context) {
var code = mustache.render(template, context),
fileName = name + '.js',
minFileName = name + '.min.js',
outputPath = __dirname + '/build/' + fileName,
minifiedOutputPath = __dirname + '/build/' + minFileName;
fs.writeFileSync(outputPath, code, 'utf-8');
console.log(fileName.bold + ' file built.'.grey);
fs.writeFileSync(minifiedOutputPath, uglify.minify(outputPath).code, 'utf-8');
console.log(minFileName.bold + ' file built.'.grey + '\n');
}
// write it to disk
writeFiles('att', context);
// phone number only
writeFiles('att.phonenumber', {phoneNumber: indent(phoneNumber)});
console.log('The ' + '/build'.bold.blue + ' directory contains the built files.\n');
// yup, we're done
process.exit(0);