confluence-cli 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +37 -0
- package/bin/confluence.js +122 -0
- package/examples/copy-tree-example.sh +117 -0
- package/examples/create-child-page-example.sh +39 -37
- package/lib/config.js +79 -29
- package/lib/confluence-client.js +260 -7
- package/llms.txt +46 -0
- package/package.json +2 -2
- package/tests/confluence-client.test.js +99 -0
- package/llm.txt +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.7.0](https://github.com/pchuri/confluence-cli/compare/v1.6.0...v1.7.0) (2025-09-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* support basic auth for Atlassian API tokens ([#12](https://github.com/pchuri/confluence-cli/issues/12)) ([e80ea9b](https://github.com/pchuri/confluence-cli/commit/e80ea9b7913d5f497b60bf72149737b6f704c6b8))
|
|
7
|
+
|
|
8
|
+
# [1.6.0](https://github.com/pchuri/confluence-cli/compare/v1.5.0...v1.6.0) (2025-09-05)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Add copy-tree command for recursive page copying with children ([#9](https://github.com/pchuri/confluence-cli/issues/9)) ([29efa5b](https://github.com/pchuri/confluence-cli/commit/29efa5b2f8edeee1c5072ad8d7077f38f860c2ba))
|
|
14
|
+
|
|
1
15
|
# [1.5.0](https://github.com/pchuri/confluence-cli/compare/v1.4.1...v1.5.0) (2025-08-13)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -58,12 +58,19 @@ npx confluence-cli
|
|
|
58
58
|
confluence init
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
The wizard now asks for your authentication method. Choose **Basic** to supply your Atlassian email and API token, or switch to **Bearer** when working with self-hosted/Data Center environments.
|
|
62
|
+
|
|
61
63
|
### Option 2: Environment Variables
|
|
62
64
|
```bash
|
|
63
65
|
export CONFLUENCE_DOMAIN="your-domain.atlassian.net"
|
|
64
66
|
export CONFLUENCE_API_TOKEN="your-api-token"
|
|
67
|
+
export CONFLUENCE_EMAIL="your.email@example.com" # required when using Atlassian Cloud
|
|
68
|
+
# Optional: set to 'bearer' for self-hosted/Data Center instances
|
|
69
|
+
export CONFLUENCE_AUTH_TYPE="basic"
|
|
65
70
|
```
|
|
66
71
|
|
|
72
|
+
`CONFLUENCE_AUTH_TYPE` defaults to `basic` when an email is present and falls back to `bearer` otherwise. Provide an email for Atlassian Cloud (Basic auth) or set `CONFLUENCE_AUTH_TYPE=bearer` to keep bearer-token flows for on-premises installations.
|
|
73
|
+
|
|
67
74
|
### Getting Your API Token
|
|
68
75
|
|
|
69
76
|
1. Go to [Atlassian Account Settings](https://id.atlassian.com/manage-profile/security/api-tokens)
|
|
@@ -131,6 +138,35 @@ confluence create-child "Meeting Notes" 123456789 --content "This is a child pag
|
|
|
131
138
|
confluence create-child "Tech Specs" 123456789 --file ./specs.md --format markdown
|
|
132
139
|
```
|
|
133
140
|
|
|
141
|
+
### Copy Page Tree
|
|
142
|
+
```bash
|
|
143
|
+
# Copy a page and all its children to a new location
|
|
144
|
+
confluence copy-tree 123456789 987654321 "Project Docs (Copy)"
|
|
145
|
+
|
|
146
|
+
# Copy with maximum depth limit (only 3 levels deep)
|
|
147
|
+
confluence copy-tree 123456789 987654321 --max-depth 3
|
|
148
|
+
|
|
149
|
+
# Exclude pages by title (supports wildcards * and ?; case-insensitive)
|
|
150
|
+
confluence copy-tree 123456789 987654321 --exclude "temp*,test*,*draft*"
|
|
151
|
+
|
|
152
|
+
# Control pacing and naming
|
|
153
|
+
confluence copy-tree 123456789 987654321 --delay-ms 150 --copy-suffix " (Backup)"
|
|
154
|
+
|
|
155
|
+
# Dry run (preview only)
|
|
156
|
+
confluence copy-tree 123456789 987654321 --dry-run
|
|
157
|
+
|
|
158
|
+
# Quiet mode (suppress progress output)
|
|
159
|
+
confluence copy-tree 123456789 987654321 --quiet
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Notes:
|
|
163
|
+
- Preserves the original parent-child hierarchy when copying.
|
|
164
|
+
- Continues on errors: failed pages are logged and the copy proceeds.
|
|
165
|
+
- Exclude patterns use simple globbing: `*` matches any sequence, `?` matches any single character, and special regex characters are treated literally.
|
|
166
|
+
- Large trees may take time; the CLI applies a small delay between sibling page creations to avoid rate limits (configurable via `--delay-ms`).
|
|
167
|
+
- Root title suffix defaults to ` (Copy)`; override with `--copy-suffix`. Child pages keep their original titles.
|
|
168
|
+
- Use `--fail-on-error` to exit non-zero if any page fails to copy.
|
|
169
|
+
|
|
134
170
|
### Update an Existing Page
|
|
135
171
|
```bash
|
|
136
172
|
# Update title only
|
|
@@ -176,6 +212,7 @@ confluence stats
|
|
|
176
212
|
| `find <title>` | Find a page by its title | `--space <spaceKey>` |
|
|
177
213
|
| `create <title> <spaceKey>` | Create a new page | `--content <string>`, `--file <path>`, `--format <storage\|html\|markdown>`|
|
|
178
214
|
| `create-child <title> <parentId>` | Create a child page | `--content <string>`, `--file <path>`, `--format <storage\|html\|markdown>` |
|
|
215
|
+
| `copy-tree <sourcePageId> <targetParentId> [newTitle]` | Copy page tree with all children | `--max-depth <number>`, `--exclude <patterns>`, `--delay-ms <ms>`, `--copy-suffix <text>`, `--dry-run`, `--fail-on-error`, `--quiet` |
|
|
179
216
|
| `update <pageId>` | Update a page's title or content | `--title <string>`, `--content <string>`, `--file <path>`, `--format <storage\|html\|markdown>` |
|
|
180
217
|
| `edit <pageId>` | Export page content for editing | `--output <file>` |
|
|
181
218
|
| `stats` | View your usage statistics | |
|
package/bin/confluence.js
CHANGED
|
@@ -337,4 +337,126 @@ program
|
|
|
337
337
|
}
|
|
338
338
|
});
|
|
339
339
|
|
|
340
|
+
// Copy page tree command
|
|
341
|
+
program
|
|
342
|
+
.command('copy-tree <sourcePageId> <targetParentId> [newTitle]')
|
|
343
|
+
.description('Copy a page and all its children to a new location')
|
|
344
|
+
.option('--max-depth <depth>', 'Maximum depth to copy (default: 10)', '10')
|
|
345
|
+
.option('--exclude <patterns>', 'Comma-separated patterns to exclude (supports wildcards)')
|
|
346
|
+
.option('--delay-ms <ms>', 'Delay between sibling creations in ms (default: 100)', '100')
|
|
347
|
+
.option('--copy-suffix <suffix>', 'Suffix for new root title (default: " (Copy)")', ' (Copy)')
|
|
348
|
+
.option('-n, --dry-run', 'Preview operations without creating pages')
|
|
349
|
+
.option('--fail-on-error', 'Exit with non-zero code if any page fails')
|
|
350
|
+
.option('-q, --quiet', 'Suppress progress output')
|
|
351
|
+
.action(async (sourcePageId, targetParentId, newTitle, options) => {
|
|
352
|
+
const analytics = new Analytics();
|
|
353
|
+
try {
|
|
354
|
+
const config = getConfig();
|
|
355
|
+
const client = new ConfluenceClient(config);
|
|
356
|
+
|
|
357
|
+
// Parse numeric flags with safe fallbacks
|
|
358
|
+
const parsedDepth = parseInt(options.maxDepth, 10);
|
|
359
|
+
const maxDepth = Number.isNaN(parsedDepth) ? 10 : parsedDepth;
|
|
360
|
+
const parsedDelay = parseInt(options.delayMs, 10);
|
|
361
|
+
const delayMs = Number.isNaN(parsedDelay) ? 100 : parsedDelay;
|
|
362
|
+
const copySuffix = options.copySuffix ?? ' (Copy)';
|
|
363
|
+
|
|
364
|
+
console.log(chalk.blue('🚀 Starting page tree copy...'));
|
|
365
|
+
console.log(`Source: ${sourcePageId}`);
|
|
366
|
+
console.log(`Target parent: ${targetParentId}`);
|
|
367
|
+
if (newTitle) console.log(`New root title: ${newTitle}`);
|
|
368
|
+
console.log(`Max depth: ${maxDepth}`);
|
|
369
|
+
console.log(`Delay: ${delayMs} ms`);
|
|
370
|
+
if (copySuffix) console.log(`Root suffix: ${copySuffix}`);
|
|
371
|
+
console.log('');
|
|
372
|
+
|
|
373
|
+
// Parse exclude patterns
|
|
374
|
+
let excludePatterns = [];
|
|
375
|
+
if (options.exclude) {
|
|
376
|
+
excludePatterns = options.exclude.split(',').map(p => p.trim()).filter(Boolean);
|
|
377
|
+
if (excludePatterns.length > 0) {
|
|
378
|
+
console.log(chalk.yellow(`Exclude patterns: ${excludePatterns.join(', ')}`));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Progress callback
|
|
383
|
+
const onProgress = (message) => {
|
|
384
|
+
console.log(message);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// Dry-run: compute plan without creating anything
|
|
388
|
+
if (options.dryRun) {
|
|
389
|
+
const info = await client.getPageInfo(sourcePageId);
|
|
390
|
+
const rootTitle = newTitle || `${info.title}${copySuffix}`;
|
|
391
|
+
const descendants = await client.getAllDescendantPages(sourcePageId, maxDepth);
|
|
392
|
+
const filtered = descendants.filter(p => !client.shouldExcludePage(p.title, excludePatterns));
|
|
393
|
+
console.log(chalk.yellow('Dry run: no changes will be made.'));
|
|
394
|
+
console.log(`Would create root: ${chalk.blue(rootTitle)} (under parent ${targetParentId})`);
|
|
395
|
+
console.log(`Would create ${filtered.length} child page(s)`);
|
|
396
|
+
// Show a preview list (first 50)
|
|
397
|
+
const tree = client.buildPageTree(filtered, sourcePageId);
|
|
398
|
+
const lines = [];
|
|
399
|
+
const walk = (nodes, depth = 0) => {
|
|
400
|
+
for (const n of nodes) {
|
|
401
|
+
if (lines.length >= 50) return; // limit output
|
|
402
|
+
lines.push(`${' '.repeat(depth)}- ${n.title}`);
|
|
403
|
+
if (n.children && n.children.length) walk(n.children, depth + 1);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
walk(tree);
|
|
407
|
+
if (lines.length) {
|
|
408
|
+
console.log('Planned children:');
|
|
409
|
+
lines.forEach(l => console.log(l));
|
|
410
|
+
if (filtered.length > lines.length) {
|
|
411
|
+
console.log(`...and ${filtered.length - lines.length} more`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
analytics.track('copy_tree_dry_run', true);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Copy the page tree
|
|
419
|
+
const result = await client.copyPageTree(
|
|
420
|
+
sourcePageId,
|
|
421
|
+
targetParentId,
|
|
422
|
+
newTitle,
|
|
423
|
+
{
|
|
424
|
+
maxDepth,
|
|
425
|
+
excludePatterns,
|
|
426
|
+
onProgress: options.quiet ? null : onProgress,
|
|
427
|
+
quiet: options.quiet,
|
|
428
|
+
delayMs,
|
|
429
|
+
copySuffix
|
|
430
|
+
}
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
console.log('');
|
|
434
|
+
console.log(chalk.green('✅ Page tree copy completed'));
|
|
435
|
+
console.log(`Root page: ${chalk.blue(result.rootPage.title)} (ID: ${result.rootPage.id})`);
|
|
436
|
+
console.log(`Total copied pages: ${chalk.blue(result.totalCopied)}`);
|
|
437
|
+
if (result.failures?.length) {
|
|
438
|
+
console.log(chalk.yellow(`Failures: ${result.failures.length}`));
|
|
439
|
+
result.failures.slice(0, 10).forEach(f => {
|
|
440
|
+
const reason = f.status ? `${f.status}` : '';
|
|
441
|
+
console.log(` - ${f.title} (ID: ${f.id})${reason ? `: ${reason}` : ''}`);
|
|
442
|
+
});
|
|
443
|
+
if (result.failures.length > 10) {
|
|
444
|
+
console.log(` - ...and ${result.failures.length - 10} more`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
console.log(`URL: ${chalk.gray(`https://${config.domain}/wiki${result.rootPage._links.webui}`)}`);
|
|
448
|
+
if (options.failOnError && result.failures?.length) {
|
|
449
|
+
analytics.track('copy_tree', false);
|
|
450
|
+
console.error(chalk.red('Completed with failures and --fail-on-error is set.'));
|
|
451
|
+
process.exit(1);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
analytics.track('copy_tree', true);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
analytics.track('copy_tree', false);
|
|
457
|
+
console.error(chalk.red('Error:'), error.message);
|
|
458
|
+
process.exit(1);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
340
462
|
program.parse();
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Confluence CLI - Copy Page Tree Example
|
|
4
|
+
# This script shows how to copy a page and all its descendants to a new location.
|
|
5
|
+
|
|
6
|
+
echo "📋 Confluence CLI - Copy Page Tree Example"
|
|
7
|
+
echo "=================================================="
|
|
8
|
+
|
|
9
|
+
# Prerequisites
|
|
10
|
+
echo ""
|
|
11
|
+
echo "📝 Prerequisites:"
|
|
12
|
+
echo "- confluence CLI is set up (confluence init)"
|
|
13
|
+
echo "- You have access to source and target locations"
|
|
14
|
+
echo "- You have permissions to create pages"
|
|
15
|
+
echo ""
|
|
16
|
+
|
|
17
|
+
# Step 1: Find the source page
|
|
18
|
+
echo "1️⃣ Find the source page"
|
|
19
|
+
echo "=============================="
|
|
20
|
+
echo ""
|
|
21
|
+
echo "Method 1: Find by title"
|
|
22
|
+
echo "confluence find \"Project Docs\" --space MYTEAM"
|
|
23
|
+
echo ""
|
|
24
|
+
echo "Method 2: Search"
|
|
25
|
+
echo "confluence search \"Project\""
|
|
26
|
+
echo ""
|
|
27
|
+
echo "📝 Note the source page ID from the output (e.g., 123456789)"
|
|
28
|
+
echo ""
|
|
29
|
+
|
|
30
|
+
# Step 2: Find the target parent page
|
|
31
|
+
echo "2️⃣ Find the target parent page"
|
|
32
|
+
echo "========================="
|
|
33
|
+
echo ""
|
|
34
|
+
echo "confluence find \"Backup\" --space BACKUP"
|
|
35
|
+
echo "or"
|
|
36
|
+
echo "confluence find \"Archive\" --space ARCHIVE"
|
|
37
|
+
echo ""
|
|
38
|
+
echo "📝 Note the target parent page ID (e.g., 987654321)"
|
|
39
|
+
echo ""
|
|
40
|
+
|
|
41
|
+
# Step 3: Run the copy
|
|
42
|
+
echo "3️⃣ Run copy"
|
|
43
|
+
echo "========================"
|
|
44
|
+
echo ""
|
|
45
|
+
|
|
46
|
+
echo "📄 Basic: copy with all children"
|
|
47
|
+
echo 'confluence copy-tree 123456789 987654321 "Project Docs (Backup)"'
|
|
48
|
+
echo ""
|
|
49
|
+
|
|
50
|
+
echo "📄 Depth-limited (3 levels)"
|
|
51
|
+
echo 'confluence copy-tree 123456789 987654321 "Project Docs (Summary)" --max-depth 3'
|
|
52
|
+
echo ""
|
|
53
|
+
|
|
54
|
+
echo "📄 Exclude patterns"
|
|
55
|
+
echo 'confluence copy-tree 123456789 987654321 "Project Docs (Clean)" --exclude "temp*,test*,*draft*"'
|
|
56
|
+
echo ""
|
|
57
|
+
|
|
58
|
+
echo "📄 Quiet mode"
|
|
59
|
+
echo 'confluence copy-tree 123456789 987654321 --quiet'
|
|
60
|
+
echo ""
|
|
61
|
+
|
|
62
|
+
echo "📄 Control pacing and naming"
|
|
63
|
+
echo 'confluence copy-tree 123456789 987654321 --delay-ms 150 --copy-suffix " (Backup)"'
|
|
64
|
+
echo ""
|
|
65
|
+
|
|
66
|
+
# Practical example
|
|
67
|
+
echo "💡 Practical example"
|
|
68
|
+
echo "================="
|
|
69
|
+
echo ""
|
|
70
|
+
echo "# 1. Capture source page ID"
|
|
71
|
+
echo 'SOURCE_ID=$(confluence find "Project Docs" --space MYTEAM | grep "ID:" | awk "{print \$2}")'
|
|
72
|
+
echo ""
|
|
73
|
+
echo "# 2. Capture target parent ID"
|
|
74
|
+
echo 'TARGET_ID=$(confluence find "Backup Folder" --space BACKUP | grep "ID:" | awk "{print \$2}")'
|
|
75
|
+
echo ""
|
|
76
|
+
echo "# 3. Run backup with date suffix"
|
|
77
|
+
echo 'confluence copy-tree $SOURCE_ID $TARGET_ID "Project Docs Backup - $(date +%Y%m%d)"'
|
|
78
|
+
echo ""
|
|
79
|
+
|
|
80
|
+
# Advanced usage
|
|
81
|
+
echo "🚀 Advanced"
|
|
82
|
+
echo "============="
|
|
83
|
+
echo ""
|
|
84
|
+
echo "1. Large trees with progress"
|
|
85
|
+
echo " confluence copy-tree 123456789 987654321 | tee copy-log.txt"
|
|
86
|
+
echo ""
|
|
87
|
+
echo "2. Multiple exclude patterns"
|
|
88
|
+
echo " confluence copy-tree 123456789 987654321 --exclude \"temp*,test*,*draft*,*temp*\""
|
|
89
|
+
echo ""
|
|
90
|
+
echo "3. Shallow copy (only direct children)"
|
|
91
|
+
echo " confluence copy-tree 123456789 987654321 --max-depth 1"
|
|
92
|
+
echo ""
|
|
93
|
+
|
|
94
|
+
# Notes and tips
|
|
95
|
+
echo "⚠️ Notes and tips"
|
|
96
|
+
echo "=================="
|
|
97
|
+
echo "- Large trees may take time to copy"
|
|
98
|
+
echo "- A short delay between siblings helps avoid rate limits (tune with --delay-ms)"
|
|
99
|
+
echo "- Partial copies can remain if errors occur"
|
|
100
|
+
echo "- Pages without permission are skipped; run with --fail-on-error to fail the run"
|
|
101
|
+
echo "- Validate links and references after copying"
|
|
102
|
+
echo "- Try with a small tree first"
|
|
103
|
+
echo ""
|
|
104
|
+
|
|
105
|
+
echo "📊 Verify results"
|
|
106
|
+
echo "================"
|
|
107
|
+
echo "After completion, you can check the results:"
|
|
108
|
+
echo ""
|
|
109
|
+
echo "# Root page info"
|
|
110
|
+
echo "confluence info [NEW_PAGE_ID]"
|
|
111
|
+
echo ""
|
|
112
|
+
echo "# Find copied pages"
|
|
113
|
+
echo "confluence search \"Copy\" --limit 20"
|
|
114
|
+
echo ""
|
|
115
|
+
|
|
116
|
+
echo "✅ Example complete!"
|
|
117
|
+
echo "Replace example IDs with real ones when running."
|
|
@@ -1,65 +1,67 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
#!/bin/bash
|
|
4
|
+
|
|
5
|
+
# Create a test page under the Project Documentation page
|
|
6
|
+
# This script demonstrates typical Confluence CLI usage.
|
|
5
7
|
|
|
6
|
-
echo "🔍
|
|
7
|
-
echo "
|
|
8
|
+
echo "🔍 Create a test page under Project Documentation"
|
|
9
|
+
echo "================================================"
|
|
8
10
|
|
|
9
|
-
# 1
|
|
11
|
+
# Step 1: Find the parent page
|
|
10
12
|
echo ""
|
|
11
|
-
echo "1️⃣
|
|
12
|
-
echo "
|
|
13
|
+
echo "1️⃣ Find the parent page..."
|
|
14
|
+
echo "Run: confluence find \"Project Documentation\" --space MYTEAM"
|
|
13
15
|
echo ""
|
|
14
16
|
|
|
15
|
-
#
|
|
17
|
+
# For real execution, uncomment below
|
|
16
18
|
# confluence find "Project Documentation" --space MYTEAM
|
|
17
19
|
|
|
18
|
-
echo "📝
|
|
20
|
+
echo "📝 Note the page ID from the output (e.g., 123456789)"
|
|
19
21
|
echo ""
|
|
20
22
|
|
|
21
|
-
# 2
|
|
22
|
-
echo "2️⃣
|
|
23
|
-
echo "
|
|
24
|
-
echo "
|
|
23
|
+
# Step 2: Inspect page info
|
|
24
|
+
echo "2️⃣ Inspect page info..."
|
|
25
|
+
echo "Run: confluence info [PAGE_ID]"
|
|
26
|
+
echo "Example: confluence info 123456789"
|
|
25
27
|
echo ""
|
|
26
28
|
|
|
27
|
-
# 3
|
|
28
|
-
echo "3️⃣
|
|
29
|
-
echo "
|
|
30
|
-
echo "
|
|
29
|
+
# Step 3: Read page content (optional)
|
|
30
|
+
echo "3️⃣ Read content (optional)..."
|
|
31
|
+
echo "Run: confluence read [PAGE_ID] | head -20"
|
|
32
|
+
echo "Example: confluence read 123456789 | head -20"
|
|
31
33
|
echo ""
|
|
32
34
|
|
|
33
|
-
# 4
|
|
34
|
-
echo "4️⃣
|
|
35
|
+
# Step 4: Create a child test page
|
|
36
|
+
echo "4️⃣ Create child test page..."
|
|
35
37
|
echo ""
|
|
36
38
|
|
|
37
|
-
#
|
|
38
|
-
echo "📄
|
|
39
|
-
echo 'confluence create-child "Test Page - $(date +%Y%m%d)" [
|
|
39
|
+
# Simple text content
|
|
40
|
+
echo "📄 Option 1: Simple text content"
|
|
41
|
+
echo 'confluence create-child "Test Page - $(date +%Y%m%d)" [PARENT_PAGE_ID] --content "This is a test page created via CLI. Created at: $(date)"'
|
|
40
42
|
echo ""
|
|
41
43
|
|
|
42
|
-
#
|
|
43
|
-
echo "📄
|
|
44
|
-
echo "confluence create-child \"Test Documentation - $(date +%Y%m%d)\" [
|
|
44
|
+
# From Markdown file
|
|
45
|
+
echo "📄 Option 2: From Markdown file"
|
|
46
|
+
echo "confluence create-child \"Test Documentation - $(date +%Y%m%d)\" [PARENT_PAGE_ID] --file ./sample-page.md --format markdown"
|
|
45
47
|
echo ""
|
|
46
48
|
|
|
47
|
-
# HTML
|
|
48
|
-
echo "📄
|
|
49
|
-
echo 'confluence create-child "Test HTML Page" [
|
|
49
|
+
# From HTML content
|
|
50
|
+
echo "📄 Option 3: From HTML content"
|
|
51
|
+
echo 'confluence create-child "Test HTML Page" [PARENT_PAGE_ID] --content "<h1>Test Page</h1><p>This is a <strong>HTML</strong> example page.</p>" --format html'
|
|
50
52
|
echo ""
|
|
51
53
|
|
|
52
|
-
echo "💡
|
|
54
|
+
echo "💡 Practical example:"
|
|
53
55
|
echo "=============================="
|
|
54
|
-
echo "# 1.
|
|
56
|
+
echo "# 1. Get parent page ID"
|
|
55
57
|
echo 'PARENT_ID=$(confluence find "Project Documentation" --space MYTEAM | grep "ID:" | cut -d" " -f2)'
|
|
56
58
|
echo ""
|
|
57
|
-
echo "# 2.
|
|
58
|
-
echo 'confluence create-child "
|
|
59
|
+
echo "# 2. Create test page"
|
|
60
|
+
echo 'confluence create-child "Test Page - $(date +%Y%m%d_%H%M)" $PARENT_ID --content "Page for CLI testing."'
|
|
59
61
|
echo ""
|
|
60
62
|
|
|
61
|
-
echo "⚠️
|
|
62
|
-
echo "- confluence CLI
|
|
63
|
-
echo "-
|
|
64
|
-
echo "-
|
|
65
|
-
echo "-
|
|
63
|
+
echo "⚠️ Notes:"
|
|
64
|
+
echo "- confluence CLI must be set up (confluence init)"
|
|
65
|
+
echo "- You need appropriate permissions on the Confluence instance"
|
|
66
|
+
echo "- Ensure you have page creation permission"
|
|
67
|
+
echo "- Clean up test pages afterward"
|
package/lib/config.js
CHANGED
|
@@ -7,9 +7,26 @@ const chalk = require('chalk');
|
|
|
7
7
|
const CONFIG_DIR = path.join(os.homedir(), '.confluence-cli');
|
|
8
8
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const AUTH_CHOICES = [
|
|
11
|
+
{ name: 'Basic (email + API token)', value: 'basic' },
|
|
12
|
+
{ name: 'Bearer token', value: 'bearer' }
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const requiredInput = (label) => (input) => {
|
|
16
|
+
if (!input || !input.trim()) {
|
|
17
|
+
return `${label} is required`;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const normalizeAuthType = (rawValue, hasEmail) => {
|
|
23
|
+
const normalized = (rawValue || '').trim().toLowerCase();
|
|
24
|
+
if (normalized === 'basic' || normalized === 'bearer') {
|
|
25
|
+
return normalized;
|
|
26
|
+
}
|
|
27
|
+
return hasEmail ? 'basic' : 'bearer';
|
|
28
|
+
};
|
|
29
|
+
|
|
13
30
|
async function initConfig() {
|
|
14
31
|
console.log(chalk.blue('🚀 Confluence CLI Configuration'));
|
|
15
32
|
console.log('Please provide your Confluence connection details:\n');
|
|
@@ -19,70 +36,103 @@ async function initConfig() {
|
|
|
19
36
|
type: 'input',
|
|
20
37
|
name: 'domain',
|
|
21
38
|
message: 'Confluence domain (e.g., yourcompany.atlassian.net):',
|
|
22
|
-
validate: (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
validate: requiredInput('Domain')
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'list',
|
|
43
|
+
name: 'authType',
|
|
44
|
+
message: 'Authentication method:',
|
|
45
|
+
choices: AUTH_CHOICES,
|
|
46
|
+
default: 'basic'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'input',
|
|
50
|
+
name: 'email',
|
|
51
|
+
message: 'Confluence email (used with API token):',
|
|
52
|
+
when: (responses) => responses.authType === 'basic',
|
|
53
|
+
validate: requiredInput('Email')
|
|
28
54
|
},
|
|
29
55
|
{
|
|
30
56
|
type: 'password',
|
|
31
57
|
name: 'token',
|
|
32
58
|
message: 'API Token:',
|
|
33
|
-
validate: (
|
|
34
|
-
if (!input.trim()) {
|
|
35
|
-
return 'API Token is required';
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
59
|
+
validate: requiredInput('API Token')
|
|
39
60
|
}
|
|
40
61
|
]);
|
|
41
62
|
|
|
42
|
-
// Create config directory if it doesn't exist
|
|
43
63
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
44
64
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
45
65
|
}
|
|
46
66
|
|
|
47
|
-
// Save configuration
|
|
48
67
|
const config = {
|
|
49
68
|
domain: answers.domain.trim(),
|
|
50
|
-
token: answers.token.trim()
|
|
69
|
+
token: answers.token.trim(),
|
|
70
|
+
authType: answers.authType,
|
|
71
|
+
email: answers.authType === 'basic' ? answers.email.trim() : undefined
|
|
51
72
|
};
|
|
52
73
|
|
|
53
74
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
54
|
-
|
|
75
|
+
|
|
55
76
|
console.log(chalk.green('✅ Configuration saved successfully!'));
|
|
56
77
|
console.log(`Config file location: ${chalk.gray(CONFIG_FILE)}`);
|
|
57
78
|
console.log(chalk.yellow('\n💡 Tip: You can regenerate this config anytime by running "confluence init"'));
|
|
58
79
|
}
|
|
59
80
|
|
|
60
|
-
/**
|
|
61
|
-
* Get configuration
|
|
62
|
-
*/
|
|
63
81
|
function getConfig() {
|
|
64
|
-
// First check for environment variables
|
|
65
82
|
const envDomain = process.env.CONFLUENCE_DOMAIN || process.env.CONFLUENCE_HOST;
|
|
66
83
|
const envToken = process.env.CONFLUENCE_API_TOKEN;
|
|
84
|
+
const envEmail = process.env.CONFLUENCE_EMAIL;
|
|
85
|
+
const envAuthType = process.env.CONFLUENCE_AUTH_TYPE;
|
|
67
86
|
|
|
68
87
|
if (envDomain && envToken) {
|
|
88
|
+
const authType = normalizeAuthType(envAuthType, Boolean(envEmail));
|
|
89
|
+
|
|
90
|
+
if (authType === 'basic' && !envEmail) {
|
|
91
|
+
console.error(chalk.red('❌ Basic authentication requires CONFLUENCE_EMAIL.'));
|
|
92
|
+
console.log(chalk.yellow('Set CONFLUENCE_EMAIL or switch to bearer auth by setting CONFLUENCE_AUTH_TYPE=bearer.'));
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
69
96
|
return {
|
|
70
|
-
domain: envDomain,
|
|
71
|
-
token: envToken
|
|
97
|
+
domain: envDomain.trim(),
|
|
98
|
+
token: envToken.trim(),
|
|
99
|
+
email: envEmail ? envEmail.trim() : undefined,
|
|
100
|
+
authType
|
|
72
101
|
};
|
|
73
102
|
}
|
|
74
103
|
|
|
75
|
-
// Check for config file
|
|
76
104
|
if (!fs.existsSync(CONFIG_FILE)) {
|
|
77
105
|
console.error(chalk.red('❌ No configuration found!'));
|
|
78
106
|
console.log(chalk.yellow('Please run "confluence init" to set up your configuration.'));
|
|
79
|
-
console.log(chalk.gray('Or set environment variables: CONFLUENCE_DOMAIN and
|
|
107
|
+
console.log(chalk.gray('Or set environment variables: CONFLUENCE_DOMAIN, CONFLUENCE_API_TOKEN, and CONFLUENCE_EMAIL.'));
|
|
80
108
|
process.exit(1);
|
|
81
109
|
}
|
|
82
110
|
|
|
83
111
|
try {
|
|
84
|
-
const
|
|
85
|
-
|
|
112
|
+
const storedConfig = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
113
|
+
const trimmedDomain = (storedConfig.domain || '').trim();
|
|
114
|
+
const trimmedToken = (storedConfig.token || '').trim();
|
|
115
|
+
const trimmedEmail = storedConfig.email ? storedConfig.email.trim() : undefined;
|
|
116
|
+
const authType = normalizeAuthType(storedConfig.authType, Boolean(trimmedEmail));
|
|
117
|
+
|
|
118
|
+
if (!trimmedDomain || !trimmedToken) {
|
|
119
|
+
console.error(chalk.red('❌ Configuration file is missing required values.'));
|
|
120
|
+
console.log(chalk.yellow('Run "confluence init" to refresh your settings.'));
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (authType === 'basic' && !trimmedEmail) {
|
|
125
|
+
console.error(chalk.red('❌ Basic authentication requires an email address.'));
|
|
126
|
+
console.log(chalk.yellow('Please rerun "confluence init" to add your Confluence email.'));
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
domain: trimmedDomain,
|
|
132
|
+
token: trimmedToken,
|
|
133
|
+
email: trimmedEmail,
|
|
134
|
+
authType
|
|
135
|
+
};
|
|
86
136
|
} catch (error) {
|
|
87
137
|
console.error(chalk.red('❌ Error reading configuration file:'), error.message);
|
|
88
138
|
console.log(chalk.yellow('Please run "confluence init" to recreate your configuration.'));
|
package/lib/confluence-client.js
CHANGED
|
@@ -4,21 +4,34 @@ const MarkdownIt = require('markdown-it');
|
|
|
4
4
|
|
|
5
5
|
class ConfluenceClient {
|
|
6
6
|
constructor(config) {
|
|
7
|
-
this.baseURL = `https://${config.domain}/rest/api`;
|
|
8
|
-
this.token = config.token;
|
|
9
7
|
this.domain = config.domain;
|
|
8
|
+
this.token = config.token;
|
|
9
|
+
this.email = config.email;
|
|
10
|
+
this.authType = (config.authType || (this.email ? 'basic' : 'bearer')).toLowerCase();
|
|
11
|
+
this.baseURL = `https://${this.domain}/rest/api`;
|
|
10
12
|
this.markdown = new MarkdownIt();
|
|
11
13
|
this.setupConfluenceMarkdownExtensions();
|
|
12
|
-
|
|
14
|
+
|
|
15
|
+
const headers = {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
'Authorization': this.authType === 'basic' ? this.buildBasicAuthHeader() : `Bearer ${this.token}`
|
|
18
|
+
};
|
|
19
|
+
|
|
13
20
|
this.client = axios.create({
|
|
14
21
|
baseURL: this.baseURL,
|
|
15
|
-
headers
|
|
16
|
-
'Authorization': `Bearer ${this.token}`,
|
|
17
|
-
'Content-Type': 'application/json'
|
|
18
|
-
}
|
|
22
|
+
headers
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
buildBasicAuthHeader() {
|
|
27
|
+
if (!this.email) {
|
|
28
|
+
throw new Error('Basic authentication requires an email address.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const encodedCredentials = Buffer.from(`${this.email}:${this.token}`).toString('base64');
|
|
32
|
+
return `Basic ${encodedCredentials}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
/**
|
|
23
36
|
* Extract page ID from URL or return the ID if it's already a number
|
|
24
37
|
*/
|
|
@@ -648,6 +661,246 @@ class ConfluenceClient {
|
|
|
648
661
|
url: content._links?.webui || ''
|
|
649
662
|
};
|
|
650
663
|
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Get child pages of a given page
|
|
667
|
+
*/
|
|
668
|
+
async getChildPages(pageId, limit = 500) {
|
|
669
|
+
const response = await this.client.get(`/content/${pageId}/child/page`, {
|
|
670
|
+
params: {
|
|
671
|
+
limit: limit,
|
|
672
|
+
// Fetch lightweight payload; content fetched on-demand when copying
|
|
673
|
+
expand: 'space,version'
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
return response.data.results.map(page => ({
|
|
678
|
+
id: page.id,
|
|
679
|
+
title: page.title,
|
|
680
|
+
type: page.type,
|
|
681
|
+
status: page.status,
|
|
682
|
+
space: page.space,
|
|
683
|
+
version: page.version?.number || 1
|
|
684
|
+
}));
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Get all descendant pages recursively
|
|
689
|
+
*/
|
|
690
|
+
async getAllDescendantPages(pageId, maxDepth = 10, currentDepth = 0) {
|
|
691
|
+
if (currentDepth >= maxDepth) {
|
|
692
|
+
return [];
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
const children = await this.getChildPages(pageId);
|
|
696
|
+
// Attach parentId so we can later reconstruct hierarchy if needed
|
|
697
|
+
const childrenWithParent = children.map(child => ({ ...child, parentId: pageId }));
|
|
698
|
+
let allDescendants = [...childrenWithParent];
|
|
699
|
+
|
|
700
|
+
for (const child of children) {
|
|
701
|
+
const grandChildren = await this.getAllDescendantPages(
|
|
702
|
+
child.id,
|
|
703
|
+
maxDepth,
|
|
704
|
+
currentDepth + 1
|
|
705
|
+
);
|
|
706
|
+
allDescendants = allDescendants.concat(grandChildren);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
return allDescendants;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Copy a page tree (page and all its descendants) to a new location
|
|
714
|
+
*/
|
|
715
|
+
async copyPageTree(sourcePageId, targetParentId, newTitle = null, options = {}) {
|
|
716
|
+
const {
|
|
717
|
+
maxDepth = 10,
|
|
718
|
+
excludePatterns = [],
|
|
719
|
+
onProgress = null,
|
|
720
|
+
quiet = false,
|
|
721
|
+
delayMs = 100,
|
|
722
|
+
copySuffix = ' (Copy)'
|
|
723
|
+
} = options;
|
|
724
|
+
|
|
725
|
+
// Get source page information
|
|
726
|
+
const sourcePage = await this.getPageForEdit(sourcePageId);
|
|
727
|
+
const sourceInfo = await this.getPageInfo(sourcePageId);
|
|
728
|
+
|
|
729
|
+
// Determine new title
|
|
730
|
+
const finalTitle = newTitle || `${sourcePage.title}${copySuffix}`;
|
|
731
|
+
|
|
732
|
+
if (!quiet && onProgress) {
|
|
733
|
+
onProgress(`Copying root: ${sourcePage.title} -> ${finalTitle}`);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Create the root copied page
|
|
737
|
+
const newRootPage = await this.createChildPage(
|
|
738
|
+
finalTitle,
|
|
739
|
+
sourceInfo.space.key,
|
|
740
|
+
targetParentId,
|
|
741
|
+
sourcePage.content,
|
|
742
|
+
'storage'
|
|
743
|
+
);
|
|
744
|
+
|
|
745
|
+
if (!quiet && onProgress) {
|
|
746
|
+
onProgress(`Root page created: ${newRootPage.title} (ID: ${newRootPage.id})`);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const result = {
|
|
750
|
+
rootPage: newRootPage,
|
|
751
|
+
copiedPages: [newRootPage],
|
|
752
|
+
failures: [],
|
|
753
|
+
totalCopied: 1,
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
// Precompile exclude patterns once for efficiency
|
|
757
|
+
const compiledExclude = Array.isArray(excludePatterns)
|
|
758
|
+
? excludePatterns.filter(Boolean).map(p => this.globToRegExp(p))
|
|
759
|
+
: [];
|
|
760
|
+
|
|
761
|
+
await this.copyChildrenRecursive(
|
|
762
|
+
sourcePageId,
|
|
763
|
+
newRootPage.id,
|
|
764
|
+
0,
|
|
765
|
+
{
|
|
766
|
+
spaceKey: sourceInfo.space.key,
|
|
767
|
+
maxDepth,
|
|
768
|
+
excludePatterns,
|
|
769
|
+
compiledExclude,
|
|
770
|
+
onProgress,
|
|
771
|
+
quiet,
|
|
772
|
+
delayMs,
|
|
773
|
+
},
|
|
774
|
+
result
|
|
775
|
+
);
|
|
776
|
+
|
|
777
|
+
result.totalCopied = result.copiedPages.length;
|
|
778
|
+
return result;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Build a tree structure from flat array of pages
|
|
783
|
+
*/
|
|
784
|
+
buildPageTree(pages, rootPageId) {
|
|
785
|
+
const pageMap = new Map();
|
|
786
|
+
const tree = [];
|
|
787
|
+
|
|
788
|
+
// Create nodes
|
|
789
|
+
pages.forEach(page => {
|
|
790
|
+
pageMap.set(page.id, { ...page, children: [] });
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// Link by parentId if available; otherwise attach to root
|
|
794
|
+
pages.forEach(page => {
|
|
795
|
+
const node = pageMap.get(page.id);
|
|
796
|
+
const parentId = page.parentId;
|
|
797
|
+
if (parentId && pageMap.has(parentId)) {
|
|
798
|
+
pageMap.get(parentId).children.push(node);
|
|
799
|
+
} else if (parentId === rootPageId || !parentId) {
|
|
800
|
+
tree.push(node);
|
|
801
|
+
} else {
|
|
802
|
+
// Parent not present in the list; treat as top-level under root
|
|
803
|
+
tree.push(node);
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
return tree;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Recursively copy pages maintaining hierarchy
|
|
812
|
+
*/
|
|
813
|
+
async copyChildrenRecursive(sourceParentId, targetParentId, currentDepth, opts, result) {
|
|
814
|
+
const { spaceKey, maxDepth, excludePatterns, compiledExclude = [], onProgress, quiet, delayMs = 100 } = opts || {};
|
|
815
|
+
|
|
816
|
+
if (currentDepth >= maxDepth) {
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const children = await this.getChildPages(sourceParentId);
|
|
821
|
+
for (let i = 0; i < children.length; i++) {
|
|
822
|
+
const child = children[i];
|
|
823
|
+
const patterns = (compiledExclude && compiledExclude.length) ? compiledExclude : excludePatterns;
|
|
824
|
+
if (this.shouldExcludePage(child.title, patterns)) {
|
|
825
|
+
if (!quiet && onProgress) {
|
|
826
|
+
onProgress(`Skipped: ${child.title}`);
|
|
827
|
+
}
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
if (!quiet && onProgress) {
|
|
832
|
+
onProgress(`Copying: ${child.title}`);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
try {
|
|
836
|
+
// Fetch full content to ensure complete copy
|
|
837
|
+
const fullChild = await this.getPageForEdit(child.id);
|
|
838
|
+
const newPage = await this.createChildPage(
|
|
839
|
+
fullChild.title,
|
|
840
|
+
spaceKey,
|
|
841
|
+
targetParentId,
|
|
842
|
+
fullChild.content,
|
|
843
|
+
'storage'
|
|
844
|
+
);
|
|
845
|
+
|
|
846
|
+
result.copiedPages.push(newPage);
|
|
847
|
+
if (!quiet && onProgress) {
|
|
848
|
+
onProgress(`Created: ${newPage.title} (ID: ${newPage.id})`);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// Rate limiting safety: only pause between siblings
|
|
852
|
+
if (delayMs > 0 && i < children.length - 1) {
|
|
853
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// Recurse into this child's subtree
|
|
857
|
+
await this.copyChildrenRecursive(child.id, newPage.id, currentDepth + 1, opts, result);
|
|
858
|
+
} catch (error) {
|
|
859
|
+
if (!quiet && onProgress) {
|
|
860
|
+
const status = error?.response?.status;
|
|
861
|
+
const statusText = error?.response?.statusText;
|
|
862
|
+
const msg = status ? `${status} ${statusText || ''}`.trim() : error.message;
|
|
863
|
+
onProgress(`Failed: ${child.title} - ${msg}`);
|
|
864
|
+
}
|
|
865
|
+
result.failures.push({
|
|
866
|
+
id: child.id,
|
|
867
|
+
title: child.title,
|
|
868
|
+
error: error.message,
|
|
869
|
+
status: error?.response?.status || null
|
|
870
|
+
});
|
|
871
|
+
// Continue with other pages (do not throw)
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Convert a simple glob pattern to a safe RegExp
|
|
879
|
+
* Supports '*' → '.*' and '?' → '.', escapes other regex metacharacters.
|
|
880
|
+
*/
|
|
881
|
+
globToRegExp(pattern, flags = 'i') {
|
|
882
|
+
// Escape regex special characters: . + ^ $ { } ( ) | [ ] \
|
|
883
|
+
// Note: backslash must be escaped properly in string and class contexts
|
|
884
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
885
|
+
const regexPattern = escaped
|
|
886
|
+
.replace(/\*/g, '.*')
|
|
887
|
+
.replace(/\?/g, '.');
|
|
888
|
+
return new RegExp(`^${regexPattern}$`, flags);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Check if a page should be excluded based on patterns
|
|
893
|
+
*/
|
|
894
|
+
shouldExcludePage(title, excludePatterns) {
|
|
895
|
+
if (!excludePatterns || excludePatterns.length === 0) {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
return excludePatterns.some(pattern => {
|
|
900
|
+
if (pattern instanceof RegExp) return pattern.test(title);
|
|
901
|
+
return this.globToRegExp(pattern).test(title);
|
|
902
|
+
});
|
|
903
|
+
}
|
|
651
904
|
}
|
|
652
905
|
|
|
653
906
|
module.exports = ConfluenceClient;
|
package/llms.txt
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Confluence CLI
|
|
2
|
+
|
|
3
|
+
> A powerful command-line interface for Atlassian Confluence that allows you to read, search, and manage your Confluence content from the terminal.
|
|
4
|
+
|
|
5
|
+
This CLI tool provides a comprehensive set of commands for interacting with Confluence. Key features include creating, reading, updating, and searching for pages. It supports various content formats like markdown and HTML.
|
|
6
|
+
|
|
7
|
+
To get started, install the tool via npm and initialize the configuration:
|
|
8
|
+
```sh
|
|
9
|
+
npm install -g confluence-cli
|
|
10
|
+
confluence init
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Documentation
|
|
14
|
+
|
|
15
|
+
- [README.md](./README.md): Main documentation with installation, usage, and command reference.
|
|
16
|
+
|
|
17
|
+
## Core Source Code
|
|
18
|
+
|
|
19
|
+
- [bin/confluence.js](./bin/confluence.js): The main entry point for the CLI, defines commands and argument parsing.
|
|
20
|
+
- [lib/confluence-client.js](./lib/confluence-client.js): The client library for interacting with the Confluence REST API.
|
|
21
|
+
- [package.json](./package.json): Project metadata, dependencies, and scripts.
|
|
22
|
+
|
|
23
|
+
## Recent Changes & Fixes
|
|
24
|
+
|
|
25
|
+
This section summarizes recent improvements to align the codebase with its documentation and fix bugs.
|
|
26
|
+
|
|
27
|
+
### `update` Command Logic and Documentation:
|
|
28
|
+
- **Inconsistency:** The `README.md` suggested that updating a page's title without changing its content was possible. However, the implementation in `bin/confluence.js` incorrectly threw an error if the `--content` or `--file` flags were not provided, making title-only updates impossible.
|
|
29
|
+
- **Fix:**
|
|
30
|
+
- Modified `updatePage` in `lib/confluence-client.js` to fetch and re-use existing page content if no new content is provided.
|
|
31
|
+
- Adjusted validation in `bin/confluence.js` for the `update` command to only require one of `--title`, `--content`, or `--file`.
|
|
32
|
+
- Updated `README.md` with an example of a title-only update.
|
|
33
|
+
|
|
34
|
+
### Incomplete `README.md` Command Reference:
|
|
35
|
+
- **Inconsistency:** The main command table in `README.md` was missing several commands (`create`, `create-child`, `update`, `edit`, `find`).
|
|
36
|
+
- **Fix:** Expanded the command table in `README.md` to include all available commands.
|
|
37
|
+
|
|
38
|
+
### Misleading `read` Command URL Examples:
|
|
39
|
+
- **Inconsistency:** The documentation for the `read` command used "display" or "pretty" URLs, which are not supported by the `extractPageId` function.
|
|
40
|
+
- **Fix:** Removed incorrect URL examples and clarified that only URLs with a `pageId` query parameter are supported.
|
|
41
|
+
|
|
42
|
+
## Next Steps
|
|
43
|
+
|
|
44
|
+
- Refer to [README.md](./README.md) for detailed usage instructions and advanced configuration.
|
|
45
|
+
- For troubleshooting or to contribute, visit the project's GitHub repository at https://github.com/pchuri/confluence-cli.
|
|
46
|
+
- If you encounter issues, open an issue or check the FAQ section in the documentation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "confluence-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A command-line interface for Atlassian Confluence with page creation and editing capabilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "pchuri",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"axios": "^1.
|
|
25
|
+
"axios": "^1.12.0",
|
|
26
26
|
"chalk": "^4.1.2",
|
|
27
27
|
"commander": "^11.1.0",
|
|
28
28
|
"html-to-text": "^9.0.5",
|
|
@@ -10,6 +10,37 @@ describe('ConfluenceClient', () => {
|
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
describe('authentication setup', () => {
|
|
14
|
+
test('uses bearer token headers by default', () => {
|
|
15
|
+
const bearerClient = new ConfluenceClient({
|
|
16
|
+
domain: 'test.atlassian.net',
|
|
17
|
+
token: 'bearer-token'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
expect(bearerClient.client.defaults.headers.Authorization).toBe('Bearer bearer-token');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('builds basic auth headers when email is provided', () => {
|
|
24
|
+
const basicClient = new ConfluenceClient({
|
|
25
|
+
domain: 'test.atlassian.net',
|
|
26
|
+
token: 'basic-token',
|
|
27
|
+
authType: 'basic',
|
|
28
|
+
email: 'user@example.com'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const encoded = Buffer.from('user@example.com:basic-token').toString('base64');
|
|
32
|
+
expect(basicClient.client.defaults.headers.Authorization).toBe(`Basic ${encoded}`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('throws when basic auth is missing an email', () => {
|
|
36
|
+
expect(() => new ConfluenceClient({
|
|
37
|
+
domain: 'test.atlassian.net',
|
|
38
|
+
token: 'missing-email',
|
|
39
|
+
authType: 'basic'
|
|
40
|
+
})).toThrow('Basic authentication requires an email address.');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
13
44
|
describe('extractPageId', () => {
|
|
14
45
|
test('should return numeric page ID as is', () => {
|
|
15
46
|
expect(client.extractPageId('123456789')).toBe('123456789');
|
|
@@ -154,4 +185,72 @@ describe('ConfluenceClient', () => {
|
|
|
154
185
|
expect(typeof client.findPageByTitle).toBe('function');
|
|
155
186
|
});
|
|
156
187
|
});
|
|
188
|
+
|
|
189
|
+
describe('page tree operations', () => {
|
|
190
|
+
test('should have required methods for tree operations', () => {
|
|
191
|
+
expect(typeof client.getChildPages).toBe('function');
|
|
192
|
+
expect(typeof client.getAllDescendantPages).toBe('function');
|
|
193
|
+
expect(typeof client.copyPageTree).toBe('function');
|
|
194
|
+
expect(typeof client.buildPageTree).toBe('function');
|
|
195
|
+
expect(typeof client.shouldExcludePage).toBe('function');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('should correctly exclude pages based on patterns', () => {
|
|
199
|
+
const patterns = ['temp*', 'test*', '*draft*'];
|
|
200
|
+
|
|
201
|
+
expect(client.shouldExcludePage('temporary document', patterns)).toBe(true);
|
|
202
|
+
expect(client.shouldExcludePage('test page', patterns)).toBe(true);
|
|
203
|
+
expect(client.shouldExcludePage('my draft page', patterns)).toBe(true);
|
|
204
|
+
expect(client.shouldExcludePage('normal document', patterns)).toBe(false);
|
|
205
|
+
expect(client.shouldExcludePage('production page', patterns)).toBe(false);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('should handle empty exclude patterns', () => {
|
|
209
|
+
expect(client.shouldExcludePage('any page', [])).toBe(false);
|
|
210
|
+
expect(client.shouldExcludePage('any page', null)).toBe(false);
|
|
211
|
+
expect(client.shouldExcludePage('any page', undefined)).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('globToRegExp should escape regex metacharacters and match case-insensitively', () => {
|
|
215
|
+
const patterns = [
|
|
216
|
+
'file.name*', // dot should be literal
|
|
217
|
+
'[draft]?', // brackets should be literal
|
|
218
|
+
'Plan (Q1)?', // parentheses literal, ? wildcard
|
|
219
|
+
'DATA*SET', // case-insensitive
|
|
220
|
+
];
|
|
221
|
+
const rx = patterns.map(p => client.globToRegExp(p));
|
|
222
|
+
expect('file.name.v1').toMatch(rx[0]);
|
|
223
|
+
expect('filexname').not.toMatch(rx[0]);
|
|
224
|
+
expect('[draft]1').toMatch(rx[1]);
|
|
225
|
+
expect('[draft]AB').not.toMatch(rx[1]);
|
|
226
|
+
expect('Plan (Q1)A').toMatch(rx[2]);
|
|
227
|
+
expect('Plan Q1A').not.toMatch(rx[2]);
|
|
228
|
+
expect('data big set').toMatch(rx[3]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('buildPageTree should link children by parentId and collect orphans at root', () => {
|
|
232
|
+
const rootId = 'root';
|
|
233
|
+
const pages = [
|
|
234
|
+
{ id: 'a', title: 'A', parentId: rootId },
|
|
235
|
+
{ id: 'b', title: 'B', parentId: 'a' },
|
|
236
|
+
{ id: 'c', title: 'C', parentId: 'missing' }, // orphan
|
|
237
|
+
];
|
|
238
|
+
const tree = client.buildPageTree(pages, rootId);
|
|
239
|
+
// tree should contain A and C at top-level (B is child of A)
|
|
240
|
+
const topTitles = tree.map(n => n.title).sort();
|
|
241
|
+
expect(topTitles).toEqual(['A', 'C']);
|
|
242
|
+
const a = tree.find(n => n.title === 'A');
|
|
243
|
+
expect(a.children.map(n => n.title)).toEqual(['B']);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('exclude parser should tolerate spaces and empty items', () => {
|
|
247
|
+
const raw = ' temp* , , *draft* ,,test? ';
|
|
248
|
+
const patterns = raw.split(',').map(p => p.trim()).filter(Boolean);
|
|
249
|
+
expect(patterns).toEqual(['temp*', '*draft*', 'test?']);
|
|
250
|
+
expect(client.shouldExcludePage('temp file', patterns)).toBe(true);
|
|
251
|
+
expect(client.shouldExcludePage('my draft page', patterns)).toBe(true);
|
|
252
|
+
expect(client.shouldExcludePage('test1', patterns)).toBe(true);
|
|
253
|
+
expect(client.shouldExcludePage('production', patterns)).toBe(false);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
157
256
|
});
|
package/llm.txt
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
I have analyzed the codebase and identified several inconsistencies between the `README.md` documentation and the actual implementation of the CLI tool. I have addressed these issues by modifying the code to be more robust and by updating the documentation to be accurate and comprehensive.
|
|
2
|
-
|
|
3
|
-
Here is a summary of the changes:
|
|
4
|
-
|
|
5
|
-
1. **`update` Command Logic and Documentation:**
|
|
6
|
-
* **Inconsistency:** The `README.md` suggested that updating a page's title without changing its content was possible. However, the implementation in `bin/confluence.js` incorrectly threw an error if the `--content` or `--file` flags were not provided, making title-only updates impossible.
|
|
7
|
-
* **Fix:**
|
|
8
|
-
* I modified the `updatePage` function in `lib/confluence-client.js` to check if new content is provided. If not, it now fetches and re-uses the existing page content, preventing accidental data loss during title-only updates.
|
|
9
|
-
* I adjusted the validation logic in `bin/confluence.js` for the `update` command to only require that at least one of `--title`, `--content`, or `--file` is present.
|
|
10
|
-
* I updated the `README.md` to include an explicit example of a title-only update.
|
|
11
|
-
|
|
12
|
-
2. **Incomplete `README.md` Command Reference:**
|
|
13
|
-
* **Inconsistency:** The main command table in the `README.md` was missing several important commands that were fully implemented in the code, including `create`, `create-child`, `update`, `edit`, and `find`.
|
|
14
|
-
* **Fix:** I expanded the command table in `README.md` to include all available commands and their respective options, providing a complete and accurate reference for users.
|
|
15
|
-
|
|
16
|
-
3. **Misleading `read` Command URL Examples:**
|
|
17
|
-
* **Inconsistency:** The documentation for the `read` command provided examples using "display" or "pretty" URLs. The `extractPageId` function in the code, however, explicitly does not support this URL format and can only parse URLs that contain a `pageId` query parameter (e.g., `.../viewpage.action?pageId=12345`).
|
|
18
|
-
* **Fix:** I removed the incorrect URL examples from the `README.md` and replaced them with a valid example that uses the `pageId` parameter. I also added a note to clarify that this is the only supported URL format for the `read` command.
|
|
19
|
-
|
|
20
|
-
These changes have brought the code and documentation into alignment, fixed a bug in the update functionality, and improved the overall user experience by providing clearer and more accurate instructions.
|