Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fb package and an option to bench local file #335

Merged
merged 4 commits into from Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 21 additions & 8 deletions scripts/benchmark.js
Expand Up @@ -20,15 +20,22 @@ let packagename, filename;
const script = new Command("benchmark.js")
.option("-o, --offline", "Only install package if not present; package not removed after testing")
.option("-r, --runs <n>", "Number of times to run tests")
.option("-l, --local", "Use local file instead of a package")
.usage("[options] <package> [file]")
.arguments("<package> [file]")
.action(function(pname, fname) {
packagename = pname;
filename = fname;
.action(function(pname, fname, command) {
if (command.local) {
packagename = "";
filename = pname;
}
else {
packagename = pname;
filename = fname;
}
})
.parse(process.argv);

if (!packagename) {
if (!packagename && !script.local) {
console.error("Error: No package specified");
process.exit(1);
}
Expand Down Expand Up @@ -91,8 +98,14 @@ function uninstallPackage() {
}

function checkFile() {
// If filename has not been passed as an argument, attempt to resolve file from package.json
filename = filename ? path.join(pathToScripts, "node_modules", filename) : require.resolve(packagename.split("@")[0]);

if (!script.local) {
// If filename has not been passed as an argument, attempt to resolve file from package.json
filename = filename
? path.join(pathToScripts, "node_modules", filename)
: require.resolve(packagename.split("@")[0]);
}

console.log("file: " + path.basename(filename));

if (!filename || !pathExists(filename)) {
Expand Down Expand Up @@ -224,14 +237,14 @@ function pathExists(path) {

const packagePath = path.join(pathToScripts, "node_modules", packagename);

if (!pathExists(packagePath) || !script.offline) {
if ((!pathExists(packagePath) || !script.offline) && !script.local) {
installPackage();
}

checkFile();
testFile();
processResults();

if (!script.offline) {
if (!script.offline && !script.local) {
uninstallPackage();
}
11 changes: 11 additions & 0 deletions scripts/benchmark_assets/LICENSE-examples
@@ -0,0 +1,11 @@
Copyright (c) 2008-present, Facebook, Inc. All rights reserved.

The examples provided by Facebook are for non-commercial testing and evaluation
purposes only. Facebook reserves all rights not expressly granted.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.