in gulpfile.js [910:992]
var cacheNpmPackage = function (name, version) {
// Validate the parameters.
if (!name) {
throw new Error('Parameter "name" cannot be null or empty.');
}
if (!version) {
throw new Error('Parameter "version" cannot be null or empty.');
}
// Short-circuit if already downloaded.
gutil.log('Downloading npm package ' + name + '@' + version);
var targetPath = path.join(_tempPath, 'npm', name, version);
if (shell.test('-d', targetPath)) {
console.log('Package already cached. Skipping.');
return;
}
// Delete any previous partial attempt.
var partialPath = path.join(_tempPath, 'partial', 'npm', name, version);
if (shell.test('-d', partialPath)) {
shell.rm('-rf', partialPath);
}
// Write a temporary package.json file to npm install warnings.
//
// Note, write the file higher up in the directory hierarchy so it is not included
// when the partial directory is moved into the target location
shell.mkdir('-p', partialPath);
var pkg = {
"name": "temp",
"version": "1.0.0",
"description": "temp to avoid warnings",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"repository": "http://norepo/but/nowarning",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
};
fs.writeFileSync(
path.join(_tempPath, 'partial', 'npm', 'package.json'),
JSON.stringify(pkg, null, 2));
// Validate npm is in the PATH.
var npmPath = shell.which('npm');
if (!npmPath) {
throw new Error('npm not found. ensure npm 3 or greater is installed');
}
// Validate the version of npm.
var versionOutput = cp.execSync('"' + npmPath + '" --version');
var npmVersion = versionOutput.toString().replace(/[\n\r]+/g, '')
console.log('npm version: "' + npmVersion + '"');
if (semver.lt(npmVersion, NPM_MIN_VER)) {
throw new Error('npm version must be at least ' + NPM_MIN_VER + '. Found ' + npmVersion);
}
// Make a node_modules directory. Otherwise the modules will be installed in a node_modules
// directory further up the directory hierarchy.
shell.mkdir('-p', path.join(partialPath, 'node_modules'));
// Run npm install.
shell.pushd(partialPath);
try {
var cmdline = '"' + npmPath + '" install ' + name + '@' + version;
var result = cp.execSync(cmdline);
gutil.log(result.toString());
if (result.status > 0) {
throw new Error('npm failed with exit code ' + result.status);
}
}
finally {
shell.popd();
}
// Move the intermediate directory to the target location.
shell.mkdir('-p', path.dirname(targetPath));
shell.mv(partialPath, targetPath);
}