Skip to content

Commit

Permalink
feat(init): generate coffee config files
Browse files Browse the repository at this point in the history
If the file is *.coffee, generate CoffeeScript config file.
  • Loading branch information
vojtajina committed May 5, 2013
1 parent 5fc1795 commit d217371
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
58 changes: 58 additions & 0 deletions config.tpl.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Karma configuration
# Generated on %DATE%

module.exports = (karma) ->
karma.configure

# base path, that will be used to resolve all patterns, eg. files, exclude
basePath: '%BASE_PATH%'

# frameworks to use
frameworks: [%FRAMEWORKS%]

# list of files / patterns to load in the browser
files: [
%FILES%
]

# list of files to exclude
exclude: [
%EXCLUDE%
]

# test results reporter to use
# possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress']

# web server port
port: 9876

# cli runner port
runnerPort: 9100

# enable / disable colors in the output (reporters and logs)
colors: true

# level of logging
# possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG
logLevel: karma.LOG_INFO

# enable / disable watching file and executing tests whenever any file changes
autoWatch: %AUTO_WATCH%

# Start these browsers, currently available:
# - Chrome
# - ChromeCanary
# - Firefox
# - Opera
# - Safari (only Mac)
# - PhantomJS
# - IE (only Windows)
browsers: [%BROWSERS%]

# If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000

# Continuous Integration mode
# if true, it capture browsers, run tests and exit
singleRun: false
File renamed without changes.
13 changes: 9 additions & 4 deletions lib/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO(vojta): generate coffee syntax

var readline = require('readline');
var fs = require('fs');
var util = require('util');
Expand All @@ -12,7 +10,8 @@ var constant = require('./constants');

var log = logger.create('init');

var CONFIG_TPL_PATH = __dirname + '/../config.template';
var JS_TPL_PATH = __dirname + '/../config.tpl.js';
var COFFEE_TPL_PATH = __dirname + '/../config.tpl.coffee';


var COLORS_ON = {
Expand Down Expand Up @@ -315,6 +314,11 @@ var getReplacementsFromAnswers = function(answers, basePath) {
};


var isCoffeeFile = function(filename) {
return /\.coffee$/.test(filename);
};


exports.init = function(config) {
var useColors = true;
var logLevel = constant.LOG_INFO;
Expand Down Expand Up @@ -344,8 +348,9 @@ exports.init = function(config) {
sm.process(questions, function(answers) {
var cwd = process.cwd();
var configFile = config.configFile;
var templateFile = isCoffeeFile(configFile) ? COFFEE_TPL_PATH : JS_TPL_PATH;
var replacements = getReplacementsFromAnswers(answers, getBasePath(configFile, process.cwd()));
var content = fs.readFileSync(CONFIG_TPL_PATH).toString().replace(/%(.*)%/g, function(a, key) {
var content = fs.readFileSync(templateFile).toString().replace(/%(.*)%/g, function(a, key) {
return replacements[key];
});

Expand Down

0 comments on commit d217371

Please sign in to comment.