@jincheng_1995/react-native-device-info-plus 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/PUBLISHING.md ADDED
@@ -0,0 +1,385 @@
1
+ # 发布指南
2
+
3
+ 本文档说明如何将 React Native 插件发布到 npm 和 GitHub。
4
+
5
+ ## 📋 发布前准备
6
+
7
+ ### 1. 完善 package.json
8
+
9
+ 确保以下信息正确:
10
+
11
+ ```json
12
+ {
13
+ "name": "react-native-device-info-plus",
14
+ "version": "1.0.0",
15
+ "description": "一个全面的 React Native 设备信息和操作模块",
16
+ "author": "你的名字 <你的邮箱@example.com>",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/你的用户名/react-native-device-info-plus.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/你的用户名/react-native-device-info-plus/issues"
24
+ },
25
+ "homepage": "https://github.com/你的用户名/react-native-device-info-plus#readme"
26
+ }
27
+ ```
28
+
29
+ ### 2. 检查 .npmignore
30
+
31
+ 确保不发布不必要的文件:
32
+
33
+ ```
34
+ # .npmignore
35
+ example/
36
+ node_modules/
37
+ src/
38
+ *.log
39
+ .vscode/
40
+ .idea/
41
+ .DS_Store
42
+ tsconfig.json
43
+ .eslintrc.js
44
+ ```
45
+
46
+ ### 3. 构建项目
47
+
48
+ ```bash
49
+ npm run prepare
50
+ ```
51
+
52
+ 确保 `lib/` 目录生成成功。
53
+
54
+ ### 4. 测试
55
+
56
+ ```bash
57
+ # 类型检查
58
+ npm run typescript
59
+
60
+ # 代码检查
61
+ npm run lint
62
+ ```
63
+
64
+ ---
65
+
66
+ ## 🐙 发布到 GitHub
67
+
68
+ ### 步骤 1: 创建 GitHub 仓库
69
+
70
+ 1. 访问 https://github.com/new
71
+ 2. 填写仓库信息:
72
+ - **Repository name**: `react-native-device-info-plus`
73
+ - **Description**: `一个全面的 React Native 设备信息和操作模块`
74
+ - **Public** 或 **Private**(推荐 Public)
75
+ - ❌ 不要勾选 "Initialize with README"(我们已有 README)
76
+
77
+ ### 步骤 2: 初始化 Git
78
+
79
+ ```bash
80
+ # 初始化 Git(如果还没有)
81
+ git init
82
+
83
+ # 添加所有文件
84
+ git add .
85
+
86
+ # 提交
87
+ git commit -m "Initial commit: React Native device info plugin"
88
+ ```
89
+
90
+ ### 步骤 3: 关联远程仓库
91
+
92
+ ```bash
93
+ # 关联 GitHub 仓库
94
+ git remote add origin https://github.com/你的用户名/react-native-device-info-plus.git
95
+
96
+ # 推送代码
97
+ git branch -M main
98
+ git push -u origin main
99
+ ```
100
+
101
+ ### 步骤 4: 添加标签(可选)
102
+
103
+ ```bash
104
+ # 为版本打标签
105
+ git tag v1.0.0
106
+ git push origin v1.0.0
107
+ ```
108
+
109
+ ---
110
+
111
+ ## 📦 发布到 npm
112
+
113
+ ### 步骤 1: 注册 npm 账号
114
+
115
+ 如果还没有 npm 账号:
116
+
117
+ 1. 访问 https://www.npmjs.com/signup
118
+ 2. 填写用户名、邮箱、密码
119
+ 3. 验证邮箱
120
+
121
+ ### 步骤 2: 登录 npm
122
+
123
+ ```bash
124
+ npm login
125
+ ```
126
+
127
+ 输入:
128
+ - Username: 你的 npm 用户名
129
+ - Password: 你的密码
130
+ - Email: 你的邮箱
131
+
132
+ ### 步骤 3: 检查包名是否可用
133
+
134
+ ```bash
135
+ npm search react-native-device-info-plus
136
+ ```
137
+
138
+ 如果已存在,需要修改 `package.json` 中的 `name`:
139
+ ```json
140
+ {
141
+ "name": "@你的用户名/react-native-device-info-plus"
142
+ }
143
+ ```
144
+
145
+ ### 步骤 4: 发布
146
+
147
+ ```bash
148
+ # 首次发布
149
+ npm publish
150
+
151
+ # 如果使用了 scope (@你的用户名/xxx)
152
+ npm publish --access public
153
+ ```
154
+
155
+ ### 步骤 5: 验证发布
156
+
157
+ 访问 https://www.npmjs.com/package/react-native-device-info-plus
158
+
159
+ ---
160
+
161
+ ## 🔄 更新版本
162
+
163
+ ### 版本号规则(语义化版本)
164
+
165
+ ```
166
+ 主版本号.次版本号.修订号
167
+ 1 . 0 . 0
168
+
169
+ - 主版本号:不兼容的 API 修改
170
+ - 次版本号:向下兼容的功能性新增
171
+ - 修订号:向下兼容的问题修正
172
+ ```
173
+
174
+ ### 更新步骤
175
+
176
+ ```bash
177
+ # 1. 修复 bug(修订号 +1)
178
+ npm version patch
179
+ # 1.0.0 → 1.0.1
180
+
181
+ # 2. 添加新功能(次版本号 +1)
182
+ npm version minor
183
+ # 1.0.1 → 1.1.0
184
+
185
+ # 3. 重大更新(主版本号 +1)
186
+ npm version major
187
+ # 1.1.0 → 2.0.0
188
+
189
+ # 4. 推送到 GitHub
190
+ git push origin main --tags
191
+
192
+ # 5. 重新构建
193
+ npm run prepare
194
+
195
+ # 6. 发布到 npm
196
+ npm publish
197
+ ```
198
+
199
+ ---
200
+
201
+ ## 📝 发布检查清单
202
+
203
+ ### 发布前
204
+
205
+ - [ ] 更新 `package.json` 中的版本号
206
+ - [ ] 更新 `CHANGELOG.md`(如果有)
207
+ - [ ] 运行 `npm run typescript` 检查类型
208
+ - [ ] 运行 `npm run lint` 检查代码
209
+ - [ ] 运行 `npm run prepare` 构建
210
+ - [ ] 测试在真实项目中的使用
211
+ - [ ] 更新 `README.md` 文档
212
+ - [ ] 检查 `.npmignore` 配置
213
+
214
+ ### 发布后
215
+
216
+ - [ ] 在 npm 上验证包已发布
217
+ - [ ] 测试安装:`npm install react-native-device-info-plus`
218
+ - [ ] 在 GitHub 上创建 Release
219
+ - [ ] 更新文档网站(如果有)
220
+ - [ ] 通知用户(社交媒体、论坛等)
221
+
222
+ ---
223
+
224
+ ## 🎯 完整发布流程示例
225
+
226
+ ```bash
227
+ # 1. 确保代码已提交
228
+ git status
229
+
230
+ # 2. 更新版本号
231
+ npm version patch
232
+
233
+ # 3. 构建
234
+ npm run prepare
235
+
236
+ # 4. 推送到 GitHub
237
+ git push origin main --tags
238
+
239
+ # 5. 发布到 npm
240
+ npm publish
241
+
242
+ # 6. 在 GitHub 创建 Release
243
+ # 访问 https://github.com/你的用户名/react-native-device-info-plus/releases/new
244
+ ```
245
+
246
+ ---
247
+
248
+ ## 🔐 私有包发布
249
+
250
+ 如果不想公开发布,可以发布私有包:
251
+
252
+ ### npm 私有包(需要付费)
253
+
254
+ ```bash
255
+ npm publish --access restricted
256
+ ```
257
+
258
+ ### GitHub Packages(免费)
259
+
260
+ 1. 修改 `package.json`:
261
+ ```json
262
+ {
263
+ "name": "@你的用户名/react-native-device-info-plus",
264
+ "publishConfig": {
265
+ "registry": "https://npm.pkg.github.com"
266
+ }
267
+ }
268
+ ```
269
+
270
+ 2. 创建 `.npmrc`:
271
+ ```
272
+ @你的用户名:registry=https://npm.pkg.github.com
273
+ //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
274
+ ```
275
+
276
+ 3. 发布:
277
+ ```bash
278
+ npm publish
279
+ ```
280
+
281
+ ---
282
+
283
+ ## 🚫 取消发布
284
+
285
+ **注意**:npm 有严格的取消发布政策
286
+
287
+ ```bash
288
+ # 只能取消发布 72 小时内的版本
289
+ npm unpublish react-native-device-info-plus@1.0.0
290
+
291
+ # 取消整个包(慎用!)
292
+ npm unpublish react-native-device-info-plus --force
293
+ ```
294
+
295
+ **建议**:使用 `npm deprecate` 代替:
296
+ ```bash
297
+ npm deprecate react-native-device-info-plus@1.0.0 "此版本有 bug,请使用 1.0.1"
298
+ ```
299
+
300
+ ---
301
+
302
+ ## 📊 发布后的维护
303
+
304
+ ### 监控下载量
305
+
306
+ 访问 https://www.npmjs.com/package/react-native-device-info-plus
307
+
308
+ ### 处理 Issues
309
+
310
+ 在 GitHub 上回复用户问题:
311
+ https://github.com/你的用户名/react-native-device-info-plus/issues
312
+
313
+ ### 持续更新
314
+
315
+ ```bash
316
+ # 定期更新依赖
317
+ npm update
318
+
319
+ # 检查过时的依赖
320
+ npm outdated
321
+
322
+ # 更新 React Native 版本支持
323
+ npm install react-native@latest --save-peer
324
+ ```
325
+
326
+ ---
327
+
328
+ ## 🔗 相关链接
329
+
330
+ - [npm 文档](https://docs.npmjs.com/)
331
+ - [语义化版本](https://semver.org/lang/zh-CN/)
332
+ - [GitHub Packages](https://docs.github.com/en/packages)
333
+ - [npm 发布最佳实践](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry)
334
+
335
+ ---
336
+
337
+ ## ❓ 常见问题
338
+
339
+ ### Q: 包名已被占用怎么办?
340
+
341
+ **A**: 使用 scoped package:
342
+ ```json
343
+ {
344
+ "name": "@你的用户名/react-native-device-info-plus"
345
+ }
346
+ ```
347
+
348
+ ### Q: 发布失败提示权限错误?
349
+
350
+ **A**: 确保已登录:
351
+ ```bash
352
+ npm whoami
353
+ npm login
354
+ ```
355
+
356
+ ### Q: 如何删除已发布的版本?
357
+
358
+ **A**: 只能在 72 小时内删除,建议使用 deprecate:
359
+ ```bash
360
+ npm deprecate react-native-device-info-plus@1.0.0 "请使用新版本"
361
+ ```
362
+
363
+ ### Q: 发布后发现 bug 怎么办?
364
+
365
+ **A**:
366
+ 1. 修复 bug
367
+ 2. 更新版本号:`npm version patch`
368
+ 3. 重新发布:`npm publish`
369
+ 4. 标记旧版本:`npm deprecate react-native-device-info-plus@1.0.0 "有 bug,请升级"`
370
+
371
+ ---
372
+
373
+ ## 💡 最佳实践
374
+
375
+ 1. **使用语义化版本**:严格遵循 semver 规范
376
+ 2. **编写 CHANGELOG**:记录每个版本的变更
377
+ 3. **自动化发布**:使用 GitHub Actions 自动发布
378
+ 4. **测试后发布**:确保在真实项目中测试过
379
+ 5. **文档完善**:提供清晰的 README 和示例
380
+ 6. **及时响应**:快速处理 Issues 和 PR
381
+ 7. **版本标签**:在 GitHub 上为每个版本打标签
382
+
383
+ ---
384
+
385
+ **祝发布顺利!** 🎉
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # react-native-device-info-plus
2
+
3
+ 一个全面的 React Native 设备信息和操作模块,支持新架构(Turbo Modules)。
4
+
5
+ ## 功能特性
6
+
7
+ ### 设备信息
8
+ - 设备型号、品牌、制造商
9
+ - 系统版本
10
+ - 唯一标识符(UUID)
11
+ - 网络状态
12
+ - 电池信息
13
+ - 存储空间
14
+ - 屏幕信息
15
+
16
+ ### 传感器数据
17
+ - 加速度计
18
+ - 陀螺仪
19
+
20
+ ### 设备操作
21
+ - 振动
22
+ - 亮度调节
23
+ - 音量控制
24
+ - 剪贴板操作
25
+ - 打开系统设置
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ npm install react-native-device-info-plus
31
+ # 或
32
+ yarn add react-native-device-info-plus
33
+ ```
34
+
35
+ ### iOS
36
+ ```bash
37
+ cd ios && pod install
38
+ ```
39
+
40
+ ## 使用示例
41
+
42
+ ```typescript
43
+ import DeviceInfoPlus from 'react-native-device-info-plus';
44
+
45
+ // 获取设备信息
46
+ const deviceModel = await DeviceInfoPlus.getDeviceModel();
47
+ const systemVersion = await DeviceInfoPlus.getSystemVersion();
48
+ const uniqueId = await DeviceInfoPlus.getUniqueId();
49
+
50
+ // 获取电池信息
51
+ const batteryLevel = await DeviceInfoPlus.getBatteryLevel();
52
+
53
+ // 获取网络状态
54
+ const networkType = await DeviceInfoPlus.getNetworkType();
55
+
56
+ // 获取存储信息
57
+ const totalStorage = await DeviceInfoPlus.getTotalStorage();
58
+ const freeStorage = await DeviceInfoPlus.getFreeStorage();
59
+
60
+ // 获取屏幕信息
61
+ const screenInfo = await DeviceInfoPlus.getScreenInfo();
62
+
63
+ // 振动
64
+ DeviceInfoPlus.vibrate(500); // 振动 500ms
65
+
66
+ // 设置亮度
67
+ await DeviceInfoPlus.setBrightness(0.8); // 0.0 - 1.0
68
+
69
+ // 获取亮度
70
+ const brightness = await DeviceInfoPlus.getBrightness();
71
+
72
+ // 剪贴板操作
73
+ await DeviceInfoPlus.setClipboard('Hello World');
74
+ const text = await DeviceInfoPlus.getClipboard();
75
+
76
+ // 打开系统设置
77
+ DeviceInfoPlus.openSettings();
78
+
79
+ // 传感器监听
80
+ const subscription = DeviceInfoPlus.addAccelerometerListener((data) => {
81
+ console.log('Accelerometer:', data.x, data.y, data.z);
82
+ });
83
+
84
+ // 取消监听
85
+ subscription.remove();
86
+ ```
87
+
88
+ ## 权限配置
89
+
90
+ ### ✅ Android 权限自动配置
91
+
92
+ 插件所需的 Android 权限会**自动合并**到你的应用,无需手动配置。
93
+
94
+ **⚠️ 注意**: `setBrightness()` 方法需要在运行时请求 `WRITE_SETTINGS` 权限。
95
+
96
+ ### ⚠️ iOS 权限必须手动配置
97
+
98
+ iOS 不支持权限自动合并,如果使用传感器功能,**必须手动**在 `ios/YourApp/Info.plist` 中添加:
99
+
100
+ ```xml
101
+ <key>NSMotionUsageDescription</key>
102
+ <string>需要访问传感器数据来提供更好的用户体验</string>
103
+ ```
104
+
105
+ **重要**:不添加此配置,传感器功能将无法使用。
106
+
107
+ **详细权限说明**: 查看 [PERMISSIONS.md](./PERMISSIONS.md)
108
+
109
+ ## License
110
+
111
+ MIT
@@ -0,0 +1,50 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+
7
+ dependencies {
8
+ classpath "com.android.tools.build:gradle:7.4.2"
9
+ }
10
+ }
11
+
12
+ apply plugin: "com.android.library"
13
+
14
+ def isNewArchitectureEnabled() {
15
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
16
+ }
17
+
18
+ android {
19
+ compileSdkVersion 33
20
+
21
+ defaultConfig {
22
+ minSdkVersion 21
23
+ targetSdkVersion 33
24
+ }
25
+
26
+ buildTypes {
27
+ release {
28
+ minifyEnabled false
29
+ }
30
+ }
31
+
32
+ sourceSets {
33
+ main {
34
+ if (isNewArchitectureEnabled()) {
35
+ java.srcDirs += ["src/newarch"]
36
+ } else {
37
+ java.srcDirs += ["src/oldarch"]
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ repositories {
44
+ mavenCentral()
45
+ google()
46
+ }
47
+
48
+ dependencies {
49
+ implementation "com.facebook.react:react-native:+"
50
+ }
@@ -0,0 +1,15 @@
1
+ #import <RCTTypeSafety/RCTConvertHelpers.h>
2
+ #import <React/RCTBridgeModule.h>
3
+ #import <React/RCTEventEmitter.h>
4
+
5
+ #ifdef RCT_NEW_ARCH_ENABLED
6
+ #import "RNDeviceInfoPlusSpec.h"
7
+
8
+ @interface DeviceInfoPlus : RCTEventEmitter <NativeDeviceInfoPlusSpec>
9
+ #else
10
+ #import <React/RCTBridgeModule.h>
11
+
12
+ @interface DeviceInfoPlus : RCTEventEmitter <RCTBridgeModule>
13
+ #endif
14
+
15
+ @end