Skip to content

Commit

Permalink
feat(init): install karma-coffee-preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Dec 8, 2013
1 parent b4da1a0 commit 29f5cf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config.tpl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module.exports = (config) ->
%EXCLUDE%
]


# preprocess matching files before serving them to the browser
# available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: %PREPROCESSORS%


# test results reporter to use
# possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress']
Expand Down
5 changes: 5 additions & 0 deletions config.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ module.exports = function(config) {
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: %PREPROCESSORS%,


// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
Expand Down
28 changes: 27 additions & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var fs = require('fs');
var util = require('util');
var path = require('path');
var glob = require('glob');
var mm = require('minimatch');
var exec = require('child_process').exec;
var EventEmitter = require('events').EventEmitter;

Expand Down Expand Up @@ -315,6 +316,21 @@ var formatFiles = function(files) {
};


var pad = function(str, pad) {
return str.replace(/\n/g, '\n' + pad);
};


var formatPreprocessors = function(preprocessors) {
var lines = [];
Object.keys(preprocessors).forEach(function(pattern) {
lines.push(' ' + quote(pattern) + ': [' + preprocessors[pattern].map(quote).join(', ') + ']');
});

return pad('{\n' + lines.join(',\n') + '\n}', ' ');
};


var getBasePath = function(configFilePath, cwd) {
var configParts = path.dirname(configFilePath).split(path.sep);
var cwdParts = cwd.split(path.sep);
Expand Down Expand Up @@ -355,14 +371,24 @@ var getReplacementsFromAnswers = function(answers, basePath) {
frameworks.push('requirejs');
}

var allPatterns = answers.files.concat(answers.includedFiles || []);
var preprocessors = {};
if (allPatterns.some(function(pattern) {
return mm(pattern, '**/*.coffee');
})) {
installPackage('karma-coffee-preprocessor');
preprocessors['**/*.coffee'] = ['coffee'];
}

return {
DATE: new Date(),
BASE_PATH: basePath,
FRAMEWORKS: frameworks.map(quote).join(', '),
FILES: formatFiles(files),
EXCLUDE: answers.exclude ? formatFiles(answers.exclude.map(quote)) : '',
AUTO_WATCH: answers.autoWatch ? 'true' : 'false',
BROWSERS: answers.browsers.map(quote).join(', ')
BROWSERS: answers.browsers.map(quote).join(', '),
PREPROCESSORS: formatPreprocessors(preprocessors)
};
};

Expand Down

0 comments on commit 29f5cf2

Please sign in to comment.