expo-gaode-map 2.0.0-alpha.6 → 2.0.0-alpha.7

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.
@@ -0,0 +1,146 @@
1
+ # 🚀 发布检查清单
2
+
3
+ 快速参考 - 发布新版本时需要执行的命令
4
+
5
+ ## 📋 发布前检查
6
+
7
+ ```bash
8
+ # 1. 确保在主分支且代码最新
9
+ git checkout main
10
+ git pull origin main
11
+
12
+ # 2. 确保没有未提交的更改
13
+ git status
14
+ ```
15
+
16
+ ## 🔨 构建和测试
17
+
18
+ ```bash
19
+ # 1. 清理旧的构建产物
20
+ npm run clean
21
+
22
+ # 2. 安装依赖(如果需要)
23
+ npm install
24
+
25
+ # 3. 构建项目(包含主模块和 Config Plugin)
26
+ npm run build
27
+
28
+ # 4. 运行测试
29
+ npm test
30
+
31
+ # 5. 运行 lint 检查
32
+ npm run lint
33
+ ```
34
+
35
+ ## 📝 更新版本信息
36
+
37
+ ```bash
38
+ # 选择一个版本更新命令:
39
+
40
+ # Patch 版本 (1.0.0 -> 1.0.1) - 修复 bug
41
+ npm version patch
42
+
43
+ # Minor 版本 (1.0.0 -> 1.1.0) - 新增功能
44
+ npm version minor
45
+
46
+ # Major 版本 (1.0.0 -> 2.0.0) - 破坏性更新
47
+ npm version major
48
+
49
+ # 或手动编辑 package.json 中的 version 字段
50
+ ```
51
+
52
+ ## 📦 发布到 npm
53
+
54
+ ```bash
55
+ # 发布稳定版本(推荐)
56
+ npm run publish:latest
57
+
58
+ # 或发布预览版本(alpha/beta)
59
+ npm run publish:next
60
+ ```
61
+
62
+ ## 🏷️ 创建 Git 标签
63
+
64
+ ```bash
65
+ # 自动创建(如果使用 npm version 命令会自动创建标签)
66
+ # 或手动创建:
67
+
68
+ git tag -a v2.0.0 -m "Release v2.0.0"
69
+ git push origin v2.0.0
70
+ git push origin main
71
+ ```
72
+
73
+ ## 📄 完整命令序列(复制粘贴)
74
+
75
+ ```bash
76
+ # === 稳定版发布 ===
77
+ npm run clean && \
78
+ npm run build && \
79
+ npm test && \
80
+ npm run lint && \
81
+ npm version patch && \
82
+ npm run publish:latest && \
83
+ git push origin main && \
84
+ git push --tags
85
+
86
+ # === 预览版发布 ===
87
+ npm run clean && \
88
+ npm run build && \
89
+ npm test && \
90
+ npm run lint && \
91
+ npm version prerelease --preid=alpha && \
92
+ npm run publish:next && \
93
+ git push origin main && \
94
+ git push --tags
95
+ ```
96
+
97
+ ## ✅ 发布后验证
98
+
99
+ ```bash
100
+ # 1. 检查 npm 上的版本
101
+ npm view expo-gaode-map version
102
+
103
+ # 2. 在测试项目中安装新版本
104
+ cd /path/to/test-project
105
+ npm install expo-gaode-map@latest
106
+
107
+ # 3. 验证 Config Plugin 是否工作
108
+ npx expo prebuild
109
+ ```
110
+
111
+ ## 🔙 回滚(如有问题)
112
+
113
+ ```bash
114
+ # 废弃有问题的版本
115
+ npm deprecate expo-gaode-map@版本号 "此版本存在问题,请使用 x.x.x 版本"
116
+ ```
117
+
118
+ ## 📊 检查清单
119
+
120
+ - [ ] 代码已提交且推送到 main 分支
121
+ - [ ] 运行 `npm run clean`
122
+ - [ ] 运行 `npm run build` 成功
123
+ - [ ] 运行 `npm test` 通过
124
+ - [ ] 运行 `npm run lint` 无错误
125
+ - [ ] 确认 `build/` 目录存在
126
+ - [ ] 确认 `plugin/build/` 目录存在
127
+ - [ ] 更新了 CHANGELOG.md
128
+ - [ ] 版本号已更新
129
+ - [ ] 发布到 npm 成功
130
+ - [ ] Git 标签已创建并推送
131
+ - [ ] 在 GitHub 创建了 Release
132
+ - [ ] 测试项目中验证新版本可用
133
+
134
+ ## 💡 常用版本号规则
135
+
136
+ | 类型 | 命令 | 示例 | 说明 |
137
+ |------|------|------|------|
138
+ | Patch | `npm version patch` | 1.0.0 → 1.0.1 | Bug 修复 |
139
+ | Minor | `npm version minor` | 1.0.0 → 1.1.0 | 新功能(向下兼容) |
140
+ | Major | `npm version major` | 1.0.0 → 2.0.0 | 破坏性更新 |
141
+ | Prerelease | `npm version prerelease --preid=alpha` | 1.0.0 → 1.0.1-alpha.0 | 预发布版本 |
142
+
143
+ ## 🔗 相关文档
144
+
145
+ - 详细发布流程: [PUBLISHING.md](./PUBLISHING.md)
146
+ - 项目部署文档: [DEPLOY_DOCS.md](./DEPLOY_DOCS.md)
package/app.plugin.js ADDED
@@ -0,0 +1,11 @@
1
+
2
+ // Expo Config Plugin 入口文件
3
+ // 这个文件会在用户运行 npx expo prebuild 时被调用
4
+
5
+ const { createRunOncePlugin } = require('@expo/config-plugins');
6
+
7
+ // 导入编译后的插件
8
+ const withGaodeMap = require('./plugin/build/withGaodeMap').default;
9
+
10
+ // 导出插件
11
+ module.exports = withGaodeMap;
@@ -178,11 +178,12 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
178
178
  private func initLocationManager() {
179
179
  locationManager = AMapLocationManager()
180
180
  locationManager?.delegate = self
181
- // 推荐配置:百米精度,快速定位(2-3秒)
181
+ // 推荐配置:百米精度,快速定位
182
182
  locationManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters
183
183
  locationManager?.distanceFilter = 10
184
- locationManager?.locationTimeout = 2 // 2秒超时
185
- locationManager?.reGeocodeTimeout = 2 // 2秒超时
184
+ // 增加超时时间,避免首次授权时超时(首次定位建议10秒以上)
185
+ locationManager?.locationTimeout = 10 // 10秒超时
186
+ locationManager?.reGeocodeTimeout = 5 // 5秒超时
186
187
  locationManager?.locatingWithReGeocode = true
187
188
 
188
189
  // iOS 9 之前:防止后台被系统挂起(默认关闭,用户可通过 setPausesLocationUpdatesAutomatically 配置)
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.7",
4
4
  "description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
7
  "scripts": {
8
- "build": "expo-module build",
9
- "clean": "expo-module clean",
8
+ "build": "expo-module build && npm run build:plugin",
9
+ "build:plugin": "tsc --project plugin/tsconfig.json",
10
+ "clean": "expo-module clean && rm -rf plugin/build",
10
11
  "lint": "expo-module lint",
11
12
  "test": "expo-module test",
12
- "prepare": "expo-module prepare",
13
+ "prepare": "expo-module prepare && npm run build:plugin",
13
14
  "prepublishOnly": "expo-module prepublishOnly",
14
15
  "expo-module": "expo-module",
15
16
  "open:ios": "xed example/ios",
@@ -35,10 +36,12 @@
35
36
  "supercluster": "^8.0.1"
36
37
  },
37
38
  "devDependencies": {
39
+ "@expo/config-plugins": "^9.1.7",
38
40
  "@types/react": "~19.1.0",
39
41
  "expo": "^54.0.18",
40
42
  "expo-module-scripts": "^5.0.7",
41
- "react-native": "0.81.5"
43
+ "react-native": "0.81.5",
44
+ "typescript": "^5.9.3"
42
45
  },
43
46
  "peerDependencies": {
44
47
  "expo": "*",
@@ -0,0 +1,52 @@
1
+ # Expo Config Plugin for expo-gaode-map
2
+
3
+ 这是 `expo-gaode-map` 的 Expo Config Plugin 实现。
4
+
5
+ ## 功能
6
+
7
+ - 自动配置 iOS 和 Android 平台的高德地图 API Key
8
+ - 自动添加定位权限
9
+ - 自动初始化高德地图 SDK
10
+
11
+ ## 开发
12
+
13
+ ### 构建插件
14
+
15
+ ```bash
16
+ npm run build:plugin
17
+ ```
18
+
19
+ ### 目录结构
20
+
21
+ ```
22
+ plugin/
23
+ ├── src/
24
+ │ └── withGaodeMap.ts # 插件源代码
25
+ ├── build/ # 编译输出目录
26
+ ├── tsconfig.json # TypeScript 配置
27
+ └── README.md # 本文件
28
+ ```
29
+
30
+ ## 使用方法
31
+
32
+ 请查看主文档: [CONFIG_PLUGIN.md](../docs/CONFIG_PLUGIN.md)
33
+
34
+ ## 技术细节
35
+
36
+ ### 修改的文件
37
+
38
+ **iOS:**
39
+ - `Info.plist` - 添加 API Key 和权限
40
+ - `AppDelegate.m` - 添加 SDK 初始化代码
41
+
42
+ **Android:**
43
+ - `AndroidManifest.xml` - 添加 API Key 和权限
44
+
45
+ ### 依赖
46
+
47
+ - `@expo/config-plugins` - Expo 配置插件核心库
48
+
49
+ ## 参考
50
+
51
+ - [Expo Config Plugins](https://docs.expo.dev/config-plugins/introduction/)
52
+ - [Creating a Config Plugin](https://docs.expo.dev/config-plugins/plugins-and-mods/)
@@ -0,0 +1,20 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ /**
3
+ * 高德地图插件配置类型
4
+ */
5
+ export type GaodeMapPluginProps = {
6
+ /** iOS 平台 API Key */
7
+ iosApiKey?: string;
8
+ /** Android 平台 API Key */
9
+ androidApiKey?: string;
10
+ /** 是否启用定位功能 */
11
+ enableLocation?: boolean;
12
+ /** iOS 定位权限描述 */
13
+ locationDescription?: string;
14
+ };
15
+ /**
16
+ * 导出为可运行一次的插件
17
+ * 这确保插件只会运行一次,即使在配置中被多次引用
18
+ */
19
+ declare const _default: ConfigPlugin<GaodeMapPluginProps>;
20
+ export default _default;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_plugins_1 = require("@expo/config-plugins");
4
+ /**
5
+ * iOS: 修改 Info.plist 添加 API Key 和权限
6
+ */
7
+ const withGaodeMapInfoPlist = (config, props) => {
8
+ return (0, config_plugins_1.withInfoPlist)(config, (config) => {
9
+ // 添加高德地图 API Key
10
+ if (props.iosApiKey) {
11
+ config.modResults.AMapApiKey = props.iosApiKey;
12
+ }
13
+ // 添加定位相关权限
14
+ if (props.enableLocation !== false) {
15
+ const description = props.locationDescription || '需要访问您的位置信息以提供地图服务';
16
+ config.modResults.NSLocationWhenInUseUsageDescription = description;
17
+ config.modResults.NSLocationAlwaysUsageDescription = description;
18
+ config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription = description;
19
+ }
20
+ // 添加后台定位模式(如果需要)
21
+ if (props.enableLocation !== false) {
22
+ if (!config.modResults.UIBackgroundModes) {
23
+ config.modResults.UIBackgroundModes = [];
24
+ }
25
+ if (!config.modResults.UIBackgroundModes.includes('location')) {
26
+ config.modResults.UIBackgroundModes.push('location');
27
+ }
28
+ }
29
+ return config;
30
+ });
31
+ };
32
+ /**
33
+ * iOS: 修改 AppDelegate 添加初始化代码
34
+ */
35
+ const withGaodeMapAppDelegate = (config, props) => {
36
+ return (0, config_plugins_1.withAppDelegate)(config, (config) => {
37
+ if (!props.iosApiKey) {
38
+ return config;
39
+ }
40
+ let contents = config.modResults.contents;
41
+ // 添加 import 语句
42
+ if (!contents.includes('#import <AMapFoundationKit/AMapFoundationKit.h>')) {
43
+ // 在 #import "AppDelegate.h" 之后添加
44
+ contents = contents.replace(/#import "AppDelegate.h"/g, `#import "AppDelegate.h"\n#import <AMapFoundationKit/AMapFoundationKit.h>`);
45
+ }
46
+ // 在 didFinishLaunchingWithOptions 方法中添加初始化代码
47
+ const initCode = ` [AMapServices sharedServices].apiKey = @"${props.iosApiKey}";`;
48
+ if (!contents.includes(initCode)) {
49
+ // 在 didFinishLaunchingWithOptions 方法的开始处添加
50
+ contents = contents.replace(/(- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions\s*\{)/g, `$1\n${initCode}`);
51
+ }
52
+ config.modResults.contents = contents;
53
+ return config;
54
+ });
55
+ };
56
+ /**
57
+ * Android: 修改 AndroidManifest.xml 添加 API Key 和权限
58
+ */
59
+ const withGaodeMapAndroidManifest = (config, props) => {
60
+ return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
61
+ const androidManifest = config.modResults.manifest;
62
+ // 添加权限
63
+ if (props.enableLocation !== false) {
64
+ const permissions = [
65
+ 'android.permission.ACCESS_COARSE_LOCATION',
66
+ 'android.permission.ACCESS_FINE_LOCATION',
67
+ 'android.permission.ACCESS_WIFI_STATE',
68
+ 'android.permission.ACCESS_NETWORK_STATE',
69
+ 'android.permission.CHANGE_WIFI_STATE',
70
+ 'android.permission.INTERNET',
71
+ 'android.permission.WRITE_EXTERNAL_STORAGE',
72
+ 'android.permission.READ_EXTERNAL_STORAGE',
73
+ 'android.permission.ACCESS_LOCATION_EXTRA_COMMANDS',
74
+ ];
75
+ if (!androidManifest['uses-permission']) {
76
+ androidManifest['uses-permission'] = [];
77
+ }
78
+ permissions.forEach((permission) => {
79
+ const hasPermission = androidManifest['uses-permission']?.some((item) => item.$?.['android:name'] === permission);
80
+ if (!hasPermission) {
81
+ androidManifest['uses-permission']?.push({
82
+ $: { 'android:name': permission },
83
+ });
84
+ }
85
+ });
86
+ }
87
+ // 添加 API Key 到 application 标签
88
+ const mainApplication = androidManifest.application?.[0];
89
+ if (mainApplication && props.androidApiKey) {
90
+ if (!mainApplication['meta-data']) {
91
+ mainApplication['meta-data'] = [];
92
+ }
93
+ // 检查是否已存在
94
+ const hasApiKey = mainApplication['meta-data'].some((item) => item.$?.['android:name'] === 'com.amap.api.v2.apikey');
95
+ if (!hasApiKey) {
96
+ mainApplication['meta-data'].push({
97
+ $: {
98
+ 'android:name': 'com.amap.api.v2.apikey',
99
+ 'android:value': props.androidApiKey,
100
+ },
101
+ });
102
+ }
103
+ else {
104
+ // 更新现有的 API Key
105
+ const apiKeyIndex = mainApplication['meta-data'].findIndex((item) => item.$?.['android:name'] === 'com.amap.api.v2.apikey');
106
+ if (apiKeyIndex !== -1) {
107
+ mainApplication['meta-data'][apiKeyIndex].$ = {
108
+ 'android:name': 'com.amap.api.v2.apikey',
109
+ 'android:value': props.androidApiKey,
110
+ };
111
+ }
112
+ }
113
+ }
114
+ return config;
115
+ });
116
+ };
117
+ /**
118
+ * Android: 修改 app/build.gradle 添加依赖
119
+ */
120
+ const withGaodeMapAppBuildGradle = (config, props) => {
121
+ return (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
122
+ // 这里可以添加额外的 Gradle 配置,如果需要的话
123
+ // 例如添加 maven 仓库或其他依赖
124
+ return config;
125
+ });
126
+ };
127
+ /**
128
+ * 主插件函数 - 组合所有修改器
129
+ */
130
+ const withGaodeMap = (config, props = {}) => {
131
+ // 验证配置
132
+ if (!props.iosApiKey && !props.androidApiKey) {
133
+ config_plugins_1.WarningAggregator.addWarningIOS('expo-gaode-map', '未配置 API Key。请在 app.json 的 plugins 中配置 iosApiKey 和 androidApiKey');
134
+ }
135
+ // 应用 iOS 配置
136
+ config = withGaodeMapInfoPlist(config, props);
137
+ config = withGaodeMapAppDelegate(config, props);
138
+ // 应用 Android 配置
139
+ config = withGaodeMapAndroidManifest(config, props);
140
+ config = withGaodeMapAppBuildGradle(config, props);
141
+ return config;
142
+ };
143
+ /**
144
+ * 导出为可运行一次的插件
145
+ * 这确保插件只会运行一次,即使在配置中被多次引用
146
+ */
147
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withGaodeMap, 'expo-gaode-map', '1.0.0');
@@ -0,0 +1 @@
1
+ {"root":["./src/withgaodemap.ts"],"version":"5.9.3"}