@khatastroffik/treefolder 1.4.0 → 1.5.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.
Files changed (3) hide show
  1. package/README.md +23 -3
  2. package/dist/index.js +30 -26
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -44,7 +44,8 @@ This is the recommanded and easiest approach.
44
44
  1. [Extended help / man page](#extended-halp--man-page)
45
45
  1. [Verbose output](#verbose-output)
46
46
  1. [Debug Output](#debug-output)
47
- 1. Limit scanning / output size (todo)
47
+ 1. [Limit the maximum amount of processed items / limit the output size](#limit-the-amount-of-processed-items)
48
+ 1. [Clear screen (command line stdout) forehand](#clear-the-command-line-screen-before-displaying-the-result)
48
49
  1. Set default options/flags per env variables (todo)
49
50
  1. Auto update (in evaluation)
50
51
 
@@ -71,7 +72,7 @@ This behavior can be _disabled_ using the command line argument `--unsorted` or
71
72
 
72
73
  ### List output
73
74
 
74
- When the command line argument `--list` (short: `-l`) is used, all the folders and files will be displayed as a flat list instead of as a treeview.
75
+ When the command line argument `--list` or `-l` is used, all the folders and files will be displayed as a flat list instead of as a treeview.
75
76
 
76
77
  Note: the command line arguments `--unsorted` and `--style colored` may also be applied to refine i.e. adapt the list output. See the [List output examples](docs/readme.md#list-output-examples)
77
78
 
@@ -91,17 +92,36 @@ Notes:
91
92
 
92
93
  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
 
95
+ Note: this flag is having the second highest priority - after the _help_ flag: if set, it will dismiss all other options/flag (but the _clear_ and _help_ flag).
96
+
94
97
  ### Extended halp / man page
95
98
 
96
99
  Use the command line argument `--help` or `-h` to display detailled instructions and hints about using treefolder in a suitable way.
97
100
 
101
+ Note: this flag is having the highest priority: if set, it will dismiss all other options/flag (but the _clear_ flag, which may always be triggered).
102
+
98
103
  ### Verbose output
99
104
 
100
105
  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.
101
106
 
102
107
  ### Debug output
103
108
 
104
- Use the flag `--debug` (short `-d`) to display additional information about the used tool configuration.
109
+ Use the flag `--debug` or `-d` to display additional information about the used tool configuration.
110
+
111
+ ### Limit the amount of processed items
112
+
113
+ In order to avoid very long processing time and memory consumption/wastage, _treefolder_ defines a default amount of items (folders + files), that may be processed i.e. displayed at once.
114
+
115
+ The _default_ limit is: **`500` items**.
116
+
117
+ If you'd like or await to proceed with more than this limit, then you may rise it using the `--max-items` or `-m` command line argument.
118
+ The _max-items_ value must be a _valid number_ and must not be below `1` or above `32768`.
119
+
120
+ _Treefolder_ will exit with an **error** if the (default or manually defined) limit is reached or if the _max-items_ command line argument is not valid.
121
+
122
+ ### Clear the command line screen before displaying the result
123
+
124
+ Use the flag `--clear` or `-c` to cleanup the command line (_stdout_) screen before displaying the result.
105
125
 
106
126
  ## Development
107
127
 
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #! /usr/bin/env node
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}
2
+ "use strict";var U=Object.create;var A=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var Y=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of G(t))!X.call(e,s)&&s!==n&&A(e,s,{get:()=>t[s],enumerable:!(i=_(t,s))||i.enumerable});return e};var b=(e,t,n)=>(n=e!=null?U(J(e)):{},Y(t||!e||!e.__esModule?A(n,"default",{value:e,enumerable:!0}):n,e));var k=b(require("node:path"));var L=require("node:process"),r=class e{static _folderCount=0;static _fileCount=0;static ignoredCount=0;static commandLineArgs={};static pad=" ";static maxOutputWidth=L.stdout.columns-e.pad.length;static maxItems=500;static maxItemsCountReached(){return e.totalItemsCount>e.maxItems}static get totalItemsCount(){return e._folderCount+e._fileCount}static get folderCount(){return e._folderCount}static incFolderCount(){e._folderCount++}static get fileCount(){return e._fileCount}static incFileCount(){e._fileCount++}};var f=require("node:process"),c=require("node:util");var g="1.5.0";var C={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."},"max-items":{type:"string",default:"",short:"m",description:`Define the maximum numbers of processable items (folders + files). If this limit is reached, the tool will exit with an error and won't display any result.
3
+ -> Min value: 1
4
+ -> Max value: 32768`},clear:{type:"boolean",default:!1,short:"c",description:"Clear the (stdout) screen prior displaying the result."}};function l(e){return(0,c.styleText)("yellow",`${e}`)}function a(e){return(0,c.styleText)("blueBright",`${e}`)}function I(e){return(0,c.styleText)("redBright",`${e}`)}async function ee(){let e=await fetch("https://registry.npmjs.org/@khatastroffik/treefolder");return await new Promise(i=>setTimeout(i,100)),(await e.json())["dist-tags"].latest}function d(e){return e.replace(new RegExp(`(?![^\\n]{1,${r.maxOutputWidth}}$)([^\\n]{1,${r.maxOutputWidth}})\\s`,"g"),`${r.pad}$1
5
+ `)}function te(e,t){let n=t.short?`-${t.short}, `:"",i=t.type==="string"?` <${e}-value>`:"";return d(l(`${n}--${e}${i}
6
+ `))+d(`${t.description}
5
7
 
6
- `)}async function A(){if(o.version){let e=`
8
+ `)}async function O(){if(o.version){let e=`
7
9
  \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
8
10
  | |
9
11
  \u256D\u2501\u2533\u2501\u256D\u2501\u256D\u2501\u256E\u256E
@@ -16,42 +18,44 @@
16
18
  \u2523\u2501\u2501\u2501\u2501\u2501\u2501\u252B
17
19
  | |
18
20
  \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
19
- `,t,n=await G();return n&&n!==m&&(t=(0,c.styleText)("yellow",`
21
+ `,t,n=await ee();return n&&n!==g&&(t=(0,c.styleText)("yellow",`
20
22
  \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
21
23
  | A new version of Treefolder is available: |
22
- | current: ${m} -> latest: ${n} |
24
+ | current: ${g} -> latest: ${n} |
23
25
  | |
24
26
  | Install the latest version with: |
25
27
  | "npm update -g @khatastroffik/treefolder@latest" |
26
28
  \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
27
- `)),console.info(i(`
29
+ `)),console.info(a(`
28
30
  Treefolder aka "tfold"
29
- Version ${m}
31
+ Version ${g}
30
32
 
31
33
  https://npmjs.com/@khatastroffik/treefolder
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
+ ${t??e}`)),(0,f.exit)(0)}}function $(){r.maxItemsCountReached()&&(console.error(I(`[LIMIT REACHED] The maximum number of processible items has been reached:
35
+ `)),S(),console.error(I(`Please define a higher limit using the ${l("'--max-items'")} command line argument if you want to output more items in the result.`)),(0,f.exit)(1))}function M(e){let t=Number.parseInt(e,10);return(Number.isNaN(t)||t<1||t>32768)&&(console.info(I(`[BAD LIMIT] The value of the ${l("'--maxItems'")} command line argument must be a valid number and must not be below ${l("1")} or above ${l("32768")}. The current argument value is ${l(e)}.
36
+ `)),(0,f.exit)(1)),t}async function S(){console.info(a("Processed items (so far):"));let e={folderCount:r.folderCount,fileCount:r.fileCount,totalItemsCount:r.totalItemsCount,maxItems:r.maxItems,ignoredCount:r.ignoredCount};console.info(e)}async function N(){o.debug&&(console.info(a("Command line arguments:")),console.info(r.commandLineArgs),console.info(a("Treefolder configuration:")),console.info(o),S())}async function V(){o.verbose&&(console.info(a(`Scanned : ${l(r.folderCount.toString())} folders and ${l(r.fileCount.toString())} files.`)),console.info(a(`Filtered out : ${l(r.ignoredCount.toString())} folders or files.`)))}async function B(){if(o.help){let e=a(`Treefolder version ${g}
37
+ `),t=a(`Usage:
34
38
 
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
+ `);t+=d(`tfold [flags] [options] [root folder]
40
+ `),t+=d(a(`or
41
+ `)),t+=d(`treefolder [flags] [options] [root folder]
42
+ `);let n=`${a(`Example:
39
43
 
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:
44
+ `)}`;n+=d(l(`tfold -s colored --verbose -du
45
+ `)),n+=d(`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.
46
+ `);let i=`${a(`Notes:
43
47
 
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.
48
+ `)}`;i+=d(`The position of the [flags], [options] and [root folder] command line arguments doesn't matter as long as those are well-formed/valid.
45
49
 
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:
50
+ `),i+=d(`The positional argument [root folder] may be ommited. In this case, the current working directory will be processed.
51
+ `);let s=a(`Options and Flags:
48
52
 
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();
53
+ `);s+=Object.keys(C).reduce((w,h)=>w+te(h,C[h]),""),console.info([e,t,n,s,i].join(`
54
+ `)),(0,f.exit)(0)}}function E(){o.clear&&f.stdout.write("\x1Bc")}function R(){try{return(0,c.parseArgs)({options:C,allowPositionals:!0,strict:!0})}catch(e){let t=e;return console.error(`[${(0,c.styleText)("red",t.name)}]: ${t.message}`),(0,f.exit)(1)}}var u=" ",T=(s=>(s.none="none",s.wireframe="wireframe",s.black="black",s.colored="colored",s))(T||{}),W={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:W.none,root:".",ignores:["node_modules","dist","build",".git",".husky\\_","logs",".angular","coverage"],verbose:!1,unsorted:!1,formatAsList:!1,version:!1,debug:!1,help:!1,maxItems:r.maxItems,clear:!1};async function H(){let{values:e,positionals:t}=R();o.version=e.version,o.formatAsList=e.list,o.style=T[e.style]??o.style,o.symbols=W[o.style],o.root=k.default.resolve(t[0]??o.root),o.ignores=o.ignores.map(n=>k.default.join(o.root,n)),o.unsorted=e.unsorted,o.verbose=e.verbose,o.debug=e.debug,o.help=e.help,o.maxItems=e["max-items"]?M(e["max-items"]):r.maxItems,o.clear=e.clear,r.maxItems=o.maxItems,r.commandLineArgs={...e,root:t[0]??"n/a"}}var z=b(require("node:fs")),m=b(require("node:path")),x=b(require("node:util"));var oe=x.default.promisify(z.default.readdir),F,P;function ne(e){return`${e.indent+e.folderPrefix+e.foldersymbol+m.default.basename(e.folderName)}
55
+ `}function re(e){return`${e.indent+e.contentItemPrefix+e.entityPrefix+e.contentItem.name}
56
+ `}function se(e){let t=e.folderName+m.default.sep;return o.style==="colored"&&(t=(0,x.styleText)("blueBright",t)),`${t}
57
+ `}function ie(e){return`${m.default.join(e.contentItem.parentPath,e.contentItem.name)}
58
+ `}function ae(e,t){return e.isDirectory()?t.isFile()?-1:e.name.localeCompare(t.name):t.isDirectory()?1:e.name.localeCompare(t.name)}function le(e,t){let n=o.ignores.includes(m.default.join(e,t));return n&&r.ignoredCount++,n}async function de(e){let t=(await oe(e,{withFileTypes:!0})).filter(n=>!le(e,n.name));return o.unsorted?t:t.sort(ae)}async function K(e,t,n,i){let s=await de(e),w=s.length<1?o.symbols.closed:o.symbols.open,h=n?"":(i?"\u2514\u2500":"\u251C\u2500")+(o.symbols.open?"":u),v=F({indent:t,folderPrefix:h,foldersymbol:w,folderName:e}),D=n?"":i?`${u}${u}${u}`:`\u2502${u}${u}`,j=s.length-1;for(let p=0;p<s.length;p++){let y=s[p];if(y.isDirectory()&&(v+=await K(m.default.join(e,y.name),t+D,!1,p===j)),y.isFile()){r.incFileCount(),$();let Q=p===j?`\u2514\u2500${o.symbols.file}${u}`:`\u251C\u2500${o.symbols.file}${u}`;v+=P({indent:t,contentItemPrefix:D,entityPrefix:Q,contentItem:y})}}return r.incFolderCount(),$(),v}async function q(){F=ne,P=re,o.formatAsList&&(F=se,P=ie);let e=await K(o.root,"",!0,!0);console.info(e)}async function ue(){await H(),await E(),await B(),await O(),await q(),await N(),await V()}ue();
55
59
  /*!
56
60
  * @khatastroffik/treefolder
57
61
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khatastroffik/treefolder",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "devEngines": {
5
5
  "packageManager": [
6
6
  {