2012-11-02 13:03:09 +08:00
|
|
|
/*jshint latedef:false, curly:false*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var grunt = require('grunt'),
|
|
|
|
path = require('path');
|
|
|
|
|
|
|
|
var baseDir = '.';
|
|
|
|
|
|
|
|
exports.buildSpecrunner = buildSpecrunner;
|
|
|
|
exports.getRelativeFileList = getRelativeFileList;
|
|
|
|
|
|
|
|
function buildSpecrunner(src, options){
|
|
|
|
var reporters = [
|
|
|
|
__dirname + '/../jasmine/reporters/PhantomReporter.js'
|
|
|
|
];
|
|
|
|
|
|
|
|
var jasmineCss = [
|
2012-12-03 16:17:06 +08:00
|
|
|
__dirname + '/../../vendor/jasmine-1.3.0/jasmine.css'
|
2012-11-02 13:03:09 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
var jasmineCore = [
|
2012-12-03 16:17:06 +08:00
|
|
|
__dirname + '/../../vendor/jasmine-1.3.0/jasmine.js',
|
|
|
|
__dirname + '/../../vendor/jasmine-1.3.0/jasmine-html.js'
|
2012-11-02 13:03:09 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
var jasmineHelper = __dirname + '/../jasmine/jasmine-helper.js';
|
|
|
|
|
|
|
|
var context = {
|
|
|
|
css : getRelativeFileList(jasmineCss),
|
|
|
|
scripts : {
|
|
|
|
jasmine : getRelativeFileList(jasmineCore),
|
|
|
|
helpers : getRelativeFileList(options.helpers),
|
|
|
|
specs : getRelativeFileList(options.specs),
|
|
|
|
src : getRelativeFileList(src),
|
|
|
|
vendor : getRelativeFileList(options.vendor),
|
|
|
|
reporters : getRelativeFileList(reporters),
|
|
|
|
start : getRelativeFileList(jasmineHelper)
|
|
|
|
},
|
|
|
|
options : options.templateOptions || {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var source = '';
|
|
|
|
grunt.file.copy(options.template, path.join(baseDir,options.outfile), {
|
|
|
|
process : function(src) {
|
|
|
|
source = grunt.util._.template(src, context);
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getRelativeFileList(/* args... */) {
|
|
|
|
|
|
|
|
var list = Array.prototype.slice.call(arguments);
|
|
|
|
var base = path.resolve(baseDir);
|
|
|
|
var files = [];
|
|
|
|
list.forEach(function(listItem){
|
|
|
|
if (listItem) files = files.concat(grunt.file.expandFiles(listItem));
|
|
|
|
});
|
|
|
|
files = grunt.util._(files).map(function(file){
|
|
|
|
return path.resolve(file).replace(base,'.').replace(/\\/g,'/');
|
|
|
|
});
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|