Example #1
0
var main = function () {
  // Parse CLI Args
  parser.command('install')
    .callback(installDependencies)
    .option('forceRefresh', {
      abbr: 'r',
      flag: true,
      default: false,
      help: 'force installing dependencies from package manager without cache'
    })
    .help('install specified dependencies');

  parser.command('clean')
    .callback(cleanCache)
    .help('clear cache directory');

  parser.command('hash')
    .callback(reportHash)
    .help('reports the current working hash');

  parser.option('cacheDirectory', {
    default: process.env.NPM_CACHE_DIR || path.resolve(process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE, '.package_cache'),
    abbr: 'c',
    help: 'directory where dependencies will be cached'
  });

  parser.option('version', {
    abbr: 'v',
    help: 'displays version info and exit',
    flag: true,
    callback: function () {
      var packagePath = path.resolve(__dirname, 'package.json');
      var packageFile = fs.readFileSync(packagePath);
      var packageParsed = JSON.parse(packageFile);
      console.log(packageParsed.version);
      process.exit(0);
    }
  });


  var examples = [
    'Examples:',
    '\tnpm-cache install\t# try to install npm, bower, and composer components',
    '\tnpm-cache install bower\t# install only bower components',
    '\tnpm-cache install bower npm\t# install bower and npm components',
    '\tnpm-cache install bower --allow-root composer --dry-run\t# install bower with allow-root, and composer with --dry-run',
    '\tnpm-cache install --cacheDirectory /home/cache/ bower \t# install components using /home/cache as cache directory',
    '\tnpm-cache install --forceRefresh  bower\t# force installing dependencies from package manager without cache',
    '\tnpm-cache clean\t# cleans out all cached files in cache directory',
    '\tnpm-cache hash\t# reports the current working hash'
  ];
  parser.help(examples.join('\n'));

  var npmCacheArgs = ParseUtils.getNpmCacheArgs();
  parser.parse(npmCacheArgs);
};
Example #2
0
var permissionsBits = parseInt('777', 8);

var checkPermissionSynch = function(mode, mask) {
	return ((mode & permissionsBits) & mask) === mask;
};

var validatePathOption = function(optionName, path) {
	if (!fs.existsSync(path)) {
		return '--' + optionName + ': \'' + path + '\' can\'t be found';
	}
};

var cli = nomnom.help(
	'sitespeed.io is a tool that helps you analyze your website performance and show you what you should optimize, more info at http://www.sitespeed.io.' +
	EOL +
	'To collect timings in Chrome you need to install the ChromeDriver. Firefox works out of the box. Example:' + EOL +
	'$ sitespeed.io -u http://www.sitespeed.io -b chrome,firefox'
).options({
	url: {
		abbr: 'u',
		metavar: '<URL>',
		help: 'The start url that will be used when crawling.',
		callback: function(url) {
			if (!validUrl.isWebUri(url)) {
				return '--url: \'' + url + '\' is not a valid url (you need to include protocol)';
			}
		}
	},
	file: {
		abbr: 'f',
		metavar: '<FILE>',