1 if (system.args.length !== 1) {
2 system.print('Usage:');
3 system.print(' hammerjs build-test.js');
7 // Traverses the specified path and collects all *.js files.
8 // Note: the traversal is recursive to all subdirectories.
10 var scanDirectory = function (path) {
13 if (fs.exists(path) && fs.isFile(path) && path.match('.js$')) {
15 } else if (fs.isDirectory(path)) {
16 fs.list(path).forEach(function (e) {
17 subdirs = scanDirectory(path + '/' + e);
18 subdirs.forEach(function (s) {
26 var getFileContent = function(fname) {
27 var f = fs.open(fname, 'r'),
32 if (line.length === 0) {
41 var writeFile = function(fname, content) {
42 var f = fs.open(fname, 'w'),
43 lines = content.split('\n'),
44 length = lines.length,
47 for (; i < length; i++) {
48 f.writeLine(lines[i]);
53 // Loads the content of a json file and return an object.
54 var json2js = function (fname) {
55 var content = getFileContent(fname);
56 return eval('(' + content + ')');
59 var generateIndexFor = function(config) {
60 var packages = json2js(config.sources).packages,
61 tpl = getFileContent(config.tpl),
63 specs, slength, j, specPaths, source, name, package, files, file, i, length;
65 tpl = tpl.replace('_TITLE_', config.title);
67 for (name in packages) {
68 package = packages[name];
69 if (config.packages.indexOf(package.name) != -1) {
70 files = package.files;
71 length = files.length;
73 for (i = 0; i < length; i++) {
75 source = file.path + file.name;
76 if (config.srcMustMatch) {
77 if (!source.match(config.srcMustMatch)) {
81 if (config.excludes.indexOf(source) === -1) {
82 sources += (config.prepare[source] || '') + '{ type: "js", src: "' + source.replace(config.srcReplace[0], config.srcReplace[1]) + '"},\n' + (config.overrides[source] || '');
88 specPaths = config.specPaths;
89 length = specPaths.length;
90 for (i = 0; i < length; i++) {
91 specs = scanDirectory(specPaths[i]);
92 slength = specs.length;
93 for (j = 0; j < slength; j++) {
96 if (config.excludes.indexOf(source) === -1) {
97 sources += '{ type: "js", src: "' + source.replace(config.srcReplace[0], config.srcReplace[1]) + '"}'+ (i === length - 1 && j === slength - 1 ? ']' : ',') + '\n';
102 tpl = tpl.replace('_INCLUDES_', sources);
103 writeFile(config.destination, tpl);
106 var indexes = json2js('tests/indexes.json'),
107 ilength = indexes.length,
110 for (; x < ilength; x++) {
111 system.print('Generating test index for ' + indexes[x].title);
112 generateIndexFor(indexes[x]);