-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgobblefile.js
70 lines (60 loc) · 1.88 KB
/
gobblefile.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
var gobble = require('gobble');
var sander = gobble.sander;
var request = require('request-promise');
var RACTIVE_VERSION = 'edge';
var FNAME = 'ractive-json-editor.js';
// TODO: add an es6 build
function ractive(code, opts) {
if (gobble.env() === 'production') {
var r = require('./lib/ractive.js');
return 'const template = ' + JSON.stringify(r.parse(code)) + ';\nexport default template;';
} else {
return 'const template = ' + JSON.stringify(code) + ';\nexport default template;';
}
}
ractive.defaults = {
accept: ['.html'],
ext: '.js'
};
var globalCSS = '';
function grabCSS(code, opts) {
globalCSS = code;
return '';
}
grabCSS.defaults = {
accept: ['.css']
};
function inlineCSS(indir, outdir, opts) {
return sander.readFile(indir, FNAME).then(function(buf) {
var code = buf.toString('utf8');
if (code.indexOf('"<@ cssHere @>"') !== -1) {
code = code.replace('"<@ cssHere @>"', JSON.stringify(globalCSS));
}
return sander.writeFile(outdir, FNAME, code);
});
}
var src = gobble('src').
transform('stylus', { compress: true }).
transform(grabCSS).
transform(ractive).
transform('buble', { transforms: { modules: false } }).
transform('rollup', {
entry: 'index.js',
dest: FNAME,
format: 'umd',
moduleName: 'JsonEditor'
}).
transform(inlineCSS);
if (gobble.env() !== 'production') {
var sandbox = gobble('sandbox').moveTo('sandbox').
transform('buble-html').
transform('stylus-html');
var lib = gobble('lib').moveTo('lib');
module.exports = gobble([src, lib, sandbox]);
sander.stat('lib/ractive.js').then(null, function() {
request('http://cdn.ractivejs.org/' + RACTIVE_VERSION + '/ractive.js').then(function(text) {
console.log('getting ' + RACTIVE_VERSION + ' version of Ractive.js...');
return sander.writeFile('lib/ractive.js', text);
});
});
} else module.exports = gobble([src]);