-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
46 lines (35 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
var util = require('util');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var jasmineCore = require('jasmine-core');
var template = require('./specRunnerTemplate');
var jasmineFiles = jasmineCore.files;
var jasminePath = resolveJasmineDir(jasmineFiles.path);
var jasmineBootDir = resolveJasmineDir(jasmineFiles.bootDir);
var jasmineJsFiles = resolveJasmineFiles(jasminePath, jasmineFiles.jsFiles);
var jasmineCssFiles = resolveJasmineFiles(jasminePath, jasmineFiles.cssFiles);
var jasmineBootFiles = resolveJasmineFiles(jasmineBootDir, jasmineFiles.bootFiles);
function JasmineWebpackPlugin(options) {
options = options || {};
var externalJsFiles = options.externalJsFiles || [];
var htmlOptions = {
inject: true,
filename: options.filename || '_specRunner.html',
templateContent: template,
jasmineJsFiles: jasmineJsFiles.concat(jasmineBootFiles),
jasmineCssFiles: jasmineCssFiles,
externalJsFiles: externalJsFiles
};
for (var attrname in options.htmlOptions) {
htmlOptions[attrname] = options.htmlOptions[attrname];
}
return new HtmlWebpackPlugin(htmlOptions);
}
function resolveJasmineDir(dirname) {
return dirname.replace(process.cwd(), '').replace(/^\//, '');
}
function resolveJasmineFiles(dirname, files) {
return files.map(function(file) { return path.join(dirname, file); });
}
module.exports = JasmineWebpackPlugin;