const spawnAsync = require('@expo/spawn-async'); const expoVersion = require('expo/package.json').version; const fs = require('fs/promises'); const path = require('path'); const semver = require('semver'); /* eslint-env node */ run(); /** Export, patch, and upload Snack Runtime web */ async function run() { const workingDir = path.resolve(__dirname, '../'); const exportDir = './web-build'; await exportWeb({ workingDir, exportDir }); await patchBundleImportPath({ workingDir, exportDir }); await patchAssetPath({ workingDir, exportDir }); await uploadWeb({ workingDir, exportDir }); } /** * Export the Snack Runtime to deploy to S3. * * @param {object} options * @param {string} options.workingDir * @param {string} options.exportDir */ async function exportWeb(options) { await spawnAsync( 'yarn', ['expo', 'export', '--platform=web', `--output-dir=${options.exportDir}`], { cwd: options.workingDir, stdio: process.env.CI ? 'inherit' : 'ignore', env: { ...process.env, SNACK_EXPORT_WEB: 'true', }, }, ); console.log( `✅ Exported the Snack Runtime to: ${path.join(options.workingDir, options.exportDir)}`, ); } /** * Fix the bundle path import in the `dist/index.html` export. * This is required because the Snack Runtime is hosted in S3 under subfolders. * We need to convert `