-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.js
126 lines (107 loc) · 3.72 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* 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');
var VersionChecker = require('ember-cli-version-checker');
var debug = require('debug')('ember-cli-blanket');
var VersionChecker = require('ember-cli-version-checker');
function logErrors(err, req, res, next) {
console.error(err.stack);
next(err);
}
module.exports = {
name: 'Ember CLI Blanket',
checkDeps: function() {
var checker = new VersionChecker(this),
bowerDep = checker.for('loader.js', 'bower'),
npmDep = checker.for('loader.js', 'npm');
debug('loader.js version (bower): ', bowerDep.version);
debug('loader.js version (npm): ', npmDep.version);
return (bowerDep.satisfies('>= 3.6.1') || npmDep.satisfies('>= 4.0.0'));
},
init: function() {
this._super.init && this._super.init.apply(this, arguments); // jshint ignore:line
if (!this.checkDeps()) {
throw new Error('loader.js must be >= 3.6.1 (bower) or >= 4.0.0 (npm)');
}
},
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();
var checker = new VersionChecker(this);
var isNpmTestLoader = checker.for('ember-cli', 'npm').satisfies('>= 2.7.0');
var testLoaderFile = isNpmTestLoader ? 'tests.js' : 'test-loader.js';
if (type === 'all' && this.app.tests) {
var treeTestLoader = new Funnel(tree, {
files: isNpmTestLoader ? [testLoaderFile, 'tests.map'] : [testLoaderFile], // don't loose the sourcemaps
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/' + testLoaderFile
});
return mergeTrees([tree, blanketOptions, blanketLoader, testLoaderTree], {
overwrite: true
});
} else {
return tree;
}
}
};