scrat-command-install
Advanced tools
Comparing version 0.0.1 to 0.0.2
61
index.js
@@ -10,7 +10,23 @@ /** | ||
exports.usage = '[name] [options]'; | ||
exports.desc = 'init project'; | ||
exports.desc = 'install component modules'; | ||
exports.register = function(commander){ | ||
commander | ||
.option('--save') | ||
.option('-s, --save', 'save dependencies into json file', Boolean) | ||
.action(function(){ | ||
var path = require('path'); | ||
var resolve = path.resolve; | ||
var dirname = function(){ | ||
return resolve(this.dest, this.name.toLowerCase().split('/').join('-'), this.version); | ||
}; | ||
var args = Array.prototype.slice.call(arguments); | ||
var options = args.pop(); | ||
var name = args.shift(); | ||
if(name){ | ||
var pos = name.indexOf('@'); | ||
var version = '*'; | ||
if(pos > -1){ | ||
version = name.substring(pos + 1); | ||
name = name.substring(0, pos); | ||
} | ||
} | ||
var Installer = require('component-installer'); | ||
@@ -21,15 +37,40 @@ var installer = new Installer(process.cwd()); | ||
installer.remote('https://raw.github.com'); | ||
if(options.save || !name){ | ||
var conf = installer.path('component.json'); | ||
if(!fis.util.isFile(conf)){ | ||
fis.log.error('missing component.json'); | ||
} | ||
} | ||
if(name && options.save){ | ||
var json = installer.json(); | ||
json.dependencies = json.dependencies || {}; | ||
var write = function(){ | ||
json.dependencies[this.name] = this.version === 'master' ? '*' : this.version; | ||
fis.util.write(conf, JSON.stringify(json, null, 4)); | ||
}; | ||
} | ||
installer.on('package', function (pkg) { | ||
console.log(' ➜ installing', pkg.name, pkg.version); | ||
pkg.constructor.prototype.dirname = dirname; | ||
if(name && options.save){ | ||
pkg.on('end', write); | ||
pkg.on('exists', write); | ||
} | ||
pkg.on('error', onerror); | ||
console.log(' ➜ ' + 'installing '.grey + pkg.name + '@'.yellow + pkg.version); | ||
}); | ||
installer.install(function (err) { | ||
console.log(this.config); | ||
if(err){ | ||
console.error(err); | ||
var onerror = function(err){ | ||
if(err.message === 'dns lookup failed'){ | ||
console.log(' ✗ ' + err.message.yellow); | ||
} else { | ||
//TODO move | ||
console.log(' √ all done'); | ||
console.log(' ✗ ' + err.message.red); | ||
} | ||
}); | ||
}; | ||
if(name){ | ||
installer.installPackage(name, version); | ||
} else { | ||
installer.install(function(err){ | ||
}); | ||
} | ||
}); | ||
}; |
{ | ||
"name" : "scrat-command-install", | ||
"description" : "install component modules", | ||
"version" : "0.0.1", | ||
"version" : "0.0.2", | ||
"author" : "fouber <fouber.NET@gmail.com>", | ||
@@ -6,0 +6,0 @@ "engines" : { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3312
69