MCPcopy
hub / github.com/WebODM/WebODM / build_plugins

Function build_plugins

app/plugins/functions.py:84–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82
83
84def build_plugins():
85 for plugin in get_plugins():
86 # Check for package.json in public directory
87 # and run npm install if needed
88 if plugin.path_exists("public/package.json") and not plugin.path_exists("public/node_modules"):
89 logger.info("Running npm install for {}".format(plugin))
90
91 try:
92 npm = "npm"
93 if platform.system() == "Windows":
94 npm = "npm.cmd"
95 command = [npm, 'install']
96 if plugin.is_persistent():
97 command.append('--ignore-scripts')
98 subprocess.call(command, cwd=plugin.get_path("public"))
99 except FileNotFoundError:
100 logger.warn("npm is not installed, will skip this plugin")
101 continue
102
103 # Check if we need to generate a webpack.config.js
104 if len(plugin.build_jsx_components()) > 0 and plugin.path_exists('public'):
105 build_paths = map(lambda p: os.path.join(plugin.get_path('public'), p), plugin.build_jsx_components())
106 paths_ok = not (False in map(lambda p: os.path.exists, build_paths))
107
108 if paths_ok:
109 wpc_path = os.path.join(settings.BASE_DIR, 'app', 'plugins', 'templates', 'webpack.config.js.tmpl')
110 with open(wpc_path) as f:
111 tmpl = Template(f.read())
112
113 # Create entry configuration
114 entry = {}
115 for e in plugin.build_jsx_components():
116 entry[os.path.splitext(os.path.basename(e))[0]] = ['./' + e]
117 wpc_content = tmpl.substitute({
118 'entry_json': json.dumps(entry)
119 })
120
121 with open(plugin.get_path('public/webpack.config.js'), 'w') as f:
122 f.write(wpc_content)
123 else:
124 logger.warning(
125 "Cannot generate webpack.config.js for {}, a path is missing: {}".format(plugin, ' '.join(build_paths)))
126
127 # Check for webpack.config.js (if we need to build it)
128 if plugin.path_exists("public/webpack.config.js"):
129 if settings.DEV and webpack_watch_process_count() <= 2 and settings.DEV_WATCH_PLUGINS:
130 logger.info("Running webpack with watcher for {}".format(plugin.get_name()))
131 subprocess.Popen(['webpack-cli', '--watch'], cwd=plugin.get_path("public"))
132 elif not plugin.path_exists("public/build"):
133 logger.info("Running webpack for {}".format(plugin.get_name()))
134
135 try:
136 webpack = "webpack-cli"
137 if platform.system() == "Windows":
138 webpack = "webpack-cli.cmd"
139
140 subprocess.call([webpack], cwd=plugin.get_path("public"))
141 except FileNotFoundError:

Callers 2

handleMethod · 0.90
init_pluginsFunction · 0.85

Calls 12

get_pluginsFunction · 0.85
path_existsMethod · 0.80
is_persistentMethod · 0.80
appendMethod · 0.80
get_pathMethod · 0.80
writeMethod · 0.80
get_nameMethod · 0.80
mapFunction · 0.50
formatMethod · 0.45
build_jsx_componentsMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected