65 lines
2.4 KiB
PowerShell
65 lines
2.4 KiB
PowerShell
|
|
#!/usr/bin/env pwsh
|
||
|
|
# https://docs.sheetjs.com/docs/demos/frontend/bundler/esbuild
|
||
|
|
|
||
|
|
$oldDir = Get-Location
|
||
|
|
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-esbrowser"
|
||
|
|
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
|
||
|
|
Invoke-WebRequest -Uri "https://docs.sheetjs.com/esbuild/esbrowser.js" -OutFile "esbrowser.js"
|
||
|
|
Invoke-WebRequest -Uri "https://docs.sheetjs.com/esbuild/esbnode.js" -OutFile "esbnode.js"
|
||
|
|
|
||
|
|
@'
|
||
|
|
<body><script src="esb.browser.js"></script></body>
|
||
|
|
'@ | Out-File -FilePath "index.html" -Encoding utf8
|
||
|
|
|
||
|
|
@'
|
||
|
|
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();
|
||
|
|
});
|
||
|
|
'@ | Out-File -FilePath "test.js" -Encoding utf8
|
||
|
|
|
||
|
|
for ($i = 9; $i -le 27; $i++) {
|
||
|
|
$n = "0.$i"
|
||
|
|
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 | Select-Object -First 3
|
||
|
|
if (Test-Path -Path "esb.browser.js") { Remove-Item -Path "esb.browser.js" -Force }
|
||
|
|
if (Test-Path -Path "Presidents.xlsx") { Remove-Item -Path "Presidents.xlsx" -Force }
|
||
|
|
|
||
|
|
## Node test
|
||
|
|
npx -y esbuild@$n esbnode.js --bundle --platform=node --outfile=esb.node.js
|
||
|
|
node esb.node.js
|
||
|
|
npx -y xlsx-cli Presidents.xlsx | Select-Object -First 3
|
||
|
|
if (Test-Path -Path "esb.node.js") { Remove-Item -Path "esb.node.js" -Force }
|
||
|
|
if (Test-Path -Path "Presidents.xlsx") { Remove-Item -Path "Presidents.xlsx" -Force }
|
||
|
|
}
|
||
|
|
|
||
|
|
Set-Location $oldDir
|
||
|
|
Remove-Item -Path $tempDir -Recurse -Force
|