From dbef0d09739e4b6b8dc143a29dad3c7789fe75fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20B=C3=A9ranger?= Date: Tue, 3 Sep 2024 18:45:44 +0200 Subject: [PATCH] Cut files with more than 500 lines (#5) * add future improvement * fix command * cut large files * fix build script * rm output file * fix output file name --- .gitignore | 3 +- README.md | 8 +-- package-managers.md | 119 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- src/index.ts | 40 ++++++++++++--- 5 files changed, 158 insertions(+), 16 deletions(-) create mode 100644 package-managers.md diff --git a/.gitignore b/.gitignore index d860341..246d599 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /dist -/node_modules -zhankai_output.md \ No newline at end of file +/node_modules \ No newline at end of file diff --git a/README.md b/README.md index f44df43..18b7e20 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ zhankai --version zhankai ``` -A `zhankai_output.md` is created at the root of your repository. +A `zhankai_output.md` file is created at the root of your repository. ## Contrib @@ -36,14 +36,14 @@ pnpm i ```bash pnpm build -npm run install -g . +npm install -g . zhankai ``` ## Versions -- pnpm v8.7.5 -- node v20.9.0 +- pnpm `v8.7.5` +- node `v20.9.0` ## Support diff --git a/package-managers.md b/package-managers.md new file mode 100644 index 0000000..5f9dbd2 --- /dev/null +++ b/package-managers.md @@ -0,0 +1,119 @@ +# Package Managers and Installation Methods by Language + +1. Python + - pip: `pip install zhankai` + - conda: `conda install zhankai` + +2. PHP + - Composer: `composer require zhankai/zhankai` + +3. Ruby + - RubyGems: `gem install zhankai` + +4. Perl + - CPAN: `cpan Zhankai` + +5. Java + - Maven: Add to `pom.xml` + - Gradle: Add to `build.gradle` + +6. Rust + - Cargo: `cargo install zhankai` + +7. Go + - Go Modules: `go get github.com/username/zhankai` + +8. .NET (C#, F#, etc.) + - NuGet: `dotnet add package Zhankai` + +9. Haskell + - Cabal: `cabal install zhankai` + +10. Scala + - sbt: Add to `build.sbt` + +11. Kotlin + - Gradle: Add to `build.gradle.kts` + +12. Swift + - Swift Package Manager: Add to `Package.swift` + +13. Dart + - Pub: `pub global activate zhankai` + +14. Elixir + - Hex: Add to `mix.exs` + +15. Clojure + - Leiningen: Add to `project.clj` + +16. R + - CRAN: `install.packages("zhankai")` + +17. MATLAB + - Add-On Explorer + +18. Julia + - Pkg: `] add Zhankai` + +19. Lua + - LuaRocks: `luarocks install zhankai` + +20. OCaml + - OPAM: `opam install zhankai` + +21. Erlang + - Rebar3: Add to `rebar.config` + +22. Shell (Bash, Zsh, etc.) + - Homebrew (macOS/Linux): `brew install zhankai` + - apt (Debian/Ubuntu): `sudo apt install zhankai` + - yum (CentOS/RHEL): `sudo yum install zhankai` + +23. Windows + - Chocolatey: `choco install zhankai` + - Scoop: `scoop install zhankai` + +24. Docker + - Docker Hub: `docker pull username/zhankai` + +25. Platform-agnostic + - Binary releases: Downloadable executables for various platforms + - Installation script: `curl -sSL https://install.zhankai.com | bash` + +# Installation objectives + +Ideally, yes, if the installation script is well-designed, users should be able to simply type "zhankai" in their terminal to run the app after using the curl command. However, there are a few important considerations: + +1. Path addition: The installation script would need to add the zhankai executable to the user's PATH. This typically involves: + - Placing the executable in a standard location (e.g., /usr/local/bin on Unix-like systems) + - Or adding the installation directory to the user's PATH environment variable + +2. Shell configuration: If the PATH is modified, the script might need to update the user's shell configuration file (e.g., .bashrc, .zshrc) and prompt them to restart their terminal or source the updated configuration. + +3. Permissions: The script would need to ensure that the installed executable has the correct permissions to be run by the user. + +4. Multiple shells: If the user uses multiple shells, the script should ideally configure zhankai for all of them. + +5. System vs. user installation: The script should handle both system-wide installations (requiring sudo) and user-specific installations appropriately. + +6. Dependencies: If zhankai has any runtime dependencies, the script should check for and possibly install them. + +To ensure this smooth experience, the installation script should: + +1. Detect the user's environment (OS, shell, etc.) +2. Install zhankai in an appropriate location +3. Update PATH if necessary +4. Set correct permissions +5. Provide clear output about what it's doing and any next steps required + +With a well-implemented installation script, users should indeed be able to simply type "zhankai" to run the app immediately after installation. However, in some cases, they might need to open a new terminal window or source their updated shell configuration first. + +It's also good practice for the script to output instructions at the end, such as: + +``` +Installation complete! You can now run zhankai by typing 'zhankai' in your terminal. +If it doesn't work immediately, try opening a new terminal window or running 'source ~/.bashrc' (or your appropriate shell config file). +``` + +This approach provides a smooth, user-friendly installation experience across different systems and shells. \ No newline at end of file diff --git a/package.json b/package.json index 5780a37..e26f172 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "zhankai": "./dist/index.js" }, "scripts": { - "build": "tsc", + "build": "tsc && npm install -g . && zhankai", "start": "node dist/index.js", "prepublishOnly": "npm run build" }, @@ -22,4 +22,4 @@ "@types/node": "^16.11.12", "typescript": "^4.5.2" } -} +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 39958c5..b2e78f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ const program = new Command(); program .version("1.0.0") - .option("-o, --output ", "output filename", "zhankai_output.md") + .option("-o, --output ", "output filename") .option("-d, --depth ", "maximum depth to traverse", "Infinity") .option("-c, --contents", "include file contents", false) .parse(process.argv); @@ -71,6 +71,11 @@ const getLanguageTag = (filePath: string): string => { return langMap[ext] || ""; }; +const isImageFile = (filePath: string): boolean => { + const ext = path.extname(filePath).toLowerCase(); + return [".png", ".jpg", ".jpeg", ".ico"].includes(ext); +}; + const excludedItems = ["LICENSE", ".git"]; const loadGitignorePatterns = async (dir: string): Promise => { @@ -126,10 +131,29 @@ const processFile = async ( options: ZhankaiOptions ): Promise => { const langTag = getLanguageTag(filePath); + await fs.appendFile(options.output, `\n### ${relativePath}\n\n`); await fs.appendFile(options.output, "```" + langTag + "\n"); - const content = await fs.readFile(filePath, "utf8"); - await fs.appendFile(options.output, content); + + if (isImageFile(filePath)) { + await fs.appendFile(options.output, "[This is an image file]"); + } else { + const content = await fs.readFile(filePath, "utf8"); + const lines = content.split("\n"); + + if (lines.length > 500) { + const truncatedContent = lines.slice(0, 30).join("\n"); + await fs.appendFile(options.output, truncatedContent); + await fs.appendFile(options.output, "\n```\n"); + await fs.appendFile( + options.output, + "\n[This file was cut: it has more than 500 lines]\n" + ); + } else { + await fs.appendFile(options.output, content); + } + } + await fs.appendFile(options.output, "\n```\n"); }; @@ -182,8 +206,11 @@ const generateFileStructure = async ( }; const main = async () => { + const baseDir = process.cwd(); + const repoName = await getRepoName(baseDir); + const options: ZhankaiOptions = { - output: program.opts().output, + output: program.opts().output || `${repoName}_app_description.md`, depth: program.opts().depth === "Infinity" ? Infinity @@ -191,9 +218,6 @@ const main = async () => { contents: program.opts().contents, }; - const baseDir = process.cwd(); - const repoName = await getRepoName(baseDir); - const gitignorePatterns = await loadGitignorePatterns(baseDir); const ig = ignore().add(gitignorePatterns); @@ -219,7 +243,7 @@ const main = async () => { await fs.appendFile(options.output, content); console.log( - `\nContent of all files and repo structure written: ${options.output}` + `\nContent of all files and repo structure written in ${repoName}_app_description.md` ); };