forked from ember-learn/ember-cli-addon-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
113 lines (98 loc) · 2.88 KB
/
index.js
File metadata and controls
113 lines (98 loc) · 2.88 KB
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
/* eslint-env node */
'use strict';
const path = require('path');
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
module.exports = {
name: 'ember-cli-addon-docs',
options: {
ace: {
modes: ['handlebars']
},
nodeAssets: {
'highlight.js': {
public: {
include: [ 'styles/monokai.css' ]
},
vendor: {
include: [ 'styles/monokai.css' ]
}
}
}
},
config(env, baseConfig) {
return {
'ember-component-css': {
namespacing: false
},
snippetSearchPaths: ['tests/dummy/app'],
snippetRegexes: {
begin: /{{#docs-snippet\sname=\"(\S+)\"/,
end: /{{\/docs-snippet}}/,
},
};
},
included() {
this._super.included.apply(this, arguments);
let importer = findImporter(this);
importer.import(`${this._hasEmberSource() ? 'vendor' : 'bower_components'}/ember/ember-template-compiler.js`);
// importer.import('vendor/highlightjs-styles/default.css');
// importer.import('vendor/styles/highlightjs-styles/default.css');
// importer.import('vendor/highlight.js/styles/monokai.css');
// importer.import('vendor/highlightjs-styles/github.css');
},
setupPreprocessorRegistry(type, registry) {
if (type === 'parent') {
let TemplateCompiler = require('./lib/preprocessors/markdown-template-compiler');
registry.add('template', new TemplateCompiler());
}
},
treeForVendor(vendor) {
return new MergeTrees([
vendor,
this._highlightJSTree(),
this._templateCompilerTree()
].filter(Boolean));
},
treeForPublic() {
let parentAddon = this.parent.findAddonByName(this.parent.name());
if (!parentAddon) { return; }
let DocsGenerator = require('./lib/broccoli/docs-generator');
let addonSources = path.resolve(parentAddon.root, parentAddon.treePaths.addon);
return new DocsGenerator([addonSources], {
project: this.project,
destDir: 'docs'
});
},
_highlightJSTree() {
return new Funnel(path.dirname(require.resolve('highlightjs/package.json')), {
srcDir: 'styles',
destDir: 'highlightjs-styles'
});
},
_templateCompilerTree() {
if (this._hasEmberSource()) {
return new Funnel(path.dirname(require.resolve('ember-source/package.json')), {
srcDir: 'dist',
destDir: 'ember'
});
}
},
_hasEmberSource() {
return 'ember-source' in this.project.pkg.devDependencies;
}
};
function findImporter(addon) {
if (typeof addon.import === 'function') {
// If addon.import() is present (CLI 2.7+) use that
return addon;
} else {
// Otherwise, reuse the _findHost implementation that would power addon.import()
let current = addon;
let app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
}
}