UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

52 lines (51 loc) โ€ข 1.98 kB
import { $ } from "../lib/$.mjs"; export const debugSync = async (opts) => { const { targetDir, dev, watch, build } = opts; if (!targetDir) { console.error("โŒ Please provide a target directory as an argument."); process.exit(1); } const syncCommand = `echo ๐Ÿ—๏ธ rebuilding... && pnpm build && rm -rf ${targetDir}/node_modules/rwsdk/dist ${targetDir}/node_modules/rwsdk/package.json && echo ๐Ÿ“ syncing sdk from ${process.cwd()} to ${targetDir}/node_modules/rwsdk/... && cp -r package.json dist ${targetDir}/node_modules/rwsdk/ && echo โœ… done syncing`; // Run initial sync await $({ stdio: "inherit", shell: true }) `${syncCommand}`; if (!process.env.NO_CLEAN_VITE) { console.log("๐Ÿงน Cleaning Vite cache..."); await $({ stdio: "inherit", shell: true, cwd: targetDir, }) `rm -rf node_modules/.vite`; } // If dev flag is present, clean vite cache and start dev server if (dev) { console.log("๐Ÿš€ Starting dev server..."); await $({ stdio: "inherit", shell: true, cwd: targetDir }) `npm run dev`; } // Start watching if watch flag is present else if (watch) { console.log("๐Ÿ‘€ Watching for changes..."); $({ stdio: "inherit", shell: true, }) `npx chokidar-cli './src/**' './package.json' -c "${syncCommand}"`; } else if (build) { console.log("๐Ÿ—๏ธ Running build in target directory..."); await $({ stdio: "inherit", shell: true, cwd: targetDir, }) `npm run build`; } }; if (import.meta.url === new URL(process.argv[1], import.meta.url).href) { const args = process.argv.slice(2); const targetDir = args[0]; const flags = new Set(args.slice(1)); debugSync({ targetDir, dev: flags.has("--dev"), watch: flags.has("--watch"), build: flags.has("--build"), }); }