Skip to content

Commit

Permalink
feat(core): use gray-matter to stringify dependencies frontmatter (
Browse files Browse the repository at this point in the history
…#1083)

Fixes #1081

Co-authored-by: Craig Roberts <[email protected]>
  • Loading branch information
craig0990 and Craig Roberts authored Jan 23, 2025
1 parent 63b4bec commit c8f86b7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/quote-dependencies-frontmatter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

fix(core): fixed dependencies frontmatter quoting when values would be interpreted as non-scalar
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default {
services: [
{ id: 'TestingServiceOrder', version: '5.0.0' }
],
channels: [
{ id: 'TestingChannelOrder', version: '5.0.0'},
{ id: '{env}.testing.channel.order', version: '5.0.0'}
],
domains: [
{ id: 'TestingDomainOrder', version: '5.0.0' }
],
Expand Down
22 changes: 22 additions & 0 deletions src/__tests__/resolve-catalog-dependencies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,27 @@ describe('resolve-catalog-dependencies', () => {
expect(content).toContain('version: 5.0.0');
});
});

describe('channels', () => {
it('creates a dependency file for each channel', async () => {
const content = await fs.readFile(
path.join(CATALOG_DIR, 'dependencies', 'channels', 'TestingChannelOrder', 'index.md'),
'utf8'
);
expect(content).toContain('id: TestingChannelOrder');
expect(content).toContain('name: TestingChannelOrder');
expect(content).toContain('version: 5.0.0');
});

it('creates a dependency file for parameterized channels', async () => {
const content = await fs.readFile(
path.join(CATALOG_DIR, 'dependencies', 'channels', '{env}.testing.channel.order', 'index.md'),
'utf8'
);
expect(content).toContain(`id: '{env}.testing.channel.order'`);
expect(content).toContain(`name: '{env}.testing.channel.order'`);
expect(content).toContain('version: 5.0.0');
});
});
});
});
33 changes: 16 additions & 17 deletions src/resolve-catalog-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getEventCatalogConfigFile } from './eventcatalog-config-file-utils';
import path from 'node:path';
import fs from 'node:fs';
import matter from 'gray-matter';

// Create a fake file for this dependency in the project directory ()

Expand All @@ -27,27 +28,25 @@ export default async (catalogDir, core) => {
const resourceTypes = Object.keys(dependencies);
for (const resourceType of resourceTypes) {
for (const dependency of dependencies[resourceType]) {
const resource = {
const frontmatter = {
id: dependency.id,
name: dependency.id,
version: dependency.version || '1.0.0',
};

const markdown = `---
id: ${resource.id}
name: ${resource.id}
version: ${resource.version}
---
:::warning
You are running EventCatalog with dependencies enabled.
This resource is mocked and is a dependency. This means that the resource is managed and owned by another catalog.
:::
`;

const resourceFile = path.join(dependenciesDir, resourceType, resource.id, `index.md`);
const markdown = matter.stringify(
{
content: [
':::warning',
'You are running EventCatalog with dependencies enabled.',
'This resource is mocked and is a dependency. This means that the resource is managed and owned by another catalog.',
':::',
].join('\n\n'),
},
frontmatter
);

const resourceFile = path.join(dependenciesDir, resourceType, dependency.id, `index.md`);
// ensure the directory exists
fs.mkdirSync(path.dirname(resourceFile), { recursive: true });
fs.writeFileSync(resourceFile, markdown);
Expand Down

0 comments on commit c8f86b7

Please sign in to comment.