Skip to content

Commit

Permalink
Cut files with more than 500 lines (#5)
Browse files Browse the repository at this point in the history
* add future improvement

* fix command

* cut large files

* fix build script

* rm output file

* fix output file name
  • Loading branch information
julienbrg authored Sep 3, 2024
1 parent 3402d34 commit dbef0d0
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/dist
/node_modules
zhankai_output.md
/node_modules
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
119 changes: 119 additions & 0 deletions package-managers.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -22,4 +22,4 @@
"@types/node": "^16.11.12",
"typescript": "^4.5.2"
}
}
}
40 changes: 32 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const program = new Command();

program
.version("1.0.0")
.option("-o, --output <filename>", "output filename", "zhankai_output.md")
.option("-o, --output <filename>", "output filename")
.option("-d, --depth <number>", "maximum depth to traverse", "Infinity")
.option("-c, --contents", "include file contents", false)
.parse(process.argv);
Expand Down Expand Up @@ -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<string[]> => {
Expand Down Expand Up @@ -126,10 +131,29 @@ const processFile = async (
options: ZhankaiOptions
): Promise<void> => {
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");
};

Expand Down Expand Up @@ -182,18 +206,18 @@ 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
: parseInt(program.opts().depth),
contents: program.opts().contents,
};

const baseDir = process.cwd();
const repoName = await getRepoName(baseDir);

const gitignorePatterns = await loadGitignorePatterns(baseDir);
const ig = ignore().add(gitignorePatterns);

Expand All @@ -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`
);
};

Expand Down

0 comments on commit dbef0d0

Please sign in to comment.