-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (54 loc) · 2.13 KB
/
index.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
var fs = require('fs'),
path = require('path'),
_ = require('underscore');
// looks for .js modules ending in "_spec".
// excludes those modules beginning with "_".
var pattern = /\/[^_][^\/]*_spec.js$/,
newline = '\n',
tab = ' ';
function generateSpecsModule (specs) {
var out = '';
_.each(specs, function (spec) {
out += tab + '\'' + spec + '\',' + newline;
});
return ['define([', out.slice(0, -2) ,']);'].join(newline);
}
module.exports = {
summary: 'Collects unit test specs and compiles them as dependencies ' +
'in an amd module.',
doc: fs.readFileSync(path.join(__dirname, 'doc.md'), 'utf8'),
validate: function (namedArgs, configPath) {
if (!configPath) {
return new Error('Please enter path to a requirejs config json');
}
},
run: function (d, v, namedArgs, configPath, outputPath) {
var file = path.resolve(path.join(v.path, configPath)),
config = require(file),
baseDir = path.resolve(path.join(path.dirname(file),
// config.appDir,
config.baseUrl)),
specs = [],
out = '';
specs = _.map(_.extend({'': './'}, config.paths), function (val, key) {
var pathDir = path.join(baseDir, val);
var matches = v.getFilteredFileList(pathDir, pattern);
return _.map(matches, function (match) {
// replace folder path with module path and remove .js extension
return path.join(key, path.relative(pathDir, match)).slice(0, -3);
});
});
specs = _.chain(specs).flatten().uniq().value();
try {
v.write(path.join(v.path, outputPath), generateSpecsModule(specs));
out = 'Collected ' + specs.length + ' specs to ' + outputPath
} catch (err) {
out = 'Found ' + specs.length + ' specs to collect:' + newline;
_.each(specs, function (spec) {
out += spec + newline;
});
} finally {
d.resolve(out);
}
}
};