Skip to content

Commit 027c14d

Browse files
authored
Merge pull request #207 from ember-learn/build-order-agnostic
Build order agnostic
2 parents a775c0d + 9d0fc63 commit 027c14d

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = {
123123
let TemplateCompiler = require('./lib/preprocessors/markdown-template-compiler');
124124
let ContentExtractor = require('./lib/preprocessors/hbs-content-extractor');
125125
registry.add('template', new TemplateCompiler());
126-
registry.add('template', this.contentExtractor = new ContentExtractor());
126+
registry.add('template', new ContentExtractor(this.getBroccoliBridge()));
127127
}
128128
},
129129

@@ -197,7 +197,7 @@ module.exports = {
197197

198198
let docsTree = new MergeTrees(docsTrees);
199199

200-
let templateContentsTree = this.contentExtractor.getTemplateContentsTree();
200+
let templateContentsTree = this.getBroccoliBridge().placeholderFor('template-contents');
201201
let searchIndexTree = new SearchIndexer(new MergeTrees([docsTree, templateContentsTree]), {
202202
outputFile: 'ember-cli-addon-docs/search-index.json',
203203
config: this.project.config(EmberApp.env())
@@ -206,6 +206,14 @@ module.exports = {
206206
return new MergeTrees([ defaultTree, docsTree, searchIndexTree ]);
207207
},
208208

209+
getBroccoliBridge() {
210+
if (!this._broccoliBridge) {
211+
const Bridge = require('broccoli-bridge');
212+
this._broccoliBridge = new Bridge();
213+
}
214+
return this._broccoliBridge;
215+
},
216+
209217
_lunrTree() {
210218
return new Funnel(path.dirname(require.resolve('lunr/package.json')), { destDir: 'lunr' });
211219
},

lib/preprocessors/hbs-content-extractor.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
const HBSContentFilter = require('../broccoli/hbs-content-filter');
44

55
module.exports = class HBSContentExtractor {
6-
constructor() {
6+
constructor(bridge) {
77
this.name = 'hbs-content-extractor';
88
this.ext = ['hbs'];
9-
this._contentsTree = null;
10-
}
11-
12-
getTemplateContentsTree() {
13-
if (!this._contentsTree) {
14-
throw new Error(`Templates contents haven't been extracted yet`);
15-
}
16-
return this._contentsTree;
9+
this._bridge = bridge;
1710
}
1811

1912
toTree(tree) {
20-
this._contentsTree = new HBSContentFilter(tree);
13+
let contentsTree = new HBSContentFilter(tree);
14+
this._bridge.fulfill('template-contents', contentsTree);
2115
return tree;
2216
}
2317
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@glimmer/syntax": "^0.30.5",
26+
"broccoli-bridge": "^1.0.0",
2627
"broccoli-caching-writer": "^3.0.3",
2728
"broccoli-filter": "^1.2.4",
2829
"broccoli-funnel": "^2.0.1",

yarn.lock

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,14 @@ broccoli-babel-transpiler@^6.1.2, broccoli-babel-transpiler@^6.4.2:
13611361
rsvp "^4.8.2"
13621362
workerpool "^2.3.0"
13631363

1364+
broccoli-bridge@^1.0.0:
1365+
version "1.0.0"
1366+
resolved "https://registry.yarnpkg.com/broccoli-bridge/-/broccoli-bridge-1.0.0.tgz#6223fd64b62062c31333539f0f3c42d0acd92fb1"
1367+
dependencies:
1368+
broccoli-plugin "^1.3.0"
1369+
fs-extra "^7.0.0"
1370+
symlink-or-copy "^1.2.0"
1371+
13641372
broccoli-builder@^0.18.8:
13651373
version "0.18.11"
13661374
resolved "https://registry.yarnpkg.com/broccoli-builder/-/broccoli-builder-0.18.11.tgz#a42393c7b10bb0380df255a616307945f5e26efb"
@@ -4446,6 +4454,14 @@ fs-extra@^5.0.0:
44464454
jsonfile "^4.0.0"
44474455
universalify "^0.1.0"
44484456

4457+
fs-extra@^7.0.0:
4458+
version "7.0.0"
4459+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.0.tgz#8cc3f47ce07ef7b3593a11b9fb245f7e34c041d6"
4460+
dependencies:
4461+
graceful-fs "^4.1.2"
4462+
jsonfile "^4.0.0"
4463+
universalify "^0.1.0"
4464+
44494465
fs-tree-diff@^0.5.2, fs-tree-diff@^0.5.3, fs-tree-diff@^0.5.4, fs-tree-diff@^0.5.6:
44504466
version "0.5.7"
44514467
resolved "https://registry.yarnpkg.com/fs-tree-diff/-/fs-tree-diff-0.5.7.tgz#315e2b098d5fe7f622880ac965b1b051868ac871"
@@ -8620,7 +8636,7 @@ [email protected]:
86208636
version "3.2.2"
86218637
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
86228638

8623-
symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8:
8639+
symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8, symlink-or-copy@^1.2.0:
86248640
version "1.2.0"
86258641
resolved "https://registry.yarnpkg.com/symlink-or-copy/-/symlink-or-copy-1.2.0.tgz#5d49108e2ab824a34069b68974486c290020b393"
86268642

0 commit comments

Comments
 (0)