forked from ef4/ember-code-snippet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (49 loc) · 1.62 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
60
61
'use strict';
const fs = require('fs');
const mergeTrees = require('broccoli-merge-trees');
const flatiron = require('broccoli-flatiron');
const snippetFinder = require('./snippet-finder');
const findHost = require('./utils/findHost');
module.exports = {
name: require('./package').name,
snippetPaths() {
let app = findHost(this);
return app.options.snippetPaths || ['snippets'];
},
snippetSearchPaths(){
let app = findHost(this);
return app.options.snippetSearchPaths || ['app'];
},
snippetRegexes() {
let app = findHost(this);
return [{
begin: /\bBEGIN-SNIPPET\s+(\S+)\b/,
end: /\bEND-SNIPPET\b/
}].concat(app.options.snippetRegexes || []);
},
snippetExtensions() {
let app = findHost(this);
return app.options.snippetExtensions || ['js','ts','coffee','html','hbs','md','css','sass','scss','less','emblem','yaml'];
},
includeExtensions() {
let app = findHost(this);
return app.options.includeFileExtensionInSnippetNames !== false;
},
treeForAddon(tree) {
let snippets = mergeTrees(this.snippetPaths().filter(function(path){
return fs.existsSync(path);
}));
let snippetOptions = {
snippetRegexes: this.snippetRegexes(),
includeExtensions: this.includeExtensions(),
snippetExtensions: this.snippetExtensions()
};
snippets = mergeTrees(this.snippetSearchPaths().map(function(path){
return snippetFinder(path, snippetOptions);
}).concat(snippets));
snippets = flatiron(snippets, {
outputFile: 'snippets.js'
});
return this._super.treeForAddon.call(this, mergeTrees([tree, snippets]));
}
};