Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
61929d0
Allow custom node env variables for plugins
pkulkark Sep 20, 2020
60a512f
Sorts Additional Node Env Variables to keep Webpack Hashes Consistent
nizarmah Nov 25, 2020
193bf47
Passes additional tinymce plugins from env settings to javascript tin…
nizarmah Nov 25, 2020
c0cf6ce
Makes necessary changes to backport changes to juniper
nizarmah Nov 25, 2020
00c367d
Removes forgotten negation on conditional statements
nizarmah Nov 25, 2020
b8e450b
Renames tinymce additional plugins variable to be consistent with con…
nizarmah Nov 27, 2020
632045a
Renames ADDITIONAL_NODE_ENV_VARS to JS_ENV_EXTRA_CONFIG
nizarmah Dec 3, 2020
d24734f
Fixes issue with getting django setting when running webpack build
nizarmah Dec 3, 2020
5a15bad
Fixes javascript error failure by checking if process is of type unde…
nizarmah Dec 3, 2020
78b2ce5
Fixes python failing tests
nizarmah Dec 5, 2020
53b1186
Fixes the way the environment string is appended for webpack command
nizarmah Dec 5, 2020
29df5dd
Merge branch 'opencraft-release/juniper.3' of github.com:open-craft/e…
nizarmah Dec 6, 2020
810c565
Updates the way tinymce plugins are added through the configuration
nizarmah Dec 14, 2020
cb5d965
Removes key sorting because configuration already takes care of that …
nizarmah Dec 15, 2020
d7811b6
Simplifies the way js env extra config is being passed to webpack
nizarmah Dec 27, 2020
8b141ef
Re-formats js env extra config settings to valid json parseable string
nizarmah Dec 27, 2020
b596514
Removes the need to parse the webpack env variable passed
nizarmah Dec 27, 2020
63b4d77
Updates tests based on the latest changes
nizarmah Dec 27, 2020
49942e2
Removes trailing commas from webpack configurations
nizarmah Dec 28, 2020
ac27b1e
Adds string type check before formatting js extra config to json
nizarmah Dec 28, 2020
4b89f6f
Adds more information about the JS_ENV_EXTRA_CONFIG env setting
nizarmah Dec 31, 2020
6897568
Sorts js env extra config to keep Webpack hashes consistent
nizarmah Oct 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,11 @@
##### EMBARGO #####
EMBARGO_SITE_REDIRECT_URL = None

##### custom vendor plugin variables #####
# JavaScript code can access this data using `process.env.JS_ENV_EXTRA_CONFIG`
# One of the current use cases for this is enabling custom TinyMCE plugins
JS_ENV_EXTRA_CONFIG = {}

############################### PIPELINE #######################################

PIPELINE = {
Expand Down
39 changes: 37 additions & 2 deletions common/lib/xmodule/xmodule/js/src/html/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
tinyMCE incorrectly decides that the suffix should be "", which means it fails to load files.
*/
tinyMCE.suffix = ".min";
this.tiny_mce_textarea = $(".tiny-mce", this.element).tinymce({

var tinyMceConfig = {
script_url: baseUrl + "js/vendor/tinymce/js/tinymce/tinymce.full.min.js",
font_formats: _getFonts(),
theme: "modern",
Expand Down Expand Up @@ -171,7 +172,41 @@
*/
init_instance_callback: this.initInstanceCallback,
browser_spellcheck: true
});
};

if (typeof process != "undefined" && process.env.JS_ENV_EXTRA_CONFIG) {
var tinyMceAdditionalPlugins = process.env.JS_ENV_EXTRA_CONFIG.TINYMCE_ADDITIONAL_PLUGINS;
// check if we have any additional plugins passed
if (tinyMceAdditionalPlugins) {
// go over each plugin
tinyMceAdditionalPlugins.forEach(function (tinyMcePlugin) {
// check if plugins is not empty (ie there are existing plugins)
if (tinyMceConfig.plugins.trim()) {
tinyMceConfig.plugins += ', ';
}

// add the plugin to the list of plugins
tinyMceConfig.plugins += tinyMcePlugin.name;

// check if the plugin should be included in the toolbar
if (tinyMcePlugin.toolbar) {
// check if toolbar is not empty (ie there are already items in the toolbar)
if (tinyMceConfig.toolbar.trim()) {
tinyMceConfig.toolbar += ' | ';
}

tinyMceConfig.toolbar += tinyMcePlugin.name;
}

// add the additional settings for each plugin (if there is any)
if (tinyMcePlugin.extra_settings) {
tinyMceConfig[tinyMcePlugin.name] = tinyMcePlugin.extra_settings;
}
});
}
}

this.tiny_mce_textarea = $(".tiny-mce", this.element).tinymce(tinyMceConfig);
tinymce.addI18n('en', {

/*
Expand Down
27 changes: 25 additions & 2 deletions pavelib/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import argparse
import glob
import json
import os
import re
import traceback
from datetime import datetime
from functools import wraps
Expand Down Expand Up @@ -763,14 +765,35 @@ def webpack(options):
"""
Run a Webpack build.
"""
def json_format_setting(setting_value):
"""
Replaces capitalized booleans with booleans that
are compatible with parsed JSON in javascript.
"""
if isinstance(setting_value, str):
# replace python bools with json valid bools
setting_value = re.sub(r'(\:\s?)True', r'\1true', setting_value)
setting_value = re.sub(r'(\:\s?)False', r'\1false', setting_value)

setting_value = setting_value.replace("'", '"')

return setting_value

settings = getattr(options, 'settings', Env.DEVSTACK_SETTINGS)
static_root_lms = Env.get_django_setting("STATIC_ROOT", "lms", settings=settings)
static_root_cms = Env.get_django_setting("STATIC_ROOT", "cms", settings=settings)
config_path = Env.get_django_setting("WEBPACK_CONFIG_PATH", "lms", settings=settings)
environment = u'NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms}'.format(
js_env_extra_config_setting = Env.get_django_setting("JS_ENV_EXTRA_CONFIG", "cms", settings=settings)
js_env_extra_config_json_setting = json.loads(json_format_setting(js_env_extra_config_setting) or '{}')
js_env_extra_config = json.dumps(json.dumps(js_env_extra_config_json_setting, sort_keys=True))
environment = (
u'NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} '
u'JS_ENV_EXTRA_CONFIG={js_env_extra_config}'
).format(
node_env="development" if config_path == 'webpack.dev.config.js' else "production",
static_root_lms=static_root_lms,
static_root_cms=static_root_cms
static_root_cms=static_root_cms,
js_env_extra_config=js_env_extra_config,
)
sh(
cmd(
Expand Down
8 changes: 7 additions & 1 deletion pavelib/paver_tests/test_servers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Unit tests for the Paver server tasks."""


import json

import ddt
from paver.easy import call_task

Expand Down Expand Up @@ -46,10 +48,12 @@
EXPECTED_PRINT_SETTINGS_COMMAND = [
u"python manage.py lms --settings={settings} print_setting STATIC_ROOT 2>{log_file}",
u"python manage.py cms --settings={settings} print_setting STATIC_ROOT 2>{log_file}",
u"python manage.py lms --settings={settings} print_setting WEBPACK_CONFIG_PATH 2>{log_file}"
u"python manage.py lms --settings={settings} print_setting WEBPACK_CONFIG_PATH 2>{log_file}",
u"python manage.py cms --settings={settings} print_setting JS_ENV_EXTRA_CONFIG 2>{log_file}",
]
EXPECTED_WEBPACK_COMMAND = (
u"NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} "
u"JS_ENV_EXTRA_CONFIG={js_env_extra_config} "
u"$(npm bin)/webpack --config={webpack_config_path}"
)

Expand Down Expand Up @@ -252,6 +256,7 @@ def verify_server_task(self, task_name, options, contracts_default=False):
node_env="production",
static_root_lms=None,
static_root_cms=None,
js_env_extra_config=json.dumps({}),
webpack_config_path=None
))
expected_messages.extend(self.expected_sass_commands(system=system, asset_settings=expected_asset_settings))
Expand Down Expand Up @@ -298,6 +303,7 @@ def verify_run_all_servers_task(self, options):
node_env="production",
static_root_lms=None,
static_root_cms=None,
js_env_extra_config=json.dumps({}),
webpack_config_path=None
))
expected_messages.extend(self.expected_sass_commands(asset_settings=expected_asset_settings))
Expand Down
3 changes: 2 additions & 1 deletion webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = _.values(Merge.smart(commonConfig, {
debug: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
'process.env.NODE_ENV': JSON.stringify('development'),
'process.env.JS_ENV_EXTRA_CONFIG': process.env.JS_ENV_EXTRA_CONFIG
})
],
module: {
Expand Down
3 changes: 2 additions & 1 deletion webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var optimizedConfig = Merge.smart(commonConfig, {
devtool: false,
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
'process.env.NODE_ENV': JSON.stringify('production'),
'process.env.JS_ENV_EXTRA_CONFIG': process.env.JS_ENV_EXTRA_CONFIG
}),
new webpack.LoaderOptionsPlugin({ // This may not be needed; legacy option for loaders written for webpack 1
minimize: true
Expand Down