Skip to content

Commit

Permalink
webbundle: add conditions to execute
Browse files Browse the repository at this point in the history
webbundle
- only npm ci if not exists
- only npm run build if not exists or newer
  • Loading branch information
ewoudwijma committed Jul 23, 2024
1 parent abee152 commit 7786bbf
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tools/webbundle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Import("env")
import shutil
import glob
import os

cmd_ex = shutil.which("node")
# Check if Node.js is not installed
Expand All @@ -9,12 +11,26 @@
# Install the necessary node packages for the pre-build asset bundling script
print('\x1b[6;33;42m' + 'Install the node packages' + '\x1b[0m')

# npm ci performs a clean install of all existing dependencies
env.Execute("npm ci")
# npm ci performs a clean install of all existing dependencies, if not installed
if not os.path.isdir('node_modules'):
env.Execute("npm ci")

# if html_ui does not exist, create it (and others)
if not os.path.exists('src/html_ui.h'):
env.Execute("npm run build")

latest_source = max(glob.glob('data/*.*'), key=os.path.getmtime) #any file in data folder
latest_export = max(glob.glob('src/html_*.h'), key=os.path.getmtime)

# if any files in data newer then html_*.h, recreate it (and others)
if os.path.getmtime(latest_source) > os.path.getmtime(latest_export):
print (' updated file(s) in /data -> npm run build')
env.Execute("npm run build")

# Call the bundling script
exitCode = env.Execute("node tools/cdata.js")
# exitCode = env.Execute("node tools/cdata.js")

# If it failed, abort the build
if (exitCode):
Exit(exitCode)
# if (exitCode):
# Exit(exitCode)

0 comments on commit 7786bbf

Please sign in to comment.