Skip to content

Commit

Permalink
getTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
paula-stacho committed Feb 28, 2024
1 parent 24b7e21 commit 5679f30
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/oidc-http-server-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"depcheck": "depcheck",
"check": "npm run typecheck && npm run lint && npm run depcheck",
"check-ci": "npm run check",
"test": "mocha",
"test": "npm run compile && mocha",
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
"test-watch": "npm run test -- --watch",
"test-ci": "npm run test-cov",
Expand Down
19 changes: 11 additions & 8 deletions packages/oidc-http-server-pages/src/create-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,19 @@ function generateJS(data: string): void {
},
});
writeFileSync(
path.join(__dirname, 'templates.js'),
path.join(__dirname, 'get-templates.js'),
`
const { brotliDecompressSync } = require('zlib');
const buffer = brotliDecompressSync(
Buffer.from(
'${buffer.toString('base64')}',
'base64'
)
);
module.exports = JSON.parse(buffer.toString());
function getTemplates() {
const buffer = brotliDecompressSync(
Buffer.from(
'${buffer.toString('base64')}',
'base64'
)
);
return JSON.parse(buffer.toString());
}
module.exports = getTemplates;
`
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import type { PageTemplates } from './types';
import { getStaticPage } from './get-static-page';
import { getStaticPage } from '../dist/get-static-page';

describe('getStaticPage', function () {
enum TestPage {
Expand Down
3 changes: 2 additions & 1 deletion packages/oidc-http-server-pages/src/get-static-page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ITemplate, HttpServerPage, PageTemplates } from './types';
import getTemplates from './get-templates.js';

function findTemplate(
templates: ITemplate[],
Expand Down Expand Up @@ -39,7 +40,7 @@ export function getStaticPage<TPage extends string = HttpServerPage>(
templates?: PageTemplates<TPage>
): string {
if (!templates) {
templates = require('./templates.js');
templates = getTemplates() as PageTemplates<TPage>;
}

const pageTemplates = templates && templates[page];
Expand Down
5 changes: 5 additions & 0 deletions packages/oidc-http-server-pages/src/get-templates.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { PageTemplates } from './types';

declare const TGetTemplates: () => PageTemplates;

export default TGetTemplates;
5 changes: 0 additions & 5 deletions packages/oidc-http-server-pages/src/templates.js.d.ts

This file was deleted.

0 comments on commit 5679f30

Please sign in to comment.