-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.js
169 lines (154 loc) · 5.64 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use strict';
// Module requirements
const fs = require('fs');
const path = require('path');
module.exports = {
name: require('./package').name,
options: {
'@embroider/macros': {
setOwnConfig: {
languages: [],
plugins: { css: [], js: [] },
third_party: { css: [], js: [] },
themes: [],
},
},
autoImport: {
skipBabel: [
{
package: 'froala-editor',
semverRange: '*',
},
],
webpack: {
resolve: {
fallback: {
// https://github.com/froala/wysiwyg-editor/issues/4156
crypto: false,
},
},
},
},
babel: {
plugins: [require.resolve('ember-auto-import/babel-plugin')],
},
'ember-froala-editor': {
languages: [],
plugins: [],
themes: [],
},
},
included(app) {
// https://ember-cli.com/api/classes/addon#method_included
this._super.included.apply(this, arguments);
// For nested usage, build the options up through the entire tree,
// with priority going up the tree and the "root" app always overriding
let appOptions = {};
let current = this;
do {
app = current.app || app;
if (app.options && app.options[this.name]) {
appOptions = Object.assign(appOptions, app.options[this.name]);
}
} while (current.parent.parent && (current = current.parent));
// Build options by merging default options
// with the apps ember-cli-build.js options
let options = Object.assign(this.options[this.name], appOptions);
// Ensure the addon options are arrays
['languages', 'plugins', 'themes'].forEach((type) => {
if (!Array.isArray(options[type])) {
throw new Error(
`${this.name}: ${type} ` +
'option in ember-cli-build.js must be an array. ' +
'Boolean and string values have been depreciated.',
);
}
});
// Replace plugin "names" with filenames
options.plugins = options.plugins.map((plugin) => {
switch (plugin) {
/* eslint-disable prettier/prettier */
case 'charCounter': return 'char_counter';
case 'codeBeautifier': return 'code_beautifier';
case 'codeView': return 'code_view';
case 'editInPopup': return 'edit_in_popup';
case 'filesManager': return 'files_manager';
case 'fontAwesome': return 'font_awesome';
case 'fontFamily': return 'font_family';
case 'fontSize': return 'font_size';
case 'imageManager': return 'image_manager';
case 'imageTUI': return 'image_tui';
case 'inlineClass': return 'inline_class';
case 'inlineStyle': return 'inline_style';
case 'lineBreaker': return 'line_breaker';
case 'lineHeight': return 'line_height';
case 'paragraphFormat': return 'paragraph_format';
case 'paragraphStyle': return 'paragraph_style';
case 'quickInsert': return 'quick_insert';
case 'specialCharacters': return 'special_characters';
case 'spellChecker': return 'spell_checker';
case 'trackChanges': return 'track_changes';
case 'trimVideo': return 'trim_video';
case 'wordPaste': return 'word_paste';
default: return plugin;
/* eslint-enable prettier/prettier */
}
});
// Paths to use for validating optional assets
let froalaPath = path.dirname(
require.resolve('froala-editor/package.json'),
);
let languagePath = path.join(froalaPath, 'js', 'languages');
let pluginJsPath = path.join(froalaPath, 'js', 'plugins');
let pluginCssPath = path.join(froalaPath, 'css', 'plugins');
let thirdPartyJsPath = path.join(froalaPath, 'js', 'third_party');
let thirdPartyCssPath = path.join(froalaPath, 'css', 'third_party');
let themePath = path.join(froalaPath, 'css', 'themes');
// Validate language options and add to proper import list
options.languages.forEach((language) => {
let filename = language + '.js';
if (fs.existsSync(path.join(languagePath, filename))) {
this.options['@embroider/macros'].setOwnConfig.languages.push(filename);
} else {
throw new Error(
`${this.name}: languages "${language}" is not available.`,
);
}
});
// Validate plugin options and add to proper import list(s)
options.plugins.forEach((plugin) => {
let jsFilename = plugin + '.min.js';
let cssFilename = plugin + '.min.css';
if (fs.existsSync(path.join(pluginJsPath, jsFilename))) {
this.options['@embroider/macros'].setOwnConfig.plugins.js.push(
jsFilename,
);
if (fs.existsSync(path.join(pluginCssPath, cssFilename))) {
this.options['@embroider/macros'].setOwnConfig.plugins.css.push(
cssFilename,
);
}
} else if (fs.existsSync(path.join(thirdPartyJsPath, jsFilename))) {
this.options['@embroider/macros'].setOwnConfig.third_party.js.push(
jsFilename,
);
if (fs.existsSync(path.join(thirdPartyCssPath, cssFilename))) {
this.options['@embroider/macros'].setOwnConfig.third_party.css.push(
cssFilename,
);
}
} else {
throw new Error(`${this.name}: plugins "${plugin}" is not available.`);
}
});
// Validate theme options and add to proper import list
options.themes.forEach((theme) => {
let filename = theme + '.min.css';
if (fs.existsSync(path.join(themePath, filename))) {
this.options['@embroider/macros'].setOwnConfig.themes.push(filename);
} else {
throw new Error(`${this.name}: themes "${theme}" is not available.`);
}
});
},
};