Skip to content

Commit 4fbbb94

Browse files
committed
Ported over to service-host.
Django integration is currently untested.
1 parent 203f2be commit 4fbbb94

25 files changed

Lines changed: 257 additions & 297 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ docs/_build/
5454
target/
5555

5656
node_modules
57-
tests/static_root
5857
example/static

django_react/conf.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

django_react/services/__init__.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

django_react/services/package.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

django_react/services/render.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,57 @@
11
import os
22
import re
33
import tempfile
4-
from django_webpack.compiler import webpack
4+
from webpack.compiler import webpack
5+
from service_host.conf import settings as service_host_settings
56
from .templates import BUNDLE_CONFIG, BUNDLE_TRANSLATE_CONFIG, DEV_TOOL_CONFIG
67
from .conf import settings
78

8-
COMPONENT_CONFIG_FILES = {}
9-
10-
PATH_TO_NODE_MODULES = os.path.join(os.path.dirname(__file__), 'services', 'node_modules')
11-
129

1310
def bundle_component(path, translate=None, watch_source=None):
1411
filename = get_component_config_filename(path, translate)
1512
return webpack(filename, watch_source=watch_source)
1613

14+
# TODO: replace this with a deterministic config file writer in webpack
15+
COMPONENT_CONFIG_FILES = {}
1716

18-
def get_var_from_path(path):
19-
var = '{parent_dir}__{filename}'.format(
20-
parent_dir=os.path.basename(os.path.dirname(path)),
21-
filename=os.path.splitext(os.path.basename(path))[0]
22-
)
23-
return re.sub(r'\W+', '_', var)
17+
18+
def get_component_config_filename(path, translate=None):
19+
cache_key = (path, translate)
20+
if cache_key in COMPONENT_CONFIG_FILES:
21+
return COMPONENT_CONFIG_FILES[cache_key]
22+
23+
config = get_webpack_config(path, translate)
24+
filename = tempfile.mkstemp(suffix='.webpack.config.js')[1]
25+
with open(filename, 'w') as config_file:
26+
config_file.write(config)
27+
28+
COMPONENT_CONFIG_FILES[cache_key] = filename
29+
30+
return filename
2431

2532

2633
def get_webpack_config(path, translate=None):
2734
var = get_var_from_path(path)
2835

36+
# TODO: clean up and scrap resolve?
37+
# TODO: probably easiest to rely on node_modules babel-loader and provide a `path_to_react` arg
38+
# TODO: actually, given that this is a pure convenience thing, I think just make it as rigid as possible
39+
node_modules = os.path.join(service_host_settings.SOURCE_ROOT, 'node_modules')
40+
2941
translate_config = ''
3042
if translate:
3143
# JSX + ES6/7 support
3244
translate_config += BUNDLE_TRANSLATE_CONFIG.format(
3345
ext=os.path.splitext(path)[-1],
34-
node_modules=PATH_TO_NODE_MODULES
46+
node_modules=node_modules
3547
)
3648

3749
dev_tool_config = ''
3850
if settings.DEV_TOOL:
3951
dev_tool_config = DEV_TOOL_CONFIG
4052

4153
return BUNDLE_CONFIG.format(
42-
path_to_resolve=os.path.join(PATH_TO_NODE_MODULES, 'resolve'),
54+
path_to_react=os.path.join(node_modules, 'react'),
4355
dir=os.path.dirname(path),
4456
file='./' + os.path.basename(path),
4557
var=var,
@@ -48,16 +60,9 @@ def get_webpack_config(path, translate=None):
4860
)
4961

5062

51-
def get_component_config_filename(path, translate=None):
52-
cache_key = (path, translate)
53-
if cache_key in COMPONENT_CONFIG_FILES:
54-
return COMPONENT_CONFIG_FILES[cache_key]
55-
56-
config = get_webpack_config(path, translate)
57-
filename = tempfile.mkstemp(suffix='.webpack.config.js')[1]
58-
with open(filename, 'w') as config_file:
59-
config_file.write(config)
60-
61-
COMPONENT_CONFIG_FILES[cache_key] = filename
62-
63-
return filename
63+
def get_var_from_path(path):
64+
var = '{parent_dir}__{filename}'.format(
65+
parent_dir=os.path.basename(os.path.dirname(path)),
66+
filename=os.path.splitext(os.path.basename(path))[0]
67+
)
68+
return re.sub(r'\W+', '_', var)

react/conf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from optional_django import conf
2+
3+
4+
class Conf(conf.Conf):
5+
django_namespace = 'REACT'
6+
7+
DEV_TOOL = False
8+
WATCH_SOURCE = False
9+
10+
settings = Conf()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class ComponentSourceFileNotFound(Exception):
22
pass
33

44

5-
class ComponentRenderingError(Exception):
5+
class ReactRenderingError(Exception):
66
pass
77

88

File renamed without changes.

0 commit comments

Comments
 (0)