Skip to content

Commit dbef0d0

Browse files
authored
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
1 parent 3402d34 commit dbef0d0

File tree

5 files changed

+158
-16
lines changed

5 files changed

+158
-16
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/dist
2-
/node_modules
3-
zhankai_output.md
2+
/node_modules

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ zhankai --version
2222
zhankai
2323
```
2424

25-
A `zhankai_output.md` is created at the root of your repository.
25+
A `zhankai_output.md` file is created at the root of your repository.
2626

2727
## Contrib
2828

@@ -36,14 +36,14 @@ pnpm i
3636

3737
```bash
3838
pnpm build
39-
npm run install -g .
39+
npm install -g .
4040
zhankai
4141
```
4242

4343
## Versions
4444

45-
- pnpm v8.7.5
46-
- node v20.9.0
45+
- pnpm `v8.7.5`
46+
- node `v20.9.0`
4747

4848
## Support
4949

package-managers.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Package Managers and Installation Methods by Language
2+
3+
1. Python
4+
- pip: `pip install zhankai`
5+
- conda: `conda install zhankai`
6+
7+
2. PHP
8+
- Composer: `composer require zhankai/zhankai`
9+
10+
3. Ruby
11+
- RubyGems: `gem install zhankai`
12+
13+
4. Perl
14+
- CPAN: `cpan Zhankai`
15+
16+
5. Java
17+
- Maven: Add to `pom.xml`
18+
- Gradle: Add to `build.gradle`
19+
20+
6. Rust
21+
- Cargo: `cargo install zhankai`
22+
23+
7. Go
24+
- Go Modules: `go get github.com/username/zhankai`
25+
26+
8. .NET (C#, F#, etc.)
27+
- NuGet: `dotnet add package Zhankai`
28+
29+
9. Haskell
30+
- Cabal: `cabal install zhankai`
31+
32+
10. Scala
33+
- sbt: Add to `build.sbt`
34+
35+
11. Kotlin
36+
- Gradle: Add to `build.gradle.kts`
37+
38+
12. Swift
39+
- Swift Package Manager: Add to `Package.swift`
40+
41+
13. Dart
42+
- Pub: `pub global activate zhankai`
43+
44+
14. Elixir
45+
- Hex: Add to `mix.exs`
46+
47+
15. Clojure
48+
- Leiningen: Add to `project.clj`
49+
50+
16. R
51+
- CRAN: `install.packages("zhankai")`
52+
53+
17. MATLAB
54+
- Add-On Explorer
55+
56+
18. Julia
57+
- Pkg: `] add Zhankai`
58+
59+
19. Lua
60+
- LuaRocks: `luarocks install zhankai`
61+
62+
20. OCaml
63+
- OPAM: `opam install zhankai`
64+
65+
21. Erlang
66+
- Rebar3: Add to `rebar.config`
67+
68+
22. Shell (Bash, Zsh, etc.)
69+
- Homebrew (macOS/Linux): `brew install zhankai`
70+
- apt (Debian/Ubuntu): `sudo apt install zhankai`
71+
- yum (CentOS/RHEL): `sudo yum install zhankai`
72+
73+
23. Windows
74+
- Chocolatey: `choco install zhankai`
75+
- Scoop: `scoop install zhankai`
76+
77+
24. Docker
78+
- Docker Hub: `docker pull username/zhankai`
79+
80+
25. Platform-agnostic
81+
- Binary releases: Downloadable executables for various platforms
82+
- Installation script: `curl -sSL https://install.zhankai.com | bash`
83+
84+
# Installation objectives
85+
86+
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:
87+
88+
1. Path addition: The installation script would need to add the zhankai executable to the user's PATH. This typically involves:
89+
- Placing the executable in a standard location (e.g., /usr/local/bin on Unix-like systems)
90+
- Or adding the installation directory to the user's PATH environment variable
91+
92+
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.
93+
94+
3. Permissions: The script would need to ensure that the installed executable has the correct permissions to be run by the user.
95+
96+
4. Multiple shells: If the user uses multiple shells, the script should ideally configure zhankai for all of them.
97+
98+
5. System vs. user installation: The script should handle both system-wide installations (requiring sudo) and user-specific installations appropriately.
99+
100+
6. Dependencies: If zhankai has any runtime dependencies, the script should check for and possibly install them.
101+
102+
To ensure this smooth experience, the installation script should:
103+
104+
1. Detect the user's environment (OS, shell, etc.)
105+
2. Install zhankai in an appropriate location
106+
3. Update PATH if necessary
107+
4. Set correct permissions
108+
5. Provide clear output about what it's doing and any next steps required
109+
110+
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.
111+
112+
It's also good practice for the script to output instructions at the end, such as:
113+
114+
```
115+
Installation complete! You can now run zhankai by typing 'zhankai' in your terminal.
116+
If it doesn't work immediately, try opening a new terminal window or running 'source ~/.bashrc' (or your appropriate shell config file).
117+
```
118+
119+
This approach provides a smooth, user-friendly installation experience across different systems and shells.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"zhankai": "./dist/index.js"
88
},
99
"scripts": {
10-
"build": "tsc",
10+
"build": "tsc && npm install -g . && zhankai",
1111
"start": "node dist/index.js",
1212
"prepublishOnly": "npm run build"
1313
},
@@ -22,4 +22,4 @@
2222
"@types/node": "^16.11.12",
2323
"typescript": "^4.5.2"
2424
}
25-
}
25+
}

src/index.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const program = new Command();
1616

1717
program
1818
.version("1.0.0")
19-
.option("-o, --output <filename>", "output filename", "zhankai_output.md")
19+
.option("-o, --output <filename>", "output filename")
2020
.option("-d, --depth <number>", "maximum depth to traverse", "Infinity")
2121
.option("-c, --contents", "include file contents", false)
2222
.parse(process.argv);
@@ -71,6 +71,11 @@ const getLanguageTag = (filePath: string): string => {
7171
return langMap[ext] || "";
7272
};
7373

74+
const isImageFile = (filePath: string): boolean => {
75+
const ext = path.extname(filePath).toLowerCase();
76+
return [".png", ".jpg", ".jpeg", ".ico"].includes(ext);
77+
};
78+
7479
const excludedItems = ["LICENSE", ".git"];
7580

7681
const loadGitignorePatterns = async (dir: string): Promise<string[]> => {
@@ -126,10 +131,29 @@ const processFile = async (
126131
options: ZhankaiOptions
127132
): Promise<void> => {
128133
const langTag = getLanguageTag(filePath);
134+
129135
await fs.appendFile(options.output, `\n### ${relativePath}\n\n`);
130136
await fs.appendFile(options.output, "```" + langTag + "\n");
131-
const content = await fs.readFile(filePath, "utf8");
132-
await fs.appendFile(options.output, content);
137+
138+
if (isImageFile(filePath)) {
139+
await fs.appendFile(options.output, "[This is an image file]");
140+
} else {
141+
const content = await fs.readFile(filePath, "utf8");
142+
const lines = content.split("\n");
143+
144+
if (lines.length > 500) {
145+
const truncatedContent = lines.slice(0, 30).join("\n");
146+
await fs.appendFile(options.output, truncatedContent);
147+
await fs.appendFile(options.output, "\n```\n");
148+
await fs.appendFile(
149+
options.output,
150+
"\n[This file was cut: it has more than 500 lines]\n"
151+
);
152+
} else {
153+
await fs.appendFile(options.output, content);
154+
}
155+
}
156+
133157
await fs.appendFile(options.output, "\n```\n");
134158
};
135159

@@ -182,18 +206,18 @@ const generateFileStructure = async (
182206
};
183207

184208
const main = async () => {
209+
const baseDir = process.cwd();
210+
const repoName = await getRepoName(baseDir);
211+
185212
const options: ZhankaiOptions = {
186-
output: program.opts().output,
213+
output: program.opts().output || `${repoName}_app_description.md`,
187214
depth:
188215
program.opts().depth === "Infinity"
189216
? Infinity
190217
: parseInt(program.opts().depth),
191218
contents: program.opts().contents,
192219
};
193220

194-
const baseDir = process.cwd();
195-
const repoName = await getRepoName(baseDir);
196-
197221
const gitignorePatterns = await loadGitignorePatterns(baseDir);
198222
const ig = ignore().add(gitignorePatterns);
199223

@@ -219,7 +243,7 @@ const main = async () => {
219243
await fs.appendFile(options.output, content);
220244

221245
console.log(
222-
`\nContent of all files and repo structure written: ${options.output}`
246+
`\nContent of all files and repo structure written in ${repoName}_app_description.md`
223247
);
224248
};
225249

0 commit comments

Comments
 (0)