@khatastroffik/treefolder 1.3.1 → 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 +33 -5
  2. package/dist/index.js +36 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -41,8 +41,13 @@ 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 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)
49
+ 1. Set default options/flags per env variables (todo)
50
+ 1. Auto update (in evaluation)
46
51
 
47
52
  ### Auto "root folder"
48
53
 
@@ -63,11 +68,11 @@ Notes:
63
68
 
64
69
  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
70
 
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).
71
+ 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
72
 
68
73
  ### List output
69
74
 
70
- 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.
71
76
 
72
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)
73
78
 
@@ -85,15 +90,38 @@ Notes:
85
90
 
86
91
  ### Version information
87
92
 
88
- Use the command line argument `--version` or `-v` to display the version information about the tool.
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.
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
+
97
+ ### Extended halp / man page
98
+
99
+ Use the command line argument `--help` or `-h` to display detailled instructions and hints about using treefolder in a suitable way.
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).
89
102
 
90
103
  ### Verbose output
91
104
 
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.
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.
93
106
 
94
107
  ### Debug output
95
108
 
96
- 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.
97
125
 
98
126
  ## Development
99
127
 
package/dist/index.js CHANGED
@@ -1,5 +1,11 @@
1
1
  #! /usr/bin/env node
2
- "use strict";var O=Object.create;var F=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var R=(e,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of M(t))!K.call(e,i)&&i!==n&&F(e,i,{get:()=>t[i],enumerable:!(l=S(t,i))||l.enumerable});return e};var u=(e,t,n)=>(n=e!=null?O(z(e)):{},R(t||!e||!e.__esModule?F(n,"default",{value:e,enumerable:!0}):n,e));var b=u(require("node:path"));var s=class{static folderCount=1;static fileCount=0;static ignoredCount=0;static commandLineArgs={}};var h=require("node:process"),f=require("node:util");var p="1.3.1";function r(e){return(0,f.styleText)(typeof e=="number"?"yellow":"blueBright",`${e}`)}async function G(){let e=await fetch("https://registry.npmjs.org/@khatastroffik/treefolder");return await new Promise(l=>setTimeout(l,100)),(await e.json())["dist-tags"].latest}async function $(){if(o.version){let e=`
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}
7
+
8
+ `)}async function O(){if(o.version){let e=`
3
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
4
10
  | |
5
11
  \u256D\u2501\u2533\u2501\u256D\u2501\u256D\u2501\u256E\u256E
@@ -12,25 +18,44 @@
12
18
  \u2523\u2501\u2501\u2501\u2501\u2501\u2501\u252B
13
19
  | |
14
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
15
- `,t,n=await G();return n&&n!==p&&(t=(0,f.styleText)("yellow",`
21
+ `,t,n=await ee();return n&&n!==g&&(t=(0,c.styleText)("yellow",`
16
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
17
23
  | A new version of Treefolder is available: |
18
- | current: ${p} -> latest: ${n} |
24
+ | current: ${g} -> latest: ${n} |
19
25
  | |
20
26
  | Install the latest version with: |
21
27
  | "npm update -g @khatastroffik/treefolder@latest" |
22
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
23
- `)),console.info(r(`
29
+ `)),console.info(a(`
24
30
  Treefolder aka "tfold"
25
- Version ${p}
31
+ Version ${g}
26
32
 
27
33
  https://npmjs.com/@khatastroffik/treefolder
28
- ${t??e}`)),(0,h.exit)(0)}}async function P(){o.debug&&(console.info(r(`${"+".repeat(26)} DEBUG ${"+".repeat(27)}`)),console.info(r("Command line arguments:")),console.info(s.commandLineArgs),console.info(r("Treefolder configuration:")),console.info(o),console.info(r("FolderCount:"),r(s.folderCount)),console.info(r("FileCount:"),r(s.fileCount)),console.info(r("IgnoredCount:"),r(s.ignoredCount)),console.info(r("+".repeat(60))))}async function j(){o.verbose&&(console.info(r(`
29
- Scanned ${r(s.folderCount)} folders and ${r(s.fileCount)} files.`)),console.info(r(`Filtered out ${r(s.ignoredCount)} items (folders or files).`)))}var Q={style:{type:"string",default:"none",short:"s"},verbose:{type:"boolean",default:!1},unsorted:{type:"boolean",default:!1,short:"u"},version:{type:"boolean",default:!1,short:"v"},list:{type:"boolean",default:!1,short:"l"},debug:{type:"boolean",default:!1,short:"d"}};function I(){try{return(0,f.parseArgs)({options:Q,allowPositionals:!0,strict:!0})}catch(e){let t=e;return console.error(`[${(0,f.styleText)("red",t.name)}]: ${t.message}`),(0,h.exit)(1)}}var a=" ",x=(i=>(i.none="none",i.wireframe="wireframe",i.black="black",i.colored="colored",i))(x||{}),T={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:T.none,root:".",ignores:["node_modules","dist","build",".git",".husky\\_","logs",".angular","coverage"],verbose:!1,unsorted:!1,formatAsList:!1,version:!1,debug:!1};async function D(){let{values:e,positionals:t}=I();o.version=e.version,o.formatAsList=e.list,o.style=x[e.style]??o.style,o.symbols=T[o.style],o.root=b.default.resolve(t[0]??o.root),o.ignores=o.ignores.map(n=>b.default.join(o.root,n)),o.unsorted=e.unsorted,o.verbose=e.verbose,o.debug=e.debug,s.commandLineArgs={...e,root:t[0]??"n/a"}}var L=u(require("node:fs")),d=u(require("node:path")),g=u(require("node:util"));var U=g.default.promisify(L.default.readdir),w,k;function W(e){return`${e.indent+e.folderPrefix+e.foldersymbol+d.default.basename(e.folderName)}
30
- `}function q(e){return`${e.indent+e.contentItemPrefix+e.entityPrefix+e.contentItem.name}
31
- `}function J(e){let t=e.folderName+d.default.sep;return o.style==="colored"&&(t=(0,g.styleText)("blueBright",t)),`${t}
32
- `}function X(e){return`${d.default.join(e.contentItem.parentPath,e.contentItem.name)}
33
- `}function Y(e,t){return e.isDirectory()?t.isFile()?-1:e.name.localeCompare(t.name):t.isDirectory()?1:e.name.localeCompare(t.name)}function Z(e,t){let n=o.ignores.includes(d.default.join(e,t));return n&&s.ignoredCount++,n}async function H(e){let t=(await U(e,{withFileTypes:!0})).filter(n=>!Z(e,n.name));return o.unsorted?t:t.sort(Y)}async function A(e,t,n,l){let i=await H(e),B=i.length<1?o.symbols.closed:o.symbols.open,N=n?"":(l?"\u2514\u2500":"\u251C\u2500")+(o.symbols.open?"":a),y=w({indent:t,folderPrefix:N,foldersymbol:B,folderName:e}),v=n?"":l?`${a}${a}${a}`:`\u2502${a}${a}`,C=i.length-1;for(let c=0;c<i.length;c++){let m=i[c];if(m.isDirectory()&&(y+=await A(d.default.join(e,m.name),t+v,!1,c===C)),m.isFile()){s.fileCount++;let E=c===C?`\u2514\u2500${o.symbols.file}${a}`:`\u251C\u2500${o.symbols.file}${a}`;y+=k({indent:t,contentItemPrefix:v,entityPrefix:E,contentItem:m})}}return s.folderCount++,y}async function V(){w=W,k=q,o.formatAsList&&(w=J,k=X);let e=await A(o.root,"",!0,!0);console.info(e)}async function ee(){await D(),await $(),await V(),await P(),await j()}ee();
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:
38
+
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:
43
+
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:
47
+
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.
49
+
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:
52
+
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();
34
59
  /*!
35
60
  * @khatastroffik/treefolder
36
61
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khatastroffik/treefolder",
3
- "version": "1.3.1",
3
+ "version": "1.5.0",
4
4
  "devEngines": {
5
5
  "packageManager": [
6
6
  {