Skip to content

Commit

Permalink
Merge pull request #233 from jaredwray/adding-in-github-release-build
Browse files Browse the repository at this point in the history
adding in github release build
  • Loading branch information
jaredwray committed Jan 5, 2024
2 parents 0d2d5a3 + 2724475 commit d076780
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,19 @@ export class WritrBuilder {
throw new Error('No templates found');
}
}

public async buildReleasePage(data: WritrData): Promise<void> {
if (data.github && data.templates) {
const releasesPath = `${data.outputPath}/releases/index.html`;
const releaseOutputPath = `${data.outputPath}/releases`;

await fs.ensureDir(releaseOutputPath);

const releasesTemplate = `${data.templatePath}/${data.templates.releases}`;
const releasesContent = await this._ecto.renderFromFile(releasesTemplate, data, data.templatePath);
await fs.writeFile(releasesPath, releasesContent, 'utf8');
} else {
throw new Error('No github data found');
}
}
}
1 change: 1 addition & 0 deletions template/releases.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<title>{{siteTitle}} Releases</title>
52 changes: 51 additions & 1 deletion test/builder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect, it, describe} from 'vitest';
import {expect, it, describe, vi} from 'vitest';
import * as fs from 'fs-extra';
import axios from 'axios';
import {WritrBuilder, type WritrData} from '../src/builder.js';
import {WritrOptions} from '../src/options.js';

Expand Down Expand Up @@ -85,8 +86,10 @@ describe('WritrBuilder', () => {
});
it('should get github data', async () => {
const builder = new WritrBuilder();
vi.spyOn(axios, 'get').mockResolvedValue({data: {}});
const githubData = await builder.getGithubData('jaredwray/writr');
expect(githubData).toBeTruthy();
vi.resetAllMocks();
});
it('should get the file without extension', async () => {
const builder = new WritrBuilder();
Expand Down Expand Up @@ -193,4 +196,51 @@ describe('WritrBuilder', () => {
await fs.remove(data.outputPath);
}
});
it('should build release page (/releases/index.html)', async () => {
const builder = new WritrBuilder();
const data = writrData;
data.templates = {
index: 'index.hbs',
releases: 'releases.hbs',
};
data.sitePath = 'site';
data.templatePath = 'template';
data.outputPath = 'test/temp-release-test';

data.github = {
releases: {},
contributors: {},
};

await fs.remove(data.outputPath);
try {
await builder.buildReleasePage(data);
const index = await fs.readFile(`${data.outputPath}/releases/index.html`, 'utf8');
expect(index).toContain('<title>Writr Releases</title>');
} finally {
await fs.remove(data.outputPath);
}
});
it('should error on build release page (/releases/index.html)', async () => {
const builder = new WritrBuilder();
const data = writrData;
data.templates = {
index: 'index.hbs',
releases: 'releases.hbs',
};
data.sitePath = 'site';
data.templatePath = 'template';
data.outputPath = 'test/temp-release-test';

data.github = undefined;

await fs.remove(data.outputPath);
try {
await builder.buildReleasePage(data);
} catch (error: any) {
expect(error.message).toBe('No github data found');
} finally {
await fs.remove(data.outputPath);
}
});
});
1 change: 0 additions & 1 deletion test/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe('Github', () => {
});
it('should be able to get the releases', async () => {
const github = new Github(defaultOptions);

// @ts-expect-error - mock
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
axios.get.mockResolvedValue({data: githubMockReleases});
Expand Down

0 comments on commit d076780

Please sign in to comment.