コード例 #1
0
ファイル: gulpfile.js プロジェクト: boolie/headstart
gulp.task('psi', ['tunnel'], function (cb) {

	// Quit this task if no flag was set
	if(!isPSI) {
		cb(null);
		return;
	}

	// Quit this task if ngrok somehow didn't run correctly
	if(tunnelUrl === null) {
		console.log(chalk.red('✘  Running PSI cancelled because Ngrok didn\'t initiate correctly...'));
		cb(null);
		return;
	}

	verbose(chalk.grey('☞  Running task "psi"'));
	console.log(chalk.grey('☞  Running PageSpeed Insights...'));

	// Define PSI options
	var opts = {
		url: tunnelUrl,
		strategy: flags.strategy || "desktop",
		threshold: 80
	};

	// Set the key if one was passed in
	if (!!flags.key && _.isString(flags.key)) {
		console.log(chalk.yellow.inverse('Using a key is not yet supported as it just crashes the process. For now, continue using `--psi` without a key.'));
		// TODO: Fix key
		//opts.key = flags.key;
	}

	// Run PSI
	psi(opts, function (err, data) {

		// If there was an error, log it and exit
		if (err !== null) {
			console.log(chalk.red('✘  Threshold of ' + opts.threshold + ' not met with score of ' + data.score));
		} else {
			console.log(chalk.green('✔  Threshold of ' + opts.threshold + ' exceeded with score of ' + data.score));
		}

		cb(null);
	});

	// Since psi throw's the threshold error,
	// we have to listen for it process-wide (bad!) — ONCE
	process.once('uncaughtException', function (err) {
		console.log(chalk.red(err));
	});
});
コード例 #2
0
ファイル: headstart.js プロジェクト: boolie/headstart
function logHeader (pkg) {
	console.log(
		chalk.cyan(
			'\n' +
			'|                  |     |              |\n' +
			'|---.,---.,---.,---|,---.|--- ,---.,---.|---\n' +
			'|   ||---\',---||   |`---.|    ,---||    |\n' +
			'`   \'`---\'`---^`---\'`---\'`---\'`---^`    `---\'\n\n'
		) +
		chalk.cyan.inverse('➳  http://headstart.io') +
		'                 ' +
		chalk.yellow.inverse('v' + pkg.version) + '\n'
	);
}
コード例 #3
0
ファイル: gulpfile.js プロジェクト: boolie/headstart
gulp.task('init', function (cb) {

	// Get all files in working directory
	// Exclude . files (such as .DS_Store on OS X)
	var cwdFiles = _.remove(fs.readdirSync(cwd), function (file) {

		return file.substring(0,1) !== '.';
	});

	// If there are any files
	if (cwdFiles.length > 0) {

		// Make sure the user knows what is about to happen
		console.log(chalk.yellow.inverse('\nThe current directory is not empty!'));
		prompt({
			type: 'confirm',
			message: 'Initializing will empty the current directory. Continue?',
			name: 'override',
			default: false
		}, function (answer) {

			if (answer.override) {
				// Make really really sure that the user wants this
				prompt({
					type: 'confirm',
					message: 'Removed files are gone forever. Continue?',
					name: 'overridconfirm',
					default: false
				}, function (answer) {

					if (answer.overridconfirm) {
						// Clean up directory, then start downloading
						console.log(chalk.grey('Emptying current directory'));
						sequence('clean-tmp', 'clean-cwd', downloadBoilerplateFiles);
					}
					// User is unsure, quit process
					else process.exit(0);
				});
			}
			// User is unsure, quit process
			else process.exit(0);
		});
	}
	// No files, start downloading
	else downloadBoilerplateFiles();

	cb(null);
});