docs.sheetjs.com/tests/static/esbuild.ps1

84 lines
2.7 KiB
PowerShell
Raw Normal View History

2026-01-29 04:58:19 +00:00
#!/usr/bin/env pwsh
# https://docs.sheetjs.com/docs/demos/static/esbuild
$oldDir = Get-Location
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-esb"
if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force }
New-Item -ItemType Directory -Path $tempDir | Out-Null
Set-Location -Path $tempDir
npm init -y
npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
npm i --save puppeteer express
@'
<!DOCTYPE html>
<html>
<head>
<title>SheetJS + ESBuild</title>
</head>
<body>
<script src="out.js"></script>
</body>
</html>
'@ | Out-File -FilePath "index.html" -Encoding utf8
@'
import data from './pres.numbers'
const elt = document.createElement('div');
elt.innerHTML = "<table><tr><th>Name</th><th>Index</th></tr>" +
data.map((row) => `<tr>
<td>${row.Name}</td>
<td>${row.Index}</td>
</tr>`).join("") +
"</table>";
document.body.appendChild(elt);
'@ | Out-File -FilePath "app.js" -Encoding utf8
Invoke-WebRequest -Uri "https://docs.sheetjs.com/esbuild/build.mjs" -OutFile "build.mjs"
Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.numbers" -OutFile "pres.numbers"
@'
const puppeteer = require('puppeteer');
const express = require('express');
const app = express();
app.use(express.static('./'));
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 new Promise((res,rej) => setTimeout(res, 1000));
const innerText = await page.evaluate(() => document.body.innerText);
console.log(innerText);
await browser.close();
process.exit();
});
'@ | Out-File -FilePath "test.js" -Encoding utf8
$versions = @("0.9.1", "0.9", "0.10", "0.11", "0.12", "0.13", "0.14", "0.15", "0.16", "0.17", "0.18", "0.19", "0.20", "0.21", "0.22", "0.23", "0.24", "0.25", "0.26", "0.27")
foreach ($n in $versions) {
npm rm --save esbuild
npm i --save esbuild@$n
npm ls | Select-String "esbuild"
if (Test-Path -Path "out.js") { Remove-Item -Path "out.js" -Force }
node build.mjs
$clintonCount = (Select-String -Path "out.js" -Pattern "Clinton" | Measure-Object).Count
$besseljCount = (Select-String -Path "out.js" -Pattern "BESSELJ" | Measure-Object).Count
Write-Host "Clinton $clintonCount BESSELJ $besseljCount"
node test.js
}
Set-Location $oldDir
Remove-Item -Path $tempDir -Recurse -Force