1 | var path = require('path');
|
2 | var fs = require('fs');
|
3 |
|
4 | var async = require('async');
|
5 | var sprintf = require('sprintf').sprintf;
|
6 | var templates = require('magic-templates');
|
7 | templates.setTemplatesDir(path.join(__dirname, '../assets/'));
|
8 | templates.setDebug(false);
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function generateMakefile(testFiles, targetPath, callback) {
|
17 | var template = new templates.Template('Makefile.magic');
|
18 | var fullPath = path.join(targetPath, 'Makefile');
|
19 | var context = {
|
20 | test_files: testFiles.join(' \\\n ')
|
21 | };
|
22 |
|
23 | if (path.existsSync(fullPath)) {
|
24 | callback(new Error(sprintf('File "%s" already exists', fullPath)));
|
25 | return;
|
26 | }
|
27 |
|
28 | async.waterfall([
|
29 | template.load.bind(template),
|
30 |
|
31 | function render(template, callback) {
|
32 | template.render(context, callback);
|
33 | },
|
34 |
|
35 | function save(output, callback) {
|
36 | fs.writeFile(fullPath, output.join(''), callback);
|
37 | }
|
38 | ], callback);
|
39 | }
|
40 |
|
41 | exports.generateMakefile = generateMakefile;
|