├── example
├── test.md
├── empty.js
├── folder1
│ └── folder-inside.md
├── folder2
│ ├── inside1
│ │ └── 5555.txt
│ └── inside2
│ │ ├── hello.txt
│ │ └── staff
│ │ └── test.txt
├── some.html
└── filemap.js
├── package.json
├── LICENSE
├── README.md
└── filemap.js
/example/test.md:
--------------------------------------------------------------------------------
1 | hello
--------------------------------------------------------------------------------
/example/empty.js:
--------------------------------------------------------------------------------
1 | // an empty file
--------------------------------------------------------------------------------
/example/folder1/folder-inside.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/folder2/inside1/5555.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/folder2/inside2/hello.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/folder2/inside2/staff/test.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/some.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Filemap.js
6 |
7 |
8 | Hello filemap!
9 |
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "filemap.js",
3 | "version": "0.0.3",
4 | "description": "A tool for creating files structure tree map.",
5 | "main": "filemap.js",
6 | "directories": {
7 | "example": "example"
8 | },
9 | "bin": {
10 | "filemap": "filemap.js"
11 | },
12 | "scripts": {
13 | "test": "echo \"Error: no test specified\" && exit 1"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/jrainlau/filemap.git"
18 | },
19 | "keywords": [
20 | "node"
21 | ],
22 | "author": "Jrain Lau",
23 | "license": "MIT",
24 | "bugs": {
25 | "url": "https://github.com/jrainlau/filemap/issues"
26 | },
27 | "homepage": "https://github.com/jrainlau/filemap#readme"
28 | }
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 JrainLau
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Introduce
2 | `filemap.js` is a tool for creating files structure tree map. It's light, fast, and clever. It helps you to creat a files structure tree map automatically by one line of command.
3 |
4 | if -d dir contains .gitignore, the script will read it and add lines to ignore configure.
5 |
6 | ## Usage && Example
7 | ```
8 | npm install filemap.js -g
9 |
10 | filemap
11 | ```
12 |
13 | And you will get a files structure tree map like this
14 | ```
15 | The files tree is:
16 | =================
17 |
18 | |__ empty.js
19 | |__ folder1
20 | |__ folder-inside.md
21 | |__ folder2
22 | |__ inside1
23 | |__ 5555.txt
24 | |__ inside2
25 | |__ hello.txt
26 | |__ staff
27 | |__ test.txt
28 | |__ some.html
29 | |__ TEST
30 | |__ xxx
31 | |__ test.md
32 | ```
33 |
34 | ## Options
35 | ```
36 | node tree.js -d ./project/ -i node_modules .DS_Store .dist > tree.text
37 | ```
38 | - -d: Read from dir.
39 | - -i: In order to ignore some folders which contains lots of files and folders, such as `node_modules` etc, you could use this command to avoid them to be unfolded. Use blank to split each `folder-name`.
40 |
41 | ## Update
42 | Set the `filemap.js` into global command.
43 |
44 | ## License
45 | MIT
46 |
--------------------------------------------------------------------------------
/example/filemap.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /**
4 | * @author Jrain Lau
5 | * @email jrainlau@163.com
6 | * @date 2016-07-14
7 | */
8 |
9 | 'use strict'
10 | const fs = require('fs')
11 |
12 | let ignoreCase = {}
13 | if(process.argv[2] === '-i'){
14 | for (let i of process.argv.slice(3)) {
15 | ignoreCase[i] = true
16 | }
17 | }
18 |
19 | console.log('\n\nThe files tree is:\n=================\n\n')
20 |
21 | const placeHolder = (num) => {
22 | if (placeHolder.cache[num]) return placeHolder.cache[num] + '|__'
23 | placeHolder.cache[num] = ''
24 | for (let i = 0; i < num; i++) {
25 | placeHolder.cache[num] += ' '
26 | }
27 | return placeHolder.cache[num] + '|__'
28 | }
29 | placeHolder.cache = {}
30 |
31 | let isDic = (url) => fs.statSync(url).isDirectory()
32 |
33 | const traverseFiles = (path, deep) => {
34 | let files = fs.readdirSync(path)
35 | let con = false
36 | for (let i = 0, len = files.length; i < len; i++) {
37 | if (files[i] !== 'filemap.js') console.log(placeHolder(deep), files[i])
38 | con = ignoreCase[files[i]] === undefined? true: false
39 | let dirPath = path + '\\' + files[i]
40 | if (isDic(dirPath) && con) traverseFiles(dirPath, deep + 1)
41 | }
42 | }
43 |
44 | traverseFiles('./', 1)
45 |
46 | process.exit()
--------------------------------------------------------------------------------
/filemap.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /**
4 | * @author Jrain Lau
5 | * @email jrainlau@163.com
6 | * @date 2016-07-14
7 | */
8 |
9 | 'use strict'
10 | const fs = require('fs');
11 |
12 | String.prototype.trim = function (char, type) {
13 | if (char) {
14 | if (type == 'left') {
15 | return this.replace(new RegExp('^\\'+char+'+', 'g'), '');
16 | } else if (type == 'right') {
17 | return this.replace(new RegExp('\\'+char+'+$', 'g'), '');
18 | }
19 | return this.replace(new RegExp('^\\'+char+'+|\\'+char+'+$', 'g'), '');
20 | }
21 | return this.replace(/^\s+|\s+$/g, '');
22 | };
23 |
24 | // dir configure
25 | let findPath = null;
26 | if(process.argv[2] === '-d' && process.argv[3]){
27 | findPath = process.argv[3];
28 | } else {
29 | console.log('\n\nPath Arg Invalid\n\n');
30 | process.exit();
31 | }
32 |
33 | let ignoreCase = {}
34 | if(process.argv[4] === '-i'){
35 | for (let i of process.argv.slice(5)) {
36 | ignoreCase[i] = true
37 | }
38 | }
39 |
40 | // read git ignore
41 | const ignFile = `${findPath}/.gitignore`;
42 | if(fs.existsSync(ignFile)) {
43 | ignoreCase['.git'] = true; // ignore .git
44 | const ignText = fs.readFileSync(ignFile, 'utf8');
45 | const lines = ignText.split('\n');
46 | lines.forEach((line) => {
47 | if (line.length && line.indexOf('#') !== 0){
48 | ignoreCase[line.trim('/')] = true;
49 | }
50 | });
51 | }
52 |
53 | // console.log('\n\nIgnore: \n\n');
54 | // console.log(JSON.stringify(ignoreCase));
55 | console.log('\n\nThe files tree is:\n=================\n\n');
56 |
57 | const placeHolder = (num) => {
58 | if (placeHolder.cache[num]) return placeHolder.cache[num] + '|__'
59 | placeHolder.cache[num] = ''
60 | for (let i = 0; i < num; i++) {
61 | placeHolder.cache[num] += ' '
62 | }
63 | return placeHolder.cache[num] + '|__'
64 | }
65 | placeHolder.cache = {}
66 |
67 | let isDic = (url) => fs.statSync(url).isDirectory()
68 |
69 | const traverseFiles = (path, deep) => {
70 | let files = fs.readdirSync(path)
71 | let con = false
72 | for (let i = 0, len = files.length; i < len; i++) {
73 | con = ignoreCase[files[i].trim('/')] === undefined? true: false;
74 | if(con) console.log(placeHolder(deep), files[i]); // if ignored, don't show it
75 | let dirPath = path + '/' + files[i];
76 | if (isDic(dirPath) && con) traverseFiles(dirPath, deep + 1)
77 | }
78 | }
79 |
80 | traverseFiles(findPath, 1)
81 |
82 | process.exit();
83 |
--------------------------------------------------------------------------------