mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
feat(post-encrypt): add help option to display usage instructions
This commit is contained in:
@@ -2,25 +2,46 @@
|
|||||||
|
|
||||||
Post-build AES-256-GCM encryption tool for the [FixIt](https://github.com/hugo-fixit/FixIt) Hugo theme.
|
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
|
## Usage
|
||||||
|
|
||||||
After building your Hugo site, run the encryption tool from your site root:
|
After building your Hugo site, run the encryption tool from your site root:
|
||||||
|
|
||||||
```bash
|
```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
|
### Options
|
||||||
|
|
||||||
| Option | Description | Default |
|
| Option | Description | Default |
|
||||||
| --- | --- | --- |
|
| --------------- | -------------------------------------------------- | -------- |
|
||||||
| `--input <dir>` | Input directory containing HTML files | `public` |
|
| `--input <dir>` | Input directory containing HTML files | `public` |
|
||||||
| `--dry-run | Show which files would be modified without writing | `false` |
|
| `--dry-run` | Show which files would be modified without writing | `false` |
|
||||||
| `--verify | Verify all encryption templates are encrypted | `false` |
|
| `--verify` | Verify all encryption templates are encrypted | `false` |
|
||||||
|
| `-h, --help` | Show CLI usage help | |
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# Show CLI help
|
||||||
|
npx @hugo-fixit/post-encrypt --help
|
||||||
|
|
||||||
# Encrypt content in the default public/ directory
|
# Encrypt content in the default public/ directory
|
||||||
npx @hugo-fixit/post-encrypt
|
npx @hugo-fixit/post-encrypt
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"description": "Post-build AES-256-GCM encryption tool for the FixIt Hugo theme",
|
"description": "Post-build AES-256-GCM encryption tool for the FixIt Hugo theme",
|
||||||
"author": "Lruihao",
|
"author": "Lruihao",
|
||||||
"license": "MIT",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/hugo-fixit/FixIt.git",
|
"url": "git+https://github.com/hugo-fixit/FixIt.git",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ interface CliOptions {
|
|||||||
cwd: string
|
cwd: string
|
||||||
dryRun: boolean
|
dryRun: boolean
|
||||||
verifyOnly: boolean
|
verifyOnly: boolean
|
||||||
|
helpRequested: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TemplateMatch {
|
interface TemplateMatch {
|
||||||
@@ -37,10 +38,15 @@ function parseArgs(argv: string[]): CliOptions {
|
|||||||
cwd: process.env.INIT_CWD || process.cwd(),
|
cwd: process.env.INIT_CWD || process.cwd(),
|
||||||
dryRun: false,
|
dryRun: false,
|
||||||
verifyOnly: false,
|
verifyOnly: false,
|
||||||
|
helpRequested: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < argv.length; i++) {
|
for (let i = 0; i < argv.length; i++) {
|
||||||
const arg = argv[i]
|
const arg = argv[i]
|
||||||
|
if (arg === '--help' || arg === '-h') {
|
||||||
|
options.helpRequested = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (arg === '--input') {
|
if (arg === '--input') {
|
||||||
options.input = argv[i + 1] || options.input
|
options.input = argv[i + 1] || options.input
|
||||||
i++
|
i++
|
||||||
@@ -63,6 +69,23 @@ function parseArgs(argv: string[]): CliOptions {
|
|||||||
return options
|
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[] {
|
function collectHtmlFiles(targetDir: string): string[] {
|
||||||
const files: string[] = []
|
const files: string[] = []
|
||||||
|
|
||||||
@@ -240,6 +263,10 @@ function hasUnencryptedTemplate(matches: TemplateMatch[]): boolean {
|
|||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const options = parseArgs(process.argv.slice(2))
|
const options = parseArgs(process.argv.slice(2))
|
||||||
|
if (options.helpRequested) {
|
||||||
|
printHelp()
|
||||||
|
return
|
||||||
|
}
|
||||||
const targetDir = path.isAbsolute(options.input)
|
const targetDir = path.isAbsolute(options.input)
|
||||||
? options.input
|
? options.input
|
||||||
: path.resolve(options.cwd, options.input)
|
: path.resolve(options.cwd, options.input)
|
||||||
|
|||||||
Reference in New Issue
Block a user