forked from sglanzer-deprecated/ember-cli-blanket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
105 lines (87 loc) · 2.67 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* jshint node: true */
'use strict';
var path = require('path');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var coverageMiddleware = require('./lib/coverage-middleware');
var bodyParser = require('body-parser');
function logErrors(err, req, res, next) {
console.error(err.stack);
next(err);
}
module.exports = {
name: 'Ember CLI Blanket',
validEnv: function() {
return this.app.env !== 'production';
},
blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},
included: function included(app) {
this._super.included(app);
if (app.tests) {
var fileAssets = [
path.join(app.bowerDirectory, 'blanket', 'dist', 'qunit', 'blanket.js'),
];
fileAssets.forEach(function(file) {
app.import(file, {
type: 'test'
});
});
}
},
middleware: function(app, options) {
app.post('/write-blanket-coverage',
bodyParser.json({ limit: '50mb' }),
coverageMiddleware(options),
logErrors);
},
testemMiddleware: function(app) {
this.middleware(app, { root: this.project.root });
},
serverMiddleware: function(options) {
this.app = options.app;
if(!this.validEnv()) { return; }
this.middleware(options.app, { root: this.project.root });
},
postprocessTree: function(type, tree) {
this._requireBuildPackages();
if (type === 'all' && this.app.tests) {
var treeTestLoader = new Funnel(tree, {
files: ['test-loader.js'],
srcDir: 'assets',
destDir: 'app'
});
var tests = this.treeGenerator(path.join(this.project.root, 'tests'));
var blanketOptions = new Funnel(tests, {
files: ['blanket-options.js'],
srcDir: '/',
destDir: '/assets'
});
var vendor = this.treeGenerator(path.join(__dirname, 'vendor'));
var blanketLoader = new Funnel(vendor, {
files: ['blanket-reporter.js', 'blanket-require.js'],
srcDir: '/',
destDir: '/'
});
blanketLoader = this.concatFiles(blanketLoader, {
inputFiles: ['blanket-reporter.js', 'blanket-require.js'], // Order here is important
outputFile: '/assets/blanket-loader.js'
});
var start = new Funnel(vendor, {
files: ['start.js'],
srcDir: '/',
destDir: '/'
});
var testLoaderTree = this.concatFiles(mergeTrees([treeTestLoader, start]), {
inputFiles: ['**/*.js'],
outputFile: '/assets/test-loader.js'
});
return mergeTrees([tree, blanketOptions, blanketLoader, testLoaderTree], {
overwrite: true
});
} else {
return tree;
}
}
};