-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
59 lines (46 loc) · 1.57 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
/* eslint-env node */
'use strict';
const MarkdownResolver = require('broccoli-markdown-resolver');
const MergeTrees = require('broccoli-merge-trees');
const fs = require('fs');
const path = require('path');
module.exports = {
name: 'ember-cli-markdown-resolver',
included(app) {
this.addonConfig = this.getAddonConfig(app);
this.testAppPath = this.getTestAppPath();
return this._super.included.apply(this, arguments);
},
treeForAddon(tree) {
let folders = Object.keys(this.addonConfig.folders || {}).reduce((folders, key) => {
return [
...folders,
this.addonConfig.folders[key]
];
}, []);
let mdPaths = folders.reduce((paths, folder) => {
let folderPathSegments = folder.split('/'),
folderPath = path.join(this.app.project.root, this.testAppPath, ...folderPathSegments),
folderExists = fs.existsSync(folderPath);
return folderExists ?
[...paths, folderPath] :
[...paths];
}, []);
if (mdPaths.length > 0) {
let mdFiles = new MarkdownResolver(mdPaths, {
basePath: path.join(this.app.project.root, this.testAppPath),
outputFile: 'files.js',
trimExtensions: true
});
tree = new MergeTrees([tree, mdFiles]);
}
return this._super.treeForAddon.call(this, tree);
},
getAddonConfig(app) {
return this.app.project.config(app.env)[this.name] || {};
},
getTestAppPath() {
let configPath = this.app.options.configPath;
return (typeof configPath === 'string' || configPath instanceof String) ? './tests/dummy' : '';
}
};