forked from Spreadsheets/WickedGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
134 lines (115 loc) · 2.76 KB
/
build.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var fs = require('fs')
, execSync = require('child_process').execSync
, uglify = require('uglify-js')
//directories of the JS files
, inDir = './src/'
, outDir = ''
//these are the paths to the final combined files that you want to have in the end
, temp = ''
, result = ''
, wrapper = 'WickedGrid'
, combinedFile = outDir + 'wickedgrid'
, combinedFileMin = outDir + 'wickedgrid.min'
, files = [
//non-constructors next
{
WickedGrid: [
//statics off of WickedGrid
'statics',
'autoFiller',
'cl',
'columnMenu',
'columnResizer',
'customTab',
'defaults',
'enclosure',
'formulaEditor',
'header',
'inPlaceEdit',
'menu',
'rowResizer',
'sheetUI',
'spreadsheetAdder',
'tab',
'tabs',
'thread',
'ui',
'utilities',
//children namespaces next
{
Event: ['cell', 'document', 'formula']
},
{
Loader: ['HTML', 'JSON', 'XML']
},
//constructors next
'ActionUI',
'Cell',
'CellContextMenu',
'CellHandler',
'CellRange',
'CellTypeHandlers',
'ColumnContextMenu',
'ColumnFreezer',
'Functions',
'Highlighter',
'SpreadsheetUI',
'RowContextMenu',
'RowFreezer',
'Theme',
'Undo'
]
},
//jQuery plugin
'jQuery.WickedGrid',
//environment correction last
'environmentCorrection'
]
, parserFiles = [
'parser/formula/formula',
'parser/tsv/tsv'
]
;
function pathify(path, cb, prefix) {
prefix = prefix || '';
if (path.constructor === Array) {
path.forEach(function(file) {
pathify(file, cb, prefix);
});
} else if (typeof path === 'object') {
for (var p in path) {
if (path.hasOwnProperty(p)) {
pathify(path[p], cb, prefix + (prefix ? '/' : '') + p + '/');
}
}
} else if (typeof path === 'string') {
cb(prefix + path);
}
}
//run through the JS files
pathify(files, function(file) {
temp += fs.readFileSync(inDir + file + '.js', 'utf8').toString() + '\n';
});
result = fs.readFileSync(inDir + wrapper + '.js', 'utf8').toString()
.replace('\'CODE_HERE\'', function() {
return temp;
});
//run through the parser files
parserFiles.forEach(function(file) {
result += fs.readFileSync(file + '.js', 'utf8').toString();
});
fs.writeFileSync(combinedFile + '.js', result);
//compress it
//add the file to the git base
execSync('git add ' + combinedFile + '.js');
var tiny = uglify.minify([combinedFile + '.js'], {
compress: {
dead_code: true,
global_defs: {
DEBUG: false
}
}
});
fs.writeFileSync(combinedFileMin + '.js', tiny.code);
execSync('git add ' + combinedFileMin + '.js');
process.exit(0);