-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f67ae8c
commit 10ec590
Showing
7 changed files
with
587 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"Auth": { | ||
"Schema": { | ||
"content": "\r\n", | ||
"stats": { | ||
"length": 2, | ||
"size": 0.001953125, | ||
"lines": 2 | ||
}, | ||
"metadata": { | ||
"created": "2023-10-27T18:31:55.897Z", | ||
"modified": "2023-10-27T18:31:55.897Z", | ||
"permissions": 33206 | ||
} | ||
} | ||
}, | ||
"index": { | ||
"content": "const fs=require(\"fs\");\r\nconst path=require(\"path\");\r\nconst dir2tree=require(\"dir2tree\");\r\nconst {markdown_to_html}=require(\"../addons/index.js\")\r\nconst ROOT = path.join(process.cwd(),'.');\r\nconst TARGET = path.join(process.cwd(),\".\");\r\nconst MyTree = dir2tree(ROOT,{\r\n fileContent:true,\r\n sortBy:\"extension\",\r\n skipFile:[\"ger.md\"],\r\n skipFolder:[\".git\",\"node_modules\"],\r\n skipExtension:[\"json\"],\r\n},[markdown_to_html]);\r\n\r\nconsole.log(MyTree.tree)\r\nMyTree.write(TARGET,\"generated.json\")\r\n\r\n", | ||
"stats": { | ||
"length": 496, | ||
"size": 0.484375, | ||
"lines": 18 | ||
}, | ||
"metadata": { | ||
"created": "2023-10-27T18:31:55.897Z", | ||
"modified": "2023-10-27T18:31:55.897Z", | ||
"permissions": 33206 | ||
} | ||
}, | ||
"index2": { | ||
"content": "var $cFoub$fs = require(\"fs\");\r\nvar $cFoub$path = require(\"path\");\r\n\r\n\r\n\r\nvar $697a68694f2aacad$exports = {};\r\n/*\r\nDevelopped by zakaria elaloui\r\nGithub : https://github.com/zakarialaoui10\r\n*/ function $697a68694f2aacad$var$flat_obj(obj, depth = Infinity, separator = \".\", replacement = \"_\") {\r\n const result = {};\r\n let i = 0;\r\n function recurse(current, path = []) {\r\n if (i === depth) {\r\n Object.assign(result, current);\r\n return;\r\n }\r\n for(const key in current){\r\n const value = current[key];\r\n const newPath = [\r\n ...path,\r\n key\r\n ];\r\n if (typeof value === \"object\" && !Array.isArray(value)) recurse(value, newPath);\r\n else {\r\n const flatKey = newPath.join(separator).replace(new RegExp(`\\\\${separator}`, \"g\"), replacement);\r\n result[flatKey] = value;\r\n }\r\n i++;\r\n }\r\n }\r\n recurse(obj);\r\n return result;\r\n}\r\nconst $697a68694f2aacad$var$mapfun = (fun, { skip: skip = [], key: key = false, value: value = true } = {}, ...X)=>{\r\n const Y = X.map((x)=>{\r\n if (typeof skip === \"string\" || [\r\n null,\r\n undefined\r\n ].includes(skip)) skip = [\r\n skip\r\n ];\r\n const skipPrimitives = [];\r\n const skipObjects = [];\r\n skip.forEach((element)=>typeof element === \"object\" && element !== null ? skipObjects.push(element) : skipPrimitives.push(element));\r\n if (skipPrimitives.includes(typeof x) || skipPrimitives.includes(x)) return x;\r\n if (skipObjects.some((n)=>x instanceof n)) return x;\r\n if (x === null) return fun(null);\r\n if ([\r\n \"number\",\r\n \"string\",\r\n \"boolean\",\r\n \"bigint\",\r\n \"undefined\"\r\n ].includes(typeof x)) return fun(x);\r\n if (typeof x === \"symbol\") throw new Error(\"symbols are not supported yet !\");\r\n if (x instanceof Array) return x.map((n)=>$697a68694f2aacad$var$mapfun(fun, {}, n));\r\n if (ArrayBuffer.isView(x)) return Array.from(x).map((n)=>fun(n));\r\n if (x instanceof Set) return new Set($697a68694f2aacad$var$mapfun(fun, {}, ...[\r\n ...x\r\n ]));\r\n if (x instanceof WeakSet) throw new Error(\"WeakSets not supported yet !\");\r\n if (x instanceof WeakMap) throw new Error(\"WeakMaps not supported yet !\");\r\n if (x instanceof Map) return new Map([\r\n ...x\r\n ].map((n)=>{\r\n return [\r\n key ? $697a68694f2aacad$var$mapfun(fun, {}, n[0]) : n[0],\r\n value ? $697a68694f2aacad$var$mapfun(fun, {}, n[1]) : n[1]\r\n ];\r\n }));\r\n if (x instanceof Object) return Object.fromEntries(Object.entries(x).map(([KEY, VALUE])=>[\r\n key ? $697a68694f2aacad$var$mapfun(fun, {}, KEY) : KEY,\r\n value ? $697a68694f2aacad$var$mapfun(fun, {}, VALUE) : VALUE\r\n ]));\r\n else throw new Error(\"Uncategorised data\");\r\n });\r\n return Y.length === 1 ? Y[0] : Y;\r\n};\r\n$697a68694f2aacad$exports = {\r\n mapfun: $697a68694f2aacad$var$mapfun,\r\n flat_obj: $697a68694f2aacad$var$flat_obj\r\n};\r\n\r\n\r\nvar $2776a60caf88deef$require$mapfun = $697a68694f2aacad$exports.mapfun;\r\nvar $2776a60caf88deef$require$flat_obj = $697a68694f2aacad$exports.flat_obj;\r\nvar $3d93cec531ae9d4c$exports = {};\r\n\r\nfunction $3d93cec531ae9d4c$var$should_skip_file(filePath) {\r\n const normalizedPath = $cFoub$path.normalize(filePath);\r\n if (this?.options?.skip?.folder?.includes($cFoub$path.basename(normalizedPath)) || this?.options?.skip?.file?.includes($cFoub$path.basename(normalizedPath)) || this?.options?.skip?.extension?.includes($cFoub$path.extname(normalizedPath).slice(1))) return true;\r\n return false;\r\n}\r\nfunction $3d93cec531ae9d4c$var$should_skip_folder(filePath) {\r\n if (typeof filePath !== \"string\") return false;\r\n const normalizedPath = $cFoub$path.normalize(filePath);\r\n if (this?.options?.skipFolder?.includes($cFoub$path.basename(normalizedPath))) return true;\r\n return false;\r\n}\r\n$3d93cec531ae9d4c$exports = {\r\n should_skip_file: $3d93cec531ae9d4c$var$should_skip_file,\r\n should_skip_folder: $3d93cec531ae9d4c$var$should_skip_folder\r\n};\r\n\r\n\r\nvar $2776a60caf88deef$require$should_skip_file = $3d93cec531ae9d4c$exports.should_skip_file;\r\nvar $2776a60caf88deef$require$should_skip_folder = $3d93cec531ae9d4c$exports.should_skip_folder;\r\nvar $82c6becc65ef4e6c$exports = {};\r\n\r\n\r\nvar $29ba264081b04b00$exports = {};\r\n\r\n\r\nfunction $29ba264081b04b00$var$is_directory(filePath) {\r\n return $cFoub$fs.statSync(filePath).isDirectory();\r\n}\r\nfunction $29ba264081b04b00$var$add_to_tree(key, value) {\r\n const keys = key.split($cFoub$path.sep);\r\n const lastKeyIndex = keys.length - 1;\r\n keys.reduce((subtree, currentKey, index)=>{\r\n if (!subtree[currentKey]) subtree[currentKey] = index === lastKeyIndex ? value : {};\r\n return subtree[currentKey];\r\n }, this.tree);\r\n}\r\n$29ba264081b04b00$exports = {\r\n is_directory: $29ba264081b04b00$var$is_directory,\r\n add_to_tree: $29ba264081b04b00$var$add_to_tree\r\n};\r\n\r\n\r\nvar $82c6becc65ef4e6c$require$is_directory = $29ba264081b04b00$exports.is_directory;\r\nfunction $82c6becc65ef4e6c$var$sort_files(files, order = 1) {\r\n return files.sort((a, b)=>{\r\n const filePathA = $cFoub$path.join(this.root, a);\r\n const filePathB = $cFoub$path.join(this.root, b);\r\n // Check if either of the files is a directory and handle accordingly\r\n const isDirectoryA = $82c6becc65ef4e6c$require$is_directory(filePathA);\r\n const isDirectoryB = $82c6becc65ef4e6c$require$is_directory(filePathB);\r\n if (isDirectoryA && !isDirectoryB) return -1; // Directories come before files\r\n else if (!isDirectoryA && isDirectoryB) return 1; // Files come after directories\r\n if (isDirectoryA && isDirectoryB) return a.localeCompare(b); // Sort directories by name\r\n // If both are files, perform the sorting based on your criteria\r\n const statsA = $cFoub$fs.statSync(filePathA);\r\n const statsB = $cFoub$fs.statSync(filePathB);\r\n const extensionA = $cFoub$path.extname(filePathA).slice(1);\r\n const extensionB = $cFoub$path.extname(filePathB).slice(1);\r\n const linesA = $cFoub$fs.readFileSync(filePathA, \"utf8\").split(\"\\n\").length;\r\n const linesB = $cFoub$fs.readFileSync(filePathB, \"utf8\").split(\"\\n\").length;\r\n // Customize sorting based on sortBy option (name, size, created, modified, extension, lines, path, etc.)\r\n switch(this.sortBy.toLowerCase()){\r\n case \"name\":\r\n return order * a.localeCompare(b);\r\n case \"size\":\r\n return order * (statsA.size - statsB.size);\r\n case \"created\":\r\n return order * (statsA.birthtime - statsB.birthtime);\r\n case \"modified\":\r\n return order * (statsA.mtime.getTime() - statsB.mtime.getTime());\r\n case \"extension\":\r\n return order * extensionA.localeCompare(extensionB);\r\n case \"lines\":\r\n return order * (linesA - linesB);\r\n case \"path\":\r\n return order * filePathB.localeCompare(filePathA);\r\n default:\r\n return 0;\r\n }\r\n });\r\n}\r\n$82c6becc65ef4e6c$exports = {\r\n sort_files: $82c6becc65ef4e6c$var$sort_files\r\n};\r\n\r\n\r\nvar $2776a60caf88deef$require$sort_files = $82c6becc65ef4e6c$exports.sort_files;\r\nvar $0b90f1fd7064b3da$exports = {};\r\n\r\n\r\nvar $0b90f1fd7064b3da$require$is_directory = $29ba264081b04b00$exports.is_directory;\r\n\r\nvar $0b90f1fd7064b3da$require$should_skip_file = $3d93cec531ae9d4c$exports.should_skip_file;\r\nfunction $0b90f1fd7064b3da$var$filter_files(files) {\r\n return files.filter((file)=>{\r\n if ($0b90f1fd7064b3da$require$is_directory($cFoub$path.join(this.root, file))) return true; // Skip directories\r\n const filePath = $cFoub$path.join(this.root, file);\r\n const shouldSkip = $0b90f1fd7064b3da$require$should_skip_file.call(this, filePath);\r\n return !shouldSkip;\r\n });\r\n}\r\n$0b90f1fd7064b3da$exports = {\r\n filter_files: $0b90f1fd7064b3da$var$filter_files\r\n};\r\n\r\n\r\nvar $2776a60caf88deef$require$filter_files = $0b90f1fd7064b3da$exports.filter_files;\r\n\r\nvar $2776a60caf88deef$require$add_to_tree = $29ba264081b04b00$exports.add_to_tree;\r\nvar $30fb452386496690$exports = {};\r\n\r\nfunction $30fb452386496690$var$file_metadata(filePath) {\r\n const stats = $cFoub$fs.statSync(filePath);\r\n const metadata = {\r\n created: stats.birthtime,\r\n modified: stats.mtime,\r\n permissions: stats.mode\r\n };\r\n return metadata;\r\n}\r\n$30fb452386496690$exports = {\r\n file_metadata: $30fb452386496690$var$file_metadata\r\n};\r\n\r\n\r\nvar $2776a60caf88deef$require$file_metadata = $30fb452386496690$exports.file_metadata;\r\nclass $2776a60caf88deef$var$Dir2Tree {\r\n constructor(root, options = {}, callbacks = {}){\r\n this.root = root;\r\n this.options = options;\r\n this.callbacks = callbacks;\r\n this.tree = {};\r\n this.sortBy = options.sortBy || \"name\";\r\n this.generate();\r\n }\r\n generate() {\r\n const stats = $cFoub$fs.statSync(this.root);\r\n if (!stats.isDirectory()) return null;\r\n const files = $cFoub$fs.readdirSync(this.root);\r\n const FILTRED_FILES = $2776a60caf88deef$require$filter_files.call(this, files);\r\n const SORTED_FILES = $2776a60caf88deef$require$sort_files.call(this, FILTRED_FILES);\r\n SORTED_FILES.forEach((file)=>{\r\n const filePath = $cFoub$path.join(this.root, file);\r\n if ($2776a60caf88deef$require$should_skip_folder.call(this, file)) return;\r\n const fileStats = $cFoub$fs.statSync(filePath);\r\n if (fileStats.isDirectory()) {\r\n const subDirectory = new $2776a60caf88deef$var$Dir2Tree(filePath, this.options, this.callbacks);\r\n Object.assign(this.tree, {\r\n [$cFoub$path.basename(filePath)]: subDirectory.tree\r\n });\r\n return this;\r\n }\r\n const fileName = $cFoub$path.parse(file).name;\r\n if ($2776a60caf88deef$require$should_skip_file.call(this, filePath)) return;\r\n if (this.options?.fileContent) this.addFileInfo(filePath, fileName);\r\n });\r\n //this.tree=tree;\r\n return this.tree;\r\n }\r\n addFileInfo(filePath, fileName) {\r\n const content = $cFoub$fs.readFileSync(filePath, \"utf8\");\r\n const fileInfo = {};\r\n const stats = {};\r\n const fullName = $cFoub$path.basename(filePath);\r\n const [name, extension] = fullName.split(\".\");\r\n const length = $cFoub$fs.statSync(filePath).size;\r\n const lines = content.split(\"\\n\").length;\r\n const metadata = $2776a60caf88deef$require$file_metadata.call(this, filePath);\r\n if (this.options?.fileContent) Object.assign(fileInfo, {\r\n content: content\r\n });\r\n if (this.options?.fileExtension) Object.assign(fileInfo, {\r\n extension: extension\r\n });\r\n if (this.options?.fileName) Object.assign(fileInfo, {\r\n name: name\r\n });\r\n Object.assign(stats, {\r\n length: length\r\n });\r\n Object.assign(stats, {\r\n size: length / 1024\r\n });\r\n Object.assign(stats, {\r\n lines: lines\r\n });\r\n Object.assign(fileInfo, {\r\n stats: stats\r\n });\r\n Object.assign(fileInfo, {\r\n metadata: metadata\r\n });\r\n this?.callbacks?.map((n)=>n(filePath, fileInfo));\r\n $2776a60caf88deef$require$add_to_tree.call(this, fileName + \"_\" + extension, fileInfo);\r\n }\r\n write(Target, filename) {\r\n const jsonTree = JSON.stringify(this.tree, null, 2); // Pretty-print the JSON\r\n const filePath = $cFoub$path.join(Target, filename); // Construct the file path\r\n $cFoub$fs.writeFileSync(filePath, jsonTree, \"utf8\");\r\n console.log(`Tree written to ${filePath}`);\r\n return this;\r\n }\r\n flat(depth = 1, separator = \"_\") {\r\n this.tree = $2776a60caf88deef$require$flat_obj(this.tree, depth, separator);\r\n return this;\r\n }\r\n reduce() {\r\n return this;\r\n }\r\n sort() {\r\n return this;\r\n }\r\n filter() {\r\n return this;\r\n }\r\n map(callback, options = {}) {\r\n this.tree = $2776a60caf88deef$require$mapfun(callback, options, this.tree);\r\n return this;\r\n }\r\n}\r\nconst $2776a60caf88deef$var$dir2tree = (root, options, callbacks = [])=>new $2776a60caf88deef$var$Dir2Tree(root, options, callbacks);\r\nmodule.exports = $2776a60caf88deef$var$dir2tree;\r\n\r\n\r\n//# sourceMappingURL=index_bundle.js.map\r\n\r\nconst fs=require(\"fs\")\r\nconst path=require(\"path\")\r\nconst dir2tree=$2776a60caf88deef$var$dir2tree;\r\nconst ROOT = path.join(process.cwd(),'.');\r\nconst TARGET = path.join(process.cwd(),\".\");\r\nconsole.log({ROOT,TARGET})\r\nconsole.log(process.env.CONFIG)\r\nconst MyTree = dir2tree(ROOT,{\r\n fileContent:true,\r\n sortBy:\"extension\",\r\n skipFile:[\"ger.md\"],\r\n skipFolder:[\"to be skipped\"],\r\n skipExtension:[\"json\"],\r\n});\r\n\r\n//console.log(MyTree.tree)\r\nMyTree.write(TARGET,\"generated.json\")\r\n", | ||
"stats": { | ||
"length": 13338, | ||
"size": 13.025390625, | ||
"lines": 333 | ||
}, | ||
"metadata": { | ||
"created": "2023-10-27T18:31:55.897Z", | ||
"modified": "2023-10-27T18:31:55.897Z", | ||
"permissions": 33206 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.