mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Bring React into the tree, and add linting and bundling framework for the JS etc.
This commit is contained in:
62
web/pgadmin/utils/javascript/javascript_bundler.py
Normal file
62
web/pgadmin/utils/javascript/javascript_bundler.py
Normal file
@@ -0,0 +1,62 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
from subprocess import call
|
||||
from pgadmin.utils import u, fs_encoding, file_quote
|
||||
|
||||
|
||||
# enum-like for tracking whether we have
|
||||
class JsState:
|
||||
NONE = 0
|
||||
OLD = 1
|
||||
NEW = 2
|
||||
|
||||
|
||||
class JavascriptBundler:
|
||||
"""Builds Javascript bundle files by delegating to webpack"""
|
||||
|
||||
def __init__(self):
|
||||
self.jsState = JsState.NONE
|
||||
|
||||
def bundle(self):
|
||||
try:
|
||||
try_building_js()
|
||||
self.jsState = JsState.NEW
|
||||
except OSError:
|
||||
webdir_path()
|
||||
generatedJavascriptDir = os.path.join(webdir_path(), 'pgadmin', 'static', 'js', 'generated')
|
||||
if os.path.exists(generatedJavascriptDir) and os.listdir(generatedJavascriptDir):
|
||||
self.jsState = JsState.OLD
|
||||
else:
|
||||
self.jsState = JsState.NONE
|
||||
|
||||
def report(self):
|
||||
return self.jsState
|
||||
|
||||
|
||||
@contextmanager
|
||||
def pushd(new_dir):
|
||||
previous_dir = os.getcwd()
|
||||
os.chdir(new_dir)
|
||||
yield
|
||||
os.chdir(previous_dir)
|
||||
|
||||
|
||||
def webdir_path():
|
||||
dirname = os.path.dirname
|
||||
thisPath = os.path.realpath(u(__file__, fs_encoding))
|
||||
return dirname(dirname(dirname(dirname(thisPath))))
|
||||
|
||||
|
||||
def try_building_js():
|
||||
with pushd(webdir_path()):
|
||||
if call(['yarn', 'run', 'bundle']) != 0:
|
||||
raise OSError('Error executing bundling the application')
|
||||
Reference in New Issue
Block a user