Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) WriteResource includes a draft changelog.md by default #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-needles-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eventcatalog/sdk': minor
---

WriteResource now includes a draft changelog.md by default
11 changes: 11 additions & 0 deletions src/internal/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ export const writeResource = async (

const document = matter.stringify(markdown.trim(), frontmatter);
fsSync.writeFileSync(lockPath, document);

// Add empty changelog with generated date to resource
await addFileToResource(
catalogDir,
resource.id,
{
content: '---\ncreatedAt: ' + new Date().toISOString().split('T')[0] + '\n---',
fileName: 'changelog.md',
},
resource.version
);
} finally {
// Always release the lock
await unlock(lockPath).catch(() => {});
Expand Down
9 changes: 4 additions & 5 deletions src/internal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { glob, globSync } from 'glob';
import fs from 'node:fs/promises';
import { globSync } from 'glob';
import fsSync from 'node:fs';
import { copy, copySync, CopyFilterAsync, CopyFilterSync } from 'fs-extra';
import { copy, CopyFilterAsync, CopyFilterSync } from 'fs-extra';
import { join } from 'node:path';
import matter from 'gray-matter';
import { satisfies, validRange, valid } from 'semver';
import { satisfies, valid, validRange } from 'semver';

/**
* Returns true if a given version of a resource id exists in the catalog
Expand Down Expand Up @@ -108,7 +107,7 @@ export const copyDir = async (catalogDir: string, source: string, target: string
fsSync.rmSync(tmpDirectory, { recursive: true });
};

// Makes sure values in sends/recieves are unique
// Makes sure values in sends/receives are unique
export const uniqueVersions = (messages: { id: string; version: string }[]): { id: string; version: string }[] => {
const uniqueSet = new Set();

Expand Down
1 change: 1 addition & 0 deletions src/test/channels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ describe('Channels SDK', () => {
const channel = await getChannel('inventory.{env}.events');

expect(fs.existsSync(path.join(CATALOG_PATH, 'channels/inventory.{env}.events', 'index.md'))).toBe(true);
expect(fs.existsSync(path.join(CATALOG_PATH, 'channels/inventory.{env}.events', 'changelog.md'))).toBe(true);

expect(channel).toEqual({
id: 'inventory.{env}.events',
Expand Down
1 change: 1 addition & 0 deletions src/test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ describe('Commands SDK', () => {
const command = await getCommand('UpdateInventory');

expect(fs.existsSync(path.join(CATALOG_PATH, 'commands/UpdateInventory', 'index.md'))).toBe(true);
expect(fs.existsSync(path.join(CATALOG_PATH, 'commands/UpdateInventory', 'changelog.md'))).toBe(true);

expect(command).toEqual({
id: 'UpdateInventory',
Expand Down
1 change: 1 addition & 0 deletions src/test/domains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ describe('Domain SDK', () => {
const domain = await getDomain('Payment');

expect(fs.existsSync(path.join(CATALOG_PATH, 'domains/Payment', 'index.md'))).toBe(true);
expect(fs.existsSync(path.join(CATALOG_PATH, 'domains/Payment', 'changelog.md'))).toBe(true);

expect(domain).toEqual({
id: 'Payment',
Expand Down
1 change: 1 addition & 0 deletions src/test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ describe('Events SDK', () => {
const event = await getEvent('InventoryAdjusted');

expect(fs.existsSync(path.join(CATALOG_PATH, 'events/InventoryAdjusted', 'index.md'))).toBe(true);
expect(fs.existsSync(path.join(CATALOG_PATH, 'events/InventoryAdjusted', 'changelog.md'))).toBe(true);

expect(event).toEqual({
id: 'InventoryAdjusted',
Expand Down
1 change: 1 addition & 0 deletions src/test/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ describe('Queries SDK', () => {
const query = await getQuery('GetOrder');

expect(fs.existsSync(path.join(CATALOG_PATH, 'queries/GetOrder', 'index.md'))).toBe(true);
expect(fs.existsSync(path.join(CATALOG_PATH, 'queries/GetOrder', 'changelog.md'))).toBe(true);

expect(query).toEqual({
id: 'GetOrder',
Expand Down
1 change: 1 addition & 0 deletions src/test/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ describe('Services SDK', () => {
const service = await getService('InventoryService');

expect(fs.existsSync(path.join(CATALOG_PATH, 'services/InventoryService', 'index.md'))).toBe(true);
expect(fs.existsSync(path.join(CATALOG_PATH, 'services/InventoryService', 'changelog.md'))).toBe(true);

expect(service).toEqual({
id: 'InventoryService',
Expand Down