|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -var fs = require('fs'); |
4 | | -var path = require('path'); |
5 | | -var rimraf = require('rimraf'); |
6 | | -var quickTemp = require('quick-temp'); |
7 | | -var hashStrings = require('broccoli-kitchen-sink-helpers').hashStrings; |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
8 | 5 |
|
9 | | -function TemplateLinter(deprecationSource) { |
10 | | - this.description = 'TemplateLinter'; |
11 | | - this.deprecationSource = deprecationSource; |
12 | | - this.lastHash = undefined; |
13 | | -} |
14 | | - |
15 | | -TemplateLinter.prototype.content = function() { |
16 | | - return this.deprecationSource._templateDeprecations |
17 | | - .map(function(item) { |
18 | | - return 'Ember.deprecate(\n' + |
19 | | - ' ' + item.message + ',\n' + |
20 | | - ' ' + item.test + ',\n' + |
21 | | - ' ' + item.options + '\n' + |
22 | | - ');'; |
23 | | - }) |
24 | | - .join('\n'); |
25 | | -}; |
26 | | - |
27 | | -TemplateLinter.prototype.read = function() { |
28 | | - var dir = quickTemp.makeOrReuse(this, 'template-linter-cache'); |
29 | | - |
30 | | - var outputPath = path.join(dir, 'template-deprecations-test.js'); |
| 6 | +const Plugin = require('broccoli-plugin'); |
31 | 7 |
|
32 | | - var content = this.content(); |
33 | | - var hash = hashStrings([content]); |
| 8 | +module.exports = class DeprecationWorkflowTemplateDeprecationProducer extends Plugin { |
| 9 | + constructor(workflowAddonInstance, tree) { |
| 10 | + super([tree], { |
| 11 | + annotation: 'deprecation-workflow-template-deprecations', |
| 12 | + persistentOutput: true, |
| 13 | + needsCache: false, |
| 14 | + }); |
34 | 15 |
|
35 | | - if (this.lastHash !== hash) { |
36 | | - this.lastHash = hash; |
37 | | - fs.writeFileSync(outputPath, content); |
| 16 | + this.workflowAddonInstance = workflowAddonInstance; |
| 17 | + this.lastContent = undefined; |
38 | 18 | } |
39 | 19 |
|
40 | | - return dir; |
41 | | -}; |
42 | | - |
43 | | -TemplateLinter.prototype.cleanup = function() { |
44 | | - return rimraf.sync(this['template-linter-cache']); |
45 | | -}; |
| 20 | + content() { |
| 21 | + return this.workflowAddonInstance._templateDeprecations |
| 22 | + .map(function(item) { |
| 23 | + return 'Ember.deprecate(\n' + |
| 24 | + ' ' + item.message + ',\n' + |
| 25 | + ' ' + item.test + ',\n' + |
| 26 | + ' ' + item.options + '\n' + |
| 27 | + ');'; |
| 28 | + }) |
| 29 | + .join('\n'); |
| 30 | + } |
46 | 31 |
|
| 32 | + build() { |
| 33 | + let outputPath = path.join(this.outputPath, 'template-deprecations-test.js'); |
47 | 34 |
|
48 | | -module.exports = TemplateLinter; |
| 35 | + let content = this.content(); |
| 36 | + if (this.lastContent !== content) { |
| 37 | + this.lastContent = content; |
| 38 | + fs.writeFileSync(outputPath, content); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments