@khatastroffik/treefolder 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/dist/index.js +32 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,8 +41,12 @@ This is the recommanded and easiest approach.
|
|
|
41
41
|
1. [List output](#list-output)
|
|
42
42
|
1. [Styled output](#styled-output)
|
|
43
43
|
1. [Version information](#version-information)
|
|
44
|
+
1. [Extended help / man page](#extended-halp--man-page)
|
|
44
45
|
1. [Verbose output](#verbose-output)
|
|
45
46
|
1. [Debug Output](#debug-output)
|
|
47
|
+
1. Limit scanning / output size (todo)
|
|
48
|
+
1. Set default options/flags per env variables (todo)
|
|
49
|
+
1. Auto update (in evaluation)
|
|
46
50
|
|
|
47
51
|
### Auto "root folder"
|
|
48
52
|
|
|
@@ -63,7 +67,7 @@ Notes:
|
|
|
63
67
|
|
|
64
68
|
By default, the list or the leaves of the treeview are sorted following the _"folders first" principle_: All the folders are listed first, then all the files. All items are alphabetically sorted. This apply at any depth within the tree structure.
|
|
65
69
|
|
|
66
|
-
This behavior can be _disabled_ using the command line argument `--unsorted`. In this case, all items are sorted the way the operating system does by default e.g. sorted by their names, regardless of their type (directory or file).
|
|
70
|
+
This behavior can be _disabled_ using the command line argument `--unsorted` or `-u`. In this case, all items are sorted the way the operating system does by default e.g. sorted by their names, regardless of their type (directory or file).
|
|
67
71
|
|
|
68
72
|
### List output
|
|
69
73
|
|
|
@@ -85,11 +89,15 @@ Notes:
|
|
|
85
89
|
|
|
86
90
|
### Version information
|
|
87
91
|
|
|
88
|
-
Use the command line argument `--version` or `-v` to display the version information about the tool.
|
|
92
|
+
Use the command line argument `--version` or `-v` to display the version information about the tool and eventually inform about the _availability of an updated version_ of treefolder.
|
|
93
|
+
|
|
94
|
+
### Extended halp / man page
|
|
95
|
+
|
|
96
|
+
Use the command line argument `--help` or `-h` to display detailled instructions and hints about using treefolder in a suitable way.
|
|
89
97
|
|
|
90
98
|
### Verbose output
|
|
91
99
|
|
|
92
|
-
When the flag i.e. command line argument `--verbose` is defined/set, then a few more information will be displayed together with the tree representation.
|
|
100
|
+
When the flag i.e. command line argument `--verbose` or `-b` is defined/set, then a few more information will be displayed together with the tree representation.
|
|
93
101
|
|
|
94
102
|
### Debug output
|
|
95
103
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var R=Object.create;var j=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var Q=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!q.call(e,s)&&s!==n&&j(e,s,{get:()=>t[s],enumerable:!(a=z(t,s))||a.enumerable});return e};var y=(e,t,n)=>(n=e!=null?R(_(e)):{},Q(t||!e||!e.__esModule?j(n,"default",{value:e,enumerable:!0}):n,e));var $=y(require("node:path"));var D=require("node:process"),r=class{static folderCount=1;static fileCount=0;static ignoredCount=0;static commandLineArgs={};static pad=" ";static maxWidth=D.stdout.columns-this.pad.length};var b=require("node:process"),c=require("node:util");var m="1.4.0";var k={style:{type:"string",default:"none",short:"s",description:`The style value can be set to 'none', 'colored', 'black' or 'wireframe' (without the quotes) e.g. "-style colored". The default style is 'none' and may be ommited.`},verbose:{type:"boolean",default:!1,short:"b",description:"Display extended information about the result after the standard output."},unsorted:{type:"boolean",default:!1,short:"u",description:"Do not enforce sorting folders first i.e. on top of the result. Instead, rely on the OS i.e. command line environment native sorting algorythm."},version:{type:"boolean",default:!1,short:"v",description:"Display version information about the tool and eventually inform about the availability of an updated version."},list:{type:"boolean",default:!1,short:"l",description:"Display the result as a simple list (with full path) instead of as a treeview."},debug:{type:"boolean",default:!1,short:"d",description:"Display some hints about the configuration used to generate the resulting output."},help:{type:"boolean",default:!1,short:"h",description:"Display THIS help information about the usage of treefolder."}};function f(e){return(0,c.styleText)("yellow",`${e}`)}function i(e){return(0,c.styleText)("blueBright",`${e}`)}async function G(){let e=await fetch("https://registry.npmjs.org/@khatastroffik/treefolder");return await new Promise(a=>setTimeout(a,100)),(await e.json())["dist-tags"].latest}function l(e){return e.replace(new RegExp(`(?![^\\n]{1,${r.maxWidth}}$)([^\\n]{1,${r.maxWidth}})\\s`,"g"),`${r.pad}$1
|
|
3
|
+
`)}function J(e,t){let n=t.short?`-${t.short}, `:"",a=t.type==="string"?` <${e}-value>`:"";return l(f(`${n}--${e}${a}
|
|
4
|
+
`))+l(`${t.description}
|
|
5
|
+
|
|
6
|
+
`)}async function A(){if(o.version){let e=`
|
|
3
7
|
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
4
8
|
| |
|
|
5
9
|
\u256D\u2501\u2533\u2501\u256D\u2501\u256D\u2501\u256E\u256E
|
|
@@ -12,25 +16,42 @@
|
|
|
12
16
|
\u2523\u2501\u2501\u2501\u2501\u2501\u2501\u252B
|
|
13
17
|
| |
|
|
14
18
|
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 made by khatastroffik \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
15
|
-
`,t,n=await G();return n&&n!==
|
|
19
|
+
`,t,n=await G();return n&&n!==m&&(t=(0,c.styleText)("yellow",`
|
|
16
20
|
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
17
21
|
| A new version of Treefolder is available: |
|
|
18
|
-
| current: ${
|
|
22
|
+
| current: ${m} -> latest: ${n} |
|
|
19
23
|
| |
|
|
20
24
|
| Install the latest version with: |
|
|
21
25
|
| "npm update -g @khatastroffik/treefolder@latest" |
|
|
22
26
|
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
|
|
23
|
-
`)),console.info(
|
|
27
|
+
`)),console.info(i(`
|
|
24
28
|
Treefolder aka "tfold"
|
|
25
|
-
Version ${
|
|
29
|
+
Version ${m}
|
|
26
30
|
|
|
27
31
|
https://npmjs.com/@khatastroffik/treefolder
|
|
28
|
-
${t??e}`)),(0,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
`
|
|
32
|
-
`
|
|
33
|
-
`
|
|
32
|
+
${t??e}`)),(0,b.exit)(0)}}async function L(){o.debug&&(console.info(i("Command line arguments:")),console.info(r.commandLineArgs),console.info(i("Treefolder configuration:")),console.info(o),console.info(i("FolderCount :"),f(r.folderCount.toString())),console.info(i("FileCount :"),f(r.fileCount.toString())),console.info(i("IgnoredCount :"),f(r.ignoredCount)))}async function O(){o.verbose&&(console.info(i(`Scanned : ${f(r.folderCount.toString())} folders and ${f(r.fileCount.toString())} files.`)),console.info(i(`Filtered out : ${f(r.ignoredCount.toString())} folders or files.`)))}async function S(){if(o.help){let e=i(`Treefolder version ${m}
|
|
33
|
+
`),t=i(`Usage:
|
|
34
|
+
|
|
35
|
+
`);t+=l(`tfold [flags] [options] [root folder]
|
|
36
|
+
`),t+=l(i(`or
|
|
37
|
+
`)),t+=l(`treefolder [flags] [options] [root folder]
|
|
38
|
+
`);let n=`${i(`Example:
|
|
39
|
+
|
|
40
|
+
`)}`;n+=l(f(`tfold -s colored --verbose -du
|
|
41
|
+
`)),n+=l(`This command line outputs a colored treeview representation of the current directory content. The leaves are "unsorted". The output includes additional infos and debug hints.
|
|
42
|
+
`);let a=`${i(`Notes:
|
|
43
|
+
|
|
44
|
+
`)}`;a+=l(`The position of the [flags], [options] and [root folder] command line arguments doesn't matter as long as those are well-formed/valid.
|
|
45
|
+
|
|
46
|
+
`),a+=l(`The positional argument [root folder] may be ommited. In this case, the current working directory will be processed.
|
|
47
|
+
`);let s=i(`Options and Flags:
|
|
48
|
+
|
|
49
|
+
`);s+=Object.keys(k).reduce((w,g)=>w+J(g,k[g]),""),console.info([e,t,n,s,a].join(`
|
|
50
|
+
`)),(0,b.exit)(0)}}function V(){try{return(0,c.parseArgs)({options:k,allowPositionals:!0,strict:!0})}catch(e){let t=e;return console.error(`[${(0,c.styleText)("red",t.name)}]: ${t.message}`),(0,b.exit)(1)}}var d=" ",C=(s=>(s.none="none",s.wireframe="wireframe",s.black="black",s.colored="colored",s))(C||{}),N={none:{closed:"",open:"",file:""},wireframe:{closed:"\u{1F5C0} ",open:"\u{1F5C1} ",file:"\u{1F5CB}"},black:{closed:"\u{1F5BF} ",open:"\u{1F5BF} ",file:"\u{1F5CE}"},colored:{closed:"\u{1F4C1} ",open:"\u{1F4C2} ",file:"\u{1F4C4}"}},o={style:"none",symbols:N.none,root:".",ignores:["node_modules","dist","build",".git",".husky\\_","logs",".angular","coverage"],verbose:!1,unsorted:!1,formatAsList:!1,version:!1,debug:!1,help:!1};async function W(){let{values:e,positionals:t}=V();o.version=e.version,o.formatAsList=e.list,o.style=C[e.style]??o.style,o.symbols=N[o.style],o.root=$.default.resolve(t[0]??o.root),o.ignores=o.ignores.map(n=>$.default.join(o.root,n)),o.unsorted=e.unsorted,o.verbose=e.verbose,o.debug=e.debug,o.help=e.help,r.commandLineArgs={...e,root:t[0]??"n/a"}}var E=y(require("node:fs")),p=y(require("node:path")),x=y(require("node:util"));var X=x.default.promisify(E.default.readdir),F,P;function Y(e){return`${e.indent+e.folderPrefix+e.foldersymbol+p.default.basename(e.folderName)}
|
|
51
|
+
`}function Z(e){return`${e.indent+e.contentItemPrefix+e.entityPrefix+e.contentItem.name}
|
|
52
|
+
`}function ee(e){let t=e.folderName+p.default.sep;return o.style==="colored"&&(t=(0,x.styleText)("blueBright",t)),`${t}
|
|
53
|
+
`}function te(e){return`${p.default.join(e.contentItem.parentPath,e.contentItem.name)}
|
|
54
|
+
`}function oe(e,t){return e.isDirectory()?t.isFile()?-1:e.name.localeCompare(t.name):t.isDirectory()?1:e.name.localeCompare(t.name)}function ne(e,t){let n=o.ignores.includes(p.default.join(e,t));return n&&r.ignoredCount++,n}async function re(e){let t=(await X(e,{withFileTypes:!0})).filter(n=>!ne(e,n.name));return o.unsorted?t:t.sort(oe)}async function B(e,t,n,a){let s=await re(e),w=s.length<1?o.symbols.closed:o.symbols.open,g=n?"":(a?"\u2514\u2500":"\u251C\u2500")+(o.symbols.open?"":d),v=F({indent:t,folderPrefix:g,foldersymbol:w,folderName:e}),T=n?"":a?`${d}${d}${d}`:`\u2502${d}${d}`,I=s.length-1;for(let u=0;u<s.length;u++){let h=s[u];if(h.isDirectory()&&(v+=await B(p.default.join(e,h.name),t+T,!1,u===I)),h.isFile()){r.fileCount++;let M=u===I?`\u2514\u2500${o.symbols.file}${d}`:`\u251C\u2500${o.symbols.file}${d}`;v+=P({indent:t,contentItemPrefix:T,entityPrefix:M,contentItem:h})}}return r.folderCount++,v}async function H(){F=Y,P=Z,o.formatAsList&&(F=ee,P=te);let e=await B(o.root,"",!0,!0);console.info(e)}async function se(){await W(),await S(),await A(),await H(),await L(),await O()}se();
|
|
34
55
|
/*!
|
|
35
56
|
* @khatastroffik/treefolder
|
|
36
57
|
*
|