npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prd-to-flutter

v0.1.38

Published

为 PRD 原型页面采集 Flutter 还原数据并生成实现计划的 CLI。

Readme

p2f CLI

p2f 是为 PRD 原型页面采集还原数据、生成实现计划的 CLI。它不直接生成 Dart 页面代码。

核心目标

  • 从原型 URL 定位对应的 PRD 页面入口和相关源码范围。
  • 使用 Playwright 采集 DOM、可访问性信息、computed styles、可见文本和运行态结构数据。
  • 按 Flutter 项目已有图片目录结构同步目标页面运行态可见图片,优先复用 assets/images/<业务目录>/;同步前会用内容、视觉指纹和语义名复用已有图片,未命中的普通 SVG 转为 PNG 2X,SVG 动画保留原文件。
  • 抽取页面结构、设计 token 候选、候选交互和运行态数据。
  • 扫描目标 Flutter 项目,判断目标页面是否已经存在。
  • 生成 main.md、页面还原清单、截图探索计划和 implementation-plan.md,把 JSON、源码范围、风险点和实现线索交给 agent。
  • CLI 负责采集、图片资源同步和规划,不直接生成 Dart 页面代码。

文档

  • 使用流程:初始化、常用命令、标准还原流程、generate 阶段和项目结构 profile。
  • 产物与 Agent 规则:任务目录、关键产物、截图规则、审阅顺序和实现规则。
  • 维护与发布:CLI 更新、发布、本地开发和 scanner/profile 维护。

环境要求

  • Node.js >= 20
  • Git 和 PRD 原型源码仓库访问权限
  • Flutter SDK
  • Flutter 项目根目录,必须存在 pubspec.yaml;默认 profile 按 lib/app 结构扫描
  • PRD 原型 Git 仓库地址,首次初始化时通过 p2f init <remote> [branch] 传入
  • CLI 会把 PRD 原型源码同步到当前项目的 .p2f-workspace/prd-source

p2f init 会自动安装 PRD 依赖、Playwright Chromium 和内置 p2f skill,不需要手工运行 npx playwright install chromium。升级 CLI 或内置 skill 变更后,可以重新执行 p2f skills-install 安装/更新 agent 规则。

原型依赖按仓库声明和锁文件选择包管理器。PRD 同时有 npm 和 pnpm 锁文件且未显式声明时,沿用项目发布流程的 npm ci。如果只有 Chromium 缺失,在用户终端执行 p2f playwright-install,安装的浏览器版本与 p2f 自带 Playwright 匹配。

日常采集复用现有的 Playwright 和 Chromium。自写截图脚本从 p2f playwright-env --json 读取 node、importSnippet 和缓存环境。诊断的 browserAction 会提示直接复用、到用户终端检查,或确认二进制是否缺失。

安装

从 npmjs.com 全局安装:

npm install -g prd-to-flutter

升级到 npmjs.com 上的最新版本:

npm install -g prd-to-flutter@latest

包页面见 prd-to-flutter。

本地开发见 维护与发布。

快速开始

在 Flutter 项目根目录执行,也就是包含 pubspec.yaml 的目录:

p2f init "[email protected]:team/prototype.git"
p2f sync
p2f generate "<页面链接>"

remote 必传,branch 可选且默认为 master。非 master 分支示例:

p2f init "[email protected]:team/prototype.git" main

初始化后仓库配置写入 ~/.config/p2f/repository.json,后续 p2f sync 和 p2f generate 直接读取该文件。

同一个 App 要接入多个原型平台时,在项目里分别登记,配置写入 .p2f-workspace/repositories.json:

p2f init [email protected]:team/prototype.git master --source app --origin https://prd.example.com
p2f init [email protected]:team/prototype-extra.git master --source extra --origin https://prd-extra.example.com
p2f generate "https://prd-extra.example.com/某个页面"

分支要换成仓库的实际分支。页面链接按站点域名自动选择原型源。旧的 .p2f-workspace/prd-source 只有在远程仓库地址一致时才会被挪到 .p2f-workspace/prd-sources/<id>。

旧用户升级时,在已经初始化过的 Flutter 项目根目录执行:

p2f update

升级过程会从 .p2f-workspace/prd-source 的 origin 生成 ~/.config/p2f/repository.json,分支按旧版行为写为 master,并刷新当前项目的内置 p2f skill。p2f generate 触发自动升级时也会执行相同迁移。

升级现有项目时需要注意:

  • 迁移只在升级过程中执行;sync、generate 和 doctor 不会从旧工作区 origin 隐式补配置。
  • 旧版 *-default profile 名会自动兼容并归一为 flutter-getx,无需手工修改。
  • cli/analysis/text-style-map.json 当前为 schemaVersion=2,条目中的文字样式字段统一为 textStyle。

如果需要人工指定页面名:

p2f generate --page "订单详情" "https://example.com/prototype/order-detail"

生成后读取:

.p2f-workspace/pages/<task-name>/main.md

再按 main.md 中的路径审阅 cli/analysis/feature-coverage.md、cli/analysis/screenshot-exploration-plan.md、cli/analysis/implementation-plan.md 等产物,让 agent 打开 live prototype 补齐 agent/screenshots/ 后再实现 Flutter 页面。

完整流程见 使用流程。

常用命令

| 命令 | 说明 | | --- | --- | | p2f init <remote> [branch] | 写入本机仓库配置并创建 p2f 工作区;branch 默认 master。 | | p2f sync | 从 PRD 远端配置分支拉取最新代码,并覆盖当前项目的 .p2f-workspace/prd-source。 | | p2f generate "<页面链接>" | 检查 p2f 版本和项目 skill;发现版本更新或规则不一致时自动刷新 skill,然后停止并提示重新加载后重跑。Version Lab 页面必须提供明确版本(URL v= 或 --v),否则会停下请确认。 | | p2f generate --v "<版本id>" "<页面链接>" | 按用户确认的 Version Lab 版本采集;只扫描该版本下的全部状态/方案。 | | p2f update | 升级 CLI;从当前旧工作区迁移仓库配置到 ~/.config/p2f/repository.json。 | | p2f paths --url "<页面链接>" | 打印当前项目的 p2f 工作区、共享项目快照、pages 和任务目录路径。 | | p2f screenshots-audit --url "<页面链接>" | 审计 agent 截图目录、375x812 基准、平台壳层以及 Flutter 根目录错误 .playwright-cli/ 产物。 | | p2f sync-assets --url "<页面链接>" | 只把 Flutter 代码引用到的原型新图片导入项目,并删除不再使用的图片。 | | p2f i18n-audit --url "<页面链接>" | 实现后检查原型 i18n key 是否已写入 Flutter 翻译文件,以及页面是否使用了 .tr。 | | p2f playwright-env --json | 输出 p2f 自带 Playwright 的解析路径,供 agent 截图脚本复用。 | | p2f doctor | 检查环境、skill、.p2f-workspace/prd-source 和 p2f 版本。 |

完整命令表见 使用流程。

定版链接示例:p2f generate "https://prd.yfcenter.com/v5.2.0/design/account/example?v=prototype_v1"。路径中的 v5.2.0 用于检出同名 Git Tag,运行态采集和截图保留这个路径前缀。?v=prototype_v1 仍用于选择该定版内的 Version Lab 版本。无定版前缀的链接继续使用已配置的分支。

项目结构 Profile

p2f generate 默认使用内置 flutter-getx profile。若 Flutter App 或 PRD 原型目录移动,但框架/语法约定没有变,可以在 Flutter 项目根目录新增 p2f.config.json 或 .p2f/config.json 覆盖扫描路径。

示例:

{
  "profile": "flutter-getx",
  "flutter": {
    "moduleRoots": ["lib/features"],
    "routeFiles": {
      "constants": ["lib/router/app_routes.dart"],
      "pages": ["lib/router/app_pages.dart"]
    }
  },
  "prototype": {
    "subprojectCandidates": ["frontend", "prototype", "."],
    "viewsDirs": ["src/pages", "src/views"]
  }
}

完整配置说明见 使用流程。

任务目录

每次 generate 会写入:

.p2f-workspace/pages/<task-name>/
  main.md
  cli/
    source/
    runtime/
    analysis/
    output/
  agent/
    manifest.json
    screenshots/
    runtime/

项目级快照固定写入 .p2f-workspace/project/flutter-project.json。完整产物说明见 产物与 Agent 规则。

原则

  • p2f CLI 不直接生成 Dart 页面代码;运行态可见图片会按 Flutter 目录规范自动同步并生成资源清单。
  • agent 实现前必须先审阅 main.md、feature coverage、截图探索计划和 implementation plan。
  • cli/analysis/flutter-mapping.md 若输出 status=uncertain 或 agentReviewRequired=true,agent 必须先复核页面是否已存在,再决定修改已有页面或新增页面。
  • agent 必须打开 live prototype 主动探索并补齐截图,截图写入 agent/screenshots/。
  • agent 生成截图、探索日志、说明文件或修改 Flutter 文件后,必须同步更新 agent/manifest.json。
  • 遇到 PRD 定位失败、Playwright 采集失败、Flutter 结构扫描失败或关键数据缺失时,必须 fail-fast,不基于不完整信息继续实现。

常见问题

为什么不让 CLI 直接写 Dart?

页面还原涉及已有页面复用、模块归属、路由、主题 token、业务状态和交互细节。纯 CLI 生成 Dart 的效果不稳定,容易偏离目标项目规范。p2f 的职责是准备还原数据和实现计划,真正实现由 agent 根据数据和项目规范完成。

为什么需要 Playwright?

PRD 原型页面的真实结构、样式和交互状态只有运行后才能看到。CLI 使用 Playwright 打开真实页面、等待渲染稳定并读取 DOM/样式/文本;截图和交互分支由 agent 后续在 live page 中主动探索。

.p2f-workspace 是否需要提交?

不建议提交。它是本地运行产物、截图、分析报告和页面目录,已经加入 .gitignore。