This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.js
99 lines (83 loc) · 2.5 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
91
92
93
94
95
96
97
98
99
'use strict';
module.exports = {
name: require('./package').name,
included() {
// Defaults that can be overriden by options
this.components = [];
this.plugins = [];
this.theme = 'themes/prism.css';
let app = findHost(this);
if (app.options && app.options['ember-prism']) {
const options = app.options['ember-prism'];
const components = options.components;
const plugins = options.plugins || [];
const theme = options.theme;
if (!plugins.includes('normalize-whitespace')) {
plugins.push('normalize-whitespace');
}
if (theme && theme !== 'none') {
this.theme = `themes/prism-${theme}.css`;
}
if (components) {
components.forEach((component) => {
this.components.push(`components/prism-${component}.js`);
});
}
if (plugins) {
plugins.forEach((plugin) => {
/**
* Most Prism plugins contains both a js file and a css file, but there
* are exception. `highlight-keywords` for instance, does not have a
* css file.
*
* When the plugin is imported, the app should check for file existence
* before calling `app.import()`.
*/
// file extensions to be tested for existence.
const fileExtensions = ['js', 'css'];
fileExtensions.forEach((fileExtension) => {
const nodeAssetsPath = `plugins/${plugin}/prism-${plugin}.${fileExtension}`;
if (maybeResolve(`prismjs/${nodeAssetsPath}`)) {
this.plugins.push(nodeAssetsPath);
}
});
});
}
}
app.import('vendor/ember-prism.js');
this._super.included.apply(this, arguments);
},
options: {
'ember-cli-babel': { enableTypeScriptTransform: true },
nodeAssets: {
prismjs() {
return {
import: ['prism.js', this.theme].concat(
this.components,
this.plugins,
),
};
},
},
},
};
function maybeResolve(path) {
try {
return require.resolve(path);
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
return null;
} else {
throw error;
}
}
}
// Polyfill [Addon._findHost](https://ember-cli.com/api/classes/Addon.html#method__findHost) for older versions of ember-cli
function findHost(addon) {
var current = addon;
var app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
}