forked from chrislopresto/ember-freestyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (72 loc) · 2.43 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
/* globals require, module */
'use strict';
var mergeTrees = require('broccoli-merge-trees');
var stew = require('broccoli-stew');
var path = require('path');
var fs = require('fs');
var flatiron = require('broccoli-flatiron');
var freestyleUsageSnippetFinder = require('./freestyle-usage-snippet-finder');
var Funnel = require('broccoli-funnel');
var unwatchedTree = require('broccoli-unwatched-tree');
module.exports = {
name: 'ember-freestyle',
treeForApp: function(tree) {
var treesToMerge = [tree];
var self = this;
var snippets = mergeTrees(this.snippetPaths().filter(function(path) {
return fs.existsSync(path);
}));
snippets = mergeTrees(this.snippetSearchPaths().map(function(path) {
return freestyleUsageSnippetFinder(path, self.ui);
}).concat(snippets));
snippets = flatiron(snippets, {
outputFile: 'snippets.js'
});
treesToMerge.push(snippets);
return mergeTrees(treesToMerge);
},
snippetPaths: function() {
if (this.app) {
var freestyleOptions = this.app.options.freestyle || {};
return freestyleOptions.snippetPaths || ['snippets'];
}
return ['snippets'];
},
snippetSearchPaths: function() {
if (this.app) {
var freestyleOptions = this.app.options.freestyle || {};
return freestyleOptions.snippetSearchPaths || ['app'];
}
return ['app'];
},
treeForStyles: function(tree) {
tree = this._super.treeForStyles.apply(this, [tree]);
var highlightJsTree = new Funnel(unwatchedTree(path.dirname(require.resolve('highlight.js/package.json'))), {
srcDir: '/styles',
destDir: '/app/styles/ember-freestyle/highlight.js'
});
highlightJsTree = stew.rename(highlightJsTree, '.css', '.scss');
return mergeTrees([highlightJsTree, tree], {
overwrite: true
});
},
included: function(app, parentAddon) {
this._super.included(app);
var target = app || parentAddon;
if (target.import) {
target.import(target.bowerDirectory + '/remarkable/dist/remarkable.js');
target.import(target.bowerDirectory + '/highlightjs/highlight.pack.js');
target.import('vendor/ember-remarkable/shim.js', {
type: 'vendor',
exports: { 'remarkable': ['default'] }
});
target.import('vendor/ember-remarkable/highlightjs-shim.js', {
type: 'vendor',
exports: { 'hljs': ['default'] }
});
}
},
isDevelopingAddon: function() {
return true;
}
};