forked from josdejong/jsoneditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile.js
316 lines (275 loc) · 8.49 KB
/
Jakefile.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/**
* Jake build script
*/
var jake = require('jake'),
path = require('path'),
cleanCss = require('clean-css'),
archiver = require('archiver'),
fs = require('fs');
require('jake-utils');
// constants
var JSONEDITOR = './jsoneditor.js',
JSONEDITOR_CSS = './jsoneditor.css',
JSONEDITOR_MIN = './jsoneditor-min.js',
JSONEDITOR_CSS_MIN = './jsoneditor-min.css',
BUILD = './build';
/**
* default task
*/
desc('Execute all tasks');
task('default', ['clear', 'build', 'minify', 'zip', 'webapp', 'chromeapp'], function () {
console.log('Done');
});
/**
* build the library
*/
desc('Clear the build directory');
task('clear', function () {
jake.rmRf(BUILD);
});
/**
* build the library
*/
desc('Build the library');
task('build', ['clear'], function () {
var jsoneditorSrc = './jsoneditor/';
// concatenate the javascript files
concat({
src: [
jsoneditorSrc + 'js/jsoneditor.js',
jsoneditorSrc + 'js/treeeditor.js',
jsoneditorSrc + 'js/texteditor.js',
jsoneditorSrc + 'js/node.js',
jsoneditorSrc + 'js/appendnode.js',
jsoneditorSrc + 'js/contextmenu.js',
jsoneditorSrc + 'js/history.js',
jsoneditorSrc + 'js/searchbox.js',
jsoneditorSrc + 'js/highlighter.js',
jsoneditorSrc + 'js/util.js',
jsoneditorSrc + 'js/module.js'
],
dest: JSONEDITOR,
header: read(jsoneditorSrc +'js/header.js') + '\n' +
'(function () {\n',
separator: '\n',
footer: '\n})();\n'
});
// update version number and stuff in the javascript files
replacePlaceholders(JSONEDITOR);
console.log('Created ' + JSONEDITOR);
// concatenate and stringify the css files
concat({
src: [
jsoneditorSrc + 'css/jsoneditor.css',
jsoneditorSrc + 'css/contextmenu.css',
jsoneditorSrc + 'css/menu.css',
jsoneditorSrc + 'css/searchbox.css'
],
dest: JSONEDITOR_CSS,
separator: '\n'
});
console.log('Created ' + JSONEDITOR_CSS);
// minify the css file
write(JSONEDITOR_CSS_MIN, cleanCss.process(String(read(JSONEDITOR_CSS))));
// create a folder img and copy the icons
jake.mkdirP('./img');
jake.cpR(jsoneditorSrc + 'css/img/jsoneditor-icons.png', './img/');
console.log('Copied jsoneditor-icons.png to ./img/');
});
/**
* minify the library
*/
desc('Minify the library');
task('minify', ['build'], function () {
// minify javascript
minify({
src: JSONEDITOR,
dest: JSONEDITOR_MIN,
header: read('./jsoneditor/js/header.js'),
separator: '\n'
});
// update version number and stuff in the javascript files
replacePlaceholders(JSONEDITOR_MIN);
console.log('Created ' + JSONEDITOR_MIN);
});
/**
* zip the library
*/
desc('Zip the library');
task('zip', ['build', 'minify'], {async: true}, function () {
var zipfolder = BUILD + '/lib';
var pkg = 'jsoneditor-' + version();
var zipfile = zipfolder + '/' + pkg + '.zip';
jake.mkdirP(zipfolder);
var output = fs.createWriteStream(zipfile);
var archive = archiver('zip');
archive.on('error', function(err) {
throw err;
});
archive.pipe(output);
var filelist = new jake.FileList();
filelist.include([
'README.md',
'NOTICE',
'LICENSE',
'HISTORY.md',
JSONEDITOR,
JSONEDITOR_CSS,
JSONEDITOR_MIN,
JSONEDITOR_CSS_MIN,
'img/*.*',
'lib/**/*.*',
'docs/**/*.*',
'examples/**/*.*'
]);
var files = filelist.toArray();
files.forEach(function (file) {
archive.append(fs.createReadStream(file), {
name: pkg + '/' + file
})
});
archive.finalize(function(err, written) {
if (err) {
throw err;
}
console.log('Zipped ' + zipfile);
complete();
});
});
/**
* build the web app
*/
desc('Build web app');
task('webapp', ['build', 'minify'], function () {
var webAppSrc = './app/web/';
var libSrc = './lib/';
var webApp = BUILD + '/app/web/';
var webAppLib = webApp + 'lib/';
var webAppAce = webAppLib + 'ace/';
var webAppImg = webApp + 'img/';
var appJs = webApp + 'app.js';
var appCss = webApp + 'app.css';
var appCssMin = webApp + 'app-min.css';
var appJsMin = webApp + 'app-min.js';
// create directories
// TODO: should be created automatically...
jake.mkdirP(webApp);
jake.mkdirP(webAppLib);
jake.mkdirP(webAppLib + 'ace/');
jake.mkdirP(webAppLib + 'jsoneditor/');
jake.mkdirP(webAppLib + 'jsoneditor/img/');
jake.mkdirP(webAppLib + 'jsonlint/');
jake.mkdirP(webAppImg);
// concatenate the javascript files
concat({
src: [
webAppSrc + 'queryparams.js',
webAppSrc + 'ajax.js',
webAppSrc + 'fileretriever.js',
webAppSrc + 'notify.js',
webAppSrc + 'splitter.js',
webAppSrc + 'app.js'
],
dest: appJs,
separator: '\n'
});
// minify javascript
minify({
src: appJs,
dest: appJsMin
});
// concatenate the css files
concat({
src: [
webAppSrc + 'fileretriever.css',
webAppSrc + 'app.css'
],
dest: appCss,
separator: '\n'
});
// minify css file
write(appCssMin, cleanCss.process(String(read(appCss))));
// remove non minified javascript and css file
fs.unlinkSync(appJs);
fs.unlinkSync(appCss);
// copy files
jake.cpR('./README.md', webApp);
jake.cpR('./HISTORY.md', webApp);
jake.cpR('./NOTICE', webApp);
jake.cpR('./LICENSE', webApp);
jake.cpR('./LICENSE', webApp);
jake.cpR(webAppSrc + 'robots.txt', webApp);
jake.cpR(webAppSrc + 'datapolicy.txt', webApp);
jake.cpR(webAppSrc + 'index.html', webApp);
jake.cpR(webAppSrc + 'favicon.ico', webApp);
jake.cpR(webAppSrc + 'fileretriever.php', webApp);
jake.cpR(webAppSrc + 'googlea47c4a0b36d11021.html', webApp);
jake.cpR(webAppSrc + 'img/logo.png', webAppImg);
jake.cpR(webAppSrc + 'img/header_background.png', webAppImg);
jake.cpR(webAppSrc + 'doc/', webApp);
// update date and verison in index.html
replacePlaceholders(webApp + 'index.html');
replacePlaceholders(webApp + 'index.html'); // TODO: fix bug in replace, should replace all occurrences
// concatenate and copy ace files
concat({
src: [
libSrc + 'ace/ace.js',
libSrc + 'ace/mode-json.js',
libSrc + 'ace/theme-textmate.js',
libSrc + 'ace/theme-jsoneditor.js'
],
dest: webAppAce + 'ace-min.js',
separator: '\n'
});
jake.cpR(libSrc + 'ace/worker-json.js', webAppAce);
// copy json lint file
jake.cpR(libSrc + 'jsonlint/jsonlint.js', webAppLib + 'jsonlint/')
// copy jsoneditor files
jake.cpR(JSONEDITOR_MIN, webAppLib + 'jsoneditor/');
jake.cpR(JSONEDITOR_CSS_MIN, webAppLib + 'jsoneditor/');
jake.cpR('img', webAppLib + 'jsoneditor/');
});
/**
* build the chrome app
*/
desc('Build chrome app');
task('chromeapp', {async: true}, function () {
var folder = BUILD + '/app/';
var file = folder + 'chrome.zip';
jake.mkdirP(folder);
var output = fs.createWriteStream(file);
var archive = archiver('zip');
archive.on('error', function(err) {
throw err;
});
// create a temporary manifest file with version number
var manifestTmp = folder + 'manifest.json.tmp';
jake.cpR('./app/chrome/manifest.json', manifestTmp);
replacePlaceholders(manifestTmp);
archive.pipe(output);
archive.append(fs.createReadStream(manifestTmp), {name: 'manifest.json'});
archive.append(fs.createReadStream('./app/web/img/icon_16.png'), {name: 'icon_16.png'});
archive.append(fs.createReadStream('./app/web/img/icon_128.png'), {name: 'icon_128.png'});
// cleanup temporary manifest file
fs.unlinkSync(manifestTmp);
archive.finalize(function(err, written) {
if (err) {
throw err;
}
console.log('Created chrome app ' + file);
complete();
});
});
/**
* replace version, date, and name placeholders in the provided file
* @param {String} filename
*/
var replacePlaceholders = function (filename) {
replace({
replacements: [
{pattern: '@@date', replacement: today()},
{pattern: '@@version', replacement: version()}
],
src: filename
});
};