69 lines
2.2 KiB
PowerShell
69 lines
2.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
# https://docs.sheetjs.com/docs/demos/frontend/bundler/systemjs
|
|
|
|
$oldDir = Get-Location
|
|
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-systemjs"
|
|
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
|
|
|
|
## NodeJS Demo
|
|
|
|
npm i --save https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz
|
|
|
|
Invoke-WebRequest -Uri "https://docs.sheetjs.com/systemjs/SheetJSystem.js" -OutFile "SheetJSystem.js"
|
|
|
|
$versions = @("6.x", "0.21.6", "0.20.19", "0.19.47")
|
|
foreach ($v in $versions) {
|
|
Write-Host "SystemJS NodeJS version $v"
|
|
|
|
npm i --save "systemjs@$v"
|
|
node SheetJSystem.js
|
|
npx -y xlsx-cli Presidents.xlsx | Select-Object -First 3
|
|
Remove-Item -Path "Presidents.xlsx" -Force
|
|
}
|
|
|
|
## Browser Demo
|
|
|
|
Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.xlsx" -OutFile "pres.xlsx"
|
|
|
|
npm i --save puppeteer
|
|
|
|
@'
|
|
const path = require('path');
|
|
const puppeteer = require('puppeteer');
|
|
(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('./')
|
|
});
|
|
await page.goto('https://docs.sheetjs.com/systemjs/systemjs');
|
|
await new Promise((res,rej) => setTimeout(res, 3000)); // required in windows tests
|
|
const xlf = await page.$('#xlf');
|
|
await xlf.uploadFile(path.resolve('./pres.xlsx'));
|
|
await page.evaluate(() => {
|
|
const xlf = document.querySelector('#xlf');
|
|
const evt = new Event('change', { bubbles: true });
|
|
xlf.dispatchEvent(evt);
|
|
});
|
|
await new Promise((res,rej) => setTimeout(res, 1000));
|
|
const text = await page.$eval('#out', el => el.innerText);
|
|
console.log(text);
|
|
await browser.close();
|
|
process.exit();
|
|
})();
|
|
'@ | Out-File -FilePath "test.js" -Encoding utf8
|
|
|
|
Write-Host "SystemJS Browser Demo"
|
|
node test.js
|
|
|
|
Set-Location $oldDir
|
|
Remove-Item -Path $tempDir -Recurse -Force |