feat(post-encrypt): add help option to display usage instructions

This commit is contained in:
Cell
2026-07-06 00:45:03 +08:00
parent ed451351d6
commit c86566fa8e
3 changed files with 55 additions and 7 deletions
+27 -6
View File
@@ -2,25 +2,46 @@
Post-build AES-256-GCM encryption tool for the [FixIt](https://github.com/hugo-fixit/FixIt) Hugo theme.
It is designed for HTML generated by FixIt content encryption templates and should be run after your site has already been built.
## Usage
After building your Hugo site, run the encryption tool from your site root:
```bash
npx @hugo-fixit/post-encrypt --input public
npx @hugo-fixit/post-encrypt
```
You can also install it globally and run the CLI directly:
```bash
npm install -g @hugo-fixit/post-encrypt
post-encrypt
```
Typical build flow:
```bash
hugo build
npx @hugo-fixit/post-encrypt
npx @hugo-fixit/post-encrypt --verify
```
### Options
| Option | Description | Default |
| --- | --- | --- |
| `--input <dir>` | Input directory containing HTML files | `public` |
| `--dry-run | Show which files would be modified without writing | `false` |
| `--verify | Verify all encryption templates are encrypted | `false` |
| Option | Description | Default |
| --------------- | -------------------------------------------------- | -------- |
| `--input <dir>` | Input directory containing HTML files | `public` |
| `--dry-run` | Show which files would be modified without writing | `false` |
| `--verify` | Verify all encryption templates are encrypted | `false` |
| `-h, --help` | Show CLI usage help | |
### Examples
```bash
# Show CLI help
npx @hugo-fixit/post-encrypt --help
# Encrypt content in the default public/ directory
npx @hugo-fixit/post-encrypt
+1 -1
View File
@@ -5,7 +5,7 @@
"description": "Post-build AES-256-GCM encryption tool for the FixIt Hugo theme",
"author": "Lruihao",
"license": "MIT",
"homepage": "https://github.com/hugo-fixit/FixIt/tree/feat/post-encrypt/packages/post-encrypt#readme",
"homepage": "https://github.com/hugo-fixit/FixIt/tree/main/packages/post-encrypt#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/hugo-fixit/FixIt.git",
+27
View File
@@ -19,6 +19,7 @@ interface CliOptions {
cwd: string
dryRun: boolean
verifyOnly: boolean
helpRequested: boolean
}
interface TemplateMatch {
@@ -37,10 +38,15 @@ function parseArgs(argv: string[]): CliOptions {
cwd: process.env.INIT_CWD || process.cwd(),
dryRun: false,
verifyOnly: false,
helpRequested: false,
}
for (let i = 0; i < argv.length; i++) {
const arg = argv[i]
if (arg === '--help' || arg === '-h') {
options.helpRequested = true
continue
}
if (arg === '--input') {
options.input = argv[i + 1] || options.input
i++
@@ -63,6 +69,23 @@ function parseArgs(argv: string[]): CliOptions {
return options
}
function printHelp(): void {
consola.log(`Usage:
post-encrypt [options]
Options:
--input <dir> Input directory containing HTML files (default: public)
--dry-run Show which files would be modified without writing
--verify Verify all encryption templates are encrypted
-h, --help Show this help message
Examples:
post-encrypt
post-encrypt --input dist
post-encrypt --verify
post-encrypt --dry-run`)
}
function collectHtmlFiles(targetDir: string): string[] {
const files: string[] = []
@@ -240,6 +263,10 @@ function hasUnencryptedTemplate(matches: TemplateMatch[]): boolean {
function main() {
const options = parseArgs(process.argv.slice(2))
if (options.helpRequested) {
printHelp()
return
}
const targetDir = path.isAbsolute(options.input)
? options.input
: path.resolve(options.cwd, options.input)