Skip to content
Browse files

subdeps command but it's super slow

  • Loading branch information...
1 parent fd46c57 commit 2331d417e7ee8b86db949799bbf2192baf7e0c34 @substack committed
Showing with 45 additions and 2 deletions.
  1. +4 −0 README.markdown
  2. +35 −0 bin/cmd.js
  3. +2 −1 index.js
  4. +4 −1 package.json
View
4 README.markdown
@@ -85,6 +85,10 @@ With [npm](http://npmjs.org) do:
npm install subdeps
+and for the CLI tool do:
+
+ npm install -g subdeps
+
licence
=======
View
35 bin/cmd.js
@@ -0,0 +1,35 @@
+#!/usr/bin/env node
+var subdeps = require('../');
+
+var entry = process.argv[2] || process.cwd();;
+var fs = require('fs');
+var path = require('path');
+
+if (path.existsSync(entry)) {
+ if (fs.statSync(entry).isDirectory()) {
+ if (path.existsSync(path.join(entry, 'package.json'))) {
+ entry = path.join(entry, 'index.js');
+ }
+ else if (path.existsSync(path.join(entry, 'index.js'))) {
+ entry = path.join(entry, 'index.js');
+ }
+ else {
+ console.error('not a file or package');
+ process.exit(1);
+ }
+ }
+}
+else {
+ console.error('file not found');
+ process.exit(1);
+}
+
+var deps = subdeps.sync(entry);
+var basedir = path.dirname(path.resolve(entry));
+deps.forEach(function (dep) {
+ var file = path.resolve(basedir, dep);
+ if (file.slice(0, basedir.length + 1) === basedir + '/') {
+ file = '.' + file.slice(basedir.length);
+ }
+ console.log(file);
+});
View
3 index.js
@@ -28,7 +28,8 @@ exports.sync = function (filename, opts) {
walked[file] = true;
var dirname = path.dirname(file);
- var src = opts.readFileSync(file);
+ var src = opts.readFileSync(file)
+ .toString().replace(/^#![^\n]+/);
detective(src).forEach(function (dep) {
opts.basedir = dirname;
View
5 package.json
@@ -3,6 +3,9 @@
"version" : "0.0.0",
"description" : "trace the dependency graph of a javascript file",
"main" : "index.js",
+ "bin" : {
+ "subdeps" : "bin/cmd.js"
+ },
"directories" : {
"lib" : ".",
"example" : "example",
@@ -16,7 +19,7 @@
"test" : "tap test/*.js"
},
"devDependencies" : {
- "tap" : "0.0.x"
+ "tap" : "~0.2.5"
},
"repository" : {
"type" : "git",

0 comments on commit 2331d41

Please sign in to comment.
Something went wrong with that request. Please try again.