obcon-scada / app /scripts /fix_missing_module_indexes.sh
chanmin0723's picture
Initial obcon SCADA deploy
e4bf523
Raw
History Blame Contribute Delete
935 Bytes
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
MODDIR="$ROOT/modules"
if [ ! -d "$MODDIR" ]; then
echo "[ERROR] modules directory not found: $MODDIR"
exit 1
fi
created=0
for d in "$MODDIR"/*; do
[ -d "$d" ] || continue
name="$(basename "$d")"
# Skip non-module folders if any (optional: adjust)
# Example: skip "modules.js" file or hidden dirs already not in glob
idx="$d/index.js"
if [ -f "$idx" ]; then
continue
fi
echo "[CREATE] $idx"
cat > "$idx" <<'JS'
'use strict';
function safeRequire(relPath) {
try { return require(relPath); } catch (e) { return null; }
}
const mod = {
model: safeRequire('./model'),
view: safeRequire('./view'),
setting: safeRequire('./setting'),
lang: safeRequire('./lang'),
};
mod.default = mod.model;
module.exports = mod;
JS
created=$((created+1))
done
echo "[DONE] created index.js for $created module(s)."