kavoru 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/features.ts +61 -29
package/package.json
CHANGED
package/src/features.ts
CHANGED
|
@@ -495,41 +495,73 @@ async function patchEntryIndex(
|
|
|
495
495
|
await writeText(projectDir, "src/index.ts", buildEntryIndex(selection));
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
498
|
+
export function buildServerIndex(selection: FeatureSelection): string {
|
|
499
|
+
const imports = [
|
|
500
|
+
'import { Elysia } from "elysia";',
|
|
501
|
+
'import { config } from "../config/index";',
|
|
502
|
+
'import { logger } from "../common/logger";',
|
|
503
|
+
'import { registerModules } from "../modules";',
|
|
504
|
+
selection.cron ? 'import { schedules } from "../schedules";' : null,
|
|
505
|
+
]
|
|
506
|
+
.filter(Boolean)
|
|
507
|
+
.join("\n");
|
|
505
508
|
|
|
506
|
-
|
|
509
|
+
const elysiaCtor = selection.websocket
|
|
510
|
+
? `new Elysia({
|
|
511
|
+
websocket: {
|
|
512
|
+
idleTimeout: 120,
|
|
513
|
+
},
|
|
514
|
+
})`
|
|
515
|
+
: "new Elysia()";
|
|
516
|
+
|
|
517
|
+
const uses = [
|
|
518
|
+
" .use(registerModules)",
|
|
519
|
+
selection.cron ? " .use(schedules)" : null,
|
|
520
|
+
]
|
|
521
|
+
.filter(Boolean)
|
|
522
|
+
.join("\n");
|
|
507
523
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
} else {
|
|
518
|
-
content = content.replace(
|
|
519
|
-
/^import \{ schedules \} from "\.\.\/schedules";\n/m,
|
|
520
|
-
"",
|
|
521
|
-
);
|
|
522
|
-
content = content.replace(/^\s*\.use\(schedules\);\n/m, "");
|
|
524
|
+
return `${imports}
|
|
525
|
+
|
|
526
|
+
export class HttpServer {
|
|
527
|
+
private app: any;
|
|
528
|
+
private server?: ReturnType<Elysia["listen"]>;
|
|
529
|
+
|
|
530
|
+
constructor() {
|
|
531
|
+
this.app = ${elysiaCtor}
|
|
532
|
+
${uses};
|
|
523
533
|
}
|
|
524
534
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
535
|
+
async start() {
|
|
536
|
+
if (this.server) return;
|
|
537
|
+
|
|
538
|
+
await this.app.modules;
|
|
539
|
+
|
|
540
|
+
this.server = this.app.listen(config.env.server.port, () => {
|
|
541
|
+
logger.info(
|
|
542
|
+
\`API ready on port \${config.env.server.port}. Version: \${config.version}\`,
|
|
543
|
+
);
|
|
544
|
+
});
|
|
530
545
|
}
|
|
531
546
|
|
|
532
|
-
|
|
547
|
+
async stop() {
|
|
548
|
+
if (!this.server) return;
|
|
549
|
+
this.server.stop();
|
|
550
|
+
this.server = undefined;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
`;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
async function patchServerIndex(
|
|
557
|
+
projectDir: string,
|
|
558
|
+
selection: FeatureSelection,
|
|
559
|
+
) {
|
|
560
|
+
await writeText(
|
|
561
|
+
projectDir,
|
|
562
|
+
"src/server/index.ts",
|
|
563
|
+
buildServerIndex(selection),
|
|
564
|
+
);
|
|
533
565
|
}
|
|
534
566
|
|
|
535
567
|
async function patchPackageJson(
|