UNPKG

reveal-sdk-node

Version:

RevealBI Node.js SDK

58 lines (57 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.download = void 0; const browsers_1 = require("@puppeteer/browsers"); const fs = require("fs"); const os = require("os"); async function download() { const buildId = '132.0.6834.110'; var chromiumPath; var chromiumDir = "."; var nextControlPoint = 0; var currentPercent = 0; const percentJump = 5; const options = { cacheDir: chromiumDir, browser: browsers_1.Browser.CHROMEHEADLESSSHELL, buildId: buildId, downloadProgressCallback: (x, y) => { if (x < nextControlPoint) return; if (nextControlPoint == 0) { console.log("Chromium is not available. Will download -this takes some time but it is done just once-"); console.log(`Downloading chromium to ${chromiumDir}`); } console.log(`${currentPercent}% complete...`); if (currentPercent == 100) { console.log("Chromium download finished. Wait a bit more for the installation to finish."); } currentPercent += percentJump; nextControlPoint = currentPercent * y / 100; }, unpack: true, }; if (os.platform() !== 'darwin' && os.arch() === 'arm64') { // puppeteer relies on existing chromium packages for the target platform, and there's none for linux-arm64. // So a warn is emmited and we try to build the executablePath manually. console.warn("For ARM64 architecture it is recommended to download chromium using sudo apt install chromium and pointing it using advanced properties"); chromiumPath = '/usr/bin/chromium'; var stats = await fs.promises.stat(chromiumPath); if (stats === undefined) { chromiumPath = '/usr/bin/chromium-browser'; stats = await fs.promises.stat(chromiumPath); if (stats === undefined) { chromiumPath = null; } } return chromiumPath; } chromiumPath = null; const installedBrowser = await (0, browsers_1.install)(options); if (installedBrowser != null) { chromiumPath = installedBrowser.executablePath; console.log(`Chromium downloaded to ${chromiumPath}`); } return chromiumPath; } exports.download = download;