+5
-2
| { | ||
| "name": "dir2tree", | ||
| "version": "0.1.2", | ||
| "version": "0.2.0", | ||
| "main": "src/index.js", | ||
@@ -31,3 +31,6 @@ "scripts": { | ||
| }, | ||
| "license": "MIT" | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "mapfun": "^0.9.17" | ||
| } | ||
| } |
+38
-2
@@ -22,3 +22,3 @@ ## Demo | ||
| ``` | ||
| ####$ Arguments | ||
| #### Arguments | ||
| - **`ROOT`** : The path to the root directory that we want handle. it's ***`required`*** | ||
@@ -43,5 +43,41 @@ - **`OPTIONS`** : An object containing various configuration options to control the behavior of the tree generation.it's ***`optional`*** , These options might include : | ||
| - **`.write(Target, filename)`** | ||
| - **`.flat(depth, separator)`** | ||
| ### Use It in your Github Repository | ||
| ```mermaid | ||
| sequenceDiagram | ||
| Your repository ->> dir2tree: ... | ||
| dir2tree-->>Your repository:... | ||
| ``` | ||
| ```yml | ||
| name: Generate Directory Tree using zakarialaoui10/dir2tree | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| build: | ||
| permissions : | ||
| contents : write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| - name: Generate Directory Tree | ||
| uses: zakarialaoui10/dir2tree@main | ||
| - name: Commit & Push | ||
| run: | | ||
| git config user.name github-actions | ||
| git config user.email github-actions@github.com | ||
| git add -A . | ||
| git commit -m "generated by zakarialaoui10/dir2tree" | ||
| git push | ||
| env: | ||
| CUSTOM_TOKEN: ${{ secrets.CUSTOM_TOKEN }} | ||
| OWNER : ${{github.repository_owner}} | ||
| NAME : ${{github.event.repository.name}} | ||
| ``` | ||
| ## License | ||
| This projet is licensed under the terms of MIT License .<br> | ||
| <img src="https://img.shields.io/github/license/zakarialaoui10/zikojs?color=rgb%2820%2C21%2C169%29"> |
+20
-12
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const {mapfun,flat_obj}=require("mapfun") | ||
| const {should_skip_file,should_skip_folder}=require("./utils/skip.js"); | ||
| const {sort_files}=require("./utils/sort.js"); | ||
| const {filter_files}=require("./utils/filter.js"); | ||
| const {isDirectory}=require("./utils/general.js"); | ||
| const {add_to_tree}=require("./utils/general.js"); | ||
| const {file_metadata}=require("./utils/stats.js"); | ||
| function add_to_tree(key, value) { | ||
| const keys = key.split(path.sep); | ||
| const lastKeyIndex = keys.length - 1; | ||
| keys.reduce((subtree, currentKey, index) => { | ||
| if (!subtree[currentKey]) { | ||
| subtree[currentKey] = index === lastKeyIndex ? value : {}; | ||
| } | ||
| return subtree[currentKey]; | ||
| }, this.tree); | ||
| } | ||
| class Dir2Tree { | ||
@@ -76,3 +67,3 @@ constructor(root, options = {}, callbacks = {}) { | ||
| this?.callbacks?.map((n) => n(filePath, fileInfo)); | ||
| add_to_tree.call(this,fileName, fileInfo); | ||
| add_to_tree.call(this,fileName+"_"+extension, fileInfo); | ||
| } | ||
@@ -87,4 +78,21 @@ | ||
| } | ||
| flat(depth=1,separator="_"){ | ||
| this.tree=flat_obj(this.tree,depth,separator); | ||
| return this; | ||
| } | ||
| reduce(){ | ||
| return this; | ||
| } | ||
| sort(){ | ||
| return this; | ||
| } | ||
| filter(){ | ||
| return this; | ||
| } | ||
| map(callback,options={}){ | ||
| this.tree=mapfun(callback,options,this.tree); | ||
| return this; | ||
| } | ||
| } | ||
| const dir2tree = (root, options, callbacks=[]) => new Dir2Tree(root, options, callbacks); | ||
| module.exports = dir2tree; |
@@ -0,1 +1,19 @@ | ||
| const fs=require("fs") | ||
| const path=require("path") | ||
| // Native | ||
| // Marked.js | ||
| const markdown_to_html=(filePath,fileInfo)=>{ | ||
| const extension = path.basename(filePath).split(".")[1]; | ||
| if(marked && extension=="md")fileInfo.html=marked.parse(fs.readFileSync(filePath,"utf-8")); | ||
| } | ||
| // Highlight.js | ||
| const highlight=()=> | ||
| // Crypto.js | ||
| const crypt=()=>{} | ||
| const decrypt=()=>{} | ||
| // Sheet.js | ||
| const xls2json=()={} | ||
| const json2xls=()={} | ||
| // | ||
| const img2x=()=>{} |
| const path=require("path"); | ||
| const {isDirectory}=require("./general.js"); | ||
| const {is_directory}=require("./general.js"); | ||
| const {should_skip_file}=require("./skip.js") | ||
| function filter_files(files) { | ||
| return files.filter((file) => { | ||
| if (isDirectory(path.join(this.root, file))) { | ||
| if (is_directory(path.join(this.root, file))) { | ||
| return true; // Skip directories | ||
@@ -8,0 +8,0 @@ } |
+13
-2
| const fs=require("fs"); | ||
| function isDirectory(filePath) { | ||
| const path=require("path") | ||
| function is_directory(filePath) { | ||
| return fs.statSync(filePath).isDirectory(); | ||
| } | ||
| module.exports={isDirectory} | ||
| function add_to_tree(key, value) { | ||
| const keys = key.split(path.sep); | ||
| const lastKeyIndex = keys.length - 1; | ||
| keys.reduce((subtree, currentKey, index) => { | ||
| if (!subtree[currentKey]) { | ||
| subtree[currentKey] = index === lastKeyIndex ? value : {}; | ||
| } | ||
| return subtree[currentKey]; | ||
| }, this.tree); | ||
| } | ||
| module.exports={is_directory,add_to_tree} |
+8
-14
@@ -5,5 +5,5 @@ const path = require("path"); | ||
| if ( | ||
| this?.options?.skipFolder?.includes(path.basename(normalizedPath)) || | ||
| this?.options?.skipFile?.includes(path.basename(normalizedPath)) || | ||
| this?.options?.skipExtension?.includes( | ||
| this?.options?.skip?.folder?.includes(path.basename(normalizedPath)) || | ||
| this?.options?.skip?.file?.includes(path.basename(normalizedPath)) || | ||
| this?.options?.skip?.extension?.includes( | ||
| path.extname(normalizedPath).slice(1) | ||
@@ -15,14 +15,8 @@ ) | ||
| function should_skip_folder(filePath) { | ||
| if (typeof filePath !== 'string') { | ||
| return false; | ||
| } | ||
| const normalizedPath = path.normalize(filePath); | ||
| if (this?.options?.skipFolder?.includes(path.basename(normalizedPath))) { | ||
| return true; | ||
| } | ||
| return false; | ||
| if (typeof filePath !== 'string') return false; | ||
| const normalizedPath = path.normalize(filePath); | ||
| if (this?.options?.skipFolder?.includes(path.basename(normalizedPath))) | ||
| return true; | ||
| return false; | ||
| } | ||
| module.exports={should_skip_file,should_skip_folder} |
| const path=require("path"); | ||
| const fs=require("fs") | ||
| const {isDirectory}=require("./general.js"); | ||
| const {is_directory}=require("./general.js"); | ||
| function sort_files(files, order = 1) { | ||
@@ -10,4 +10,4 @@ return files.sort((a, b) => { | ||
| // Check if either of the files is a directory and handle accordingly | ||
| const isDirectoryA = isDirectory(filePathA); | ||
| const isDirectoryB = isDirectory(filePathB); | ||
| const isDirectoryA = is_directory(filePathA); | ||
| const isDirectoryB = is_directory(filePathB); | ||
@@ -14,0 +14,0 @@ if (isDirectoryA && !isDirectoryB) { |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
13126
17.12%234
17%82
78.26%0
-100%1
Infinity%6
20%+ Added
+ Added
+ Added