|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +// Windows does not need this |
| 4 | +if (process.platform === 'win32') { |
| 5 | + process.exit(0); |
| 6 | +} |
| 7 | + |
| 8 | +const fs = require('fs'); |
| 9 | +const path = require('path'); |
| 10 | + |
| 11 | +// Get the installed chromium path |
| 12 | +const Downloader = require('puppeteer/utils/ChromiumDownloader'); |
| 13 | +const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision; |
| 14 | +const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision); |
| 15 | +const chromiumPath = revisionInfo.folderPath; |
| 16 | + |
| 17 | +// Some sneaky little helpers to get the job done |
| 18 | +const walkSync = (d) => { |
| 19 | + return fs.statSync(d).isDirectory() |
| 20 | + ? fs.readdirSync(d).map(f => walkSync(path.join(d, f))) : d; |
| 21 | +} |
| 22 | +const flatten = (arr) => { |
| 23 | + return arr.reduce(function (flat, toFlatten) { |
| 24 | + return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); |
| 25 | + }, []); |
| 26 | +}; |
| 27 | + |
| 28 | + |
| 29 | +// Walk over each file, check its executable permission and enable |
| 30 | +// ugo+r/ugo+rx accordingly |
| 31 | +flatten(walkSync(chromiumPath)).forEach(function(path) { |
| 32 | + const stat = fs.statSync(path); |
| 33 | + |
| 34 | + if (!stat.isFile()) { |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + const isExecutable = stat.mode & 0100; |
| 39 | + |
| 40 | + if (isExecutable) { |
| 41 | + fs.chmodSync(path, 0755); |
| 42 | + } else { |
| 43 | + fs.chmodSync(path, 0644); |
| 44 | + } |
| 45 | +}); |
0 commit comments