aboutsummaryrefslogtreecommitdiffstats
path: root/build/release/ensure-sizzle.js
blob: eb1cbd8e80d1624ecbff2aa8828df1814e94e273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";

var fs = require( "fs" ),
	npm = require( "npm" ),
	chalk = require( "chalk" ),
	sizzleLoc = __dirname + "/../../external/sizzle/dist/sizzle.js",
	rversion = /Engine v(\d+\.\d+\.\d+(?:-[-\.\d\w]+)?)/;

/**
 * Retrieve the latest tag of Sizzle from npm
 * @param {Function(string)} callback
 */
function getLatestSizzle( callback ) {
	npm.load( function( err, npm ) {
		if ( err ) {
			throw err;
		}
		npm.commands.info( [ "sizzle", "version" ], function( err, info ) {
			if ( err ) {
				throw err;
			}
			callback( Object.keys( info )[ 0 ] );
		} );
	} );
}

/**
 * Ensure the /src folder has the latest tag of Sizzle
 * @param {Object} Release
 * @param {Function} callback
 */
function ensureSizzle( Release, callback ) {
	console.log();
	console.log( "Checking Sizzle version..." );
	getLatestSizzle( function( latest ) {
		var match = rversion.exec( fs.readFileSync( sizzleLoc, "utf8" ) ),
			version = match ? match[ 1 ] : "Not Found";

		if ( version !== latest ) {

			// colors is inherited from jquery-release
			console.log(
				"The Sizzle version in the src folder (" + chalk.red( version ) +
				") is not the latest tag (" + chalk.green( latest ) + ")."
			);
			Release.confirm( callback );
		} else {
			console.log( "Sizzle is latest (" + chalk.green( latest ) + ")" );
			callback();
		}
	} );
}

module.exports = ensureSizzle;