Skip to content

Commit 6965335

Browse files
committed
feat: add undercover mode support with ANT build target
Adds support for building the application in undercover mode by introducing a new 'ant' build target. This enables specialized functionality for internal testing scenarios while maintaining the default external build behavior. The changes include: - New --ant flag to scripts/build.ts to specify build target - Updated define() function to handle process.env values based on build target - Added @types/asciichart dependency for internal metrics visualization - Set USER_TYPE=external in .env.sample as default - Enhanced frontend agent guidelines with proper formatting This builds upon recent TypeScript conversions and maintains compatibility with existing workflows.
1 parent f21f7c0 commit 6965335

6 files changed

Lines changed: 45 additions & 22 deletions

File tree

.claude/agents/frontend-expert.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ description: 专注于 TypeScript 和现代 CSS 的前端架构专家
1616

1717
### 沟通准则 (Communication Guidelines)
1818

19-
1.**拒绝直给**:严禁直接贴出完整的 Bug 修复代码。必须先质疑对方的底层逻辑。
20-
2.**升维打击**:如果对方问一个具体的 CSS 样式,你要谈到设计系统的原子化抽象;如果对方问 Bun 的路径问题,你要谈到运行时环境的跨平台解耦。
21-
3.**强调闭环**:所有的技术动作必须有反馈,必须能反哺业务。
22-
4.**亲切称呼**:开头统一使用“同学”,结尾统一使用“共勉”或“对齐一下”。
19+
1. **拒绝直给**:严禁直接贴出完整的 Bug 修复代码。必须先质疑对方的底层逻辑。
20+
2. **升维打击**:如果对方问一个具体的 CSS 样式,你要谈到设计系统的原子化抽象;如果对方问 Bun 的路径问题,你要谈到运行时环境的跨平台解耦。
21+
3. **强调闭环**:所有的技术动作必须有反馈,必须能反哺业务。
22+
4. **亲切称呼**:开头统一使用“同学”,结尾统一使用“共勉”或“对齐一下”。
2323

2424
### 响应模板 (Response Templates)
2525
### 场景 A:当有人提交了一个 Bug Issue
@@ -47,9 +47,9 @@ description: 专注于 TypeScript 和现代 CSS 的前端架构专家
4747

4848
**建议方向:**
4949

50-
1.**解构**:把路径解析逻辑从业务代码中**抽离**出来,下沉到**配置层**
51-
2.**赋能**:利用 `process.execPath` 实现环境自适应,为后续的分发场景提供护城河。
52-
3.**闭环**:在 `memoize` 之后加上兜底方案,确保系统的可观测性。
50+
1. **解构**:把路径解析逻辑从业务代码中**抽离**出来,下沉到**配置层**
51+
2. **赋能**:利用 `process.execPath` 实现环境自适应,为后续的分发场景提供护城河。
52+
3. **闭环**:在 `memoize` 之后加上兜底方案,确保系统的可观测性。
5353

5454
先按照这个**打法**去演进一下代码,我们下午再**拉通**看下效果。共勉。”
5555

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,5 @@ ANTHROPIC_API_KEY=sk-ant-your-key-here
158158
# Enable debug logging
159159
# CLAUDE_DEBUG=1
160160

161-
NODE_ENV=development
161+
NODE_ENV=development
162+
USER_TYPE=external

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dev": "bun scripts/dev.ts",
2828
"debug": "bun scripts/debug.ts --debug",
2929
"build": "bun scripts/build.ts",
30+
"build:ant": "bun scripts/build.ts --ant",
3031
"lint": "eslint",
3132
"lint:fix": "eslint --fix",
3233
"test": "bun test",
@@ -139,6 +140,7 @@
139140
"@commitlint/cli": "^20.5.0",
140141
"@commitlint/config-conventional": "^20.5.0",
141142
"@commitlint/types": "^20.5.0",
143+
"@types/asciichart": "^1.5.8",
142144
"@types/bun": "^1.3.11",
143145
"@types/cacache": "^20.0.1",
144146
"@types/lodash-es": "^4.17.12",

scripts/build.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import type { BuildTarget } from './config';
2+
13
import { rm } from 'node:fs/promises';
4+
import { parseArgs } from 'node:util';
25

36
import {
47
banner, define, external, features,
@@ -10,6 +13,17 @@ const outdir = 'dist';
1013
// Clean output directory
1114
await rm(outdir, { recursive: true, force: true });
1215

16+
const { values } = parseArgs({
17+
args: Bun.argv,
18+
options: {
19+
ant: { type: 'boolean', default: false },
20+
},
21+
strict: false,
22+
allowPositionals: true,
23+
});
24+
25+
const buildTraget: BuildTarget = Boolean(values.ant) ? 'ant' : 'external';
26+
1327
// Bundle
1428
const result = await Bun.build({
1529
entrypoints: ['src/entrypoints/cli.tsx'],
@@ -18,7 +32,7 @@ const result = await Bun.build({
1832
format: 'esm',
1933
minify: !isDevelopment,
2034
// compile: true,
21-
define: define(),
35+
define: define(buildTraget),
2236
features,
2337
banner,
2438
external,

scripts/config.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,31 @@ export const features = [
9393
// 'WORKFLOW_SCRIPTS',
9494
];
9595

96-
type BuildTarget = 'ant' | 'external';
97-
type BuildEnv = 'development' | 'production' | 'test';
96+
export const defines = {
97+
'MACRO.VERSION': JSON.stringify(version),
98+
'MACRO.BUILD_TIME': JSON.stringify(new Date().toISOString()),
99+
'MACRO.FEEDBACK_CHANNEL': JSON.stringify(bugs.url),
100+
'MACRO.ISSUES_EXPLAINER': JSON.stringify(`report the issue at ${bugs.url}`),
101+
'MACRO.NATIVE_PACKAGE_URL': JSON.stringify(name),
102+
'MACRO.PACKAGE_URL': JSON.stringify(name),
103+
'MACRO.VERSION_CHANGELOG': JSON.stringify(''),
104+
};
105+
106+
export type BuildTarget = 'ant' | 'external';
107+
export type BuildEnv = 'development' | 'production' | 'test';
98108

99109
export function define(
100110
buildTraget: BuildTarget = 'external',
101111
buildEnv: BuildEnv = 'production',
102112
) {
103113
return {
104-
'MACRO.VERSION': JSON.stringify(version),
105-
'MACRO.BUILD_TIME': JSON.stringify(new Date().toISOString()),
106-
'MACRO.FEEDBACK_CHANNEL': JSON.stringify(bugs.url),
107-
'MACRO.ISSUES_EXPLAINER': JSON.stringify(`report the issue at ${bugs.url}`),
108-
'MACRO.NATIVE_PACKAGE_URL': JSON.stringify(name),
109-
'MACRO.PACKAGE_URL': JSON.stringify(name),
110-
'MACRO.VERSION_CHANGELOG': JSON.stringify(''),
111-
// 测试使用.env中
112-
// 'process.env.NODE_ENV': JSON.stringify(buildEnv),
113-
// 'process.env.USER_TYPE': JSON.stringify(buildTraget),
114+
...defines,
115+
'process.env.NODE_ENV': JSON.stringify(buildEnv),
116+
'process.env.USER_TYPE': JSON.stringify(buildTraget),
114117
};
115118
}
116119

117-
export const defineArgs = Object.entries(define()).flatMap(([k, v]) => ['-d', `${k}:${v}`]);
120+
export const defineArgs = Object.entries(defines).flatMap(([k, v]) => ['-d', `${k}:${v}`]);
118121

119122
export const banner = `#!/usr/bin/env node
120123
// (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.

0 commit comments

Comments
 (0)