Skip to content

Commit

Permalink
fix(hono): remove handler fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed May 13, 2024
1 parent 404c197 commit 692f749
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions packages/hono/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,6 @@ const getZvalidatorImports = (verbOption: GeneratorVerbOptions) => {
return imports.join(',\n');
};

const getHandlerFix = ({
rawFile,
content,
}: {
rawFile: string;
content: string;
}) => {
let newContent = content;

if (!rawFile.includes("import { createFactory } from 'hono/factory';")) {
newContent = `import { createFactory } from 'hono/factory';\n${newContent}`;
}

if (!rawFile.includes('const factory = createFactory();')) {
newContent += '\nconst factory = createFactory();';
}

return newContent;
};

const getVerbOptionGroupByTag = (
verbOptions: Record<string, GeneratorVerbOptions>,
) => {
Expand Down Expand Up @@ -251,10 +231,7 @@ const generateHandlers = async (

if (isExist) {
const rawFile = await fs.readFile(handlerPath, 'utf8');
let content = getHandlerFix({
rawFile,
content: rawFile,
});
let content = rawFile;

if (!rawFile.includes(handlerName)) {
content += getHonoHandlers({
Expand Down Expand Up @@ -317,10 +294,7 @@ ${getHonoHandlers({

if (isExist) {
const rawFile = await fs.readFile(handlerPath, 'utf8');
let content = getHandlerFix({
rawFile,
content: rawFile,
});
let content = rawFile;

content += Object.values(verbs).reduce((acc, verbOption) => {
const handlerName = `${verbOption.operationName}Handlers`;
Expand Down Expand Up @@ -398,10 +372,7 @@ const factory = createFactory();`;

if (isExist) {
const rawFile = await fs.readFile(handlerPath, 'utf8');
let content = getHandlerFix({
rawFile,
content: rawFile,
});
let content = rawFile;

content += Object.values(verbOptions).reduce((acc, verbOption) => {
const handlerName = `${verbOption.operationName}Handlers`;
Expand Down

0 comments on commit 692f749

Please sign in to comment.