@gravito/scaffold 3.0.0 → 3.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/scaffold",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Project scaffolding engine for Gravito - Generate enterprise-grade architecture templates",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,10 +16,12 @@
16
16
  "scripts": {
17
17
  "build": "bun run build.ts",
18
18
  "dev": "bun run --watch src/index.ts",
19
- "test": "bun test",
19
+ "test": "bun test --timeout=10000",
20
20
  "typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
21
- "test:coverage": "bun test --coverage --coverage-threshold=80",
22
- "test:ci": "bun test --coverage --coverage-threshold=80"
21
+ "test:coverage": "bun test --timeout=10000 --coverage --coverage-reporter=lcov --coverage-dir coverage && bun run --bun scripts/check-coverage.ts",
22
+ "test:ci": "bun test --timeout=10000 --coverage --coverage-reporter=lcov --coverage-dir coverage && bun run --bun scripts/check-coverage.ts",
23
+ "test:unit": "bun test tests/ --timeout=10000",
24
+ "test:integration": "test $(find tests -name '*.integration.test.ts' 2>/dev/null | wc -l) -gt 0 && find tests -name '*.integration.test.ts' -print0 | xargs -0 bun test --timeout=10000 || echo 'No integration tests found'"
23
25
  },
24
26
  "files": [
25
27
  "dist",
@@ -48,4 +50,4 @@
48
50
  "url": "git+https://github.com/gravito-framework/gravito.git",
49
51
  "directory": "packages/scaffold"
50
52
  }
51
- }
53
+ }
@@ -0,0 +1,25 @@
1
+ FROM oven/bun:1.0 AS base
2
+ WORKDIR /usr/src/app
3
+
4
+ # Install dependencies
5
+ FROM base AS install
6
+ RUN mkdir -p /temp/dev
7
+ COPY package.json bun.lockb /temp/dev/
8
+ RUN cd /temp/dev && bun install --frozen-lockfile
9
+
10
+ # Build application
11
+ FROM base AS build
12
+ COPY --from=install /temp/dev/node_modules node_modules
13
+ COPY . .
14
+ ENV NODE_ENV=production
15
+ RUN bun run build
16
+
17
+ # Final production image
18
+ FROM base AS release
19
+ COPY --from=build /usr/src/app/{{entrypoint}} index.js
20
+ COPY --from=build /usr/src/app/package.json .
21
+
22
+ # Create a non-root user for security
23
+ USER bun
24
+ EXPOSE 3000/tcp
25
+ ENTRYPOINT [ "bun", "run", "index.js" ]
@@ -0,0 +1,13 @@
1
+ # Application Configuration
2
+ APP_NAME={{name}}
3
+ APP_ENV=development
4
+ APP_DEBUG=true
5
+ APP_URL=http://localhost:3000
6
+ APP_KEY=
7
+
8
+ # Database Configuration
9
+ DB_CONNECTION={{dbConnection}}
10
+ DB_DATABASE=database/database.sqlite
11
+
12
+ # Logging
13
+ LOG_LEVEL=debug
@@ -0,0 +1,10 @@
1
+ node_modules
2
+ dist
3
+ .git
4
+ .env
5
+ .env.*
6
+ .idea
7
+ .vscode
8
+ *.log
9
+ *.sqlite
10
+ coverage
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "esModuleInterop": true,
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "declaration": true,
10
+ "experimentalDecorators": true,
11
+ "emitDecoratorMetadata": true,
12
+ "types": ["bun-types"],
13
+ "outDir": "./dist",
14
+ "rootDir": "./src",
15
+ "baseUrl": ".",
16
+ "paths": {
17
+ "@/*": ["./src/*"]
18
+ }
19
+ },
20
+ "include": ["src/**/*"],
21
+ "exclude": ["node_modules", "dist"]
22
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
- "dependencies": {
3
- "@opentelemetry/sdk-node": "^0.45.0",
4
- "@opentelemetry/exporter-trace-otlp-http": "^0.45.0",
5
- "@gravito/telemetry": "workspace:*"
6
- }
7
- }
2
+ "dependencies": {
3
+ "@opentelemetry/sdk-node": "^0.45.0",
4
+ "@opentelemetry/exporter-trace-otlp-http": "^0.45.0",
5
+ "@gravito/telemetry": "workspace:*"
6
+ }
7
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "dependencies": {
3
- "ioredis": "^5.3.0"
4
- }
5
- }
2
+ "dependencies": {
3
+ "ioredis": "^5.3.0"
4
+ }
5
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "dependencies": {
3
- "better-sqlite3": "^9.0.0"
4
- }
5
- }
2
+ "dependencies": {
3
+ "better-sqlite3": "^9.0.0"
4
+ }
5
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
- "dependencies": {
3
- "ioredis": "^5.0.0",
4
- "pg": "^8.0.0",
5
- "@gravito/spectrum": "workspace:*"
6
- }
7
- }
2
+ "dependencies": {
3
+ "ioredis": "^5.0.0",
4
+ "pg": "^8.0.0",
5
+ "@gravito/spectrum": "workspace:*"
6
+ }
7
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
- "dependencies": {
3
- "ioredis": "^5.0.0",
4
- "pg": "^8.0.0"
5
- }
6
- }
2
+ "dependencies": {
3
+ "ioredis": "^5.0.0",
4
+ "pg": "^8.0.0"
5
+ }
6
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * 相依套件版本檢查腳本
3
+ *
4
+ * 檢查 package.json 中的套件是否為最新穩定版本
5
+ * 並提供更新建議
6
+ */
7
+
8
+ import { readFileSync } from 'fs'
9
+ import { join } from 'path'
10
+
11
+ interface PackageJson {
12
+ dependencies?: Record<string, string>
13
+ devDependencies?: Record<string, string>
14
+ }
15
+
16
+ interface PackageInfo {
17
+ name: string
18
+ current: string
19
+ latest: string
20
+ outdated: boolean
21
+ }
22
+
23
+ const colors = {
24
+ reset: '\x1b[0m',
25
+ green: '\x1b[32m',
26
+ yellow: '\x1b[33m',
27
+ red: '\x1b[31m',
28
+ blue: '\x1b[36m',
29
+ }
30
+
31
+ function log(message: string, color: keyof typeof colors = 'reset') {
32
+ console.log(`${colors[color]}${message}${colors.reset}`)
33
+ }
34
+
35
+ async function getLatestVersion(packageName: string): Promise<string | null> {
36
+ try {
37
+ const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`)
38
+ if (!response.ok) return null
39
+ const data = await response.json()
40
+ return data.version
41
+ } catch {
42
+ return null
43
+ }
44
+ }
45
+
46
+ function parseVersion(version: string): string {
47
+ // 移除 ^, ~, >= 等前綴
48
+ return version.replace(/^[\^~>=<]/, '')
49
+ }
50
+
51
+ async function checkPackage(
52
+ name: string,
53
+ currentVersion: string
54
+ ): Promise<PackageInfo | null> {
55
+ // 跳過本地連結的套件
56
+ if (currentVersion.startsWith('link:') || currentVersion.startsWith('workspace:')) {
57
+ return null
58
+ }
59
+
60
+ const current = parseVersion(currentVersion)
61
+ const latest = await getLatestVersion(name)
62
+
63
+ if (!latest) {
64
+ return null
65
+ }
66
+
67
+ return {
68
+ name,
69
+ current,
70
+ latest,
71
+ outdated: current !== latest,
72
+ }
73
+ }
74
+
75
+ async function main() {
76
+ log('\n=== 相依套件版本檢查 ===\n', 'blue')
77
+
78
+ const packageJsonPath = join(process.cwd(), 'package.json')
79
+ const packageJson: PackageJson = JSON.parse(
80
+ readFileSync(packageJsonPath, 'utf-8')
81
+ )
82
+
83
+ const allDependencies = {
84
+ ...packageJson.dependencies,
85
+ ...packageJson.devDependencies,
86
+ }
87
+
88
+ log(`檢查 ${Object.keys(allDependencies).length} 個套件...\n`, 'yellow')
89
+
90
+ const results: PackageInfo[] = []
91
+ const outdated: PackageInfo[] = []
92
+ const upToDate: PackageInfo[] = []
93
+
94
+ // 檢查所有套件
95
+ for (const [name, version] of Object.entries(allDependencies)) {
96
+ const info = await checkPackage(name, version)
97
+ if (info) {
98
+ results.push(info)
99
+ if (info.outdated) {
100
+ outdated.push(info)
101
+ } else {
102
+ upToDate.push(info)
103
+ }
104
+ }
105
+ }
106
+
107
+ // 顯示結果
108
+ if (upToDate.length > 0) {
109
+ log(`\n✓ 已是最新版本 (${upToDate.length}):`, 'green')
110
+ upToDate.forEach((pkg) => {
111
+ log(` ${pkg.name}: ${pkg.current}`, 'green')
112
+ })
113
+ }
114
+
115
+ if (outdated.length > 0) {
116
+ log(`\n⚠ 需要更新 (${outdated.length}):`, 'yellow')
117
+ outdated.forEach((pkg) => {
118
+ log(` ${pkg.name}: ${pkg.current} → ${pkg.latest}`, 'yellow')
119
+ })
120
+ }
121
+
122
+ // 總結
123
+ log('\n=== 檢查結果 ===', 'blue')
124
+ log(`總計: ${results.length} 個套件`, 'blue')
125
+ log(`最新: ${upToDate.length} 個`, 'green')
126
+ log(`需更新: ${outdated.length} 個`, outdated.length > 0 ? 'yellow' : 'green')
127
+
128
+ // 如果有需要更新的套件,返回非零退出碼
129
+ if (outdated.length > 0) {
130
+ log('\n建議執行以下命令更新套件:', 'yellow')
131
+ log(' bun update', 'yellow')
132
+ process.exit(1)
133
+ } else {
134
+ log('\n✓ 所有套件都是最新版本!', 'green')
135
+ process.exit(0)
136
+ }
137
+ }
138
+
139
+ main().catch((error) => {
140
+ log(`\n錯誤: ${error.message}`, 'red')
141
+ process.exit(1)
142
+ })
@@ -0,0 +1,55 @@
1
+ #!/bin/bash
2
+
3
+ # 專案檢查腳本
4
+ # 執行所有必要的檢查:類型檢查、測試、依賴檢查等
5
+
6
+ set -e
7
+
8
+ # 顏色定義
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ RED='\033[0;31m'
12
+ BLUE='\033[0;34m'
13
+ NC='\033[0m' # No Color
14
+
15
+ echo -e "${BLUE}=== 專案檢查 ===${NC}\n"
16
+
17
+ # 檢查是否在正確的目錄
18
+ if [ ! -f "package.json" ]; then
19
+ echo -e "${RED}錯誤: 請在專案根目錄執行此腳本${NC}"
20
+ exit 1
21
+ fi
22
+
23
+ # 檢查 Bun 是否安裝
24
+ if ! command -v bun &> /dev/null; then
25
+ echo -e "${RED}錯誤: 未找到 bun,請先安裝 Bun${NC}"
26
+ exit 1
27
+ fi
28
+
29
+ # 1. 類型檢查
30
+ echo -e "${YELLOW}[1/3] 執行類型檢查...${NC}"
31
+ if bun run typecheck; then
32
+ echo -e "${GREEN}✓ 類型檢查通過${NC}\n"
33
+ else
34
+ echo -e "${RED}✗ 類型檢查失敗${NC}"
35
+ exit 1
36
+ fi
37
+
38
+ # 2. 執行測試
39
+ echo -e "${YELLOW}[2/3] 執行測試...${NC}"
40
+ if bun test; then
41
+ echo -e "${GREEN}✓ 測試通過${NC}\n"
42
+ else
43
+ echo -e "${RED}✗ 測試失敗${NC}"
44
+ exit 1
45
+ fi
46
+
47
+ # 3. 檢查依賴版本(可選,因為需要網路連線)
48
+ echo -e "${YELLOW}[3/3] 檢查依賴版本...${NC}"
49
+ if bun run check:deps; then
50
+ echo -e "${GREEN}✓ 依賴檢查完成${NC}\n"
51
+ else
52
+ echo -e "${YELLOW}⚠ 依賴檢查有警告(某些套件可能需要更新)${NC}\n"
53
+ fi
54
+
55
+ echo -e "${GREEN}=== 所有檢查完成 ===${NC}"
@@ -0,0 +1,58 @@
1
+ #!/bin/bash
2
+
3
+ # Pre-commit Hook
4
+ # 在 git commit 前自動執行檢查
5
+ #
6
+ # 安裝方式:
7
+ # ln -s ../../scripts/pre-commit.sh .git/hooks/pre-commit
8
+ # 或
9
+ # cp scripts/pre-commit.sh .git/hooks/pre-commit
10
+ # chmod +x .git/hooks/pre-commit
11
+
12
+ set -e
13
+
14
+ # 顏色定義
15
+ GREEN='\033[0;32m'
16
+ YELLOW='\033[1;33m'
17
+ RED='\033[0;31m'
18
+ BLUE='\033[0;34m'
19
+ NC='\033[0m' # No Color
20
+
21
+ echo -e "${BLUE}=== Pre-commit 檢查 ===${NC}\n"
22
+
23
+ # 切換到專案根目錄
24
+ cd "$(git rev-parse --show-toplevel)"
25
+
26
+ # 檢查是否在正確的目錄
27
+ if [ ! -f "package.json" ]; then
28
+ echo -e "${RED}錯誤: 找不到 package.json${NC}"
29
+ exit 1
30
+ fi
31
+
32
+ # 檢查 Bun 是否安裝
33
+ if ! command -v bun &> /dev/null; then
34
+ echo -e "${RED}錯誤: 未找到 bun,請先安裝 Bun${NC}"
35
+ exit 1
36
+ fi
37
+
38
+ # 1. 類型檢查(快速檢查)
39
+ echo -e "${YELLOW}[1/2] 執行類型檢查...${NC}"
40
+ if bun run typecheck; then
41
+ echo -e "${GREEN}✓ 類型檢查通過${NC}\n"
42
+ else
43
+ echo -e "${RED}✗ 類型檢查失敗${NC}"
44
+ echo -e "${YELLOW}提示: 請修正類型錯誤後再提交${NC}"
45
+ exit 1
46
+ fi
47
+
48
+ # 2. 執行測試(可選,如果測試時間較長可以註解掉)
49
+ echo -e "${YELLOW}[2/2] 執行測試...${NC}"
50
+ if bun test; then
51
+ echo -e "${GREEN}✓ 測試通過${NC}\n"
52
+ else
53
+ echo -e "${RED}✗ 測試失敗${NC}"
54
+ echo -e "${YELLOW}提示: 請修正測試錯誤後再提交${NC}"
55
+ exit 1
56
+ fi
57
+
58
+ echo -e "${GREEN}=== Pre-commit 檢查通過 ===${NC}\n"