@h4pplness/confluence-cli
v1.0.2
Published
CLI tool de tao trang Confluence tu template va cap nhat trang qua storage HTML
Maintainers
Readme
confluence-cli
A CLI tool for creating Confluence pages from templates and updating existing pages through downloaded storage-format HTML files.
Installation
Install the published package globally:
npm install -g @h4pplness/confluence-cliOr install from a local checkout:
npm install -g .Quick Start
# 1. Configure a profile
confluence-cli config set
# 2. List available templates
confluence-cli template list
# 3. Inspect template variables
confluence-cli template detail feature-design
# 4. Create a new page
confluence-cli page create \
--space "DEV" \
--parent "123456" \
--title "Authentication Module" \
--template "feature-design" \
--data '{"title":"Authentication Module","mo_ta_chuc_nang":"...","thiet_ke_api":"..."}'
# Or use a JSON file
confluence-cli page create --from-file ./input.json
# Download, edit, and update an existing page
confluence-cli page get --page-id "789012" --download
confluence-cli page update --file ./confluence-pages/789012-v3-page-title.html --dry-run
confluence-cli page update --file ./confluence-pages/789012-v3-page-title.htmlConfig
Set Up a Profile
confluence-cli config set # Interactive wizard
confluence-cli config set --profile dc-prod # Specific profile nameThe CLI supports 3 authentication methods:
| Method | Use case | Header |
|---|---|---|
| cloud_basic | Confluence Cloud | Basic base64(email:apiToken) |
| server_basic | Server / Data Center | Basic base64(username:password) |
| pat | Server / Data Center v7.9+ | Bearer <token> |
Config Commands
confluence-cli config list # List profiles
confluence-cli config show # Show active profile details
confluence-cli config show --profile dc-prod
confluence-cli config use dc-prod # Switch active profile
confluence-cli config delete dc-prod # Delete a profile
confluence-cli config test # Test the connectionTemplate
Manage Templates
confluence-cli template list # List templates
confluence-cli template detail feature-design # Show details and variables
confluence-cli template detail feature-design --full # Also show generated HTML
confluence-cli template create # Create a template interactively
confluence-cli template create --name my-tpl --file ./my.hbs
confluence-cli template delete my-tpl
confluence-cli template export my-tpl --output ./export/
confluence-cli template import ./my.hbs ./my.jsonTemplate Structure
Each template contains 2 files stored in the app data directory:
feature-design.hbs - HTML content using Handlebars:
<h1>{{title}}</h1>
<h2>Feature Description</h2>
<p>{{{mo_ta_chuc_nang}}}</p>
{{var}}escapes HTML |{{{var}}}preserves raw HTML and line breaks
feature-design.json - Metadata:
{
"name": "feature-design",
"displayName": "Feature Design",
"variables": [
{ "key": "mo_ta_chuc_nang", "label": "Description", "required": true, "type": "text" }
]
}System variables are injected automatically and do not need to be provided:
{{_generated_at}}- generation time{{_template_name}}- template name
Page
Create a Page
# Using flags
confluence-cli page create \
--space "DEV" \
--parent "123456" \
--title "Page Title" \
--template "feature-design" \
--data '{"mo_ta_chuc_nang":"...", "thiet_ke_api":"..."}'
# Using a JSON file
confluence-cli page create --from-file ./input.json
# Dry run: preview HTML without calling the API
confluence-cli page create --from-file ./input.json --dry-runUpdate a Page
# Download raw Confluence storage HTML and metadata
confluence-cli page get --page-id "789012" --download
# Edit the downloaded .html file, then dry-run the update
confluence-cli page update --file ./confluence-pages/789012-v3-page-title.html --dry-run
# Push the edited file back to Confluence
confluence-cli page update --file ./confluence-pages/789012-v3-page-title.html
# Optional: change the title while updating body HTML
confluence-cli page update --file ./confluence-pages/789012-v3-page-title.html --title "Page Title v2"Downloaded pages are saved to ./confluence-pages/ by default as a .html body file plus a .meta.json file. The metadata records the page ID, title, version, URL, and profile name. page update --file checks the downloaded version against the current server version and stops if the page changed; use --force only when you intentionally want to overwrite with the local file.
Create JSON File Format (--from-file)
Create:
{
"spaceKey": "DEV",
"parentPageId": "123456",
"title": "Authentication Module",
"templateName": "feature-design",
"data": {
"title": "Authentication Module",
"mo_ta_chuc_nang": "Handle login/logout with JWT",
"thiet_ke_api": "POST /auth/login\nPOST /auth/refresh",
"thiet_ke_database": "Tables: users, refresh_tokens"
}
}Get Page Details
confluence-cli page get --page-id "789012"
confluence-cli page get --page-id "789012" --raw
confluence-cli page get --page-id "789012" --download
confluence-cli page get --page-id "789012" --download --output ./docsData Location
| OS | Config & Templates |
|---|---|
| Windows | %APPDATA%\confluence-cli\ |
| macOS | ~/Library/Application Support/confluence-cli/ |
| Linux | ~/.config/confluence-cli/ |
