create-confluence-sync 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-confluence-sync",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Bidirectional Confluence Server documentation sync via Git. Edit XHTML locally, commit, auto-sync with Confluence.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/git.js CHANGED
@@ -12,13 +12,13 @@ function exec(projectRoot, command) {
12
12
  }
13
13
 
14
14
  function getChangedFiles(projectRoot) {
15
- const output = exec(projectRoot, 'git diff --name-only HEAD~1 HEAD');
15
+ const output = exec(projectRoot, 'git -c core.quotePath=false diff --name-only HEAD~1 HEAD');
16
16
  if (!output) return [];
17
17
  return output.split('\n').filter(f => f.endsWith('.xhtml'));
18
18
  }
19
19
 
20
20
  function getDeletedFiles(projectRoot) {
21
- const output = exec(projectRoot, 'git diff --name-only --diff-filter=D HEAD~1 HEAD');
21
+ const output = exec(projectRoot, 'git -c core.quotePath=false diff --name-only --diff-filter=D HEAD~1 HEAD');
22
22
  if (!output) return [];
23
23
  return output.split('\n').filter(f => f.endsWith('.xhtml'));
24
24
  }
package/src/hook.js CHANGED
@@ -30,10 +30,8 @@ function loadConfig(projectRoot) {
30
30
  }
31
31
 
32
32
  async function main() {
33
- // Guard: prevent recursion
34
- if (process.env.CONFLUENCE_SYNC_RUNNING === '1') {
35
- return;
36
- }
33
+ // Guard is handled by the shell hook script (post-commit).
34
+ // Set env for child processes (e.g. commitAll) to prevent recursion.
37
35
  process.env.CONFLUENCE_SYNC_RUNNING = '1';
38
36
 
39
37
  // Normalize projectRoot (Windows backslashes)
package/src/sync.js CHANGED
@@ -165,9 +165,28 @@ export async function push(apiClient, tree, projectRoot, spaceKey, changedFiles)
165
165
  let created = 0;
166
166
  let updated = 0;
167
167
 
168
- for (const filePath of changedFiles) {
169
- const normalized = filePath.replace(/\\/g, '/');
170
- const absolutePath = path.resolve(projectRoot, normalized);
168
+ for (let filePath of changedFiles) {
169
+ let normalized = filePath.replace(/\\/g, '/');
170
+ let absolutePath = path.resolve(projectRoot, normalized);
171
+
172
+ // Normalize: if file is not inside a same-named folder, wrap it
173
+ const fileName = path.basename(normalized);
174
+ const folderName = path.basename(path.dirname(normalized));
175
+ const expectedFolder = fileName.replace(/\.xhtml$/, '');
176
+
177
+ if (folderName !== expectedFolder) {
178
+ const newDir = path.join(path.dirname(absolutePath), expectedFolder);
179
+ const newAbsolute = path.join(newDir, fileName);
180
+ const newNormalized = path.relative(projectRoot, newAbsolute).replace(/\\/g, '/');
181
+
182
+ await fs.mkdir(newDir, { recursive: true });
183
+ await fs.rename(absolutePath, newAbsolute);
184
+ console.log(`Normalized: ${normalized} → ${newNormalized}`);
185
+
186
+ normalized = newNormalized;
187
+ absolutePath = newAbsolute;
188
+ }
189
+
171
190
  const body = await fs.readFile(absolutePath, 'utf-8');
172
191
  const existing = getPageByPath(tree, normalized);
173
192