1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 | const VersionChecker = require('ember-cli-version-checker');
|
6 | const TemplateLinter = require('./broccoli-template-linter');
|
7 | const PrintFailing = require('./lib/commands/print-failing');
|
8 |
|
9 | module.exports = {
|
10 | name: 'ember-cli-template-lint',
|
11 |
|
12 | included: function (app) {
|
13 | this._super.included.apply(this, arguments);
|
14 | this._options = app.options['ember-cli-template-lint'] || {};
|
15 |
|
16 | if (!('testGenerator' in this._options)) {
|
17 | let VersionChecker = require('ember-cli-version-checker');
|
18 | let checker = new VersionChecker(this);
|
19 |
|
20 | if (checker.for('ember-cli-qunit', 'npm').satisfies('*')) {
|
21 | this._options.testGenerator = 'qunit';
|
22 | } else if (checker.for('ember-cli-mocha', 'npm').satisfies('*')) {
|
23 | this._options.testGenerator = 'mocha';
|
24 | } else {
|
25 | this.ui.warn(
|
26 | '[ember-cli-template-lint] Test framework detection was unsuccessful. ' +
|
27 | 'Please provide a "testGenerator" option explicitly to enable the test generators.'
|
28 | );
|
29 | }
|
30 | }
|
31 | },
|
32 |
|
33 | includedCommands() {
|
34 | return {
|
35 | 'template-lint:print-failing': PrintFailing
|
36 | };
|
37 | },
|
38 |
|
39 | lintTree(type, tree) {
|
40 | let checker = new VersionChecker(this);
|
41 | checker.for('ember-cli', 'npm').assertAbove('2.4.1');
|
42 |
|
43 | if (type === 'templates') {
|
44 | let ui = this.ui;
|
45 | let mockConsole = {
|
46 | log(data) {
|
47 | ui.writeLine(data);
|
48 | },
|
49 |
|
50 | error(data) {
|
51 | ui.writeLine(data, 'ERROR');
|
52 | }
|
53 | };
|
54 |
|
55 | return TemplateLinter.create(tree, {
|
56 | annotation: 'TemplateLinter',
|
57 | templatercPath: this.project.root + '/.template-lintrc',
|
58 | testGenerator: this._options.testGenerator,
|
59 | groupName: (this._options.group !== false) ? type : undefined,
|
60 | console: mockConsole,
|
61 | project: this.project
|
62 | });
|
63 | }
|
64 | },
|
65 |
|
66 | setupPreprocessorRegistry(type, registry) {
|
67 | let RemoveConfigurationHtmlComments = require('./lib/plugins/remove-configuration-html-comments');
|
68 |
|
69 | registry.add('htmlbars-ast-plugin', {
|
70 | name: 'remove-configuration-html-comments',
|
71 | plugin: RemoveConfigurationHtmlComments(),
|
72 | baseDir() {
|
73 | return __dirname;
|
74 | }
|
75 | });
|
76 | }
|
77 | };
|