--- name: ai-studio-project-converter description: 将 Google AI Studio 生成的 React 项目转换为本项目页面组件的流程规范;在处理 Import Map、样式迁移、依赖安装、环境变量与验收时使用。 --- # AI Studio 项目转换规范 将 Google AI Studio 生成的零配置 React 应用转换为本项目页面组件,保持视觉效果和功能,符合本项目开发规范。 ## 核心目标 - 保持页面视觉一致性 - 移除 AI Studio 特定入口与 HTML 模板 - 产出可在本项目中运行的页面组件 ## 使用方式 ### 步骤 1:运行预处理脚本 ```bash node scripts/ai-studio-converter.mjs [output-name] # 示例 node scripts/ai-studio-converter.mjs "temp/my-ai-studio-project" my-page ``` **脚本会自动完成**: - 完整复制 AI Studio 项目到 `src/prototypes/[页面名]/` - 分析项目结构(Import Map、自定义样式、依赖等) - 生成 AI 工作文档(`.ai-studio-tasks.md`) - 生成详细数据(`.ai-studio-analysis.json`) - **不修改任何代码**(100% 安全) ### 步骤 2:按任务清单完成转换 脚本会生成 `.ai-studio-tasks.md` 文件,包含: - 项目概况统计 - 5 个具体任务清单 - Import Map 依赖映射 - 环境变量配置提示 - 验收测试步骤 按任务清单与本规范示例执行转换。 ## 转换要点 ### AI Studio 项目特征 **典型目录结构**: ``` ai-studio-project/ ├── assets/ # 静态资源(可选) ├── components/ # UI 组件 ├── App.tsx # 主应用组件 ├── index.tsx # React 挂载入口 ├── index.html # HTML 模板(Import Map + Tailwind CDN) ├── constants.ts # 常量定义(可选) ├── types.ts # 类型定义(可选) ├── vite.config.ts # Vite 配置(可选) └── metadata.json # 项目元数据(可选) ``` **技术栈**: - **框架**:React 19(Function Components + Hooks) - **语言**:TypeScript - **模块**:Native ESM(Import Map,通常是 esm.sh CDN) - **样式**:Tailwind CSS(CDN Runtime Mode) - **图标**:Lucide React - **配置**:Vite(如果有 vite.config.ts) ### 关键文件特征 **index.html**: ```html ``` ### 本项目页面组件规范 默认先转换为普通 React 页面组件。只有在需求明确要求接入 Axhub / Axure 运行时能力时,才引入 `forwardRef`、`useImperativeHandle` 和 `axure-types`。 **默认格式(推荐)**: ```typescript /** * @name 页面名称 * * 参考资料: * - /rules/development-guide.md * - /skills/default-resource-recommendations/SKILL.md */ import './style.css'; import React from 'react'; export default function PageName() { // 组件逻辑 return ( // JSX 内容 ); } ``` **仅在以下场景才接入 Axure API**: - 页面需要被 Axhub / Axure 接管 - 需要配置面板、外部数据源、事件回调或动作触发 - 用户明确要求保持与现有 Axure 组件一致的接口形式 此时再参考 `/rules/axure-api-guide.md`,使用如下包装形式: ```typescript import React, { forwardRef, useImperativeHandle } from 'react'; import type { AxureProps, AxureHandle } from '../../common/axure-types'; const Component = forwardRef(function PageName(innerProps, ref) { useImperativeHandle(ref, function () { return { getVar: function () { return undefined; }, fireAction: function () {}, eventList: [], actionList: [], varList: [], configList: [], dataList: [] }; }, []); return ( // JSX 内容 ); }); export default Component; ``` ### 转换主应用组件 **AI Studio 原始代码**: ```typescript // App.tsx import { useState } from 'react'; import Header from './components/Header'; export default function App() { const [count, setCount] = useState(0); return
; } ``` **转换为本项目默认规范**: ```typescript /** * @name 页面名称 * * 参考资料: * - /rules/development-guide.md * - /skills/default-resource-recommendations/SKILL.md */ import './style.css'; import React, { useState } from 'react'; import Header from './components/Header'; export default function PageName() { const [count, setCount] = useState(0); return
; } ``` **关键转换点**: 1. 添加文件头部注释(`@name` 和参考资料) 2. 默认保持普通 React 组件写法,优先最小改造 3. 仅在明确需要 Axhub / Axure 接管时,才增加 `forwardRef` 与 `useImperativeHandle` 4. 保持原有的 JSX、Hooks 和 Tailwind 类名不变 5. 若补接 Axure API,需同步参考 `/rules/axure-api-guide.md` ### 处理样式 从 `index.html` 提取样式信息,创建 `style.css`: ```css @import "tailwindcss"; /* 提取