tree-directory
Advanced tools
+32
-2
@@ -0,4 +1,34 @@ | ||
| var glob = require('globby') | ||
| var treeify = require('treeify') | ||
| var path = require('path') | ||
| var getp = require('getp') | ||
| var set = require('getp/set') | ||
| exports = module.exports = require('./lib/async') | ||
| exports.sync = require('./lib/sync') | ||
| function stringify(root, patterns) { | ||
| return glob(patterns || '**/*', { cwd: root }) | ||
| .then(function (files) { | ||
| return treeify.asTree(obj(files)) | ||
| }) | ||
| } | ||
| function sync(root, patterns) { | ||
| patterns = patterns || '**/*' | ||
| var files = glob.sync(patterns, { cwd: root }) | ||
| return treeify.asTree(obj(files)) | ||
| } | ||
| function obj(files) { | ||
| var o = {} | ||
| files.forEach(function (file) { | ||
| var parts = file.split(path.sep).filter(Boolean) | ||
| if (getp(o, parts, false) == null) { | ||
| set(o, parts, null) | ||
| } | ||
| }) | ||
| return o | ||
| } | ||
| exports = module.exports = stringify | ||
| exports.sync = sync | ||
| exports.obj = obj | ||
+8
-6
| { | ||
| "name": "tree-directory", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Print a directory structure in the tree format", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "eslint . && tap test/*.js" | ||
| "test": "npm run lint && tap test/*.js", | ||
| "cov": "tap --cov test/*.js", | ||
| "lint": "eslint *.js 'lib/**/*.js' test/*.js bin/*.js", | ||
| "coveralls": "COVERALLS_REPO_TOKEN=REPO_TOKEN npm run cov" | ||
| }, | ||
@@ -25,10 +28,9 @@ "repository": { | ||
| "getp": "^1.2.0", | ||
| "globby": "^3.0.1", | ||
| "resolve": "^1.1.6", | ||
| "globby": "^4.0.0", | ||
| "treeify": "^1.0.1" | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "^1.6.0", | ||
| "tap": "^2.1.0" | ||
| "eslint": "^2.0.0", | ||
| "tap": "^5.0.0" | ||
| } | ||
| } |
+39
-30
| # tree-directory | ||
| [](https://www.npmjs.org/package/tree-directory) | ||
| [](https://travis-ci.org/zoubin/tree-directory) | ||
| [](https://david-dm.org/zoubin/tree-directory) | ||
| [](https://david-dm.org/zoubin/tree-directory#info=devDependencies) | ||
| Print a directory structure in the tree format | ||
| ## Usage | ||
| ## Example | ||
| **Directory structure** | ||
| ``` | ||
| example/src | ||
| ├── page | ||
| │ ├── hello | ||
| │ │ └── index.css | ||
| │ └── world | ||
| │ ├── index.css | ||
| │ └── index.js | ||
| └── vendor | ||
| └── index.js | ||
| ``` | ||
| To print all javascript files: | ||
| ```javascript | ||
| var tree = require('tree-directory') | ||
| var res = tree.sync(__dirname + '/fixtures') | ||
| tree(__dirname + '/src', '**/*.js').then(function (res) { | ||
| console.log(res) | ||
| }) | ||
| console.log(res.obj) | ||
| console.log(res.basedir) | ||
| console.log(res.str) | ||
| ``` | ||
| output: | ||
| **Output** | ||
| ``` | ||
| ⌘ node example/tree.js | ||
| { a: { b: { c: null }, d: null }, e: { f: null }, g: null } | ||
| /Users/zoubin/usr/src/zoubin/tree-directory/example/fixtures | ||
| ├─ a | ||
| │ ├─ b | ||
| │ │ └─ c | ||
| │ └─ d | ||
| ├─ e | ||
| │ └─ f | ||
| └─ g | ||
| ├─ page | ||
| │ └─ world | ||
| │ └─ index.js | ||
| └─ vendor | ||
| └─ index.js | ||
| ``` | ||
| ### rv = tree(basedir, patterns) | ||
| ## tree(root[, patterns]) | ||
| Return a promise which resolves to a treeish string | ||
| representing the directory `root` (not including itself). | ||
| Return a promise that resolves to the tree info object of `basedir`. | ||
| **root** | ||
| #### basedir | ||
| The target directory to format. | ||
| Type: `String` | ||
| The target directory | ||
| **patterns** | ||
| #### patterns | ||
| [Globs](https://github.com/sindresorhus/globby#patterns) | ||
| to match the files to include. | ||
@@ -50,9 +64,4 @@ Type: `String`, `Array` | ||
| See [globby](https://github.com/sindresorhus/globby#patterns) | ||
| ## tree.sync(root[, patterns]) | ||
| Just return the treeish string. | ||
| #### rv | ||
| * `obj`: object representation | ||
| * `str`: string representation | ||
| * `basedir`: the basedir itself | ||
-82
| --- | ||
| ecmaFeatures: | ||
| modules: true | ||
| env: | ||
| browser: true | ||
| node: true | ||
| es6: true | ||
| rules: | ||
| comma-dangle: [2, "always-multiline"] | ||
| no-dupe-args: 2 | ||
| no-dupe-keys: 2 | ||
| no-duplicate-case: 2 | ||
| no-empty-character-class: 2 | ||
| no-ex-assign: 2 | ||
| no-extra-boolean-cast: 2 | ||
| no-extra-parens: 2 | ||
| no-extra-semi: 2 | ||
| no-func-assign: 2 | ||
| no-inner-declarations: 2 | ||
| no-invalid-regexp: 2 | ||
| no-irregular-whitespace: 2 | ||
| no-negated-in-lhs: 2 | ||
| no-obj-calls: 2 | ||
| no-regex-spaces: 2 | ||
| no-sparse-arrays: 2 | ||
| no-unreachable: 2 | ||
| use-isnan: 2 | ||
| valid-typeof: 2 | ||
| no-unexpected-multiline: 2 | ||
| no-cond-assign: 2 | ||
| no-constant-condition: 2 | ||
| no-control-regex: 2 | ||
| no-debugger: 2 | ||
| # code style | ||
| consistent-return: 0 | ||
| curly: 2 | ||
| default-case: 2 | ||
| dot-notation: 2 | ||
| dot-location: [2, "property"] | ||
| eqeqeq: [2, "allow-null"] | ||
| no-else-return: 2 | ||
| no-lone-blocks: 2 | ||
| no-loop-func: 2 | ||
| no-multi-spaces: 2 | ||
| no-multi-str: 2 | ||
| no-proto: 2 | ||
| no-redeclare: 2 | ||
| no-return-assign: 2 | ||
| no-sequences: 2 | ||
| no-throw-literal: 2 | ||
| no-unused-expressions: 2 | ||
| no-void: 2 | ||
| no-warning-comments: [2, { "terms": ["todo", "fixme", "xxx"], "location": "start" }] | ||
| no-with: 2 | ||
| radix: 2 | ||
| no-delete-var: 2 | ||
| no-shadow-restricted-names: 2 | ||
| no-shadow: 2 | ||
| no-undef: 2 | ||
| no-unused-vars: 2 | ||
| brace-style: [2, "1tbs", { "allowSingleLine": true }] | ||
| comma-spacing: 2 | ||
| comma-style: 2 | ||
| indent: [2, 2] | ||
| key-spacing: 2 | ||
| max-nested-callbacks: [2, 3] | ||
| no-lonely-if: 2 | ||
| no-mixed-spaces-and-tabs: 2 | ||
| no-nested-ternary: 2 | ||
| no-spaced-func: 2 | ||
| no-trailing-spaces: 2 | ||
| one-var: [2, "never"] | ||
| operator-linebreak: 2 | ||
| quote-props: [2, "as-needed"] | ||
| quotes: [2, "single", "avoid-escape"] | ||
| semi: [2, "never"] | ||
| space-after-keywords: 2 | ||
| space-before-blocks: 2 | ||
| space-infix-ops: 2 | ||
| space-return-throw-case: 2 |
Sorry, the diff of this file is not supported yet
| language: node_js | ||
| node_js: | ||
| - "4.1" | ||
| - "4.0" | ||
| - "0.12" | ||
| - "0.11" | ||
| - "0.10" | ||
| - "iojs" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| var tree = require('..') | ||
| var res = tree.sync(__dirname + '/fixtures') | ||
| console.log(res.obj) | ||
| console.log(res.basedir) | ||
| console.log(res.str) | ||
-16
| var glob = require('globby') | ||
| var treeify = require('treeify') | ||
| var treeObj = require('./treeObj') | ||
| module.exports = function (root, patterns) { | ||
| return glob(patterns || '**/*', { cwd: root }) | ||
| .then(function (files) { | ||
| var o = treeObj(files) | ||
| return { | ||
| obj: o, | ||
| basedir: root, | ||
| str: treeify.asTree(o), | ||
| } | ||
| }) | ||
| } | ||
-16
| var glob = require('globby') | ||
| var treeify = require('treeify') | ||
| var treeObj = require('./treeObj') | ||
| module.exports = function (root, patterns) { | ||
| patterns = patterns || '**/*' | ||
| var files = glob.sync(patterns, { cwd: root }) | ||
| var o = treeObj(files) | ||
| return { | ||
| obj: o, | ||
| basedir: root, | ||
| str: treeify.asTree(o), | ||
| } | ||
| } | ||
| var path = require('path') | ||
| var getp = require('getp') | ||
| var set = require('getp/set') | ||
| module.exports = function (files) { | ||
| var o = {} | ||
| files.forEach(function (file) { | ||
| var parts = file.split(path.sep).filter(Boolean) | ||
| if (getp(o, parts, false) == null) { | ||
| set(o, parts, null) | ||
| } | ||
| }) | ||
| return o | ||
| } | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| var tree = require('..') | ||
| var test = require('tap').test | ||
| var root = __dirname + '/fixtures' | ||
| test('sync', function(t) { | ||
| t.same( | ||
| tree.sync(root).obj, | ||
| { | ||
| a: { | ||
| b: { c: null }, | ||
| d: null, | ||
| }, | ||
| e: { f: null }, | ||
| g: null, | ||
| } | ||
| ) | ||
| t.end() | ||
| }) | ||
| test('async', function(t) { | ||
| t.plan(1) | ||
| tree(root).then(function (o) { | ||
| t.same( | ||
| o.obj, | ||
| { | ||
| a: { | ||
| b: { c: null }, | ||
| d: null, | ||
| }, | ||
| e: { f: null }, | ||
| g: null, | ||
| } | ||
| ) | ||
| }) | ||
| }) | ||
3
-25%67
15.52%4175
-34.01%4
-75%29
-63.75%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated