zcw-shared 1.44.2 → 1.46.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.
@@ -1,29 +1,29 @@
1
- import { integrateThirdPartyModule } from './integrateThirdPartyModule';
1
+ import { integrateThirdPartyModule, } from "./integrateThirdPartyModule";
2
2
  async function extractPlugin(pluginPath, extractDir, deps) {
3
3
  try {
4
4
  if (!deps.existsSync(pluginPath)) {
5
5
  return {
6
6
  success: false,
7
- error: `插件路径不存在: ${pluginPath}`
7
+ error: `插件路径不存在: ${pluginPath}`,
8
8
  };
9
9
  }
10
10
  const stat = deps.statSync(pluginPath);
11
11
  if (stat.isDirectory()) {
12
12
  return {
13
13
  success: true,
14
- extractedPath: pluginPath
14
+ extractedPath: pluginPath,
15
15
  };
16
16
  }
17
17
  if (stat.isFile()) {
18
18
  const fileName = deps.basename(pluginPath);
19
- const ext = fileName.split('.').pop()?.toLowerCase();
20
- if (ext !== 'zip') {
19
+ const ext = fileName.split(".").pop()?.toLowerCase();
20
+ if (ext !== "zip") {
21
21
  return {
22
22
  success: false,
23
- error: `不支持的插件格式: ${ext},仅支持 zip 格式`
23
+ error: `不支持的插件格式: ${ext},仅支持 zip 格式`,
24
24
  };
25
25
  }
26
- const pluginName = fileName.replace(/\.zip$/i, '');
26
+ const pluginName = fileName.replace(/\.zip$/i, "");
27
27
  const targetDir = deps.join(extractDir, pluginName);
28
28
  if (!deps.existsSync(targetDir)) {
29
29
  deps.mkdirSync(targetDir, { recursive: true });
@@ -33,7 +33,7 @@ async function extractPlugin(pluginPath, extractDir, deps) {
33
33
  if (error) {
34
34
  resolve({
35
35
  success: false,
36
- error: `解压插件失败: ${error.message}${stderr ? `\n${stderr}` : ''}`
36
+ error: `解压插件失败: ${error.message}${stderr ? `\n${stderr}` : ""}`,
37
37
  });
38
38
  }
39
39
  else {
@@ -44,9 +44,10 @@ async function extractPlugin(pluginPath, extractDir, deps) {
44
44
  const singleEntry = deps.join(targetDir, entries[0]);
45
45
  const singleStat = deps.statSync(singleEntry);
46
46
  if (singleStat.isDirectory()) {
47
- const packageJsonPath = deps.join(singleEntry, 'package.json');
48
- const androidDir = deps.join(singleEntry, 'android');
49
- if (deps.existsSync(packageJsonPath) || deps.existsSync(androidDir)) {
47
+ const packageJsonPath = deps.join(singleEntry, "package.json");
48
+ const androidDir = deps.join(singleEntry, "android");
49
+ if (deps.existsSync(packageJsonPath) ||
50
+ deps.existsSync(androidDir)) {
50
51
  extractedPath = singleEntry;
51
52
  }
52
53
  }
@@ -56,7 +57,7 @@ async function extractPlugin(pluginPath, extractDir, deps) {
56
57
  }
57
58
  resolve({
58
59
  success: true,
59
- extractedPath: extractedPath
60
+ extractedPath: extractedPath,
60
61
  });
61
62
  }
62
63
  });
@@ -64,36 +65,36 @@ async function extractPlugin(pluginPath, extractDir, deps) {
64
65
  }
65
66
  return {
66
67
  success: false,
67
- error: '插件路径既不是文件也不是目录'
68
+ error: "插件路径既不是文件也不是目录",
68
69
  };
69
70
  }
70
71
  catch (error) {
71
72
  return {
72
73
  success: false,
73
- error: `解压插件失败: ${error instanceof Error ? error.message : String(error)}`
74
+ error: `解压插件失败: ${error instanceof Error ? error.message : String(error)}`,
74
75
  };
75
76
  }
76
77
  }
77
78
  function readPluginPackageJson(pluginDir, deps) {
78
79
  try {
79
- const packageJsonPath = deps.join(pluginDir, 'package.json');
80
+ const packageJsonPath = deps.join(pluginDir, "package.json");
80
81
  if (!deps.existsSync(packageJsonPath)) {
81
82
  return {
82
83
  success: false,
83
- error: `插件 package.json 不存在: ${packageJsonPath}`
84
+ error: `插件 package.json 不存在: ${packageJsonPath}`,
84
85
  };
85
86
  }
86
- const content = deps.readFileSync(packageJsonPath, 'utf8');
87
+ const content = deps.readFileSync(packageJsonPath, "utf8");
87
88
  const packageJson = deps.parse(content);
88
89
  return {
89
90
  success: true,
90
- packageJson
91
+ packageJson,
91
92
  };
92
93
  }
93
94
  catch (error) {
94
95
  return {
95
96
  success: false,
96
- error: `读取插件 package.json 失败: ${error instanceof Error ? error.message : String(error)}`
97
+ error: `读取插件 package.json 失败: ${error instanceof Error ? error.message : String(error)}`,
97
98
  };
98
99
  }
99
100
  }
@@ -108,8 +109,8 @@ function findLibFilesRecursive(dir, deps) {
108
109
  const entryPath = deps.join(dir, entry);
109
110
  const stat = deps.statSync(entryPath);
110
111
  if (stat.isFile()) {
111
- const ext = entry.split('.').pop()?.toLowerCase();
112
- if (ext === 'aar' || ext === 'jar') {
112
+ const ext = entry.split(".").pop()?.toLowerCase();
113
+ if (ext === "aar" || ext === "jar") {
113
114
  libFiles.push(entryPath);
114
115
  }
115
116
  }
@@ -123,14 +124,14 @@ function findLibFilesRecursive(dir, deps) {
123
124
  return libFiles;
124
125
  }
125
126
  function findAndroidLibFiles(pluginDir, deps) {
126
- const androidDir = deps.join(pluginDir, 'android');
127
+ const androidDir = deps.join(pluginDir, "android");
127
128
  return findLibFilesRecursive(androidDir, deps);
128
129
  }
129
130
  function copyAndroidFilesRecursive(sourceDir, projectPath, moduleDir, packageName, excludeFiles, deps) {
130
131
  const logs = [];
131
132
  let count = 0;
132
- const excludeSet = new Set(excludeFiles.map(f => deps.join(f).replace(/\\/g, '/')));
133
- function copyRecursive(currentSource, currentTarget, relativePath = '') {
133
+ const excludeSet = new Set(excludeFiles.map((f) => deps.join(f).replace(/\\/g, "/")));
134
+ function copyRecursive(currentSource, currentTarget, relativePath = "") {
134
135
  if (!deps.existsSync(currentSource)) {
135
136
  return;
136
137
  }
@@ -138,33 +139,37 @@ function copyAndroidFilesRecursive(sourceDir, projectPath, moduleDir, packageNam
138
139
  const entries = deps.readdirSync(currentSource);
139
140
  for (const entry of entries) {
140
141
  const sourcePath = deps.join(currentSource, entry);
141
- const normalizedSource = sourcePath.replace(/\\/g, '/');
142
+ const normalizedSource = sourcePath.replace(/\\/g, "/");
142
143
  if (excludeSet.has(normalizedSource)) {
143
144
  continue;
144
145
  }
145
146
  const stat = deps.statSync(sourcePath);
146
147
  const targetPath = deps.join(currentTarget, entry);
147
- const newRelativePath = relativePath ? deps.join(relativePath, entry) : entry;
148
+ const newRelativePath = relativePath
149
+ ? deps.join(relativePath, entry)
150
+ : entry;
148
151
  if (stat.isFile()) {
149
- const ext = entry.split('.').pop()?.toLowerCase();
150
- if (ext === 'java' || ext === 'kt') {
151
- const javaTargetDir = deps.join(projectPath, moduleDir, 'src', 'main', 'java', ...packageName.split('.'));
152
+ const ext = entry.split(".").pop()?.toLowerCase();
153
+ if (ext === "java" || ext === "kt") {
154
+ const javaTargetDir = deps.join(projectPath, moduleDir, "src", "main", "java", ...packageName.split("."));
152
155
  const javaTargetPath = deps.join(javaTargetDir, newRelativePath);
153
156
  const targetDir = deps.dirname(javaTargetPath);
154
157
  if (!deps.existsSync(targetDir)) {
155
158
  deps.mkdirSync(targetDir, { recursive: true });
156
159
  }
157
- let content = deps.readFileSync(sourcePath, 'utf8');
158
- deps.writeFileSync(javaTargetPath, content, 'utf8');
160
+ let content = deps.readFileSync(sourcePath, "utf8");
161
+ deps.writeFileSync(javaTargetPath, content, "utf8");
159
162
  logs.push(`已拷贝 Java 源文件: ${newRelativePath}`);
160
163
  count++;
161
164
  }
162
- else if (ext === 'xml' && (newRelativePath.includes('res/') || newRelativePath.includes('AndroidManifest'))) {
163
- if (entry === 'AndroidManifest.xml') {
165
+ else if (ext === "xml" &&
166
+ (newRelativePath.includes("res/") ||
167
+ newRelativePath.includes("AndroidManifest"))) {
168
+ if (entry === "AndroidManifest.xml") {
164
169
  logs.push(`跳过 AndroidManifest.xml(需要手动合并)`);
165
170
  }
166
171
  else {
167
- const resTargetPath = deps.join(projectPath, moduleDir, 'src', 'main', 'res', newRelativePath.replace(/^res\//, ''));
172
+ const resTargetPath = deps.join(projectPath, moduleDir, "src", "main", "res", newRelativePath.replace(/^res\//, ""));
168
173
  const targetDir = deps.dirname(resTargetPath);
169
174
  if (!deps.existsSync(targetDir)) {
170
175
  deps.mkdirSync(targetDir, { recursive: true });
@@ -175,7 +180,7 @@ function copyAndroidFilesRecursive(sourceDir, projectPath, moduleDir, packageNam
175
180
  }
176
181
  }
177
182
  else {
178
- const otherTargetPath = deps.join(projectPath, moduleDir, 'src', 'main', newRelativePath);
183
+ const otherTargetPath = deps.join(projectPath, moduleDir, "src", "main", newRelativePath);
179
184
  const targetDir = deps.dirname(otherTargetPath);
180
185
  if (!deps.existsSync(targetDir)) {
181
186
  deps.mkdirSync(targetDir, { recursive: true });
@@ -194,16 +199,18 @@ function copyAndroidFilesRecursive(sourceDir, projectPath, moduleDir, packageNam
194
199
  logs.push(`拷贝文件时出错: ${error instanceof Error ? error.message : String(error)}`);
195
200
  }
196
201
  }
197
- const androidTargetBase = deps.join(projectPath, moduleDir, 'src', 'main');
198
- copyRecursive(sourceDir, androidTargetBase, '');
202
+ const androidTargetBase = deps.join(projectPath, moduleDir, "src", "main");
203
+ copyRecursive(sourceDir, androidTargetBase, "");
199
204
  return { count, logs };
200
205
  }
201
206
  function extractPluginConfig(packageJson) {
202
207
  try {
203
208
  let plugins = null;
204
209
  let androidConfig = null;
205
- const nativePlugins = packageJson.nativePlugins || packageJson['uni-app']?.nativePlugins;
206
- if (nativePlugins && Array.isArray(nativePlugins) && nativePlugins.length > 0) {
210
+ const nativePlugins = packageJson.nativePlugins || packageJson["uni-app"]?.nativePlugins;
211
+ if (nativePlugins &&
212
+ Array.isArray(nativePlugins) &&
213
+ nativePlugins.length > 0) {
207
214
  for (const pluginGroup of nativePlugins) {
208
215
  if (pluginGroup.plugins && Array.isArray(pluginGroup.plugins)) {
209
216
  plugins = pluginGroup.plugins;
@@ -214,26 +221,31 @@ function extractPluginConfig(packageJson) {
214
221
  if (!plugins && packageJson._dp_nativeplugin) {
215
222
  androidConfig = packageJson._dp_nativeplugin.android;
216
223
  const androidPlugins = androidConfig?.plugins;
217
- if (androidPlugins && Array.isArray(androidPlugins) && androidPlugins.length > 0) {
224
+ if (androidPlugins &&
225
+ Array.isArray(androidPlugins) &&
226
+ androidPlugins.length > 0) {
218
227
  plugins = androidPlugins;
219
228
  }
220
229
  }
221
230
  if (!plugins || plugins.length === 0) {
222
231
  return {
223
232
  success: false,
224
- error: 'package.json 中未找到 nativePlugins 或 _dp_nativeplugin 配置'
233
+ error: "package.json 中未找到 nativePlugins 或 _dp_nativeplugin 配置",
225
234
  };
226
235
  }
227
236
  for (const plugin of plugins) {
228
- if (plugin.type === 'module' && plugin.name && plugin.class) {
237
+ if (plugin.type === "module" && plugin.name && plugin.class) {
229
238
  let parameters = undefined;
230
- if (androidConfig?.parameters && typeof androidConfig.parameters === 'object') {
239
+ if (androidConfig?.parameters &&
240
+ typeof androidConfig.parameters === "object") {
231
241
  parameters = {};
232
242
  for (const [paramName, paramConfig] of Object.entries(androidConfig.parameters)) {
233
- if (paramConfig && typeof paramConfig === 'object' && 'key' in paramConfig) {
243
+ if (paramConfig &&
244
+ typeof paramConfig === "object" &&
245
+ "key" in paramConfig) {
234
246
  parameters[paramName] = {
235
247
  key: paramConfig.key,
236
- des: paramConfig.des || ''
248
+ des: paramConfig.des || "",
237
249
  };
238
250
  }
239
251
  }
@@ -243,35 +255,35 @@ function extractPluginConfig(packageJson) {
243
255
  pluginItem: {
244
256
  type: plugin.type,
245
257
  name: plugin.name,
246
- class: plugin.class
258
+ class: plugin.class,
247
259
  },
248
- parameters
260
+ parameters,
249
261
  };
250
262
  }
251
263
  }
252
264
  return {
253
265
  success: false,
254
- error: 'package.json 中未找到有效的 module 类型插件配置'
266
+ error: "package.json 中未找到有效的 module 类型插件配置",
255
267
  };
256
268
  }
257
269
  catch (error) {
258
270
  return {
259
271
  success: false,
260
- error: `提取插件配置失败: ${error instanceof Error ? error.message : String(error)}`
272
+ error: `提取插件配置失败: ${error instanceof Error ? error.message : String(error)}`,
261
273
  };
262
274
  }
263
275
  }
264
276
  function readOrCreateUniPluginsConfig(assetsDir, deps) {
265
- const configPath = deps.join(assetsDir, 'dcloud_uniplugins.json');
277
+ const configPath = deps.join(assetsDir, "dcloud_uniplugins.json");
266
278
  try {
267
279
  if (!deps.existsSync(assetsDir)) {
268
280
  deps.mkdirSync(assetsDir, { recursive: true });
269
281
  }
270
282
  let config = {
271
- nativePlugins: []
283
+ nativePlugins: [],
272
284
  };
273
285
  if (deps.existsSync(configPath)) {
274
- const content = deps.readFileSync(configPath, 'utf8');
286
+ const content = deps.readFileSync(configPath, "utf8");
275
287
  try {
276
288
  config = deps.parse(content);
277
289
  if (!config.nativePlugins || !Array.isArray(config.nativePlugins)) {
@@ -283,19 +295,19 @@ function readOrCreateUniPluginsConfig(assetsDir, deps) {
283
295
  }
284
296
  return {
285
297
  success: true,
286
- config
298
+ config,
287
299
  };
288
300
  }
289
301
  catch (error) {
290
302
  return {
291
303
  success: false,
292
- error: `读取或创建 dcloud_uniplugins.json 失败: ${error instanceof Error ? error.message : String(error)}`
304
+ error: `读取或创建 dcloud_uniplugins.json 失败: ${error instanceof Error ? error.message : String(error)}`,
293
305
  };
294
306
  }
295
307
  }
296
308
  function updateUniPluginsConfig(assetsDir, pluginItem, deps) {
297
309
  try {
298
- const configPath = deps.join(assetsDir, 'dcloud_uniplugins.json');
310
+ const configPath = deps.join(assetsDir, "dcloud_uniplugins.json");
299
311
  const readResult = readOrCreateUniPluginsConfig(assetsDir, deps);
300
312
  if (!readResult.success) {
301
313
  return readResult;
@@ -316,23 +328,25 @@ function updateUniPluginsConfig(assetsDir, pluginItem, deps) {
316
328
  let targetNativePlugin = config.nativePlugins.find((np) => np.plugins && Array.isArray(np.plugins));
317
329
  if (!targetNativePlugin) {
318
330
  targetNativePlugin = {
319
- plugins: []
331
+ plugins: [],
320
332
  };
321
333
  config.nativePlugins.push(targetNativePlugin);
322
334
  }
323
335
  targetNativePlugin.plugins.push(pluginItem);
324
336
  }
325
337
  const configContent = JSON.stringify(config, null, 2);
326
- deps.writeFileSync(configPath, configContent, 'utf8');
338
+ deps.writeFileSync(configPath, configContent, "utf8");
327
339
  return {
328
340
  success: true,
329
- message: found ? `已更新插件配置: ${pluginItem.name}` : `已添加插件配置: ${pluginItem.name}`
341
+ message: found
342
+ ? `已更新插件配置: ${pluginItem.name}`
343
+ : `已添加插件配置: ${pluginItem.name}`,
330
344
  };
331
345
  }
332
346
  catch (error) {
333
347
  return {
334
348
  success: false,
335
- error: `更新 dcloud_uniplugins.json 失败: ${error instanceof Error ? error.message : String(error)}`
349
+ error: `更新 dcloud_uniplugins.json 失败: ${error instanceof Error ? error.message : String(error)}`,
336
350
  };
337
351
  }
338
352
  }
@@ -340,8 +354,8 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
340
354
  const logs = [];
341
355
  try {
342
356
  logs.push(`开始集成 UniApp 原生插件: ${pluginPath}`);
343
- logs.push('步骤 1: 解压插件');
344
- const tempDir = deps.join(projectPath, '.temp');
357
+ logs.push("步骤 1: 解压插件");
358
+ const tempDir = deps.join(projectPath, ".temp");
345
359
  if (!deps.existsSync(tempDir)) {
346
360
  deps.mkdirSync(tempDir, { recursive: true });
347
361
  }
@@ -353,87 +367,91 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
353
367
  exec: deps.exec,
354
368
  basename: deps.basename,
355
369
  dirname: deps.dirname,
356
- mkdirSync: deps.mkdirSync
370
+ mkdirSync: deps.mkdirSync,
357
371
  });
358
372
  if (!extractResult.success) {
359
373
  return {
360
374
  success: false,
361
375
  error: extractResult.error,
362
- logs
376
+ logs,
363
377
  };
364
378
  }
365
379
  const pluginDir = extractResult.extractedPath;
366
380
  logs.push(`插件已解压到: ${pluginDir}`);
367
- logs.push('步骤 2: 读取插件配置');
381
+ logs.push("步骤 2: 读取插件配置");
368
382
  const packageJsonResult = readPluginPackageJson(pluginDir, {
369
383
  existsSync: deps.existsSync,
370
384
  readFileSync: deps.readFileSync,
371
385
  join: deps.join,
372
- parse: deps.parse
386
+ parse: deps.parse,
373
387
  });
374
388
  if (!packageJsonResult.success) {
375
389
  return {
376
390
  success: false,
377
391
  error: packageJsonResult.error,
378
- logs
392
+ logs,
379
393
  };
380
394
  }
381
395
  const packageJson = packageJsonResult.packageJson;
382
- const pluginName = packageJson.name || 'UniApp Native Plugin';
396
+ const pluginName = packageJson.name || "UniApp Native Plugin";
383
397
  logs.push(`插件名称: ${pluginName}`);
384
- logs.push('步骤 3: 提取插件配置');
398
+ logs.push("步骤 3: 提取插件配置");
385
399
  const pluginConfigResult = extractPluginConfig(packageJson);
386
400
  let pluginItem = null;
387
401
  let pluginParameters = undefined;
388
402
  if (!pluginConfigResult.success) {
389
403
  logs.push(`警告: ${pluginConfigResult.error}`);
390
- logs.push('将继续处理库文件,但 dcloud_uniplugins.json 可能无法正确配置');
404
+ logs.push("将继续处理库文件,但 dcloud_uniplugins.json 可能无法正确配置");
391
405
  }
392
406
  else {
393
407
  pluginItem = pluginConfigResult.pluginItem;
394
408
  pluginParameters = pluginConfigResult.parameters;
395
409
  logs.push(`插件配置: ${pluginItem.name} (${pluginItem.class})`);
396
410
  if (pluginParameters) {
397
- logs.push(`插件参数: ${Object.keys(pluginParameters).join(', ')}`);
411
+ logs.push(`插件参数: ${Object.keys(pluginParameters).join(", ")}`);
398
412
  }
399
413
  }
400
- logs.push('步骤 4: 查找 Android 库文件');
414
+ logs.push("步骤 4: 查找 Android 库文件");
401
415
  const androidLibFiles = findAndroidLibFiles(pluginDir, {
402
416
  existsSync: deps.existsSync,
403
417
  readdirSync: deps.readdirSync,
404
418
  statSync: deps.statSync,
405
- join: deps.join
419
+ join: deps.join,
406
420
  });
407
421
  if (androidLibFiles.length === 0) {
408
- logs.push('警告: 未找到 android 目录下的 aar/jar 文件');
422
+ logs.push("警告: 未找到 android 目录下的 aar/jar 文件");
409
423
  }
410
424
  else {
411
- logs.push(`找到 ${androidLibFiles.length} 个库文件: ${androidLibFiles.map(f => deps.basename(f)).join(', ')}`);
425
+ logs.push(`找到 ${androidLibFiles.length} 个库文件: ${androidLibFiles
426
+ .map((f) => deps.basename(f))
427
+ .join(", ")}`);
412
428
  }
413
429
  if (androidLibFiles.length > 0) {
414
- logs.push('步骤 5: 拷贝库文件到 libs 目录');
415
- const libFiles = androidLibFiles.map(filePath => ({
430
+ logs.push("步骤 5: 拷贝库文件到 libs 目录");
431
+ const libFiles = androidLibFiles.map((filePath) => ({
416
432
  source: filePath,
417
- targetName: deps.basename(filePath)
433
+ targetName: deps.basename(filePath),
418
434
  }));
419
435
  const manifestModifications = [];
420
436
  if (pluginParameters && parameters) {
421
- logs.push('步骤 5.1: 配置插件参数到 AndroidManifest.xml');
437
+ logs.push("步骤 5.1: 配置插件参数到 AndroidManifest.xml");
422
438
  for (const [paramName, paramDef] of Object.entries(pluginParameters)) {
423
439
  const paramValue = parameters[paramName];
424
- if (paramValue !== undefined && paramValue !== null && paramValue !== '') {
440
+ if (paramValue !== undefined &&
441
+ paramValue !== null &&
442
+ paramValue !== "") {
425
443
  manifestModifications.push({
426
444
  xpath: `//meta-data[@android:name='${paramDef.key}']`,
427
- action: 'removeElement'
445
+ action: "removeElement",
428
446
  });
429
447
  manifestModifications.push({
430
448
  xpath: "//application",
431
- action: 'addElement',
432
- elementName: 'meta-data',
449
+ action: "addElement",
450
+ elementName: "meta-data",
433
451
  attributes: {
434
- 'android:name': paramDef.key,
435
- 'android:value': paramValue
436
- }
452
+ "android:name": paramDef.key,
453
+ "android:value": paramValue,
454
+ },
437
455
  });
438
456
  logs.push(`已配置参数: ${paramName} (${paramDef.key}) = ${paramValue}`);
439
457
  }
@@ -442,10 +460,27 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
442
460
  }
443
461
  }
444
462
  }
463
+ let pluginDependencies = undefined;
464
+ const androidConfig = packageJson._dp_nativeplugin?.android;
465
+ if (androidConfig?.dependencies) {
466
+ if (Array.isArray(androidConfig.dependencies)) {
467
+ pluginDependencies = androidConfig.dependencies.filter((dep) => typeof dep === "string");
468
+ if (pluginDependencies && pluginDependencies.length > 0) {
469
+ logs.push(`找到插件依赖: ${pluginDependencies.join(", ")}`);
470
+ }
471
+ }
472
+ else {
473
+ logs.push(`警告: android.dependencies 不是数组类型`);
474
+ }
475
+ }
476
+ else {
477
+ logs.push(`调试: androidConfig.dependencies 不存在,androidConfig=${JSON.stringify(androidConfig)}`);
478
+ }
445
479
  const moduleConfig = {
446
480
  name: pluginName,
447
481
  libFiles: libFiles,
448
- manifestModifications: manifestModifications.length > 0 ? manifestModifications : undefined
482
+ gradleDependencies: pluginDependencies,
483
+ manifestModifications: manifestModifications.length > 0 ? manifestModifications : undefined,
449
484
  };
450
485
  const thirdPartyResult = await integrateThirdPartyModule(projectPath, moduleDir, packageName, moduleConfig, deps);
451
486
  logs.push(...thirdPartyResult.logs);
@@ -453,15 +488,15 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
453
488
  return {
454
489
  success: false,
455
490
  error: thirdPartyResult.error,
456
- logs
491
+ logs,
457
492
  };
458
493
  }
459
494
  }
460
495
  else {
461
- logs.push('步骤 5: 跳过(未找到库文件)');
496
+ logs.push("步骤 5: 跳过(未找到库文件)");
462
497
  }
463
- logs.push('步骤 6: 拷贝 android 目录下的其他文件');
464
- const androidDir = deps.join(pluginDir, 'android');
498
+ logs.push("步骤 6: 拷贝 android 目录下的其他文件");
499
+ const androidDir = deps.join(pluginDir, "android");
465
500
  if (deps.existsSync(androidDir)) {
466
501
  const copiedFiles = copyAndroidFilesRecursive(androidDir, projectPath, moduleDir, packageName, androidLibFiles, deps);
467
502
  logs.push(...copiedFiles.logs);
@@ -470,41 +505,98 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
470
505
  }
471
506
  }
472
507
  else {
473
- logs.push('android 目录不存在,跳过其他文件拷贝');
508
+ logs.push("android 目录不存在,跳过其他文件拷贝");
509
+ }
510
+ logs.push("步骤 7: 更新 dcloud_uniplugins.json 配置");
511
+ const assetsDir = deps.join(projectPath, moduleDir, "src", "main", "assets");
512
+ let plugins = null;
513
+ const androidConfig = packageJson._dp_nativeplugin?.android;
514
+ if (androidConfig?.plugins && Array.isArray(androidConfig.plugins)) {
515
+ plugins = androidConfig.plugins;
516
+ }
517
+ if (plugins && plugins.length > 0) {
518
+ for (const plugin of plugins) {
519
+ if (plugin.type === "module" && plugin.name && plugin.class) {
520
+ const pluginItem = {
521
+ type: plugin.type,
522
+ name: plugin.name,
523
+ class: plugin.class,
524
+ };
525
+ const updateResult = updateUniPluginsConfig(assetsDir, pluginItem, {
526
+ existsSync: deps.existsSync,
527
+ readFileSync: deps.readFileSync,
528
+ writeFileSync: deps.writeFileSync,
529
+ mkdirSync: deps.mkdirSync,
530
+ join: deps.join,
531
+ parse: deps.parse,
532
+ });
533
+ if (updateResult.success) {
534
+ logs.push(updateResult.message || `已添加插件配置: ${pluginItem.name}`);
535
+ }
536
+ else {
537
+ logs.push(`警告: 添加插件 ${pluginItem.name} 配置失败: ${updateResult.error}`);
538
+ }
539
+ }
540
+ }
541
+ logs.push(`dcloud_uniplugins.json 配置完成,共添加 ${plugins.filter((p) => p.type === "module" && p.name && p.class)
542
+ .length} 个插件`);
474
543
  }
475
- if (pluginItem) {
476
- logs.push('步骤 7: 更新 dcloud_uniplugins.json 配置');
477
- const assetsDir = deps.join(projectPath, moduleDir, 'src', 'main', 'assets');
544
+ else if (pluginItem) {
478
545
  const updateResult = updateUniPluginsConfig(assetsDir, pluginItem, {
479
546
  existsSync: deps.existsSync,
480
547
  readFileSync: deps.readFileSync,
481
548
  writeFileSync: deps.writeFileSync,
482
549
  mkdirSync: deps.mkdirSync,
483
550
  join: deps.join,
484
- parse: deps.parse
551
+ parse: deps.parse,
485
552
  });
486
553
  if (updateResult.success) {
487
- logs.push(updateResult.message || 'dcloud_uniplugins.json 配置完成');
554
+ logs.push(updateResult.message || "dcloud_uniplugins.json 配置完成");
488
555
  }
489
556
  else {
490
557
  logs.push(`警告: dcloud_uniplugins.json 配置失败: ${updateResult.error}`);
491
558
  }
492
559
  }
493
560
  else {
494
- logs.push('步骤 7: 跳过 dcloud_uniplugins.json 配置(插件配置提取失败)');
561
+ logs.push("步骤 7: 跳过 dcloud_uniplugins.json 配置(插件配置提取失败)");
562
+ }
563
+ logs.push("步骤 8: 清理临时文件");
564
+ try {
565
+ if (deps.existsSync(tempDir)) {
566
+ deps.exec(`rm -rf "${tempDir}"`, (error) => {
567
+ if (error) {
568
+ logs.push(`警告: 清理临时目录失败: ${tempDir}`);
569
+ }
570
+ else {
571
+ logs.push(`已清理临时目录: ${tempDir}`);
572
+ }
573
+ });
574
+ }
575
+ }
576
+ catch (cleanupError) {
577
+ logs.push(`警告: 清理临时文件时出错: ${cleanupError instanceof Error
578
+ ? cleanupError.message
579
+ : String(cleanupError)}`);
495
580
  }
496
581
  logs.push(`UniApp 原生插件集成完成: ${pluginName}`);
497
582
  return {
498
583
  success: true,
499
584
  message: `成功集成 UniApp 原生插件: ${pluginName}`,
500
- logs
585
+ logs,
501
586
  };
502
587
  }
503
588
  catch (error) {
589
+ try {
590
+ const tempDir = deps.join(projectPath, ".temp");
591
+ if (deps.existsSync(tempDir)) {
592
+ deps.exec(`rm -rf "${tempDir}"`, () => { });
593
+ }
594
+ }
595
+ catch { }
504
596
  return {
505
597
  success: false,
506
598
  error: `集成 UniApp 原生插件失败: ${error instanceof Error ? error.message : String(error)}`,
507
- logs
599
+ logs,
508
600
  };
509
601
  }
510
602
  }