Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

init: add option 'dev' to include package in devDependencies

init: set default answer depending on which type of dependency it is
init: rework code to fit within 80 cols
  • Loading branch information...
commit ac85d211b82a920e2a0f3c450ba6787647b4299a 1 parent 34a891f
@wankdanker authored
Showing with 39 additions and 19 deletions.
  1. +39 −19 lib/init.js
View
58 lib/init.js
@@ -148,7 +148,10 @@ function init_ (data, folder, cb) {
}
)
(function (cb) {
- read({ prompt: "Would you like to process dependencies? ", default: "yes" }, function (er, ok) {
+ read({ prompt: "Would you like to process dependencies? "
+ , default: "yes" }
+ , function (er, ok) {
+
if (er) return cb(er)
if (ok.toLowerCase().charAt(0) !== "y") {
return cb()
@@ -206,7 +209,8 @@ function dependencies (folder, data, cb) {
(function (cb) {
var count = 0
folders.forEach(function (folder) {
- fs.readFile('./node_modules/' + folder + '/package.json', 'utf8', function (er, json) {
+ var file = './node_modules/' + folder + '/package.json';
+ fs.readFile(file, 'utf8', function (er, json) {
count += 1
if (!er) {
@@ -224,36 +228,52 @@ function dependencies (folder, data, cb) {
})
})
})
- //TODO: search for each module discovered to ensure the module/version is available with npm
+ //TODO: search for each module discovered to ensure the module/version
+ //is available with npm
(function (cb) {
var count = 0
- if (packages.length && !data.dependencies) {
- data.dependencies = {}
+ if (packages.length) {
+ if (!data.dependencies) data.dependencies = {}
+ if (!data.devDependencies) data.devDependencies = {}
}
doWhile(function (next) {
var package = packages[count]
+ , defaultAnswer = (data.devDependencies[package.name])
+ ? "dev"
+ : "yes"
+ , prompt = ["Would you like to add the dependency"
+ ,package.name
+ ,"@"
+ ,package.version
+ ,"? [yes/no/dev]"
+ ].join(" ")
count += 1
- //TODO: check version also and ask to add this version if version is different?
- if (!data.dependencies[package.name]) {
- //TODO: offer more options for selecting version compatibility
- read({ prompt: "Would you like to add the dependency: " + package.name + " @ " + package.version + "? ", default: "yes" }, function (er, ok) {
- if (er) return cb(er)
- if (ok.toLowerCase().charAt(0) !== "y") {
- return next(count !== packages.length)
- }
+ //TODO: offer more options for selecting version compatibility
+ read({ prompt: prompt, default: defaultAnswer }, function (er, ok) {
+ if (er) return cb(er)
- data.dependencies[package.name] = package.version
+ switch (ok.toLowerCase().charAt(0)) {
+ case 'y' :
+ delete data.devDependencies[package.name]
+ data.dependencies[package.name] = package.version
+ break
+ case 'd' :
+ delete data.dependencies[package.name]
+ data.devDependencies[package.name] = package.version
+ break
+ case 'n' :
+ delete data.dependencies[package.name]
+ delete data.devDependencies[package.name]
+ break
+ default :
+ }
- next(count !== packages.length)
- })
- }
- else {
next(count !== packages.length)
- }
+ })
}, function () {
cb()
})
Please sign in to comment.
Something went wrong with that request. Please try again.