Skip to content

Instantly share code, notes, and snippets.

@stoikerty
Created August 28, 2017 14:23
Show Gist options
  • Save stoikerty/d581017d6ae5e279a45cad97c829101e to your computer and use it in GitHub Desktop.
Save stoikerty/d581017d6ae5e279a45cad97c829101e to your computer and use it in GitHub Desktop.
Modern javascript at all times
const path = require('path');
// Teach Node how to use babel compilation, using closest babelrc config
require('babel-register');
// Run specified file from second argument when first argument `--run` or `-r` is given
const options = process.argv.slice(2);
const runCommandGiven = (options[0] === '--run' || options[0] === '-r');
const fileToRun = runCommandGiven && path.resolve(process.cwd(), options[1]);
if (fileToRun) {
require(fileToRun);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment