hono-takibi 0.4.0 → 0.4.1

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/dist/index.js CHANGED
@@ -59,14 +59,6 @@ async function main(dev = false, config = (0, config_1.getConfig)()) {
59
59
  }
60
60
  // 9. write to file
61
61
  node_fs_1.default.writeFileSync(output, formattedCode, { encoding: 'utf-8' });
62
- // Vite Plugin Mode
63
- const mode = process.argv[5];
64
- const vite = process.argv[6];
65
- if (mode === '--mode' && vite === 'vite') {
66
- node_fs_1.default.writeFileSync(output, formattedCode, { encoding: 'utf-8' });
67
- console.log(`Generated code written to ${output}`);
68
- return true;
69
- }
70
62
  // 10. generate app code
71
63
  const appCode = (0, app_1.generateApp)(openAPI, config);
72
64
  if (config.app?.output === true) {
@@ -1,10 +1,4 @@
1
- type HonoTakibiPluginOptions = {
2
- input: string;
3
- output: string;
4
- packageManager: 'pnpm' | 'npm' | 'yarn' | 'bun';
5
- };
6
- export default function honoTakibiPlugin(options: HonoTakibiPluginOptions): {
1
+ export default function honoTakibiPlugin(): {
7
2
  name: string;
8
3
  configureServer(server: any): void;
9
4
  };
10
- export {};
@@ -1,29 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = honoTakibiPlugin;
4
- const node_child_process_1 = require("node:child_process");
5
- function honoTakibiPlugin(options) {
4
+ const config_1 = require("../config");
5
+ const vite_mode_1 = require("./vite-mode");
6
+ function honoTakibiPlugin() {
6
7
  return {
7
8
  name: 'hono-takibi-plugin',
8
9
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
9
10
  configureServer(server) {
10
- server.watcher.add(options.input);
11
+ const config = (0, config_1.getConfig)();
11
12
  server.watcher.on('change', () => {
12
- const commandPrefixMap = {
13
- pnpm: 'pnpm',
14
- npm: 'npx',
15
- yarn: 'yarn',
16
- bun: 'bun run',
17
- };
18
- const commandPrefix = commandPrefixMap[options.packageManager];
19
- const command = `${commandPrefix} hono-takibi ${options.input} -o ${options.output}`;
20
- (0, node_child_process_1.exec)(command, (error) => {
21
- if (error) {
22
- console.error(`[hono-takibi-plugin] error: ${error.message}`);
23
- return;
24
- }
25
- // reload
26
- server.ws.send({ type: 'full-reload' });
13
+ (0, vite_mode_1.viteMode)({
14
+ ...config,
27
15
  });
28
16
  });
29
17
  },
@@ -0,0 +1,2 @@
1
+ import type { Config } from '../config';
2
+ export declare function viteMode(config?: Config): Promise<boolean | undefined>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.viteMode = viteMode;
7
+ const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const generate_zod_openapi_hono_1 = require("../generators/hono/generate-zod-openapi-hono");
11
+ const config_1 = require("../config");
12
+ const format_1 = require("../format");
13
+ async function viteMode(config = (0, config_1.getConfig)()) {
14
+ try {
15
+ if (config.input) {
16
+ const openAPI = (await swagger_parser_1.default.parse(config.input));
17
+ const hono = (0, generate_zod_openapi_hono_1.generateZodOpenAPIHono)(openAPI, config);
18
+ const formattedCode = await (0, format_1.formatCode)(hono);
19
+ if (config.output) {
20
+ const outputDir = node_path_1.default.dirname(config.output);
21
+ if (!node_fs_1.default.existsSync(outputDir)) {
22
+ node_fs_1.default.mkdirSync(outputDir, { recursive: true });
23
+ }
24
+ node_fs_1.default.writeFileSync(config.output, formattedCode, { encoding: 'utf-8' });
25
+ console.log(`Generated code written to ${config.output}`);
26
+ return true;
27
+ }
28
+ }
29
+ }
30
+ catch (e) {
31
+ console.error('Usage: hono-takibi <input-file> [-o output-file]');
32
+ return false;
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hono-takibi",
3
3
  "description": "Hono Takibi is a CLI tool that generates Hono routes from OpenAPI specifications.",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "hono",