body method

  1. @override
String body(
  1. String path,
  2. String baseName,
  3. String className
)
override

Defines the actual body code. path is passed relative to lib, baseName is the filename, and className is the filename converted to Pascal case.

実際の本体コードを定義します。pathlibからの相対パス、baseNameにファイル名が渡され、classNameにファイル名をパスカルケースに変換した値が渡されます。

Implementation

@override
String body(String path, String baseName, String className) {
  return """
/**
 * ${className.toPascalCase()}Worker
 *
 * Create a server code for Cloudflare Workers.
 */
export class ${className.toPascalCase()}Worker extends m.RequestProcessWorkdersBase {
  /**
   * @param {string} path
   * Describe the path names used in Workers.
   *
   * Workersで利用されるパス名を記述します。
   */
  path = "/${className.toSnakeCase()}";

  /**
   * Specify the actual contents of the process.
   *
   * 実際の処理の中身を指定します。
   *
   * @param {Hono} hono
   * Hono object passed to Workers.
   *
   * Workersに渡されたHonoオブジェクト。
   *
   * @return {Hono}
   * Return the processed Hono object.
   *
   * 処理後のHonoオブジェクトを返します。
   */
  process(
      hono: Hono,
  ): Hono {

      /// You will comment out and implement the GET process.
      ///
      /// メソッド名をコメントアウトしてGETの処理を記載します。
      // hono.get("/", async (c) => {
      //     return c.json({ success: true });
      // });

      /// You will comment out and implement the POST process.
      ///
      /// メソッド名をコメントアウトしてPOSTの処理を記載します。
      // hono.post("/", async (c) => {
      //     return c.json({ success: true });
      // });

      /// You will comment out and implement the PUT process.
      ///
      /// メソッド名をコメントアウトしてPUTの処理を記載します。
      // hono.put("/", async (c) => {
      //     return c.json({ success: true });
      // });

      /// You will comment out and implement the DELETE process.
      ///
      /// メソッド名をコメントアウトしてDELETEの処理を記載します。
      // hono.delete("/", async (c) => {
      //     return c.json({ success: true });
      // });

      return hono;
  }
}
""";
}