1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var spawn = require('child_process').spawn;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | task.registerHelper('config', config);
|
18 |
|
19 |
|
20 | task.registerHelper('json', file.readJson.bind(file));
|
21 |
|
22 |
|
23 | task.registerHelper('child_process', function(opts, done) {
|
24 | var child = spawn(opts.cmd, opts.args, opts.opts);
|
25 | var results = [];
|
26 | var errors = [];
|
27 | child.stdout.on('data', results.push.bind(results));
|
28 | child.stderr.on('data', errors.push.bind(errors));
|
29 | child.on('exit', function(code) {
|
30 | if (code === 0) {
|
31 | done(null, results.join('').replace(/\s+$/, ''), code);
|
32 | } else if ('fallback' in opts) {
|
33 | done(null, opts.fallback, code);
|
34 | } else {
|
35 | done(code, errors.join('').replace(/\s+$/, ''), code);
|
36 | }
|
37 | });
|
38 | });
|
39 |
|
40 |
|
41 | task.registerHelper('strip_banner', template.stripBanner);
|
42 |
|
43 |
|
44 | task.registerHelper('file_strip_banner', function(filepath) {
|
45 | return template.stripBanner(file.read(filepath));
|
46 | });
|
47 |
|
48 |
|
49 | task.registerHelper('banner', function(prop) {
|
50 | if (!prop) { prop = 'meta.banner'; }
|
51 | var banner, obj;
|
52 | var tmpl = config(prop);
|
53 | if (tmpl) {
|
54 |
|
55 |
|
56 | obj = config();
|
57 |
|
58 | verbose.write('Generating banner...');
|
59 | try {
|
60 |
|
61 | banner = template.process(tmpl, obj) + '\n';
|
62 | verbose.ok();
|
63 | } catch(e) {
|
64 | banner = '';
|
65 | verbose.error();
|
66 | fail.warn(e, 11);
|
67 | }
|
68 | } else {
|
69 | fail.warn('No "' + prop + '" banner template defined.', 11);
|
70 | banner = '';
|
71 | }
|
72 | return banner;
|
73 | });
|