Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add devDependencies support via -d, --dev. Closes #9

  • Loading branch information...
commit f01bf04c674cbd13dcef5a4fefdefdeed268344c 1 parent 1bd3ea4
@tj tj authored
Showing with 49 additions and 6 deletions.
  1. +26 −6 bin/component-install
  2. +23 −0 test/install.js
View
32 bin/component-install
@@ -14,6 +14,7 @@ var program = require('commander')
program
.usage('[pkg ...]')
+ .option('-d, --dev', 'install development dependencies')
.option('-o, --out <dir>', 'output components to the given <dir>')
.option('-f, --force', 'force installation even if previously installed')
@@ -37,6 +38,9 @@ program.on('--help', function(){
console.log(' # install a specific tag / sha');
console.log(' $ component install component/tip@8bf1ffc3f');
console.log();
+ console.log(' # install regular & development deps in .');
+ console.log(' $ component install -d');
+ console.log();
});
// parse argv
@@ -50,11 +54,15 @@ var pkgs = program.args;
// install from ./component.json
if (!pkgs.length) {
- pkgs = require(path.resolve('component.json')).dependencies;
- if (!pkgs) return;
- pkgs = Object.keys(pkgs).map(function(name){
- return name + '@' + pkgs[name];
- });
+ var conf = require(path.resolve('component.json'));
+
+ if (conf.dependencies) {
+ pkgs = normalize(conf.dependencies);
+ }
+
+ if (conf.devDependencies && program.dev) {
+ pkgs = pkgs.concat(normalize(conf.devDependencies));
+ }
}
// install
@@ -64,11 +72,23 @@ pkgs.forEach(function(pkg){
var parts = pkg.split('@');
pkg = parts.shift();
var version = parts.shift() || 'master';
- pkg = component.install(pkg, version, { dest: program.out, force: program.force });
+ pkg = component.install(pkg, version, {
+ dest: program.out,
+ force: program.force,
+ dev: program.dev
+ });
report(pkg);
pkg.install();
});
+// map deps to args
+
+function normalize(deps) {
+ return Object.keys(deps).map(function(name){
+ return name + '@' + deps[name];
+ });
+}
+
// reporter
function report(pkg) {
View
23 test/install.js
@@ -5,6 +5,8 @@
var exec = require('child_process').exec
, fs = require('fs')
+ , exists = fs.existsSync
+ , assert = require('assert')
, path = require('path');
describe('component install', function(){
@@ -17,6 +19,9 @@ describe('component install', function(){
dependencies: {
"component/tip": "*",
"component/popover": "*"
+ },
+ devDependencies: {
+ "component/inherit": "*"
}
}), done);
})
@@ -79,6 +84,24 @@ describe('component install', function(){
json.name.should.equal('tip');
var json = require(path.resolve('components/component-popover/component.json'));
json.name.should.equal('popover');
+ assert(!exists('components/component-inherit'), 'dev deps should be installed');
+ done();
+ })
+ })
+
+ it('should install dev deps when --dev is used', function(done){
+ exec('bin/component install -d', function(err, stdout){
+ if (err) return done(err);
+ stdout.should.include('install');
+ stdout.should.include('fetch');
+ stdout.should.include('complete');
+ var json = require(path.resolve('components/component-emitter/component.json'));
+ json.name.should.equal('emitter');
+ var json = require(path.resolve('components/component-tip/component.json'));
+ json.name.should.equal('tip');
+ var json = require(path.resolve('components/component-popover/component.json'));
+ json.name.should.equal('popover');
+ assert(exists('components/component-inherit'), 'dev deps should not be installed');
done();
})
})
Please sign in to comment.
Something went wrong with that request. Please try again.