Mobile-BillTracker/scripts/sync-nodejs-project.sh

79 lines
3.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# Copies the bill-tracker backend into mobile/nodejs-assets/nodejs-project/server/
# so it can be bundled into the Android app and run by nodejs-mobile (Node 18) in
# local mode.
#
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# The backend is now TypeScript (server.cts + .cts/.mts). Node 18 can't run TS, so
# this transpiles the server's own sources to CommonJS in place (keeping filenames;
# see scripts/transpile-node18.js). Dependencies run as-is on Node 18 and are NOT
# transpiled — install them separately (see the "Next" steps printed at the end).
#
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# Usage: ./scripts/sync-nodejs-project.sh [--source /path/to/bill-tracker]
# --source defaults to ../bill-tracker (sibling directory). Run from mobile root.
set -euo pipefail
MOBILE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
REPO_ROOT=""
while [[ $# -gt 0 ]]; do
case "$1" in
--source) REPO_ROOT="$(cd "$2" && pwd)"; shift 2 ;;
*) echo "Unknown arg: $1" >&2; exit 1 ;;
esac
done
if [[ -z "$REPO_ROOT" ]]; then
REPO_ROOT="$(cd "$MOBILE_DIR/../bill-tracker" && pwd)"
fi
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
if [[ ! -f "$REPO_ROOT/server.cts" ]]; then
echo "Error: Bill Tracker source not found at $REPO_ROOT (no server.cts)." >&2
echo "Use --source /path/to/bill-tracker to specify the project root." >&2
exit 1
fi
DEST="$MOBILE_DIR/nodejs-assets/nodejs-project/server"
echo "Syncing backend source from $REPO_ROOT -> $DEST"
rm -rf "$DEST"
mkdir -p "$DEST"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
cp "$REPO_ROOT/server.cts" "$DEST/"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# Backend source trees. `types/` is type-only (erased by the transpile) but cheap
# insurance; `setup/` holds firstRun.cts (required by server.cts on empty DB).
for dir in db routes services middleware utils workers setup types; do
[[ -d "$REPO_ROOT/$dir" ]] && cp -R "$REPO_ROOT/$dir" "$DEST/$dir"
done
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# routes/user.cts requires ../scripts/seedDemoData.cts (relative to server/).
mkdir -p "$DEST/scripts"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
cp "$REPO_ROOT/scripts/seedDemoData.cts" "$DEST/scripts/"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# Seed JSON read at first-run init:
# db/data/*.json -> carried with db/ above (database.cts reads them)
# docs/top_200_*.json -> db/migrations/versionedMigrations.cts reads ../../docs/
mkdir -p "$DEST/docs"
cp "$REPO_ROOT/docs/top_200_us_subscriptions_researched_2026-06-06.json" "$DEST/docs/"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# Drop dev SQLite DBs and any stray node_modules that rode along with db/.
rm -f "$DEST"/db/*.db "$DEST"/db/*.db-* 2>/dev/null || true
rm -rf "$DEST/db/node_modules"
# Transpile the server's TypeScript sources to CommonJS in place (Node 18).
# Runs BEFORE dist/ is copied so the browser ESM bundle isn't touched.
node "$MOBILE_DIR/scripts/transpile-node18.js" "$DEST"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
# Built frontend, served as static files by server.cts (path.join(__dirname,'dist')).
cp -R "$REPO_ROOT/dist" "$DEST/dist"
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
cat <<EOF
Done syncing server source.
feat(mobile): run the TypeScript backend on Node 18 in local mode (batch 7-9) The web app migrated its server to TypeScript (server.cts) on Express 5 / openid-client 6 / kysely, none of which ran on the old embedded Node 12.19. Rebuild the local-mode pipeline for Node 18: - sync-nodejs-project.sh: sync server.cts + .cts/.mts + setup/ + seed data. - transpile-node18.js (replaces transpile-node12.js): esbuild TS->CJS in place, keeping .cts/.mts filenames (Node 18's CJS loader loads unknown extensions via the .js handler, so the explicit-extension require() graph keeps resolving). - prepare-local-mode-deps.js: bundle ESM-only kysely to CJS, stub openid-client (unused on-device), and rewrite path-to-regexp's \p{} regexes to ASCII (the no-ICU Node 18 build can't compile unicode-property escapes). - build-better-sqlite3-node18.sh (replaces the Node-12 build/fix scripts): cross-compile for all three ABIs against the Node 18 ABI, injecting libnode.so as a NEEDED entry so V8 symbols resolve at dlopen. - main.js: entry -> server.cts; drop the now-native randomUUID/hkdfSync polyfills (keep the Intl shim); add TMPDIR + a startup-error relay to the WebView. - nodejs-project/package.json: server dep set matched to the web app. Verified end-to-end on the x86_64 emulator: boot -> migrations -> seed -> login -> create bill -> force-stop -> relaunch -> data persists. arm64/armv7 prebuilds are built and link-verified; a physical-device run is still pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:42:53 -05:00
Next (only when deps changed):
1. cd "$MOBILE_DIR/nodejs-assets/nodejs-project" && npm install
2. node "$MOBILE_DIR/scripts/prepare-local-mode-deps.js" # kysely->CJS, stub openid-client
3. "$MOBILE_DIR/scripts/install-node18-runtime.sh" # (re)apply Node 18 runtime + bridge patch
4. "$MOBILE_DIR/scripts/build-better-sqlite3-node18.sh" # better-sqlite3 for the Node 18 ABI
EOF