Created
January 15, 2015 22:41
-
-
Save yocontra/de3c0ea120437d8207ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const os = require('os'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const execFile = require('child_process').execFile; | |
const tmpfile = path.join(os.tmpdir(), process.versions.v8+'.flags.json'); | |
const exclusions = ['--help']; | |
module.exports = function (cb) { | |
fs.exists(tmpfile, function (exists) { | |
if (exists) { | |
cb(null, require(tmpfile)); | |
} else { | |
execFile(process.execPath, ['--v8-options'], function (execErr, result) { | |
var flags; | |
if (execErr) { | |
return cb(execErr); | |
} | |
flags = result.match(/\s\s--(\w+)/gm).map(function (match) { | |
return match.substring(2); | |
}).filter(function (name) { | |
return exclusions.indexOf(name) === -1; | |
}); | |
fs.writeFile(tmpfile, JSON.stringify(flags), { encoding:'utf8' }, | |
function (writeErr) { | |
if (writeErr) { | |
return cb(writeErr); | |
} | |
cb(null, flags); | |
} | |
); | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment