Test Failed
Pull Request — master (#77)
by Terzi
05:49
created

publishes/mix/editors.js   A

Complexity

Total Complexity 10
Complexity/F 1.25

Size

Lines of Code 87
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 37
c 0
b 0
f 0
dl 0
loc 87
rs 10
wmc 10
mnd 2
bc 2
fnc 8
bpm 0.25
cpm 1.25
noi 0
1
class EditorManager {
2
    constructor(mix) {
3
        this.mix = {...mix}
4
5
        this.KNOWN_EDITORS = [
6
            'TinyMce',
7
            'Medium',
8
            'Markdown',
9
            'Ck'
10
        ]
11
    }
12
13
    /**
14
     * Assemble required editors.
15
     */
16
    enable(editors) {
17
        if (!Array.isArray(editors)) {
18
            editors = Array.from(arguments)
19
        }
20
21
        editors.forEach((editor) => {
22
            if (this.KNOWN_EDITORS.indexOf(editor) === -1) {
23
                throw new Error(`Unknown editor: ${editor}`)
24
            }
25
26
            const method = `handle${editor}Editor`
27
            this[method]()
28
        })
29
    }
30
31
    /**
32
     * Assembles TinyMCE editor
33
     *
34
     * @requires `tinymce@^4.6.4` package
35
     * @note npm i tinymce@^4.6.4 --save-dev
36
     */
37
    handleTinyMceEditor() {
38
        this.mix.copy('node_modules/tinymce/skins', 'build/editors/skins')
39
40
        this.mix.js('resources/js/editors/tinymce.js', 'build/editors/tinymce.js')
41
    }
42
43
    /**
44
     * Assembles CK editor
45
     *
46
     * @requires `ckeditor@^4.7.0` package
47
     * @note npm i ckeditor@^4.7.0 --save-dev
48
     */
49
    handleCkEditor() {
50
        this.mix.copy([
51
            'node_modules/ckeditor/config.js',
52
            'node_modules/ckeditor/styles.js',
53
            'node_modules/ckeditor/contents.css'
54
        ], 'build/editors')
55
        this.mix.copy('node_modules/ckeditor/lang/en.js', 'build/editors/lang/en.js')
56
        this.mix.copy('node_modules/ckeditor/skins', 'build/editors/skins')
57
        this.mix.copy('node_modules/ckeditor/plugins', 'build/editors/plugins')
58
59
        this.mix.js('resources/js/editors/ckeditor.js', 'build/editors/ckeditor.js')
60
    }
61
62
    /**
63
     * Assembles Medium editor.
64
     *
65
     * @requires `medium-editor@^5.23.1` package
66
     * @note npm i medium-editor@^5.23.1 --save-dev
67
     */
68
    handleMediumEditor() {
69
        this.mix.js('resources/js/editors/medium.js', 'build/editors/medium.js')
70
        this.mix.sass('resources/sass/editors/medium.scss', 'build/editors/medium.css')
71
    }
72
73
    /**
74
     * Assembles Markdown editor.
75
     *
76
     * @requires `simplemde` package
77
     * @note npm i simplemde --save-dev
78
     */
79
    handleMarkdownEditor() {
80
        this.mix.js('resources/js/editors/markdown.js', 'build/editors/markdown.js')
81
        this.mix.sass('resources/sass/editors/markdown.scss', 'build/editors/markdown.css')
82
    }
83
}
84
85
module.exports = EditorManager
86