Skip to content

Commit d5abc8c

Browse files
committed
feat(CRC-220): Ignore option
1 parent 3ca2b99 commit d5abc8c

29 files changed

+810
-74
lines changed

components/markdown-confluence-sync/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
#### Deprecated
1212
#### Removed
1313

14+
## [1.2.0] - 2025-03-20
15+
16+
### Added
17+
18+
* feat: Add `ignore` option, enabling to define an array of globule patterns to ignore files when syncing them to Confluence. It is applied in any sync mode.
19+
20+
### Fixed
21+
22+
* fix: Images with absolute URLs were producing an error when syncing to Confluence.
23+
1424
## [1.1.1] - 2025-03-18
1525

1626
### Fixed

components/markdown-confluence-sync/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ The namespace for the configuration of this library is `markdown-confluence-sync
270270
| --- | --- | --- | --- |
271271
| `logLevel` | `string` | Log level. One of `silly`, `debug`, `info`, `warn`, `error`, `silent` | `info` |
272272
| `mode` | `string` | Mode to read the pages to send to Confluence. One of `tree`, `flat` or `id`. | `tree` |
273-
| `filesPattern` | `string` | Pattern to read the pages to send to Confluence. This option is mandatory when using `flat` or `id` sync modes. | |
273+
| `filesPattern` | `string` | Pattern to read the pages to send to Confluence. This option is mandatory when using `flat` or `id` sync modes. It has no effect in `tree` mode | |
274+
| `ignore` | `array` | Array of [globule](https://github.com/cowboy/node-globule) patterns to ignore files. Matches are calculated from the `cwd` | |
274275
| `filesMetadata` | `array` | Array of objects with the metadata of the files to sync. Each object must have the `path` property with the path of the file. For the rest of properties read the [Configuration per page](#configuration-per-page) section | |
275276
| `docsDir` | `string` | Path to the docs directory. | `./docs` |
276277
| `confluence.url` | `string` | URL of the Confluence instance. | |
@@ -285,7 +286,7 @@ The namespace for the configuration of this library is `markdown-confluence-sync
285286
| `config.readFile` | `boolean` | Read configuration from file or not | `false` |
286287
| `config.readEnvironment` | `boolean` | Read configuration from environment or not | `false` |
287288
| `preprocessor` | `function` | Hook enabling to change the content of files before processing the markdown content to send it to Confluence. It receives the content as first argument and the file path as second argument, and must return the new file content | |
288-
| `cwd`* | `string` | Path from where the library resolve docsDir, filesPattern, and searches for configuration files | `process.cwd()` |
289+
| `cwd`* | `string` | Path from where the library resolve options `docsDir`, `filesPattern` and `ignore`, and it searches for configuration files | `process.cwd()` |
289290

290291
> [!NOTE]
291292
> The `cwd` is a special property that is only settable through the `MARKDOWN_CONFLUENCE_SYNC_CWD` environment variable, or when using the library programmatically.
@@ -306,6 +307,7 @@ Just take into account that the namespace for the configuration is `markdown-con
306307
```js title="markdown-confluence-sync.config.js"
307308
module.exports = {
308309
docsDir: "docs",
310+
ignore: ["docs/no-sync/**"],
309311
confluence: {
310312
url: "https://my-confluence.es",
311313
personalAccessToken: "*******",
@@ -320,7 +322,7 @@ module.exports = {
320322
Configuration properties can be provided through CLI arguments. The name of the argument is the property name prefixed with `--`. For example, to set the `docsDir` property, you have to set the `--docsDir` argument. For boolean properties with a default value of `true`, you can set the `--no-` prefix to set the property to `false`. For example, to set the `config.readArguments` property to `false`, you have to set the `--no-config.readArguments` argument.
321323

322324
```sh
323-
npx markdown-confluence-sync --docsDir ./docs --logLevel debug
325+
npx markdown-confluence-sync --docsDir ./docs --logLevel debug --ignore "docs/no-sync/**" "docs/ignore-file.md"
324326
```
325327

326328
### Environment variables

components/markdown-confluence-sync/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tid-xcut/markdown-confluence-sync",
33
"description": "Creates/updates/deletes Confluence pages based on markdown files in a directory. Supports Mermaid diagrams and per-page configuration using frontmatter metadata. Works great with Docusaurus",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"license": "Apache-2.0",
66
"author": "Telefónica Innovación Digital",
77
"repository": {
@@ -76,6 +76,7 @@
7676
"@tid-xcut/confluence-sync": "workspace:*",
7777
"fs-extra": "11.2.0",
7878
"glob": "10.3.10",
79+
"globule": "1.3.4",
7980
"handlebars": "4.7.8",
8081
"hast": "1.0.0",
8182
"hast-util-to-string": "2.0.0",
@@ -116,6 +117,7 @@
116117
"@tid-xcut/child-process-manager": "workspace:*",
117118
"@types/fs-extra": "11.0.4",
118119
"@types/glob": "8.1.0",
120+
"@types/globule": "1.1.9",
119121
"@types/hast": "2.3.10",
120122
"@types/mdast": "3.0.15",
121123
"@types/tmp": "0.2.6",

components/markdown-confluence-sync/src/lib/MarkdownConfluenceSync.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import type {
2929
ModeOption,
3030
FilesPatternOption,
3131
FilesMetadataOptionDefinition,
32+
FilesIgnoreOptionDefinition,
33+
FilesIgnoreOption,
3234
FilesMetadataOption,
3335
ContentPreprocessorOptionDefinition,
3436
ContentPreprocessorOption,
@@ -61,6 +63,11 @@ const filesPatternOption: FilesPatternOptionDefinition = {
6163
type: "string",
6264
};
6365

66+
const filesIgnoreOption: FilesIgnoreOptionDefinition = {
67+
name: "ignore",
68+
type: "array",
69+
};
70+
6471
const filesMetadataOption: FilesMetadataOptionDefinition = {
6572
name: "filesMetadata",
6673
type: "array",
@@ -84,6 +91,7 @@ export const MarkdownConfluenceSync: MarkdownConfluenceSyncConstructor = class M
8491
private _modeOption: ModeOption;
8592
private _filesPatternOption: FilesPatternOption;
8693
private _filesMetadataOption: FilesMetadataOption;
94+
private _filesIgnoreOption: FilesIgnoreOption;
8795
private _contentPreprocessorOption: ContentPreprocessorOption;
8896
private _cwd: string;
8997

@@ -112,6 +120,10 @@ export const MarkdownConfluenceSync: MarkdownConfluenceSyncConstructor = class M
112120
filesMetadataOption,
113121
) as FilesMetadataOption;
114122

123+
this._filesIgnoreOption = this._configuration.addOption(
124+
filesIgnoreOption,
125+
) as FilesIgnoreOption;
126+
115127
this._contentPreprocessorOption = this._configuration.addOption(
116128
contentPreprocessorOption as ContentPreprocessorOptionDefinition,
117129
) as unknown as ContentPreprocessorOption;
@@ -127,6 +139,7 @@ export const MarkdownConfluenceSync: MarkdownConfluenceSyncConstructor = class M
127139
logger: markdownLogger,
128140
mode: this._modeOption,
129141
filesPattern: this._filesPatternOption,
142+
filesIgnore: this._filesIgnoreOption,
130143
filesMetadata: this._filesMetadataOption,
131144
contentPreprocessor: this._contentPreprocessorOption,
132145
cwd: this._cwd,

components/markdown-confluence-sync/src/lib/MarkdownConfluenceSync.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export type FilesPatternOptionDefinition = OptionDefinition<FilesPattern>;
8585

8686
export type FilesPatternOption = OptionInterfaceOfType<FilesPattern>;
8787

88+
export type FilesIgnoreOptionDefinition = OptionDefinition<FilesPattern>;
89+
90+
export type FilesIgnoreOption = OptionInterfaceOfType<FilesPattern>;
91+
8892
export type FilesMetadataOptionDefinition = OptionDefinition<FilesMetadata>;
8993

9094
export type FilesMetadataOption = OptionInterfaceOfType<FilesMetadata>;

components/markdown-confluence-sync/src/lib/confluence/transformer/support/rehype/rehype-replace-img-tags.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ const rehypeReplaceImgTags: UnifiedPlugin<[], Root> =
2929
function rehypeReplaceImgTags() {
3030
return function transformer(tree) {
3131
replace(tree, { type: "element", tagName: "img" }, (node) => {
32-
console.log("Image node", JSON.stringify(node));
3332
const src = node.properties?.src;
3433
if (typeof src !== "string" || src.toString().length === 0) {
3534
return node;
3635
}
3736
if (src.startsWith("http")) {
38-
// eslint-disable-next-line no-console
39-
console.log("Image source is a URL!", src);
4037
return {
4138
type: "element" as const,
4239
tagName: "ac:image",

components/markdown-confluence-sync/src/lib/docusaurus/DocusaurusFlatPages.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { relative } from "node:path";
55

66
import type { LoggerInterface } from "@mocks-server/logger";
77
import { glob } from "glob";
8+
import globule from "globule";
89

910
import type {
1011
ContentPreprocessor,
@@ -27,25 +28,28 @@ import { SyncModes } from "@tid-xcut/confluence-sync";
2728
export const MarkdownFlatDocuments: MarkdownFlatDocumentsConstructor = class MarkdownFlatDocuments
2829
implements MarkdownDocumentsInterface
2930
{
30-
private _path: string;
31+
private _cwd: string;
3132
private _logger: LoggerInterface;
3233
private _initialized = false;
3334
private _filesPattern: FilesPattern;
35+
private _filesIgnore?: FilesPattern;
3436
private _filesMetadata?: FilesMetadata;
3537
private _mode: SyncModes.FLAT | SyncModes.ID;
3638
private _contentPreprocessor?: ContentPreprocessor;
3739

3840
constructor({
3941
logger,
4042
filesPattern,
43+
filesIgnore,
4144
filesMetadata,
4245
cwd,
4346
mode,
4447
contentPreprocessor,
4548
}: MarkdownFlatDocumentsOptions) {
4649
this._mode = mode;
47-
this._path = cwd;
50+
this._cwd = cwd;
4851
this._filesPattern = filesPattern as FilesPattern;
52+
this._filesIgnore = filesIgnore;
4953
this._filesMetadata = filesMetadata;
5054
this._contentPreprocessor = contentPreprocessor;
5155
this._logger = logger.namespace("doc-flat");
@@ -55,17 +59,28 @@ export const MarkdownFlatDocuments: MarkdownFlatDocumentsConstructor = class Mar
5559
await this._init();
5660
const filesPaths = await this._obtainedFilesPaths();
5761
this._logger.debug(
58-
`Found ${filesPaths.length} files in ${this._path} matching the pattern '${this._filesPattern}'`,
62+
`Found ${filesPaths.length} files in ${this._cwd} matching the pattern '${this._filesPattern}'`,
5963
);
6064
return await this._transformFilePathsToMarkdownDocuments(filesPaths);
6165
}
6266

6367
private async _obtainedFilesPaths(): Promise<string[]> {
6468
return await glob(this._filesPattern, {
65-
cwd: this._path,
69+
cwd: this._cwd,
6670
absolute: true,
71+
// @ts-expect-error The globule types are not compatible with the glob types
6772
ignore: {
68-
ignored: (p) => !/\.mdx?$/.test(p.name),
73+
ignored: (p) => {
74+
return (
75+
!/\.mdx?$/.test(p.name) ||
76+
(this._filesIgnore &&
77+
globule.isMatch(
78+
this._filesIgnore,
79+
// cspell:disable-next-line
80+
relative(this._cwd, p.fullpath()),
81+
))
82+
);
83+
},
6984
},
7085
});
7186
}
@@ -84,12 +99,12 @@ export const MarkdownFlatDocuments: MarkdownFlatDocumentsConstructor = class Mar
8499
title: item.meta.confluenceTitle || item.meta.title,
85100
id: item.meta.confluencePageId,
86101
path: item.path,
87-
relativePath: relative(this._path, item.path),
102+
relativePath: relative(this._cwd, item.path),
88103
content: item.content,
89104
ancestors: [],
90105
name: item.meta.confluenceShortName,
91106
}));
92-
this._logger.debug(`Found ${pages.length} pages in ${this._path}`);
107+
this._logger.debug(`Found ${pages.length} pages in ${this._cwd}`);
93108
return pages;
94109
}
95110

components/markdown-confluence-sync/src/lib/docusaurus/DocusaurusFlatPages.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface MarkdownFlatDocumentsOptions
1313
extends MarkdownDocumentsModeOptions {
1414
/** Pattern to search files when flat mode is active */
1515
filesPattern?: FilesPattern;
16+
/** Pattern with files to be ignored */
17+
filesIgnore?: FilesPattern;
1618
/** Working directory */
1719
cwd: string;
1820
/** Mode */

components/markdown-confluence-sync/src/lib/docusaurus/DocusaurusPages.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
ModeOption,
1515
ContentPreprocessorOption,
1616
ContentPreprocessor,
17+
FilesIgnoreOption,
1718
} from "../MarkdownConfluenceSync.types.js";
1819

1920
import type {
@@ -46,6 +47,7 @@ export const MarkdownDocuments: MarkdownDocumentsConstructor = class MarkdownDoc
4647
private _config: ConfigInterface;
4748
private _filesPattern?: FilesPatternOption;
4849
private _filesMetadata?: FilesMetadataOption;
50+
private _filesIgnore?: FilesIgnoreOption;
4951
private _contentPreprocessorOption: ContentPreprocessorOption;
5052
private _contentPreprocessor?: ContentPreprocessor;
5153
private _cwd: string;
@@ -56,6 +58,7 @@ export const MarkdownDocuments: MarkdownDocumentsConstructor = class MarkdownDoc
5658
mode,
5759
filesPattern,
5860
filesMetadata,
61+
filesIgnore,
5962
contentPreprocessor,
6063
cwd,
6164
}: MarkdownDocumentsOptions) {
@@ -64,6 +67,7 @@ export const MarkdownDocuments: MarkdownDocumentsConstructor = class MarkdownDoc
6467
this._modeOption = mode;
6568
this._filesPattern = filesPattern;
6669
this._filesMetadata = filesMetadata;
70+
this._filesIgnore = filesIgnore;
6771
this._contentPreprocessorOption = contentPreprocessor;
6872
this._config = config;
6973
this._logger = logger;
@@ -95,6 +99,7 @@ export const MarkdownDocuments: MarkdownDocumentsConstructor = class MarkdownDoc
9599
logger: this._logger,
96100
path: this._path,
97101
filesPattern: this._filesPattern?.value as FilesPattern,
102+
filesIgnore: this._filesIgnore?.value,
98103
filesMetadata,
99104
cwd: this._cwd,
100105
});

components/markdown-confluence-sync/src/lib/docusaurus/DocusaurusPages.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type { LoggerInterface } from "@mocks-server/logger";
1111
import type {
1212
FilesMetadataOption,
1313
FilesPatternOption,
14+
FilesIgnoreOption,
15+
FilesPattern,
1416
FilesMetadata,
1517
ModeOption,
1618
ContentPreprocessorOption,
@@ -50,6 +52,8 @@ export interface MarkdownDocumentsOptions {
5052
mode: ModeOption;
5153
/** Pattern to search files when flat mode is active */
5254
filesPattern?: FilesPatternOption;
55+
/** Pattern with files to be ignored */
56+
filesIgnore?: FilesIgnoreOption;
5357
/** Metadata for specific files */
5458
filesMetadata?: FilesMetadataOption;
5559
/** Preprocessor for content */
@@ -96,6 +100,8 @@ export interface MarkdownDocumentsModeOptions {
96100
contentPreprocessor?: ContentPreprocessor;
97101
/** Metadata for specific files */
98102
filesMetadata?: FilesMetadata;
103+
/** Files to be ignored */
104+
filesIgnore?: FilesPattern;
99105
/** Configuration interface */
100106
config: ConfigInterface;
101107
/** Logger */

0 commit comments

Comments
 (0)