From 88deebe74a0b6f01e23f3ceefea5811183218600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?= Date: Tue, 24 Dec 2013 19:23:48 +0800 Subject: [PATCH] feat: support LiveScript configuration --- config.tpl.ls | 68 ++++++++++++++++++++++++++++++++++++++++++ lib/config.js | 5 ++++ lib/init/formatters.js | 21 ++++++++++++- package.json | 3 +- 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 config.tpl.ls diff --git a/config.tpl.ls b/config.tpl.ls new file mode 100644 index 000000000..9ea73648e --- /dev/null +++ b/config.tpl.ls @@ -0,0 +1,68 @@ +# Karma configuration +# Generated on %DATE% + +module.exports = (config) -> + config.set do + + # base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '%BASE_PATH%' + + + # frameworks to use + # available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: [%FRAMEWORKS%] + + + # list of files / patterns to load in the browser + files: [ + %FILES% + ] + + + # list of files to exclude + exclude: [ + %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' + # available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'] + + + # web server port + port: 9876 + + + # enable / disable colors in the output (reporters and logs) + colors: true + + + # level of logging + # possible values: + # - config.LOG_DISABLE + # - config.LOG_ERROR + # - config.LOG_WARN + # - config.LOG_INFO + # - config.LOG_DEBUG + logLevel: config.LOG_INFO + + + # enable / disable watching file and executing tests whenever any file changes + autoWatch: %AUTO_WATCH% + + + # satart these browsers + # available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [%BROWSERS%] + + + # Continuous Integration mode + # if true, Karma captures browsers, runs the tests and exits + singleRun: false diff --git a/lib/config.js b/lib/config.js index 364088224..22d77fa04 100644 --- a/lib/config.js +++ b/lib/config.js @@ -9,6 +9,11 @@ var constant = require('./constants'); // It's not directly used in this file. require('coffee-script'); +// LiveScript is required here to enable config files written in LiveScript. +// It's not directly used in this file. +try { + require('LiveScript'); +} catch (e) {} var Pattern = function(pattern, served, included, watched) { this.pattern = pattern; diff --git a/lib/init/formatters.js b/lib/init/formatters.js index 0f9fe4c55..758e0da2b 100644 --- a/lib/init/formatters.js +++ b/lib/init/formatters.js @@ -4,12 +4,17 @@ var util = require('util'); var JS_TEMPLATE_PATH = __dirname + '/../../config.tpl.js'; var COFFEE_TEMPLATE_PATH = __dirname + '/../../config.tpl.coffee'; var COFFEE_REGEXP = /\.coffee$/; +var LIVE_TEMPLATE_PATH = __dirname + '/../../config.tpl.ls'; +var LIVE_REGEXP = /\.ls$/; var isCoffeeFile = function(filename) { return COFFEE_REGEXP.test(filename); }; +var isLiveFile = function(filename) { + return LIVE_REGEXP.test(filename); +}; var JavaScriptFormatter = function() { @@ -87,10 +92,24 @@ var CoffeeFormatter = function() { this.TEMPLATE_FILE_PATH = COFFEE_TEMPLATE_PATH; }; +var LiveFormatter = function() { + JavaScriptFormatter.call(this); + + this.TEMPLATE_FILE_PATH = LIVE_TEMPLATE_PATH; +}; exports.JavaScript = JavaScriptFormatter; exports.Coffee = CoffeeFormatter; +exports.Live = LiveFormatter; exports.createForPath = function(path) { - return isCoffeeFile(path) ? new CoffeeFormatter() : new JavaScriptFormatter(); + if (isCoffeeFile(path)) { + return new CoffeeFormatter(); + } + + if (isLiveFile(path)) { + return new LiveFormatter(); + } + + return new JavaScriptFormatter(); }; diff --git a/package.json b/package.json index 8630d7ec0..7827320be 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,8 @@ "karma-ng-scenario": "*", "karma-coffee-preprocessor": "*", "karma-html2js-preprocessor": "*", - "karma-browserstack-launcher": "*" + "karma-browserstack-launcher": "*", + "LiveScript": "~1.2.0" }, "main": "./lib/index", "bin": {},