forked from Spreadsheets/WickedGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
125 lines (108 loc) · 2.66 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
var fs = require('fs')
, execSync = require('child_process').execSync
//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',
'cellTypeHandlers',
'cl',
'columnFreezer',
'columnResizer',
'customTab',
'defaults',
'enclosure',
'functions',
'header',
'inPlaceEdit',
'menu',
'rowFreezer',
'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',
'ColumnMenu',
'ColumnContextMenu',
'Highlighter',
'SpreadsheetUI',
'RowContextMenu',
'Theme'
]
},
//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');
try {
execSync('yui-compressor -o ' + combinedFileMin + ' ' + combinedFile + '.js');
execSync('git add ' + combinedFileMin + '.js');
} catch (e) {
console.log('WARNING: attempted to use yui-compressor, but it is not installed correctly');
}
process.exit(0);