docs.sheetjs.com/tests/bundler-esbuild.sh

56 lines
1.7 KiB
Bash
Raw Normal View History

2024-06-08 01:37:27 +00:00
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/frontend/bundler/esbuild
cd /tmp
rm -rf sheetjs-esbrowser
mkdir sheetjs-esbrowser
cd sheetjs-esbrowser
npm init -y
2024-07-18 22:19:02 +00:00
npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
2024-06-08 01:37:27 +00:00
curl -LO https://docs.sheetjs.com/esbuild/esbrowser.js
curl -LO https://docs.sheetjs.com/esbuild/esbnode.js
cat >index.html <<EOF
<body><script src="esb.browser.js"></script></body>
EOF
cat >test.js <<EOF
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));
await browser.close();
process.exit();
});
EOF
for n in 0.9.7 0.10.2 0.11.23 0.12.29 0.13.15 0.14.54 0.15.18 0.16.17 0.17.19 0.18.20 0.19.12 0.20.2 0.21.4; do
npx -y esbuild@$n --version
## Browser Test
npx -y esbuild@$n esbrowser.js --bundle --outfile=esb.browser.js
node test.js
npx -y xlsx-cli Presidents.xlsx | head -n 3
rm -f esb.browser.js Presidents.xlsx
npx -y esbuild@$n esbnode.js --bundle --platform=node --outfile=esb.node.js
node esb.node.js
npx -y xlsx-cli Presidents.xlsx | head -n 3
rm -f esb.node.js Presidents.xlsx
done