Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 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
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
3 changes: 3 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,9 @@
##### EMBARGO #####
EMBARGO_SITE_REDIRECT_URL = None

##### custom vendor plugin variables #####
ADDITIONAL_NODE_ENV_VARS = {}

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

PIPELINE = {
Expand Down
35 changes: 33 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,37 @@
*/
init_instance_callback: this.initInstanceCallback,
browser_spellcheck: true
});
};

if (process.env.ADDITIONAL_NODE_ENV_VARS) {
var tinyMceAdditionalPlugins = JSON.parse(process.env.ADDITIONAL_NODE_ENV_VARS).TINYMCE_ADDITIONAL_PLUGINS;
// check if we have any additional plugins passed
if (tinyMceAdditionalPlugins) {
// go over each plugin
for (var plugin_name in tinyMceAdditionalPlugins) {
// 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 += plugin_name;

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

// add the additional context for each plugin (if there is any)
if (tinyMceAdditionalPlugins[plugin_name]) {
tinyMceConfig[plugin_name] = tinyMceAdditionalPlugins[plugin_name];
}
}
}
}

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

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

import argparse
import glob
import json
import os
import traceback
from datetime import datetime
Expand Down Expand Up @@ -767,10 +768,23 @@ def webpack(options):
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(
additional_node_env_vars_sorted_json = json.dumps(
json.loads(
Comment thread
pkulkark marked this conversation as resolved.
Outdated
Env.get_django_setting( # pylint: disable=no-member
"ADDITIONAL_NODE_ENV_VARS",
"cms",
settings=settings
).replace("'", '"')
),
sort_keys=True,
)
additional_node_env_vars = json.dumps(additional_node_env_vars_sorted_json)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json.dumps is already called in the previous step while defining the variable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this commit please.

So in that commit, what I did was take the Env.get_django_setting("ADDITIONAL_NODE_ENV_VARS", "cms", settings=settings).replace("'", '"') and simply sort it. So I json.loads to sort it and then json.dumps after it is sorted.

But we need to run json.dumps again in order to escape the previous string, which is the dump of the sorted json.

So we dump twice in order to make sure that the string is escaped when it is added to the command.

environment = u'NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} \
ADDITIONAL_NODE_ENV_VARS={additional_node_env_vars}'.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,
additional_node_env_vars=additional_node_env_vars
)
sh(
cmd(
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.ADDITIONAL_NODE_ENV_VARS': JSON.stringify(process.env.ADDITIONAL_NODE_ENV_VARS)
})
],
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.ADDITIONAL_NODE_ENV_VARS': JSON.stringify(process.env.ADDITIONAL_NODE_ENV_VARS)
}),
new webpack.LoaderOptionsPlugin({ // This may not be needed; legacy option for loaders written for webpack 1
minimize: true
Expand Down