cf-yoyo 1.0.0

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.
Files changed (141) hide show
  1. package/.eslintrc.json +28 -0
  2. package/.github/workflows/ci.yml +96 -0
  3. package/.prettierrc.json +10 -0
  4. package/CHANGELOG.md +55 -0
  5. package/README.md +138 -0
  6. package/__tests__/cli-e2e.test.ts +145 -0
  7. package/__tests__/config.test.ts +268 -0
  8. package/__tests__/filesystem.test.ts +453 -0
  9. package/__tests__/logger.test.ts +274 -0
  10. package/__tests__/template-engine.test.ts +450 -0
  11. package/__tests__/types.test.ts +25 -0
  12. package/deep_todos.md +766 -0
  13. package/dist/cli/commands/create.d.ts +26 -0
  14. package/dist/cli/commands/create.d.ts.map +1 -0
  15. package/dist/cli/commands/create.js +308 -0
  16. package/dist/cli/commands/create.js.map +1 -0
  17. package/dist/cli/commands/git.d.ts +10 -0
  18. package/dist/cli/commands/git.d.ts.map +1 -0
  19. package/dist/cli/commands/git.js +887 -0
  20. package/dist/cli/commands/git.js.map +1 -0
  21. package/dist/cli/commands/list.d.ts +10 -0
  22. package/dist/cli/commands/list.d.ts.map +1 -0
  23. package/dist/cli/commands/list.js +90 -0
  24. package/dist/cli/commands/list.js.map +1 -0
  25. package/dist/cli/index.d.ts +15 -0
  26. package/dist/cli/index.d.ts.map +1 -0
  27. package/dist/cli/index.js +62 -0
  28. package/dist/cli/index.js.map +1 -0
  29. package/dist/core/config.d.ts +35 -0
  30. package/dist/core/config.d.ts.map +1 -0
  31. package/dist/core/config.js +260 -0
  32. package/dist/core/config.js.map +1 -0
  33. package/dist/core/filesystem.d.ts +84 -0
  34. package/dist/core/filesystem.d.ts.map +1 -0
  35. package/dist/core/filesystem.js +417 -0
  36. package/dist/core/filesystem.js.map +1 -0
  37. package/dist/core/git-token.d.ts +81 -0
  38. package/dist/core/git-token.d.ts.map +1 -0
  39. package/dist/core/git-token.js +244 -0
  40. package/dist/core/git-token.js.map +1 -0
  41. package/dist/core/git.d.ts +70 -0
  42. package/dist/core/git.d.ts.map +1 -0
  43. package/dist/core/git.js +367 -0
  44. package/dist/core/git.js.map +1 -0
  45. package/dist/core/prompt.d.ts +28 -0
  46. package/dist/core/prompt.d.ts.map +1 -0
  47. package/dist/core/prompt.js +253 -0
  48. package/dist/core/prompt.js.map +1 -0
  49. package/dist/core/template-engine.d.ts +52 -0
  50. package/dist/core/template-engine.d.ts.map +1 -0
  51. package/dist/core/template-engine.js +308 -0
  52. package/dist/core/template-engine.js.map +1 -0
  53. package/dist/core/template-manager.d.ts +54 -0
  54. package/dist/core/template-manager.d.ts.map +1 -0
  55. package/dist/core/template-manager.js +330 -0
  56. package/dist/core/template-manager.js.map +1 -0
  57. package/dist/index.d.ts +12 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +19 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/types/index.d.ts +244 -0
  62. package/dist/types/index.d.ts.map +1 -0
  63. package/dist/types/index.js +51 -0
  64. package/dist/types/index.js.map +1 -0
  65. package/dist/utils/logger.d.ts +68 -0
  66. package/dist/utils/logger.d.ts.map +1 -0
  67. package/dist/utils/logger.js +140 -0
  68. package/dist/utils/logger.js.map +1 -0
  69. package/memory.md +241 -0
  70. package/need-debug.md +395 -0
  71. package/package.json +42 -0
  72. package/src/cli/commands/create.ts +326 -0
  73. package/src/cli/commands/git.ts +1001 -0
  74. package/src/cli/commands/list.ts +97 -0
  75. package/src/cli/index.ts +71 -0
  76. package/src/core/config.ts +262 -0
  77. package/src/core/filesystem.ts +408 -0
  78. package/src/core/git-token.ts +248 -0
  79. package/src/core/git.ts +384 -0
  80. package/src/core/prompt.ts +345 -0
  81. package/src/core/template-engine.ts +324 -0
  82. package/src/core/template-manager.ts +338 -0
  83. package/src/index.ts +19 -0
  84. package/src/types/index.ts +259 -0
  85. package/src/utils/logger.ts +150 -0
  86. package/templates/pages/basic/README.md.mustache +63 -0
  87. package/templates/pages/basic/package.json.mustache +23 -0
  88. package/templates/pages/basic/public/css/style.css +199 -0
  89. package/templates/pages/basic/public/index.html.mustache +72 -0
  90. package/templates/pages/basic/public/js/main.js +103 -0
  91. package/templates/pages/basic/template.json +38 -0
  92. package/templates/pages/basic/tsconfig.json +21 -0
  93. package/templates/pages/basic/wrangler.toml.mustache +14 -0
  94. package/templates/pages/basic-js/README.md.mustache +62 -0
  95. package/templates/pages/basic-js/package.json.mustache +25 -0
  96. package/templates/pages/basic-js/public/css/style.css +212 -0
  97. package/templates/pages/basic-js/public/index.html.mustache +53 -0
  98. package/templates/pages/basic-js/public/js/main.js +134 -0
  99. package/templates/pages/basic-js/template.json +35 -0
  100. package/templates/pages/basic-js/wrangler.toml.mustache +14 -0
  101. package/templates/pages/react/README.md.mustache +97 -0
  102. package/templates/pages/react/index.html.mustache +14 -0
  103. package/templates/pages/react/package.json.mustache +34 -0
  104. package/templates/pages/react/src/App.css +168 -0
  105. package/templates/pages/react/src/App.tsx.mustache +62 -0
  106. package/templates/pages/react/src/index.css +53 -0
  107. package/templates/pages/react/src/main.tsx.mustache +10 -0
  108. package/templates/pages/react/src/vite-env.d.ts +1 -0
  109. package/templates/pages/react/template.json +54 -0
  110. package/templates/pages/react/tsconfig.json +21 -0
  111. package/templates/pages/react/tsconfig.node.json +10 -0
  112. package/templates/pages/react/vite.config.ts +16 -0
  113. package/templates/worker/basic/README.md.mustache +56 -0
  114. package/templates/worker/basic/package.json.mustache +29 -0
  115. package/templates/worker/basic/src/index.ts.mustache +125 -0
  116. package/templates/worker/basic/template.json +30 -0
  117. package/templates/worker/basic/tsconfig.json +24 -0
  118. package/templates/worker/basic/wrangler.toml.mustache +33 -0
  119. package/templates/worker/basic-js/README.md.mustache +55 -0
  120. package/templates/worker/basic-js/package.json.mustache +25 -0
  121. package/templates/worker/basic-js/src/index.js.mustache +146 -0
  122. package/templates/worker/basic-js/template.json +27 -0
  123. package/templates/worker/basic-js/wrangler.toml.mustache +33 -0
  124. package/templates/worker/hono/README.md.mustache +79 -0
  125. package/templates/worker/hono/package.json.mustache +33 -0
  126. package/templates/worker/hono/src/index.ts.mustache +64 -0
  127. package/templates/worker/hono/src/routes/index.ts.mustache +165 -0
  128. package/templates/worker/hono/template.json +34 -0
  129. package/templates/worker/hono/tsconfig.json +24 -0
  130. package/templates/worker/hono/wrangler.toml.mustache +36 -0
  131. package/templates/worker/hono-js/README.md.mustache +67 -0
  132. package/templates/worker/hono-js/package.json.mustache +29 -0
  133. package/templates/worker/hono-js/src/index.js.mustache +55 -0
  134. package/templates/worker/hono-js/src/routes/index.js.mustache +127 -0
  135. package/templates/worker/hono-js/template.json +31 -0
  136. package/templates/worker/hono-js/wrangler.toml.mustache +36 -0
  137. package/thoughts/ledgers/CONTINUITY_ses_287e.md +74 -0
  138. package/thoughts/ledgers/CONTINUITY_ses_28b5.md +85 -0
  139. package/tsconfig.json +30 -0
  140. package/vitest.config.ts +20 -0
  141. package//351/240/205/347/233/256/350/241/250.md +140 -0
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "bundler",
9
+ "allowImportingTsExtensions": true,
10
+ "resolveJsonModule": true,
11
+ "isolatedModules": true,
12
+ "noEmit": true,
13
+ "jsx": "react-jsx",
14
+ "strict": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noFallthroughCasesInSwitch": true
18
+ },
19
+ "include": ["src"],
20
+ "references": [{ "path": "./tsconfig.node.json" }]
21
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ server: {
8
+ port: 3000,
9
+ open: true,
10
+ },
11
+ build: {
12
+ outDir: 'dist',
13
+ sourcemap: true,
14
+ minify: 'terser',
15
+ },
16
+ });
@@ -0,0 +1,56 @@
1
+ # {{projectName}}
2
+
3
+ {{description}}
4
+
5
+ 這是一個基於 Cloudflare Worker 的專案,使用 create-cf-project 腳手架工具建立。
6
+
7
+ ## 快速開始
8
+
9
+ ### 安裝依賴
10
+
11
+ \`\`\`bash
12
+ npm install
13
+ \`\`\`
14
+
15
+ ### 開發模式
16
+
17
+ \`\`\`bash
18
+ npm run dev
19
+ \`\`\`
20
+
21
+ 這會啟動 wrangler dev 伺服器,你可以在本地測試 Worker。
22
+
23
+ ### 部署
24
+
25
+ \`\`\`bash
26
+ npm run deploy
27
+ \`\`\`
28
+
29
+ ## 專案結構
30
+
31
+ \`\`\`
32
+ {{projectName}}/
33
+ ├── src/
34
+ │ └── index.ts # Worker 入口檔案
35
+ ├── package.json # 專案配置
36
+ ├── tsconfig.json # TypeScript 配置
37
+ ├── wrangler.toml # Cloudflare 配置
38
+ └── README.md # 本文件
39
+ \`\`\`
40
+
41
+ ## API 端點
42
+
43
+ - `GET /` - 首頁
44
+ - `GET /api/health` - 健康檢查
45
+
46
+ ## 技術細節
47
+
48
+ - **平台**: Cloudflare Workers
49
+ - **語言**: TypeScript
50
+ - **執行環境**: Edge Runtime
51
+
52
+ ## 授權
53
+
54
+ {{#license}}{{license}}{{/license}}{{^license}}MIT{{/license}}
55
+
56
+ 建立於 {{date}} | {{year}}
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "version": "1.0.0",
4
+ "description": "{{description}}",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "dev": "wrangler dev",
8
+ "deploy": "wrangler deploy",
9
+ "build": "tsc",
10
+ "type-check": "tsc --noEmit",
11
+ "lint": "eslint src/**/*.ts"
12
+ },
13
+ "keywords": [
14
+ "cloudflare",
15
+ "worker",
16
+ "edge"
17
+ ],
18
+ "author": "{{#author}}{{author}}{{/author}}{{^author}}Anonymous{{/author}}",
19
+ "license": "{{#license}}{{license}}{{/license}}{{^license}}MIT{{/license}}",
20
+ "devDependencies": {
21
+ "@cloudflare/workers-types": "^4.20240403.0",
22
+ "@types/node": "^20.0.0",
23
+ "eslint": "^8.57.0",
24
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
25
+ "@typescript-eslint/parser": "^7.0.0",
26
+ "typescript": "^5.3.0",
27
+ "wrangler": "^3.39.0"
28
+ }
29
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Cloudflare Worker 入口檔案
3
+ * {{projectName}} - {{description}}
4
+ * 建立日期:{{date}}
5
+ */
6
+
7
+ export interface Env {
8
+ {{#isKV}}
9
+ CACHE: KVNamespace;
10
+ {{/isKV}}
11
+ {{#isD1}}
12
+ DB: D1Database;
13
+ {{/isD1}}
14
+ {{#isR2}}
15
+ BUCKET: R2Bucket;
16
+ {{/isR2}}
17
+ }
18
+
19
+ export default {
20
+ async fetch(
21
+ request: Request,
22
+ env: Env,
23
+ ctx: ExecutionContext
24
+ ): Promise<Response> {
25
+ const url = new URL(request.url);
26
+
27
+ // 路由處理
28
+ if (url.pathname === '/') {
29
+ return handleHome(request);
30
+ }
31
+
32
+ if (url.pathname === '/api/health') {
33
+ return handleHealth(request);
34
+ }
35
+
36
+ return handle404();
37
+ },
38
+ };
39
+
40
+ /**
41
+ * 首頁處理
42
+ */
43
+ async function handleHome(request: Request): Promise<Response> {
44
+ const html = `
45
+ <!DOCTYPE html>
46
+ <html lang="zh-TW">
47
+ <head>
48
+ <meta charset="UTF-8">
49
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
50
+ <title>{{projectName}}</title>
51
+ <style>
52
+ body {
53
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
54
+ max-width: 800px;
55
+ margin: 0 auto;
56
+ padding: 2rem;
57
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
58
+ color: white;
59
+ min-height: 100vh;
60
+ box-sizing: border-box;
61
+ }
62
+ .container {
63
+ background: rgba(255, 255, 255, 0.1);
64
+ backdrop-filter: blur(10px);
65
+ border-radius: 16px;
66
+ padding: 2rem;
67
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
68
+ }
69
+ h1 { margin: 0 0 1rem 0; font-size: 2.5rem; }
70
+ p { font-size: 1.1rem; line-height: 1.6; opacity: 0.9; }
71
+ .badge {
72
+ display: inline-block;
73
+ background: rgba(255, 255, 255, 0.2);
74
+ padding: 0.5rem 1rem;
75
+ border-radius: 20px;
76
+ font-size: 0.875rem;
77
+ margin-top: 1rem;
78
+ }
79
+ </style>
80
+ </head>
81
+ <body>
82
+ <div class="container">
83
+ <h1>🚀 {{projectName}}</h1>
84
+ <p>{{description}}</p>
85
+ <span class="badge">Cloudflare Worker</span>
86
+ </div>
87
+ </body>
88
+ </html>
89
+ `.trim();
90
+
91
+ return new Response(html, {
92
+ headers: { 'Content-Type': 'text/html; charset=utf-8' },
93
+ });
94
+ }
95
+
96
+ /**
97
+ * 健康檢查端點
98
+ */
99
+ async function handleHealth(request: Request): Promise<Response> {
100
+ const health = {
101
+ status: 'ok',
102
+ timestamp: new Date().toISOString(),
103
+ version: '1.0.0',
104
+ };
105
+
106
+ return new Response(JSON.stringify(health, null, 2), {
107
+ headers: {
108
+ 'Content-Type': 'application/json',
109
+ 'Cache-Control': 'no-cache'
110
+ },
111
+ });
112
+ }
113
+
114
+ /**
115
+ * 404 處理
116
+ */
117
+ function handle404(): Response {
118
+ return new Response(
119
+ JSON.stringify({ error: 'Not Found' }, null, 2),
120
+ {
121
+ status: 404,
122
+ headers: { 'Content-Type': 'application/json' }
123
+ }
124
+ );
125
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "基礎 Cloudflare Worker",
3
+ "description": "最簡單的 Cloudflare Worker 專案,使用原生 Fetch API",
4
+ "projectType": "worker",
5
+ "templateType": "basic",
6
+ "files": [
7
+ {
8
+ "sourcePath": "package.json.mustache",
9
+ "targetPath": "package.json"
10
+ },
11
+ {
12
+ "sourcePath": "wrangler.toml.mustache",
13
+ "targetPath": "wrangler.toml"
14
+ },
15
+ {
16
+ "sourcePath": "src/index.ts.mustache",
17
+ "targetPath": "src/index.ts"
18
+ },
19
+ {
20
+ "sourcePath": "tsconfig.json",
21
+ "targetPath": "tsconfig.json"
22
+ },
23
+ {
24
+ "sourcePath": "README.md.mustache",
25
+ "targetPath": "README.md"
26
+ }
27
+ ],
28
+ "requiredVars": ["projectName", "projectType", "template"],
29
+ "optionalVars": ["author", "email", "description", "license"]
30
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "strict": true,
8
+ "noUnusedLocals": true,
9
+ "noUnusedParameters": true,
10
+ "noImplicitReturns": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "outDir": "./dist",
16
+ "rootDir": "./src",
17
+ "declaration": true,
18
+ "declarationMap": true,
19
+ "sourceMap": true,
20
+ "types": ["@cloudflare/workers-types", "node"]
21
+ },
22
+ "include": ["src/**/*"],
23
+ "exclude": ["node_modules", "dist"]
24
+ }
@@ -0,0 +1,33 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "{{projectName}}"
3
+ main = "src/index.ts"
4
+ compatibility_date = "{{date}}"
5
+ compatibility_flags = ["nodejs_compat"]
6
+
7
+ # 環境變數(開發環境)
8
+ [env.development]
9
+
10
+ # 環境變數(生產環境)
11
+ [env.production]
12
+
13
+ {{#isKV}}
14
+ # KV 存儲綁定
15
+ [[kv_namespaces]]
16
+ binding = "CACHE"
17
+ id = "your-kv-namespace-id"
18
+ {{/isKV}}
19
+
20
+ {{#isD1}}
21
+ # D1 資料庫綁定
22
+ [[d1_databases]]
23
+ binding = "DB"
24
+ database_name = "{{projectName}}-db"
25
+ database_id = "your-d1-database-id"
26
+ {{/isD1}}
27
+
28
+ {{#isR2}}
29
+ # R2 存儲桶綁定
30
+ [[r2_buckets]]
31
+ binding = "BUCKET"
32
+ bucket_name = "{{projectName}}-bucket"
33
+ {{/isR2}}
@@ -0,0 +1,55 @@
1
+ # {{projectName}}
2
+
3
+ {{description}}
4
+
5
+ 這是一個基於 Cloudflare Worker 的專案,使用 create-cf-project 腳手架工具建立。
6
+
7
+ ## 快速開始
8
+
9
+ ### 安裝依賴
10
+
11
+ ```bash
12
+ npm install
13
+ ```
14
+
15
+ ### 開發模式
16
+
17
+ ```bash
18
+ npm run dev
19
+ ```
20
+
21
+ 這會啟動 wrangler dev 伺服器,你可以在本地測試 Worker。
22
+
23
+ ### 部署
24
+
25
+ ```bash
26
+ npm run deploy
27
+ ```
28
+
29
+ ## 專案結構
30
+
31
+ ```
32
+ {{projectName}}/
33
+ ├── src/
34
+ │ └── index.js # Worker 入口檔案
35
+ ├── package.json # 專案配置
36
+ ├── wrangler.toml # Cloudflare 配置
37
+ └── README.md # 本文件
38
+ ```
39
+
40
+ ## API 端點
41
+
42
+ - `GET /` - 首頁
43
+ - `GET /api/health` - 健康檢查
44
+
45
+ ## 技術細節
46
+
47
+ - **平台**: Cloudflare Workers
48
+ - **語言**: JavaScript (ES Module)
49
+ - **執行環境**: Edge Runtime
50
+
51
+ ## 授權
52
+
53
+ {{#license}}{{license}}{{/license}}{{^license}}MIT{{/license}}
54
+
55
+ 建立於 {{date}} | {{year}}
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "version": "1.0.0",
4
+ "description": "{{description}}",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "wrangler dev",
9
+ "deploy": "wrangler deploy",
10
+ "lint": "eslint src/**/*.js"
11
+ },
12
+ "keywords": [
13
+ "cloudflare",
14
+ "worker",
15
+ "edge",
16
+ "javascript"
17
+ ],
18
+ "author": "{{#author}}{{author}}{{/author}}{{^author}}Anonymous{{/author}}",
19
+ "license": "{{#license}}{{license}}{{/license}}{{^license}}MIT{{/license}}",
20
+ "devDependencies": {
21
+ "@cloudflare/workers-types": "^4.20240403.0",
22
+ "eslint": "^8.57.0",
23
+ "wrangler": "^3.39.0"
24
+ }
25
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Cloudflare Worker 入口檔案(JavaScript 版本)
3
+ * {{projectName}} - {{description}}
4
+ * 建立日期:{{date}}
5
+ */
6
+
7
+ /**
8
+ * 環境變數類型定義(JSDoc 註解)
9
+ * @typedef {Object} Env
10
+ * {{#isKV}} * @property {KVNamespace} CACHE{{/isKV}}
11
+ * {{#isD1}} * @property {D1Database} DB{{/isD1}}
12
+ * {{#isR2}} * @property {R2Bucket} BUCKET{{/isR2}}
13
+ */
14
+
15
+ /**
16
+ * Worker 預設導出對象
17
+ */
18
+ export default {
19
+ /**
20
+ * 處理傳入請求
21
+ * @param {Request} request - HTTP 請求對象
22
+ * @param {Env} env - 環境變數
23
+ * @param {ExecutionContext} ctx - 執行上下文
24
+ * @returns {Promise<Response>} HTTP 回應對象
25
+ */
26
+ async fetch(request, env, ctx) {
27
+ const url = new URL(request.url);
28
+
29
+ // 路由處理
30
+ if (url.pathname === '/') {
31
+ return handleHome(request);
32
+ }
33
+ if (url.pathname === '/api/health') {
34
+ return handleHealth(request);
35
+ }
36
+ return handle404();
37
+ },
38
+ };
39
+
40
+ /**
41
+ * 首頁處理
42
+ * @param {Request} request - HTTP 請求
43
+ * @returns {Promise<Response>} HTML 回應
44
+ */
45
+ async function handleHome(request) {
46
+ const html = `
47
+ <!DOCTYPE html>
48
+ <html lang="zh-TW">
49
+ <head>
50
+ <meta charset="UTF-8">
51
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
52
+ <title>{{projectName}}</title>
53
+ <style>
54
+ body {
55
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
56
+ max-width: 800px;
57
+ margin: 0 auto;
58
+ padding: 2rem;
59
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
60
+ color: white;
61
+ min-height: 100vh;
62
+ box-sizing: border-box;
63
+ }
64
+ .container {
65
+ background: rgba(255, 255, 255, 0.1);
66
+ backdrop-filter: blur(10px);
67
+ border-radius: 16px;
68
+ padding: 2rem;
69
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
70
+ }
71
+ h1 {
72
+ margin: 0 0 1rem 0;
73
+ font-size: 2.5rem;
74
+ }
75
+ p {
76
+ font-size: 1.1rem;
77
+ line-height: 1.6;
78
+ opacity: 0.9;
79
+ }
80
+ .badge {
81
+ display: inline-block;
82
+ background: rgba(255, 255, 255, 0.2);
83
+ padding: 0.5rem 1rem;
84
+ border-radius: 20px;
85
+ font-size: 0.875rem;
86
+ margin-top: 1rem;
87
+ }
88
+ .lang-badge {
89
+ background: #f7df1e;
90
+ color: #333;
91
+ margin-left: 0.5rem;
92
+ }
93
+ </style>
94
+ </head>
95
+ <body>
96
+ <div class="container">
97
+ <h1>🚀 {{projectName}}</h1>
98
+ <p>{{description}}</p>
99
+ <span class="badge">Cloudflare Worker</span>
100
+ <span class="badge lang-badge">JavaScript</span>
101
+ </div>
102
+ </body>
103
+ </html>
104
+ `.trim();
105
+
106
+ return new Response(html, {
107
+ headers: {
108
+ 'Content-Type': 'text/html; charset=utf-8',
109
+ },
110
+ });
111
+ }
112
+
113
+ /**
114
+ * 健康檢查端點
115
+ * @param {Request} request - HTTP 請求
116
+ * @returns {Promise<Response>} JSON 回應
117
+ */
118
+ async function handleHealth(request) {
119
+ const health = {
120
+ status: 'ok',
121
+ timestamp: new Date().toISOString(),
122
+ version: '1.0.0',
123
+ language: 'javascript',
124
+ };
125
+
126
+ return new Response(JSON.stringify(health, null, 2), {
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ 'Cache-Control': 'no-cache',
130
+ },
131
+ });
132
+ }
133
+
134
+ /**
135
+ * 404 處理
136
+ * @returns {Response} JSON 回應
137
+ */
138
+ function handle404() {
139
+ return new Response(
140
+ JSON.stringify({ error: 'Not Found' }, null, 2),
141
+ {
142
+ status: 404,
143
+ headers: { 'Content-Type': 'application/json' },
144
+ }
145
+ );
146
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "基礎 Cloudflare Worker (JavaScript)",
3
+ "description": "最簡單的 Cloudflare Worker 專案,使用原生 Fetch API,純 JavaScript 實作",
4
+ "projectType": "worker",
5
+ "templateType": "basic",
6
+ "language": "javascript",
7
+ "files": [
8
+ {
9
+ "sourcePath": "package.json.mustache",
10
+ "targetPath": "package.json"
11
+ },
12
+ {
13
+ "sourcePath": "wrangler.toml.mustache",
14
+ "targetPath": "wrangler.toml"
15
+ },
16
+ {
17
+ "sourcePath": "src/index.js.mustache",
18
+ "targetPath": "src/index.js"
19
+ },
20
+ {
21
+ "sourcePath": "README.md.mustache",
22
+ "targetPath": "README.md"
23
+ }
24
+ ],
25
+ "requiredVars": ["projectName", "projectType", "template"],
26
+ "optionalVars": ["author", "email", "description", "license"]
27
+ }
@@ -0,0 +1,33 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "{{projectName}}"
3
+ main = "src/index.js"
4
+ compatibility_date = "{{date}}"
5
+ compatibility_flags = ["nodejs_compat"]
6
+
7
+ # 環境變數(開發環境)
8
+ [env.development]
9
+
10
+ # 環境變數(生產環境)
11
+ [env.production]
12
+
13
+ {{#isKV}}
14
+ # KV 存儲綁定
15
+ [[kv_namespaces]]
16
+ binding = "CACHE"
17
+ id = "your-kv-namespace-id"
18
+ {{/isKV}}
19
+
20
+ {{#isD1}}
21
+ # D1 資料庫綁定
22
+ [[d1_databases]]
23
+ binding = "DB"
24
+ database_name = "{{projectName}}-db"
25
+ database_id = "your-d1-database-id"
26
+ {{/isD1}}
27
+
28
+ {{#isR2}}
29
+ # R2 存儲桶綁定
30
+ [[r2_buckets]]
31
+ binding = "BUCKET"
32
+ bucket_name = "{{projectName}}-bucket"
33
+ {{/isR2}}