forked from ef4/ember-code-snippet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (75 loc) · 2.27 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
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
'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;
},
includeHighlightJS() {
let app = findHost(this);
if (typeof app.options.includeHighlightJS === 'boolean') {
return app.options.includeHighlightJS;
} else {
return true;
}
},
includeHighlightStyle() {
let app = findHost(this);
if (typeof app.options.includeHighlightStyle === 'boolean') {
return app.options.includeHighlightStyle;
} else {
return true;
}
},
treeForApp(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 mergeTrees([tree, snippets]);
},
included(app) {
if (this.includeHighlightJS()) {
app.import('vendor/highlight.pack.js', { using: [
{ transformation: 'amd', as: 'highlight.js' }
] } );
}
if (this.includeHighlightStyle()) {
app.import('vendor/highlight-style.css');
}
}
};