Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
javascript_bundler.py65 linesDownload Raw Back to javascript
1##########################################################################2#3# pgAdmin 4 - PostgreSQL Tools4#5# Copyright (C) 2013 - 2024, The pgAdmin Development Team6# This software is released under the PostgreSQL Licence7#8##########################################################################9 10import os11from contextlib import contextmanager12from subprocess import call13from pgadmin.utils import u_encode, fs_encoding, file_quote14 15 16# enum-like for tracking whether we have17class JsState:18    NONE = 019    OLD = 120    NEW = 221 22 23class JavascriptBundler:24    """Builds Javascript bundle files by delegating to webpack"""25 26    def __init__(self):27        self.js_state = JsState.NONE28 29    def bundle(self):30        try:31            try_building_js()32            self.js_state = JsState.NEW33        except OSError:34            webdir_path()35            generated_js_dir = os.path.join(36                webdir_path(), 'pgadmin', 'static', 'js', 'generated')37            if os.path.exists(generated_js_dir) and \38                    os.listdir(generated_js_dir):39                self.js_state = JsState.OLD40            else:41                self.js_state = JsState.NONE42 43    def report(self):44        return self.js_state45 46 47@contextmanager48def pushd(new_dir):49    previous_dir = os.getcwd()50    os.chdir(new_dir)51    yield52    os.chdir(previous_dir)53 54 55def webdir_path():56    dirname = os.path.dirname57    this_path = os.path.realpath(u_encode(__file__, fs_encoding))58    return dirname(dirname(dirname(dirname(this_path))))59 60 61def try_building_js():62    with pushd(webdir_path()):63        if call(['yarn', 'run', 'bundle:dev']) != 0:64            raise OSError('Error executing bundling the application')65 
codekingpro/portable-devtools · Team Ai