How to use the npm.load function in npm

To help you get started, we’ve selected a few npm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unicode-org / full-icu-npm / install-npm.js View on Github external
module.exports = function npmInstallNpm(fullIcu, advice) {
	var icupkg = fullIcu.icupkg;
	var icudat = fullIcu.icudat;
	// var nodever = fullIcu.nodever;
	// var icuver = fullIcu.icuver;
	
	var npm = require('npm');


	
	
	npm.load({}, function(err) {
		if(err) throw err;
		npm.commands.install([ icupkg ], function(err, data) {
			if(err) {
				console.log('Your ICU version may not be available in NPM yet..');
				throw err;
			}
			
	//		console.log("Installed " + data.length + " thing(s).");
			data.forEach(function(i) {
				var datPath = path.join(i[1],icudat);
				if(fs.existsSync(icudat)) {
					console.log(' √ ' + i[0] + ' : ' + icudat + " (existing symlink?)");
				} else if(!fs.existsSync(datPath)) {
					console.log(' • ' + i[0] + ' (no ' + icudat + ')');
				} else {
					try {
github hoodiehq / hoodie / lib / hoodie-log.js View on Github external
module.exports = function HoodieLog(name, couch_url) {
  var password;
  npm.load(function(error, npm) {
    password = npm.config.get(name + "_admin_pass");
  });

  return function hoodie_log() {
    // log as usual
    console.log.apply(this, arguments);

    // make a nice object!
    var log = {
      message: util.format.apply(this, arguments),
      time: new Date()
    };

    // send to couch
    request({
      url: couch_url + "/logs",
github Foveluy / ReStory / bin / project.js View on Github external
simpleServer() {
    // const str = [
    //   'npm init -y &&',
    //   'npm install --save babel-register babel-preset-env babel-preset-react-app &&',
    //   'npm install --save express react react-helmet --color'
    // ].join(' ')
    // const c = child_process.exec(str, { encoding: 'utf-8' }, (err, stdout) => {})
    // c.stdout.pipe(process.stdout)
    npm.load(() => {
      npm.commands.install(['--save babel-register babel-preset-env babel-preset-react-app'])
      // npm.commands.install('--save express react react-helmet')
    })
  }
github spmjs / spm / lib / core / plugin_config.js View on Github external
function downloadNpmPlugin(model, key, pid, config, cb) {
  var pid = pid.slice(4);

  npm.load({}, function (er) {

    npm.view(pid, function(err, obj) {
      if (err) {
        console.warn('npm 插件 ' + pid + ' 加载失败');
      } 

      var pkg = obj[_.keys(obj)[0]];

      var dir = npm.prefix = path.join(model.globalHome, 'sources', 'npm', pkg.name, pkg.version);
      async.waterfall([function(callback) {
        if (!fsExt.existsSync(dir)) {
          npm.commands.install([pid], function(err, data) {
            if (err) {
              throw new Error('插件 ' + pid + ' 依赖模块下载失败');
            }
github nodejitsu / haibu / lib / haibu / common / npm.js View on Github external
exports.load = function (callback) {
  haibu.emit('npm:load', 'info', haibu.common.clone(npmConfig));
  npm.load(npmConfig, function (err) {
    if (err) {
      haibu.emit('npm:load', 'error', { error: err.message });
      return callback(err);
    }

    haibu.emit('npm:load:success', 'silly');
    callback();
  });
};
github linnovate / mean-cli / lib / cli.js View on Github external
function packagesNpmInstall(source) {
  var packages = path.join(process.cwd(), source);
  npm.load({
    loglevel: 'error'
  }, function(err, npm) {
    fs.readdir(packages, function(err, files) {
      if (err && 'ENOENT' !== err.code) throw Error(err);

      if (!files || !files.length) return;
      console.log(chalk.green('Auto installing package dependencies'));

      files.forEach(function(file) {
        var pkgPath = path.join(packages, file);

        packagesMeanJson(pkgPath);

        utils.loadPackageJson(path.join(pkgPath, 'package.json'), function(err, data) {
          if (err || !data.mean) return;
github hoodiehq-archive / hoodie-cli / lib / hoodie / uninstall.js View on Github external
CreateCommand.prototype.execute = function(options, callback) {

  var self = this;
  var pluginsArr = options.plugins.split(',');

  self.hoodie.emit('info', 'Removing plugin(s): ' + pluginsArr);

  npm.load(options.npmArgs, function(err, npm) {
    if (err) {
      self.hoodie.emit('warn', 'Error loading npm:');
      self.hoodie.emit('warn', err.message);
      throw err;
    }
    npm.config.set('save', true);

    async.map(pluginsArr, function (plugin, cb) {

      var fullName = 'hoodie-plugin-' + plugin;

      npm.remove(fullName, function(err) {
        if (err) {
          self.hoodie.emit('warn', 'Error uninstalling plugin: ' + plugin);
          self.hoodie.emit('warn', err.message);
          callback(err);
github repetere / periodicjs / __LEGACY / app / lib / extensionhelper.js View on Github external
get_latest_version_numbers: function (asyncCB) {
			npm.silent = true;
			npm.load(
				npmconfig,
				function (err) {
					if (err) {
						asyncCB(err);
					}
					else {
						npm.silent = true;
						async.each(list_of_extensions,
							function (item, mapCB) {
								npm.commands.view(
									[item, 'name', 'version'],
									function (err, data) {
										if (err) {
											mapCB(err);
										}
										else {
github bem-archive / bem-tools / lib / install.js View on Github external
function runNpmCommand(npmCommand, pluginName, cb) {
    npm.load({ cwd: tilde }, function (err) {
        if (err) return cb(err);

        var basename = path.basename(pluginName),
            moduleName = pluginName;

        if (moduleName.indexOf(pluginPrefix) < 0) {
            moduleName = pluginName.replace(new RegExp(basename + '$'), pluginPrefix + basename);
        }

        npm.commands[npmCommand]([moduleName], function(err, data) {
            if (err) return cb(err);

            cb(null, data);
        });
    });
};
github arei / npmbox / npmboxxer.js View on Github external
var npmInit = function(options,callback) {
		npm.load(options,callback);
	};