-
Notifications
You must be signed in to change notification settings - Fork 882
Expand file tree
/
Copy pathtypescript.mk
More file actions
164 lines (154 loc) · 6.54 KB
/
typescript.mk
File metadata and controls
164 lines (154 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# =============================================================================
# TypeScript Language Support - Makefile Module
# =============================================================================
# TypeScript project variables - use dynamic directories from config
NPM := npm
PRETTIER := prettier
ESLINT := eslint
TSC := typescript
# Get all TypeScript directories from config
TS_DIRS := $(shell \
if [ -n "$(LOCALCI_CONFIG)" ] && [ -f "$(LOCALCI_CONFIG)" ]; then \
makefiles/parse_localci.sh enabled typescript $(LOCALCI_CONFIG) | cut -d'|' -f2 | tr '\n' ' '; \
else \
echo "console/frontend"; \
fi)
TS_PRIMARY_DIR := $(shell echo $(TS_DIRS) | cut -d' ' -f1)
TS_DIR := $(TS_PRIMARY_DIR)
TS_FILES := $(shell \
for dir in $(TS_DIRS); do \
if [ -d "$$dir" ]; then \
find $$dir -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" 2>/dev/null || true; \
fi; \
done)
# =============================================================================
# Core TypeScript Commands
# =============================================================================
install-tools-typescript: ## Install TypeScript development tools
@echo "$(YELLOW)Installing TypeScript tools globally...$(RESET)"
@npm install -g \
typescript@latest \
prettier@latest \
eslint@latest \
@typescript-eslint/parser@latest \
@typescript-eslint/eslint-plugin@latest \
eslint-config-prettier@latest \
eslint-plugin-import@latest \
eslint-plugin-prettier@latest && \
echo "$(GREEN)TypeScript tools installed globally$(RESET)" || \
(echo "$(RED)Failed to install TypeScript tools$(RESET)" && exit 1)
check-tools-typescript: ## Check TypeScript development tools availability
@echo "$(YELLOW)Checking TypeScript tools...$(RESET)"
@command -v node >/dev/null 2>&1 || (echo "$(RED)Node.js is not installed$(RESET)" && exit 1)
@command -v npm >/dev/null 2>&1 || (echo "$(RED)npm is not installed$(RESET)" && exit 1)
@command -v tsc >/dev/null 2>&1 || (echo "$(RED)TypeScript is not installed globally. Run 'make install-tools-typescript'$(RESET)" && exit 1)
@command -v prettier >/dev/null 2>&1 || (echo "$(RED)Prettier is not installed globally. Run 'make install-tools-typescript'$(RESET)" && exit 1)
@command -v eslint >/dev/null 2>&1 || (echo "$(RED)ESLint is not installed globally. Run 'make install-tools-typescript'$(RESET)" && exit 1)
@echo "$(GREEN)TypeScript tools available globally$(RESET)"
@echo " TypeScript files: $(words $(TS_FILES))"
@echo " Node version: $$(node --version)"
@echo " NPM version: $$(npm --version)"
@echo " TypeScript version: $$(tsc --version)"
@echo " Prettier version: $$(prettier --version)"
@echo " ESLint version: $$(eslint --version)"
check-typescript: ## Check TypeScript code quality
@if [ -n "$(TS_DIRS)" ]; then \
echo "$(YELLOW)Checking TypeScript code quality in: $(TS_DIRS)$(RESET)"; \
for dir in $(TS_DIRS); do \
if [ -d "$$dir" ]; then \
echo "$(YELLOW) Processing $$dir...$(RESET)"; \
(cd $$dir && \
echo "$(YELLOW) Installing dependencies...$(RESET)" && \
$(NPM) ci --legacy-peer-deps && \
echo "$(YELLOW) Checking format compliance...$(RESET)" && \
UNFORMATTED=$$(npx prettier --list-different "**/*.{ts,tsx,js,jsx,json,md}" 2>/dev/null || true) && \
if [ -n "$$UNFORMATTED" ]; then \
echo "$(RED)Files that need formatting:$(RESET)" && \
echo "$$UNFORMATTED" && \
echo "$(YELLOW)Run 'npm run format' to fix formatting issues.$(RESET)" && \
exit 1; \
fi && \
echo "$(YELLOW) Running TypeScript type checking...$(RESET)" && \
(npx tsc --noEmit --pretty || echo "$(YELLOW)TypeScript type checking found errors, but continuing...$(RESET)") && \
echo "$(YELLOW) Running ESLint (errors only)...$(RESET)" && \
npx eslint "**/*.{ts,tsx}" --quiet) || exit 1; \
else \
echo "$(RED)Directory $$dir does not exist$(RESET)"; \
exit 1; \
fi; \
done; \
echo "$(GREEN)TypeScript code quality checks completed$(RESET)"; \
else \
echo "$(BLUE)Skipping TypeScript checks (no TypeScript projects configured)$(RESET)"; \
fi
test-typescript: ## Run TypeScript tests
@if [ -n "$(TS_DIRS)" ]; then \
echo "$(YELLOW)Running TypeScript tests in: $(TS_DIRS)$(RESET)"; \
for dir in $(TS_DIRS); do \
if [ -d "$$dir" ]; then \
echo "$(YELLOW) Testing $$dir...$(RESET)"; \
cd $$dir; \
if [ -f package.json ] && grep -q '"test"' package.json; then \
if grep -q '"test":.*vite.*--host' package.json || grep -q '"test":.*dev' package.json; then \
echo "$(BLUE) Test script appears to be dev server, skipping$(RESET)"; \
else \
$(NPM) test; \
fi; \
else \
echo "$(BLUE) No test script found in package.json$(RESET)"; \
fi; \
cd - > /dev/null; \
else \
echo "$(RED) Directory $$dir does not exist$(RESET)"; \
fi; \
done; \
echo "$(GREEN)TypeScript tests completed$(RESET)"; \
else \
echo "$(BLUE)Skipping TypeScript tests (no TypeScript projects configured)$(RESET)"; \
fi
build-typescript: ## Build TypeScript projects
@if [ -n "$(TS_DIRS)" ]; then \
echo "$(YELLOW)Building TypeScript projects in: $(TS_DIRS)$(RESET)"; \
for dir in $(TS_DIRS); do \
if [ -d "$$dir" ]; then \
echo "$(YELLOW) Building $$dir...$(RESET)"; \
cd $$dir; \
if [ -f package.json ]; then \
$(NPM) ci --prefer-offline; \
if grep -q '"build"' package.json; then \
$(NPM) run build; \
echo "$(GREEN) Built: $$dir$(RESET)"; \
else \
echo "$(BLUE) No build script found in $$dir/package.json$(RESET)"; \
fi; \
else \
echo "$(RED) No package.json found in $$dir$(RESET)"; \
fi; \
cd - > /dev/null; \
else \
echo "$(RED) Directory $$dir does not exist$(RESET)"; \
fi; \
done; \
echo "$(GREEN)TypeScript build completed$(RESET)"; \
else \
echo "$(BLUE)Skipping TypeScript build (no TypeScript projects configured)$(RESET)"; \
fi
clean-typescript: ## Clean TypeScript build artifacts
@if [ -n "$(TS_DIRS)" ]; then \
echo "$(YELLOW)Cleaning TypeScript build artifacts in: $(TS_DIRS)$(RESET)"; \
for dir in $(TS_DIRS); do \
if [ -d "$$dir" ]; then \
echo "$(YELLOW) Cleaning $$dir...$(RESET)"; \
cd $$dir && \
rm -rf dist/ build/ .next/ out/ coverage/ && \
rm -rf node_modules/.cache/ .eslintcache .tsbuildinfo && \
echo "$(GREEN) Cleaned: $$dir$(RESET)"; \
cd - > /dev/null; \
else \
echo "$(RED) Directory $$dir does not exist$(RESET)"; \
fi; \
done; \
echo "$(GREEN)TypeScript build artifacts cleaned$(RESET)"; \
else \
echo "$(BLUE)Skipping TypeScript clean (no TypeScript projects configured)$(RESET)"; \
fi