#!/usr/bin/env pwsh # https://docs.sheetjs.com/docs/demos/frontend/bundler/vitejs $oldDir = Get-Location $tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-vite-tests" if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force } New-Item -ItemType Directory -Path $tempDir | Out-Null Set-Location -Path $tempDir for ($n = 3; $n -le 7; $n++) { Write-Host "Processing Vite version $n" $projectDir = Join-Path -Path $tempDir -ChildPath "sheetjs-vite$n" npm create -y "vite@$n" sheetjs-vite$n -- --template vue-ts --no-rolldown --no-interactive Set-Location -Path $projectDir npm i npm i --save puppeteer express@4 npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz npm ls | Select-String "vite" ## See https://github.com/vuejs/language-tools/issues/4484#issuecomment-2182469459 if ($n -eq 4) { npm i "vue-tsc@2" } New-Item -ItemType Directory -Path "data" -Force | Out-Null Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.xlsx" -OutFile "data\pres.xlsx" @' '@ | Out-File -FilePath "src\components\HelloWorld.vue" -Encoding utf8 npx vite build @' const puppeteer = require('puppeteer'); const express = require('express'); const app = express(); app.use(express.static('./dist/')); app.listen(7262, async() => { await new Promise((res,rej) => setTimeout(res, 1000)); const browser = await puppeteer.launch(); const page = await browser.newPage(); page.on("console", msg => console.log("PAGE LOG:", msg.text())); await page.setViewport({width: 1920, height: 1080}); const client = await page.target().createCDPSession(); await client.send('Browser.setDownloadBehavior', { behavior: 'allow', downloadPath: require("path").resolve('./') }); page.on('request', req => console.log(req.url())); await page.goto('http://localhost:7262/'); await page.click("button"); await new Promise((res,rej) => setTimeout(res, 2000)); await browser.close(); process.exit(); }); '@ | Out-File -FilePath "test.cjs" -Encoding utf8 node test.cjs npx -y xlsx-cli Presidents.xlsx | Select-Object -First 3 Remove-Item -Path "Presidents.xlsx" -Force Set-Location -Path $tempDir } Set-Location $oldDir Remove-Item -Path $tempDir -Recurse -Force