Comparing version 0.0.3-alpha1 to 0.0.4
375
bin/neco.js
#!/usr/bin/env node | ||
require.paths.shift('../deps'); | ||
var list = require('../cmd/list.js'), | ||
@@ -11,3 +13,3 @@ find = require('../cmd/find.js'), | ||
var parsePkgConfig = require('../lib/config.js').parsePkgConfig, | ||
var filterConfig = require('../lib/config.js').filterConfig, | ||
parseUserConfig = require('../lib/config.js').parseUserConfig, | ||
@@ -18,6 +20,9 @@ parseGlobalConfig = require('../lib/config.js').parseGlobalConfig, | ||
var envReady = require('../lib/inception.js').envReady, | ||
toolReady = require('../lib/inception.js').toolReady, | ||
rootReady = require('../lib/inception.js').rootReady, | ||
recordReady = require('../lib/inception.js').recordReady, | ||
activateReady = require('../lib/inception.js').activateReady; | ||
upgradeReady = require('../lib/inception.js').upgradeReady; | ||
var parseArgv = require('../lib/parser.js').parseArgv; | ||
var idUnique = require('../lib/validation.js').idUnique, | ||
@@ -34,204 +39,155 @@ idExsit = require('../lib/validation.js').idExsit, | ||
var argv = process.argv, id, target, cmd = argv[2]; | ||
var argv = parseArgv(); | ||
//var argv = process.argv, id, target, cmd = argv[2]; | ||
if (cmd === undefined) { | ||
error = 'Missing command'; | ||
// Set global varialbles namae space; | ||
process.neco = {}; | ||
// Try catch all errors | ||
process.on('uncaughException', function(err) { | ||
log.emit('error', err); | ||
}); | ||
if (argv.cmd === undefined) { | ||
message = 'Missing command'; | ||
suggestion = 'Available commands: howto, create, remove, list, find, activate, deactivate'; | ||
example = 'neco howto, neco create <id>, neco list'; | ||
log('error', error, suggestion, example); | ||
} else if (!cmdValid(cmd)) { | ||
error = 'Not a valid command'; | ||
log.emit('exit', message, suggestion, example); | ||
} else if (!cmdValid(argv.cmd)) { | ||
message = 'Not a valid command'; | ||
suggestion = 'Available commands: howto, create, remove, list, find, activate, deactivate'; | ||
example = 'neco hwoto, neco create <id>, neco list'; | ||
log('error', error, suggestion, example); | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
// Subcommand create | ||
if (cmd === 'create') { | ||
if (argv.length < 4) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specific at least one ID( and the version of node, if you will).'; | ||
example = 'neco create <id> [stable, latest, node-version]'; | ||
log('message', message, suggestion, example); | ||
} else { | ||
id = argv[3], target = argv[4] || 'stable'; // defaut target is stable | ||
parseGlobalConfig(function(config) { | ||
config.id = id, config.cmd = cmd, config.target = target; | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
envReady(config, function(config) { | ||
rootReady(config, function(config) { | ||
activateReady(config, function(config) { | ||
recordReady(config, function(exists, config) { | ||
if (!exists) { | ||
create.run(config); | ||
} else { | ||
if (!idValid(config)) { | ||
message = 'The given id '+id+' is one of the reserved words in neco.'; | ||
suggestion = 'Please choose another one.'; | ||
log('message', message, suggestion); | ||
} else if (!idUnique(config)) { | ||
message = 'The given id '+id+' has already been used.'; | ||
suggestion = 'Please choose another one instead.'; | ||
log('message', message, suggestion); | ||
} else { | ||
create.run(config); | ||
} | ||
parseGlobalConfig(function() { parseUserConfig(function() { | ||
envReady(argv.cmd, function() { toolReady(function() { | ||
rootReady(function() { upgradeReady(function() { | ||
// Subcommand create | ||
if (argv.cmd === 'create') { | ||
if (!argv.id) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specific at least one ID( and the version of node, if you will).'; | ||
example = 'neco create <id> [stable, latest, node-version]'; | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
filterConfig(function() { | ||
recordReady(argv.cmd, function(exists) { | ||
if (!exists) { | ||
create.run(argv); | ||
} else { | ||
if (!idValid(argv.id)) { | ||
message = 'The given id '+argv.id+' is one of the reserved words in neco.'; | ||
suggestion = 'Please choose another one.'; | ||
log.emit('exit', message, suggestion); | ||
} else if (!idUnique(argv.id)) { | ||
message = 'The given id '+argv.id+' has already been used.'; | ||
suggestion = 'Please choose another one instead.'; | ||
log.emit('message', message, suggestion); | ||
} else { | ||
create.run(argv); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
// Subcommand list | ||
else if (cmd === 'list') { | ||
parseGlobalConfig(function(config) { | ||
config.cmd = cmd; | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
envReady(config, function(config) { | ||
rootReady(config, function(config) { | ||
activateReady(config, function(config) { | ||
recordReady(config, function(exists, config) { | ||
if (argv.length >= 4) { | ||
id = argv[3], config.id = target; | ||
if (ecosystemExist(config)) { | ||
list.run(config); | ||
// Subcommand list | ||
else if (argv.cmd === 'list') { | ||
filterConfig(function() { | ||
recordReady(argv.cmd, function(exists) { | ||
if (argv.id) { | ||
if (ecosystemExist(argv.id)) { | ||
list.run(argv); | ||
} else { | ||
error = 'The desired ecosystem '+id+' is not exists.'; | ||
message = 'The desired ecosystem '+argv.id+' is not exists.'; | ||
suggestion = 'Find out all the existing ecosystem.'; | ||
example = 'neco list'; | ||
log('error', error, suggestion, example); | ||
log.emit('exit', message, suggestion, example); | ||
} | ||
} else { | ||
list.run(config) | ||
list.run(argv) | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
// Subcommand find | ||
else if (cmd === 'find') { | ||
parseGlobalConfig(function(config) { | ||
config.cmd = cmd; | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
envReady(config, function(config) { | ||
rootReady(config, function(config) { | ||
activateReady(config, function(config) { | ||
recordReady(config, function(exists, config) { | ||
if (argv.length >= 4) { | ||
target = argv[3], config.target = target; | ||
if (releaseExist(config)) { | ||
find.run(config); | ||
} else { | ||
error = 'The desired release '+target+' is not available.'; | ||
suggestion = 'Find out all the available releases.'; | ||
example = 'neco find [stable, latest, node-version]'; | ||
log('error', error, suggestion, example); | ||
} | ||
// Subcommand find | ||
else if (argv.cmd === 'find') { | ||
filterConfig(function() { | ||
recordReady(argv.cmd, function(exists) { | ||
if (argv.target) { | ||
if (releaseExist(argv.target)) { | ||
find.run(argv); | ||
} else { | ||
find.run(config); | ||
message = 'The desired release '+argv.target+' is not available.'; | ||
suggestion = 'Find out all the available releases.'; | ||
example = 'neco find [stable, latest, node-version]'; | ||
log.emit('exit', message, suggestion, example); | ||
} | ||
}); | ||
} else { | ||
find.run(argv); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
// Subcommand help | ||
else if (cmd === 'howto') { | ||
parseGlobalConfig(function(config) { | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
howto.run(config); | ||
}); | ||
}); | ||
}); | ||
} | ||
// Subcommand howto | ||
else if (argv.cmd === 'howto') { | ||
filterConfig(function() { | ||
howto.run(argv); | ||
}); | ||
} | ||
// Subcommand activate | ||
else if (cmd === 'activate') { | ||
if (argv.length < 4) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specify the id of the ecosystem you want to activate.'; | ||
example = 'neco activate <id>'; | ||
log('message', message, suggestion, example); | ||
} else { | ||
id = process.argv[3]; | ||
parseGlobalConfig(function(config) { | ||
config.id = id, config.cmd = cmd; | ||
parseEcosystemConfig(config, function(config) { | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
envReady(config, function(config) { | ||
rootReady(config, function(config) { | ||
activateReady(config, function(config) { | ||
recordReady(config, function(exists, config) { | ||
if (ecosystemActive(config)) { | ||
warning = 'The node ecosystem with id '+id+' is already active.'; | ||
suggstion = 'Please use type deact in your shell to deactivate it.'; | ||
log('warning', warning, suggestion, example); | ||
} else if (!idExsit(config)) { | ||
warning = 'The node ecosystem with id '+id+' is not exists.'; | ||
suggestion = 'You can use neco list command to find out all existing ecosystem.'; | ||
example = 'neco create <id> [node-version]'; | ||
log('warning', warning, suggestion, example); | ||
} else { | ||
activate.run(config); | ||
} | ||
}); | ||
// Subcommand activate | ||
else if (argv.cmd === 'activate') { | ||
if (!argv.id) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specify the id of the ecosystem you want to activate.'; | ||
example = 'neco activate <id>'; | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
parseEcosystemConfig(argv.id, function() { | ||
filterConfig(function() { | ||
recordReady(argv.cmd, function(exists) { | ||
if (ecosystemActive(argv.id)) { | ||
message = 'The node ecosystem with id '+argv.id+' is already active.'; | ||
suggstion = 'Please use type deact in your shell to deactivate it.'; | ||
log.emit('exit', message, suggestion, example); | ||
} else if (!idExsit(argv.id)) { | ||
messge = 'The node ecosystem with id '+argv.id+' is not exists.'; | ||
suggestion = 'You can use neco list command to find out all existing ecosystem.'; | ||
example = 'neco create <id> [node-version]'; | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
activate.run(argv); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
// Subcommand deactvate | ||
else if (cmd === 'deactivate') { | ||
if (argv.length < 4) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specify the id of the ecosystem you want to deactivate.'; | ||
example = 'neco deactivate <id>'; | ||
log('message', message, suggestion, example); | ||
} else { | ||
id = process.argv[3]; | ||
parseGlobalConfig(function(config) { | ||
config.id = id, config.cmd = cmd; | ||
parseEcosystemConfig(config, function(config) { | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
envReady(config, function(config) { | ||
rootReady(config, function(config) { | ||
activateReady(config, function(config) { | ||
recordReady(config, function(exists, config) { | ||
if (!idExsit(config)) { | ||
error = 'The node ecosystem with id '+id+' is not exists.'; | ||
// Subcommand deactvate | ||
else if (argv.cmd === 'deactivate') { | ||
if (!argv.id) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specify the id of the ecosystem you want to deactivate.'; | ||
example = 'neco deactivate <id>'; | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
parseEcosystemConfig(argv.id, function() { | ||
filterConfig(function() { | ||
recordReady(argv.cmd, function(exists) { | ||
if (!idExsit(argv.id)) { | ||
message = 'The node ecosystem with id '+argv.id+' is not exists.'; | ||
suggestion = 'You can use neco list command to find out all existing ecosystem.'; | ||
example = 'neco list'; | ||
log('error', error, suggestion, example); | ||
} else if (!ecosystemActive(config)) { | ||
error = 'The node ecosystem with id '+id+' is not active.'; | ||
log.emit('exit', message, suggestion, example); | ||
} else if (!ecosystemActive(argv.id)) { | ||
message = 'The node ecosystem with id '+argv.id+' is not active.'; | ||
suggestion = 'Use neco activate command to activate it first.'; | ||
example = 'neco_activate '+ id; | ||
log('error', error, suggestion, example); | ||
example = 'neco_activate '+ argv.id; | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
deactivate.run(config); | ||
deactivate.run(argv); | ||
} | ||
@@ -241,52 +197,39 @@ }); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
// Subcommand remove | ||
else if (cmd === 'remove') { | ||
if (argv.length < 4) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specific the ID of the ecosystem that you want to remove.'; | ||
example = 'neco remove <id>'; | ||
log('message', message, suggestion, example); | ||
} else { | ||
id = argv[3]; | ||
parseGlobalConfig(function(config) { | ||
config.id = id, config.cmd = cmd; | ||
parseEcosystemConfig(config, function(config) { | ||
parsePkgConfig(config, function(config) { | ||
parseUserConfig(config, function(config) { | ||
envReady(config, function(config) { | ||
rootReady(config, function(config) { | ||
activateReady(config, function(config) { | ||
recordReady(config, function(exists, config) { | ||
if (!idExsit(config)) { | ||
message = 'The given id '+id+' is not exist.'; | ||
suggestion = 'Find out all existing ecosystem.'; | ||
example = 'neco list' | ||
log('message', message, suggestion, example); | ||
} else if (ecosystemActive(config)) { | ||
message = 'The given ecosystem with id '+id+' is in active.'; | ||
suggestion = 'Please deactivate it first.'; | ||
example = 'neco_deactivate' | ||
log('message', message, suggestion, example); | ||
} else { | ||
remove.run(config); | ||
} | ||
}); | ||
// Subcommand remove | ||
else if (argv.cmd === 'remove') { | ||
if (!argv.id) { | ||
message = 'Missing ID'; | ||
suggestion = 'Please specific the ID of the ecosystem that you want to remove.'; | ||
example = 'neco remove <id>'; | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
parseEcosystemConfig(argv.id, function() { | ||
filterConfig(function() { | ||
recordReady(argv.cmd, function(exists) { | ||
if (!idExsit(argv.id)) { | ||
message = 'The given id '+argv.id+' is not exist.'; | ||
suggestion = 'Find out all existing ecosystem.'; | ||
example = 'neco list' | ||
log.emit('exit', message, suggestion, example); | ||
} else if (ecosystemActive(argv.id)) { | ||
message = 'The given ecosystem with id '+argv.id+' is in active.'; | ||
suggestion = 'Please deactivate it first.'; | ||
example = 'neco_deactivate' | ||
log.emit('exit', message, suggestion, example); | ||
} else { | ||
remove.run(argv); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
});}); | ||
});}); | ||
});}); | ||
} |
var path = require('path'), | ||
color = require('ansi-color').set; | ||
exports.run = function(config) { | ||
var shell = color('source '+config.globalActivateFile, 'bold+yellow'); | ||
var deactivate = color('neco_deactivate', 'bold+yellow'); | ||
exports.run = function(argv) { | ||
var config = process.neco.config, id = argv.id, | ||
shell = color('source '+config.globalActivateFile, 'bold+yellow'); | ||
deactivate = color('neco_deactivate', 'bold+yellow'); | ||
console.log('add \''+shell+'\' to your .bashrc or .zshrc file, :)'); | ||
console.log('Then run '+color('neco_activate '+config.id, 'bold+yellow')+' in you shell.'); | ||
console.log('Then run '+color('neco_activate '+id, 'bold+yellow')+' in you shell.'); | ||
console.log('To deactivate it, run \''+deactivate+'\' in you shell.'); | ||
}; |
@@ -11,3 +11,3 @@ var fs = require('fs'), | ||
findlongestID = require('../lib/utils.js').findlongestID, | ||
writeGlobalConfigFile = require('../lib/assistant.js').writeGlobalConfigFile, | ||
writeLocalConfigFile = require('../lib/assistant.js').writeLocalConfigFile, | ||
writeEcosystemConfigFile = require('../lib/assistant.js').writeEcosystemConfigFile, | ||
@@ -22,23 +22,25 @@ getNodeInstallScript = require('../lib/assistant.js').getNodeInstallScript, | ||
function installNode(config, callback) { | ||
var error, version, link, install, | ||
destDir = config.destDir, script = getNodeInstallScript(config); | ||
function installNode(release, destDir, next) { | ||
var error, version, link, install, | ||
config = process.neco.config, | ||
root = config.root, | ||
script = getNodeInstallScript(); | ||
path.exists(config.root, function(exists) { | ||
path.exists(root, function(exists) { | ||
if (!exists) { | ||
fs.mkdirSync(config.root, mode=0777); | ||
fs.mkdirSync(root, mode=0777); | ||
} else { | ||
if (config.release.realver) { | ||
version = config.release.realver; | ||
if (release.realver) { | ||
version = release.realver; | ||
} else { | ||
version = config.release.version; | ||
version = release.version; | ||
} | ||
link = config.release.link; | ||
link = release.link; | ||
install = spawn('sh', [script, version, link, destDir]); | ||
install.stdout.on('data', function(data) { | ||
log('stdout',data); | ||
log.emit('stdout',data); | ||
}); | ||
install.stderr.on('data', function(data) { | ||
log('stdout',data); | ||
log.emit('stdout',data); | ||
}); | ||
@@ -49,5 +51,5 @@ | ||
error = new Error('Installing node exit wich code ' + code); | ||
callback(error, config); | ||
next(error); | ||
} else { | ||
callback(error, config); | ||
next(error); | ||
} | ||
@@ -59,12 +61,14 @@ }); | ||
function installNPM(config, callback) { | ||
var error, destDir = config.destDir, pkgDir = config.pkgDir, | ||
script = getNPMInstallScript(config), npmVer = config.npmVer; | ||
function installNPM(destDir, npmVer, next) { | ||
var error, | ||
config = process.neco.config, | ||
pkgDir = config.pkgDir, | ||
script = getNPMInstallScript(), | ||
install = spawn('sh', [script, pkgDir, destDir, npmVer]); | ||
install.stdout.on('data', function(data) { | ||
log('stdout', data); | ||
log.emit('stdout', data); | ||
}); | ||
install.stderr.on('data', function(data) { | ||
log('stdout', data); | ||
log.emit('stdout', data); | ||
}); | ||
@@ -74,5 +78,5 @@ install.on('exit', function(code) { | ||
error = new Error('Installing NPM exit with code ' + code); | ||
callback(error, config); | ||
next(error); | ||
} else { | ||
callback(error, config); | ||
next(error); | ||
} | ||
@@ -82,13 +86,26 @@ }); | ||
function installActivate(config, callback) { | ||
var error, id = config.id, version = config.release.version, | ||
pkgDir = config.pkgDir, destDir = config.destDir, | ||
script = getActivateInstallScript(config), | ||
function makeAppDirectory(id, next) { | ||
var config = process.neco.config, | ||
root = config.root, | ||
// appDir = path.join(root, '.neco', id, 'application'), | ||
appDir = path.join(root, id); | ||
fs.mkdir(appDir, mode=0777, function(err) { | ||
next(err); | ||
}); | ||
} | ||
function installActivate(id, release, destDir, next) { | ||
var error, | ||
config = process.neco.config, | ||
version = release.version, | ||
pkgDir = config.pkgDir, | ||
script = getActivateInstallScript(), | ||
install = spawn('sh', [script, id, pkgDir, destDir, version]); | ||
install.stdout.on('data', function(data) { | ||
log('stdout', data); | ||
log.emit('stdout', data); | ||
}); | ||
install.stderr.on('data', function(data) { | ||
log('stdout', data); | ||
log.emit('stdout', data); | ||
}); | ||
@@ -98,5 +115,5 @@ install.on('exit', function(code) { | ||
error = new Error('Installing Activate exit with code ' + code); | ||
callback(error, config); | ||
next(error); | ||
} else { | ||
callback(error, config); | ||
next(error); | ||
} | ||
@@ -106,8 +123,10 @@ }); | ||
function makeRecord(config) { | ||
var error, npmVer = config.npmVer || 'none', | ||
id = config.id, version = config.release.version, | ||
record, recordData, createdDate, ecosystems, newEcosystem, | ||
recordFile = path.join(config.root, '.neco', 'record.json'), | ||
date = getDateTime(config); | ||
function makeRecord(id, release, npmVer, next) { | ||
var error, | ||
config = process.neco.config, | ||
date = getDateTime(), | ||
version = release.version, | ||
root = config.root, | ||
recordFile = path.join(root, '.neco', 'record.json'), | ||
record, recordData, createdDate, ecosystems, newEcosystem; | ||
@@ -130,9 +149,3 @@ path.exists(recordFile, function(exists) { | ||
fs.writeFile(recordFile, recordData, 'utf8', function(err) { | ||
if (err) {throw err;} | ||
message = 'New node ecosystem has been created sucessfully!'; | ||
log('message', message); | ||
writeGlobalConfigFile(config, function(err, config) { | ||
if (err) {throw err;} | ||
writeEcosystemConfigFile(config); | ||
}); | ||
next(err); | ||
}); | ||
@@ -142,33 +155,92 @@ }); | ||
exports.run = function(config) { | ||
config.release = getRelease(config); | ||
if (!config.release) { | ||
error = 'The desired release '+config.target+' not found or neco can\'t handle it.'; | ||
function makeConfigFiles(argv, next) { | ||
process.neco.ecosystemConfig = {}; | ||
process.neco.ecosystemConfig.id = argv.id; | ||
process.neco.ecosystemConfig.app = argv.app; | ||
process.neco.ecosystemConfig.description = argv.d; | ||
writeLocalConfigFile(argv.id, function(err) { | ||
if (err) {log.emit('error', err);} | ||
writeEcosystemConfigFile(argv, next); | ||
}); | ||
} | ||
exports.run = function(argv) { | ||
var config = process.neco.config, | ||
id = argv.id, target = argv.target || 'stable', | ||
release = getRelease(target), npmVer = 'none', | ||
destDir = path.join(config.root, '.neco', id); | ||
if (!release) { | ||
message = 'The desired release '+target+' not found or neco can\'t handle it.'; | ||
suggestion = 'Try a newer version.'; | ||
example = 'neco create <id> stable OR neco create <id> latest'; | ||
log('error', error, suggestion, example); | ||
log.emit('message', message, suggestion, example); | ||
} else { | ||
// If the version of release smaller and equal to 0.1,9, | ||
// add 'v' prefix to version laterial | ||
if (notSmaller(config.release.version, vStartsFrom) >= 0) { | ||
config.release.realver = 'v'.concat(config.release.version); | ||
} | ||
config.destDir = path.join(config.root, '.neco', config.id); | ||
installNode(config, function(err, config) { | ||
if (err) {throw err;} | ||
if (config.installNPM && getSuitedNPM(config)) { | ||
config.npmVer = getSuitedNPM(config); | ||
installNPM(config, function(err, config) { | ||
if (err) {throw err;} | ||
installActivate(config, function(err, config) { | ||
if (err) {throw err;} | ||
makeRecord(config); | ||
}); | ||
release.realver = (notSmaller(release.version, vStartsFrom) >= 0) ? 'v'.concat(release.version) : null; | ||
installNode(release, destDir, function(err) { | ||
if (err) {log.emit('error',err);} | ||
message = 'Nodejs '+release.version+' has been installed sucessfully!'; | ||
log.emit('message', message); | ||
if ((config.installNPM || argv.npm) && getSuitedNPM(release)) { | ||
npmVer = getSuitedNPM(release); | ||
installNPM(destDir, npmVer, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'NPM '+npmVer+' has been installed sucessfully!'; | ||
log.emit('message', message); | ||
if (argv.app) { | ||
makeAppDirectory(id, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'The applicaton directory has been created sucessfully!'; | ||
log.emit('message', message); | ||
installActivate(id, release, destDir, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'New activate file has been installed sucessfully!'; | ||
log.emit('message', message); | ||
makeRecord(id, release, npmVer, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'Record file has been edited sucessfully!'; | ||
log.emit('message', message); | ||
makeConfigFiles(argv, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'New node ecosystem has been created sucessfully!'; | ||
log.emit('message', message); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
installActivate(id, release, destDir, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'New activate file has been installed sucessfully!'; | ||
log.emit('message', message); | ||
makeRecord(id, release, npmVer, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'Record file has been edited sucessfully!'; | ||
log.emit('message', message); | ||
makeConfigFiles(argv, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'New node ecosystem has been created sucessfully!'; | ||
log.emit('message', message); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
} else { | ||
installActivate(config, function(err, config) { | ||
if (err) {throw err;} | ||
makeRecord(config); | ||
installActivate(id, release, destDir, function(err) { | ||
message = 'New activate file has been created sucessfully!'; | ||
log.emit('message', message); | ||
if (err) {log.emit('error', err);} | ||
makeRecord(id, release, npmVer, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'Record file has been edited sucessfully!'; | ||
log.emit('message', message); | ||
makeConfigFiles(argv, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'New node ecosystem has been created sucessfully!'; | ||
log.emit('message', message); | ||
}); | ||
}); | ||
}); | ||
@@ -175,0 +247,0 @@ } |
var path = require('path'), | ||
color = require('ansi-color').set; | ||
exports.run = function(config) { | ||
var shell = color('neco_deactivate', 'bold+yellow'); | ||
exports.run = function(argv) { | ||
var id = argv.id, | ||
shell = color('neco_deactivate', 'bold+yellow'); | ||
console.log('run \''+shell+' command in your shell, :)'); | ||
}; |
var fs = require('fs'), | ||
path = require('path'), | ||
show = require('../lib/display.js').showReleases, | ||
log = require('../lib/display.js').lo9, | ||
show = require('../lib/display.js').show, | ||
getRelease = require('../lib/assistant.js').getRelease; | ||
exports.run = function(config) { | ||
var release; | ||
config.releases = []; | ||
fs.readFile(config.distFile, 'utf8', function(err, data) { | ||
if (err) {throw err;} | ||
if (config.target) { | ||
release = getRelease(config); | ||
config.releases[0] = release; | ||
exports.run = function(argv) { | ||
var target = argv.target, | ||
release, releases = [], | ||
config = process.neco.config; | ||
fs.readFile(config.localDistFile, 'utf8', function(err, data) { | ||
if (err) {log.emit('error', err);} | ||
if (target) { | ||
release = getRelease(target); | ||
releases[0] = release; | ||
} else { | ||
config.releases = JSON.parse(data).history; | ||
releases = JSON.parse(data).history; | ||
} | ||
show(config); | ||
show.emit('releases', releases); | ||
}); | ||
}; |
var path = require('path'); | ||
exports.run = function(config) { | ||
if (config.cmd === undefined) { | ||
exports.run = function(argv) { | ||
if (argv.target === undefined) { | ||
console.log('neco - Nodejs Ecosystem COordinator, like virtualenv for python.'); | ||
console.log(''); | ||
console.log('Usage:\n neco <command>'); | ||
@@ -7,0 +8,0 @@ console.log(''); |
var fs = require('fs'), | ||
path = require('path'), | ||
log = require('../lib/display.js').log, | ||
getEcosystem = require('../lib/assistant.js').getEcosystem, | ||
show = require('../lib/display.js').showEcosystems; | ||
show = require('../lib/display.js').show; | ||
exports.run = function(config) { | ||
var ecosystem; | ||
config.ecosystems = []; | ||
exports.run = function(argv) { | ||
var config = process.neco.config, | ||
ecosystem, ecosystems = []; | ||
fs.readFile(config.recordFile, 'utf8', function(err, data) { | ||
if (err) {throw err;} | ||
if (config.target) { | ||
ecosystem = getEcosystem(config); | ||
config.ecosystems[0] = ecosystem; | ||
if (err) {log.emit('error', err);} | ||
if (argv.id) { | ||
ecosystem = getEcosystem(argv.id); | ||
ecosystems[0] = ecosystem; | ||
} else { | ||
config.ecosystems = JSON.parse(data).ecosystems; | ||
ecosystems = JSON.parse(data).ecosystems; | ||
} | ||
show(config); | ||
show.emit('ecosystems', ecosystems); | ||
}); | ||
}; |
var fs = require('fs'), | ||
path = require('path'), | ||
spawn = require('child_process').spawn, | ||
log = require('../lib/display.js').log, | ||
removeEcosystem = require('../lib/utils.js').removeEcosystem, | ||
getEcosystem = require('../lib/assistant.js').getEcosystem, | ||
writeGlobalConfigFile = require('../lib/assistant.js').writeGlobalConfigFile; | ||
writeLocalConfigFile = require('../lib/assistant.js').writeLocalConfigFile; | ||
@@ -11,5 +12,5 @@ var log = require('../lib/display.js').log; | ||
function removeDir(config, next) { | ||
var error, remove, targetDir; | ||
targetDir = path.join(config.root, '.neco', config.id); | ||
function removeDir(id, next) { | ||
var error, remove, config = process.neco.config, | ||
root = config.root, targetDir = path.join(root, '.neco', id); | ||
@@ -23,6 +24,6 @@ path.exists(targetDir, function(exists) { | ||
remove.stdout.on('data', function(data) { | ||
log('stdout', data); | ||
log.emit('stdout', data); | ||
}); | ||
remove.stderr.on('data', function(data) { | ||
log('stdout', data); | ||
log.emit('stdout', data); | ||
}); | ||
@@ -32,5 +33,5 @@ remove.on('exit', function(code) { | ||
err = new Error('Remove exit with code '+code); | ||
next(error, config); | ||
next(error); | ||
} else { | ||
next(error, config); | ||
next(error); | ||
} | ||
@@ -42,5 +43,8 @@ }); | ||
function editRecord(config, next) { | ||
var error, index, record, ecosystem, recordData, | ||
id = config.id, recordFile = config.recordFile; | ||
function editRecord(id, next) { | ||
var error, index, record, | ||
ecosystem, recordData, | ||
config = process.neco.config, | ||
recordFile = config.recordFile; | ||
path.exists(recordFile, function(exists) { | ||
@@ -52,3 +56,3 @@ if (!exists) { | ||
fs.readFile(recordFile, 'utf8', function(err, data) { | ||
if (err) {throw err;} | ||
if (err) {log.emit('error', err);} | ||
record = JSON.parse(data); | ||
@@ -59,3 +63,3 @@ record.ecosystems = removeEcosystem(record.ecosystems, id); | ||
error = err; | ||
next(error, config); | ||
next(error); | ||
}); | ||
@@ -67,19 +71,25 @@ }); | ||
function editConfig(config) { | ||
var id = config.id; | ||
writeGlobalConfigFile(config, function(err, config) { | ||
if (err) {throw err;} | ||
message = 'ecosystem '+id+' has been removed sucessfully.'; | ||
log('message', message); | ||
function editConfig(id) { | ||
var config = process.neco.config; | ||
writeLocalConfigFile(id, function(err, id) { | ||
if (err) {log.emit('error', err);} | ||
message = 'Ecosystem '+id+' has been removed sucessfully!'; | ||
log.emit('exit', message); | ||
}); | ||
} | ||
exports.run = function(config) { | ||
removeDir(config, function(err) { | ||
if (err) {throw err;} | ||
editRecord(config, function(err, config) { | ||
if (err) {throw err;} | ||
editConfig(config); | ||
exports.run = function(argv) { | ||
var id = argv.id; | ||
removeDir(id, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'Target directory has been removeed sucessfully!'; | ||
log.emit('message', message); | ||
editRecord(id, function(err) { | ||
if (err) {log.emit('error', err);} | ||
message = 'Ecosystems record file has been edited sucessfully!'; | ||
log.emit('message', message); | ||
editConfig(id); | ||
}); | ||
}); | ||
}; |
@@ -1,4 +0,4 @@ | ||
{ "releases":69, | ||
{ "releases":71, | ||
"stable":"0.2.6", | ||
"latest":"0.3.5", | ||
"latest":"0.3.7", | ||
"history":[ | ||
@@ -53,4 +53,6 @@ {"version":"latest","link":"http://nodejs.org/dist/node-latest.tar.gz","released":"31-Dec-2010 05:02","size":4010320}, | ||
{"version":"0.3.4","link":"http://nodejs.org/dist/node-v0.3.4.tar.gz","released":"08-Jan-2011 23:50","size":4610441}, | ||
{"version":"0.3.5","link":"http://nodejs.org/dist/node-v0.3.5.tar.gz","released":"16-Jan-2011 23:15","size":4655131} | ||
{"version":"0.3.5","link":"http://nodejs.org/dist/node-v0.3.5.tar.gz","released":"16-Jan-2011 23:15","size":4655131}, | ||
{"version":"0.3.6","link":"http://nodejs.org/dist/node-v0.3.6.tar.gz","released":"22-Jan-2011 02:19","size":4727071}, | ||
{"version":"0.3.7","link":"http://nodejs.org/dist/node-v0.3.7.tar.gz","released":"28-Jan-2011 04:54","size":4748183} | ||
] | ||
} |
@@ -1,4 +0,5 @@ | ||
{ "releases":69, | ||
{ "releases":71, | ||
"stable":"0.2.6", | ||
"unstable":"0.3.5" | ||
"unstable":"0.3.7" | ||
"latest":"latest", | ||
"history":[ | ||
@@ -73,4 +74,6 @@ {"version":"latest","link":"http://nodejs.org/dist/node-latest.tar.gz","released":"31-Dec-2010 05:02","size":4010320}, | ||
{"version":"0.3.4","link":"http://nodejs.org/dist/node-v0.3.4.tar.gz","released":"08-Jan-2011 23:50","size":4610441}, | ||
{"version":"0.3.5","link":"http://nodejs.org/dist/node-v0.3.5.tar.gz","released":"16-Jan-2011 23:15","size":4655131} | ||
{"version":"0.3.5","link":"http://nodejs.org/dist/node-v0.3.5.tar.gz","released":"16-Jan-2011 23:15","size":4655131}, | ||
{"version":"0.3.6","link":"http://nodejs.org/dist/node-v0.3.6.tar.gz","released":"22-Jan-2011 02:19","size":4727071}, | ||
{"version":"0.3.7","link":"http://nodejs.org/dist/node-v0.3.7.tar.gz","released":"28-Jan-2011 04:54","size":4748183} | ||
] | ||
} |
{ | ||
"coulps": | ||
[ | ||
{"node":"0.2.3", "npm":"0.2.14-6"} | ||
{"node":"0.2.3", "npm":"0.2.16"} | ||
] | ||
} |
@@ -7,4 +7,3 @@ | ||
var mkdir = require("./utils/mkdir-p") | ||
, npm = require("../npm") | ||
var npm = require("../npm") | ||
, fs = require("./utils/graceful-fs") | ||
@@ -11,0 +10,0 @@ , log = require("./utils/log") |
@@ -186,3 +186,4 @@ | ||
if (er) return cb(new Error( | ||
"Required package: "+req.name+"("+req.version+") not found.")) | ||
"Required package: "+req.name+"("+req.version+") not found."+ | ||
"\n(required by: "+pkg._id+")")) | ||
// TODO: Get the "stable" version if there is one. | ||
@@ -194,3 +195,4 @@ // Look that up from the registry. | ||
"Required package: "+req.name+"("+req.version+") not found. "+ | ||
"(Found: "+JSON.stringify(versions)+")")) | ||
"(Found: "+JSON.stringify(versions)+")"+ | ||
"\n(required by: "+pkg._id+")")) | ||
}) | ||
@@ -228,3 +230,2 @@ }, function (er, found) { | ||
function dependencyLink (pkg, cb) { | ||
pkg.link = pkg.link || {} | ||
var dependencies = path.join(npm.dir, pkg.name, pkg.version, "node_modules") | ||
@@ -251,9 +252,2 @@ , depBin = path.join(npm.dir, pkg.name, pkg.version, "dep-bin") | ||
linkBins(dep, depBin, false, cb) | ||
}, function (dep, cb) { | ||
var linkToLib = (pkg.link || {}).hasOwnProperty(dep.name) | ||
? path.join( npm.dir, pkg.name, pkg.version | ||
, "package", pkg.link[dep.name] | ||
) | ||
: null | ||
linkToLib ? linkModules(dep, linkToLib, cb) : cb() | ||
}, cb) | ||
@@ -260,0 +254,0 @@ }) |
@@ -13,2 +13,3 @@ | ||
, rm = require("./utils/rm-rf") | ||
, url = require("url") | ||
, notAllowed = [ "adduser", "build", "bundle", "config", "init", "link" | ||
@@ -75,15 +76,12 @@ , "owner", "publish", "restart", "start", "stop", "tag" | ||
mkdir(npm.dir, function(er) { | ||
if (er) return log.er(cb, "Error creating "+npm.dir+" for bundling")(er) | ||
if (typeof cmd === "function") { | ||
return cmd(args, cb) | ||
} | ||
if (typeof cmd === "function") { | ||
return cmd(args, cb) | ||
} | ||
// no command given, just install the local deps. | ||
// just read the package.json from the directory to | ||
// avoid adding the whole package to the cache | ||
readJson(path.join(pkg, "package.json"), function (er, data) { | ||
if (er) return log.er(cb, "Error reading "+pkg+"/package.json")(er) | ||
install(data, location, cb) | ||
}) | ||
// no command given, just install the local deps. | ||
// just read the package.json from the directory to | ||
// avoid adding the whole package to the cache | ||
readJson(path.join(pkg, "package.json"), function (er, data) { | ||
if (er) return log.er(cb, "Error reading "+pkg+"/package.json")(er) | ||
install(data, location, cb) | ||
}) | ||
@@ -101,2 +99,6 @@ }) | ||
if (v === "*") v = "" | ||
var u = url.parse(v) | ||
if (u && u.protocol && u.host) { | ||
return u.href | ||
} | ||
return v ? d + "@" + v : d | ||
@@ -103,0 +105,0 @@ }) |
@@ -190,5 +190,7 @@ | ||
} | ||
function addRemoteTarball (url, shasum, cb) { | ||
function addRemoteTarball (url, shasum, name, cb) { | ||
if (!cb) cb = name, name = "" | ||
if (!cb) cb = shasum, shasum = null | ||
log.verbose([url, shasum], "addRemoteTarball") | ||
if (!cb) cb = shasum, shasum = null | ||
// todo: take a shasum, and validate it. | ||
@@ -207,5 +209,6 @@ var tmp = path.join(npm.tmp, Date.now()+"-"+Math.random(), "tmp.tgz") | ||
if (er) return cb(er) | ||
addLocalTarball(tmp, cb) | ||
addLocalTarball(tmp, name, cb) | ||
} | ||
} | ||
function addNameVersion (name, ver, cb) { | ||
@@ -226,3 +229,3 @@ registry.get(name, ver, function (er, data, json, response) { | ||
return addRemoteTarball( data.dist.tarball.replace(/^https/,'http') | ||
, data.dist.shasum, cb) | ||
, data.dist.shasum, name+"-"+ver, cb) | ||
} | ||
@@ -232,14 +235,17 @@ }) | ||
function addLocal (p, cb) { | ||
function addLocal (p, name, cb) { | ||
if (!cb) cb = name, name = "" | ||
// figure out if this is a folder or file. | ||
fs.stat(p, function (er, s) { | ||
if (er) return log.er(cb, "Doesn't exist: "+p)(er) | ||
if (s.isDirectory()) addLocalDirectory(p, cb) | ||
else addLocalTarball(p, cb) | ||
if (s.isDirectory()) addLocalDirectory(p, name, cb) | ||
else addLocalTarball(p, name, cb) | ||
}) | ||
} | ||
function addLocalTarball (p, cb) { | ||
function addLocalTarball (p, name, cb) { | ||
if (!cb) cb = name, name = "" | ||
// if it's a tar, and not in place, | ||
// then unzip to .tmp, add the tmp folder, and clean up tmp | ||
if (p.indexOf(npm.tmp) === 0) return addTmpTarball(p, cb) | ||
if (p.indexOf(npm.tmp) === 0) return addTmpTarball(p, name, cb) | ||
@@ -249,7 +255,8 @@ if (p.indexOf(npm.cache) === 0) { | ||
"Not a valid cache tarball name: "+p)) | ||
return addPlacedTarball(p, cb) | ||
return addPlacedTarball(p, name, cb) | ||
} | ||
// just copy it over and then add the temp tarball file. | ||
var tmp = path.join(npm.tmp, Date.now() + "-" + Math.random(), "tmp.tgz") | ||
var tmp = path.join(npm.tmp, name + Date.now() | ||
+ "-" + Math.random(), "tmp.tgz") | ||
mkdir(path.dirname(tmp), function (er) { | ||
@@ -270,3 +277,3 @@ if (er) return cb(er) | ||
if (er) return cb(er) | ||
addTmpTarball(tmp, cb) | ||
addTmpTarball(tmp, name, cb) | ||
}) | ||
@@ -277,3 +284,5 @@ }) | ||
} | ||
function addPlacedTarball (p, cb) { | ||
function addPlacedTarball (p, name, cb) { | ||
if (!cb) cb = name, name = "" | ||
// now we know it's in place already as .cache/name/ver/package.tgz | ||
@@ -307,3 +316,5 @@ // unpack to .cache/name/ver/package/, read the package.json, | ||
} | ||
function addLocalDirectory (p, cb) { | ||
function addLocalDirectory (p, name, cb) { | ||
if (!cb) cb = name, name = "" | ||
// if it's a folder, then read the package.json, | ||
@@ -326,7 +337,9 @@ // tar it to the proper place, and add the cache tar | ||
if (er) return log.er(cb,"couldn't pack "+p+ " to "+tgz)(er) | ||
addLocalTarball(tgz, cb) | ||
addLocalTarball(tgz, name, cb) | ||
}) | ||
}) | ||
} | ||
function addTmpTarball (tgz, cb) { | ||
function addTmpTarball (tgz, name, cb) { | ||
if (!cb) cb = name, name = "" | ||
var contents = path.join(path.dirname(tgz),"contents") | ||
@@ -350,3 +363,3 @@ unpackTar(tgz, contents, function (er) { | ||
if (er) return log.er(cb, "couldn't rename "+folder+" to package")(er) | ||
addLocalDirectory(newName, cb) | ||
addLocalDirectory(newName, name, cb) | ||
}) | ||
@@ -353,0 +366,0 @@ }) |
@@ -11,4 +11,3 @@ | ||
var mkdir = require("./utils/mkdir-p") | ||
, npm = require("../npm") | ||
var npm = require("../npm") | ||
, fs = require("./utils/graceful-fs") | ||
@@ -15,0 +14,0 @@ , log = require("./utils/log") |
@@ -38,3 +38,2 @@ | ||
, fetch = require("./utils/fetch") | ||
, mkdir = require("./utils/mkdir-p") | ||
, readJson = require("./utils/read-json") | ||
@@ -41,0 +40,0 @@ , log = require("./utils/log") |
@@ -10,3 +10,2 @@ | ||
, rm = require("./utils/rm-rf") | ||
, mkdir = require("./utils/mkdir-p") | ||
, path = require("path") | ||
@@ -13,0 +12,0 @@ , crypto |
@@ -183,3 +183,7 @@ | ||
var stdio = process.binding("stdio") | ||
, cols = stdio.isatty(stdio.stdoutFD) ? stdio.getColumns() : Infinity | ||
, cols = stdio.isatty(stdio.stdoutFD) ? | ||
( stdio.getColumns ? stdio.getColumns() | ||
: stdio.getWindowSize ? stdio.getWindowSize()[1] | ||
: Infinity ) | ||
: Infinity | ||
} | ||
@@ -190,4 +194,4 @@ catch (ex) { cols = Infinity } | ||
return (line.name + (space.substr(0, addSpace) || "") + " " | ||
+ line.attrs + " " | ||
+ (line.description ? line.description + " " : "") | ||
+ line.attrs | ||
+ (line.keywords.length ? " " + line.keywords.join(" ") : "")) | ||
@@ -229,4 +233,10 @@ .substr(0, cols) | ||
merged[p].versions[v].tags = [] | ||
var descs = remote[p].descriptions | ||
if (descs && descs[v] && descs[v] !== remote[p].description) { | ||
merged[p].versions[v].description = descs[v] | ||
} | ||
Object.keys(remote[p]["dist-tags"]).forEach(function (tag) { | ||
if (remote[p]["dist-tags"][tag] === v) merged[p].versions[v].tags.push(tag) | ||
if (remote[p]["dist-tags"][tag] === v) { | ||
merged[p].versions[v].tags.push(tag) | ||
} | ||
}) | ||
@@ -233,0 +243,0 @@ } |
@@ -62,7 +62,8 @@ /* | ||
if (er) return log.verbose(pkg, "not in registry", cb) | ||
try { | ||
Object.keys(data.versions).forEach(function (v) { | ||
readJson.processJson(data.versions[v]) | ||
}) | ||
} catch (er) { return cb(er) } | ||
Object.keys(data.versions).forEach(function (v) { | ||
try { | ||
data.versions[v] = readJson.processJson(data.versions[v]) | ||
} catch (er) { delete data.versions[v] } | ||
}) | ||
log.silly(data.versions, (data._id || data.name)+" versions") | ||
var latest = data["dist-tags"] && data["dist-tags"][tag] | ||
@@ -69,0 +70,0 @@ , have = Object.keys(inst[pkg]).sort(semver.sort) |
@@ -5,3 +5,3 @@ | ||
var npm = require("../npm") | ||
, registry = require("./utils/registry") | ||
, rpub = require("./utils/registry/publish") | ||
, log = require("./utils/log") | ||
@@ -20,4 +20,4 @@ | ||
if (!data) return cb(new Error("no package.json file found")) | ||
registry.publish(data, npm.config.get("registry"), cb) | ||
rpub(data, cb) | ||
}) | ||
} |
@@ -1,1 +0,21 @@ | ||
module.exports = require("./utils/lifecycle").cmd("test") | ||
module.exports = test | ||
var lifecycle = require("./utils/lifecycle") | ||
, cmd = lifecycle.cmd("test") | ||
, path = require("path") | ||
, readJson = require("./utils/read-json") | ||
, chain = require("./utils/chain") | ||
test.usage = cmd.usage | ||
function test (args, cb) { | ||
if (!args.length) { | ||
readJson(path.join(process.cwd(), "package.json"), function (er, d) { | ||
if (er) return cb(test.usage) | ||
chain(["pretest", "test", "posttest"].map(function (s) { | ||
return [lifecycle, d, s, process.cwd()] | ||
}).concat(cb)) | ||
}) | ||
} | ||
else cmd(args, cb) | ||
} |
@@ -25,3 +25,2 @@ | ||
, semver = require("./utils/semver") | ||
, mkdir = require("./utils/mkdir-p") | ||
, asyncMap = require("./utils/async-map") | ||
@@ -35,2 +34,3 @@ , loadPackageDefaults = require("./utils/load-package-defaults") | ||
// this way, it won't whine about not being able to remove anything, ever. | ||
if (!args.length) return rmCwdPkg(cb) | ||
unpackArgs(args, function (er, args) { | ||
@@ -56,2 +56,9 @@ if (args.length) log.verbose(args, "removing") | ||
function rmCwdPkg (cb) { | ||
readJson(path.join(process.cwd(), "package.json"), function (er, d) { | ||
if (er) return cb(uninstall.usage) | ||
return uninstall([d._id], cb) | ||
}) | ||
} | ||
// if any deps are found, and are valid (have a package.json), | ||
@@ -258,17 +265,12 @@ // and are not also on the list, then yell about it. | ||
var dependsOn = path.join(npm.dir, data.name, data.version, "dependson") | ||
// TODO: remove this mkdir kludge | ||
// A workaround for the fact that this dir didn't exist prior to 0.1.20 | ||
mkdir(dependsOn, function (er) { | ||
if (er) return cb() // meh | ||
fs.readdir(dependsOn, function (er, deps) { | ||
if (er) return cb(er) | ||
asyncMap(deps, function (dep, cb) { | ||
// <3 symlinks | ||
var p = path.join(dependsOn, dep, "dependents", data.name) | ||
, v = data.version | ||
// todo: remove this kludge v0.1.28 | ||
// just do the "@" only. | ||
asyncMap([p+"@"+v, p+"-"+v], rm, cb) | ||
}, cb) | ||
}) | ||
fs.readdir(dependsOn, function (er, deps) { | ||
if (er) return cb() // no deps, or a fossil. | ||
asyncMap(deps, function (dep, cb) { | ||
// <3 symlinks | ||
var p = path.join(dependsOn, dep, "dependents", data.name) | ||
, v = data.version | ||
// todo: remove this kludge v0.1.28 | ||
// just do the "@" only. | ||
asyncMap([p+"@"+v, p+"-"+v], rm, cb) | ||
}, cb) | ||
}) | ||
@@ -275,0 +277,0 @@ } |
@@ -7,2 +7,4 @@ | ||
, npm = require("../npm") | ||
, readJson = require("./utils/read-json") | ||
, path = require("path") | ||
@@ -20,3 +22,14 @@ unpublish.usage = "npm unpublish <project>[@<version>]" | ||
, version = thing.join("@") | ||
if (!project) return cb("Usage:\n"+unpublish.usage) | ||
if (!project) { | ||
// if there's a package.json in the current folder, then | ||
// read the package name and version out of that. | ||
var cwdJson = path.join(process.cwd(), "package.json") | ||
return readJson(cwdJson, function (er, data) { | ||
if (er) return cb("Usage:\n"+unpublish.usage) | ||
gotProject(data.name, data.version, cb) | ||
}) | ||
} | ||
return gotProject(project, version, cb) | ||
} | ||
function gotProject (project, version, cb) { | ||
// remove from the cache first | ||
@@ -23,0 +36,0 @@ npm.commands.cache(["clean", project, version], function (er) { |
@@ -1,4 +0,4 @@ | ||