rnapp-create
v1.0.2
Published
A modular CLI toolkit for React Native projects
Readme
rnapp-create
一个可模块化组合的 React Native 项目脚手架 CLI:初始化新项目、按需添加能力模块,并基于 app.json 同步原生配置(应用名、图标、版本等)。
功能
init <AppName>:基于官方 RN CLI 创建项目,并可交互选择要安装的模块add <feature>:在已有 RN 项目中按需追加模块sync:基于app.json同步原生信息与图标资源
环境要求
- Node.js:
>= 18 - macOS:仅当你使用
--pod时需要(会执行 CocoaPods 相关安装)
安装
- 直接使用(推荐)
npx rnapp-create@latest init MyApp- 全局安装
npm i -g rnapp-create
rnapp-create init MyApp使用
初始化新项目
npx rnapp-create@latest init MyApp可选参数:
# 初始化后自动执行 npm install
npx rnapp-create@latest init MyApp --install
# macOS:初始化后执行 pod install
npx rnapp-create@latest init MyApp --pod
# CI/非交互模式:默认全选所有模块(也可通过 CI=true 触发)
npx rnapp-create@latest init MyApp --yes
npx rnapp-create@latest init MyApp -y给已有项目添加模块
在 RN 项目根目录执行:
npx rnapp-create@latest add <feature>已支持的 feature:
alias:路径别名(@/)tailwind:NativeWind v4 + Reanimatedweb:React Native Web + Viterouter:路由(react-native-router-dom,react-router-dom 风格 API)i18n:多语言store:状态管理(Hox)system-ui:系统 UI 能力assets:内置字体/图标资产,并生成同步脚本
多数模块只会修改配置文件与 package.json 依赖声明,依赖安装需你自行执行:
npm install --legacy-peer-deps同步原生配置(sync)
在 RN 项目根目录执行:
npx rnapp-create@latest syncsync 会读取项目根目录的 app.json 并同步:
- Android:
app_name、applicationId、versionCode、versionName、usesCleartextTraffic、图标(含 adaptive icon) - iOS:
CFBundleDisplayName、PRODUCT_BUNDLE_IDENTIFIER、MARKETING_VERSION、CURRENT_PROJECT_VERSION、图标
app.json 关键字段(最少需要 displayName):
{
"displayName": "My App",
"version": "1.0.0",
"buildNumber": "1",
"icon": "./src/assets/app-icons/icon.png",
"iconScale": 0.78,
"ios": {
"bundleIdentifier": "com.example.myapp",
"buildNumber": "1",
"icon": "./src/assets/app-icons/icon.png"
},
"android": {
"applicationId": "com.example.myapp",
"versionCode": 1,
"usesCleartextTraffic": false,
"icon": "./src/assets/app-icons/icon.png",
"roundIcon": "./src/assets/app-icons/icon.png",
"adaptiveIcon": {
"foregroundImage": "./src/assets/app-icons/adaptive-icon.png",
"backgroundColor": "#ffffff",
"foregroundScale": 0.6,
"backgroundScale": 1
}
}
}如果你安装了 assets 模块,会在项目中注入脚本:
npm run sync它等价于:
npx rnapp-create sync && react-native-asset本仓库调试
在仓库根目录直接运行:
node scripts/cli.js
node scripts/cli.js init MyApp
node scripts/cli.js add router
node scripts/cli.js sync发布(维护者)
发包前建议先确认实际会被发布的文件:
npm pack --dry-run如果发现 DemoApp/ 等目录也被打进包里,建议在 package.json 增加 files 白名单或添加 .npmignore 进行排除。
发布流程示例:
npm login
npm version patch
npm publish --access public