zcw-shared 1.45.0 → 1.46.1
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/dist/functions/android/integrateUniAppNativePlugin.d.ts +9 -9
- package/dist/functions/android/integrateUniAppNativePlugin.js +148 -104
- package/dist/functions/android/integrateUniAppNativePlugin.js.map +1 -1
- package/dist/functions/ios/integrateNativePlugin.d.ts +20 -16
- package/dist/functions/ios/integrateNativePlugin.js +585 -188
- package/dist/functions/ios/integrateNativePlugin.js.map +1 -1
- package/dist/functions/ios/integrateThirdPartyModule.js +61 -9
- package/dist/functions/ios/integrateThirdPartyModule.js.map +1 -1
- package/dist/functions/ios/safelyModifyProjectPbxproj.js +69 -20
- package/dist/functions/ios/safelyModifyProjectPbxproj.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildIOSApp.d.ts +3 -1
- package/dist/functions/uniapp/app-plus/buildIOSApp.js +158 -147
- package/dist/functions/uniapp/app-plus/buildIOSApp.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { FileSystem, Path, ChildProcess } from
|
|
2
|
-
import type { JSON5Parser } from
|
|
3
|
-
import { type IntegrateThirdPartyModuleDeps } from
|
|
1
|
+
import type { FileSystem, Path, ChildProcess } from "../../../references/node.d";
|
|
2
|
+
import type { JSON5Parser } from "../../../references/json5.d";
|
|
3
|
+
import { type IntegrateThirdPartyModuleDeps } from "./integrateThirdPartyModule";
|
|
4
4
|
export interface UniAppNativePluginItem {
|
|
5
5
|
type: string;
|
|
6
6
|
name: string;
|
|
7
7
|
class: string;
|
|
8
8
|
}
|
|
9
9
|
export interface IntegrateUniAppNativePluginDeps extends IntegrateThirdPartyModuleDeps {
|
|
10
|
-
parse: JSON5Parser[
|
|
11
|
-
readdirSync: FileSystem[
|
|
12
|
-
statSync: FileSystem[
|
|
13
|
-
exec: ChildProcess[
|
|
14
|
-
basename: Path[
|
|
15
|
-
dirname: Path[
|
|
10
|
+
parse: JSON5Parser["parse"];
|
|
11
|
+
readdirSync: FileSystem["readdirSync"];
|
|
12
|
+
statSync: FileSystem["statSync"];
|
|
13
|
+
exec: ChildProcess["exec"];
|
|
14
|
+
basename: Path["basename"];
|
|
15
|
+
dirname: Path["dirname"];
|
|
16
16
|
}
|
|
17
17
|
export declare function integrateUniAppNativePlugin(projectPath: string, moduleDir: string, packageName: string, pluginPath: string, deps: IntegrateUniAppNativePluginDeps, parameters?: Record<string, string>): Promise<{
|
|
18
18
|
success: boolean;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { integrateThirdPartyModule } from
|
|
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(
|
|
20
|
-
if (ext !==
|
|
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,
|
|
48
|
-
const androidDir = deps.join(singleEntry,
|
|
49
|
-
if (deps.existsSync(packageJsonPath) ||
|
|
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,
|
|
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,
|
|
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(
|
|
112
|
-
if (ext ===
|
|
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,
|
|
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
|
|
148
|
+
const newRelativePath = relativePath
|
|
149
|
+
? deps.join(relativePath, entry)
|
|
150
|
+
: entry;
|
|
148
151
|
if (stat.isFile()) {
|
|
149
|
-
const ext = entry.split(
|
|
150
|
-
if (ext ===
|
|
151
|
-
const javaTargetDir = deps.join(projectPath, moduleDir,
|
|
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,
|
|
158
|
-
deps.writeFileSync(javaTargetPath, content,
|
|
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 ===
|
|
163
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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[
|
|
206
|
-
if (nativePlugins &&
|
|
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 &&
|
|
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:
|
|
233
|
+
error: "package.json 中未找到 nativePlugins 或 _dp_nativeplugin 配置",
|
|
225
234
|
};
|
|
226
235
|
}
|
|
227
236
|
for (const plugin of plugins) {
|
|
228
|
-
if (plugin.type ===
|
|
237
|
+
if (plugin.type === "module" && plugin.name && plugin.class) {
|
|
229
238
|
let parameters = undefined;
|
|
230
|
-
if (androidConfig?.parameters &&
|
|
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 &&
|
|
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:
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
338
|
+
deps.writeFileSync(configPath, configContent, "utf8");
|
|
327
339
|
return {
|
|
328
340
|
success: true,
|
|
329
|
-
message: found
|
|
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(
|
|
344
|
-
const tempDir = deps.join(projectPath,
|
|
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(
|
|
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 ||
|
|
396
|
+
const pluginName = packageJson.name || "UniApp Native Plugin";
|
|
383
397
|
logs.push(`插件名称: ${pluginName}`);
|
|
384
|
-
logs.push(
|
|
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(
|
|
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(
|
|
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(
|
|
422
|
+
logs.push("警告: 未找到 android 目录下的 aar/jar 文件");
|
|
409
423
|
}
|
|
410
424
|
else {
|
|
411
|
-
logs.push(`找到 ${androidLibFiles.length} 个库文件: ${androidLibFiles
|
|
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(
|
|
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(
|
|
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 &&
|
|
440
|
+
if (paramValue !== undefined &&
|
|
441
|
+
paramValue !== null &&
|
|
442
|
+
paramValue !== "") {
|
|
425
443
|
manifestModifications.push({
|
|
426
444
|
xpath: `//meta-data[@android:name='${paramDef.key}']`,
|
|
427
|
-
action:
|
|
445
|
+
action: "removeElement",
|
|
428
446
|
});
|
|
429
447
|
manifestModifications.push({
|
|
430
448
|
xpath: "//application",
|
|
431
|
-
action:
|
|
432
|
-
elementName:
|
|
449
|
+
action: "addElement",
|
|
450
|
+
elementName: "meta-data",
|
|
433
451
|
attributes: {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
452
|
+
"android:name": paramDef.key,
|
|
453
|
+
"android:value": paramValue,
|
|
454
|
+
},
|
|
437
455
|
});
|
|
438
456
|
logs.push(`已配置参数: ${paramName} (${paramDef.key}) = ${paramValue}`);
|
|
439
457
|
}
|
|
@@ -446,9 +464,9 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
446
464
|
const androidConfig = packageJson._dp_nativeplugin?.android;
|
|
447
465
|
if (androidConfig?.dependencies) {
|
|
448
466
|
if (Array.isArray(androidConfig.dependencies)) {
|
|
449
|
-
pluginDependencies = androidConfig.dependencies.filter((dep) => typeof dep ===
|
|
467
|
+
pluginDependencies = androidConfig.dependencies.filter((dep) => typeof dep === "string");
|
|
450
468
|
if (pluginDependencies && pluginDependencies.length > 0) {
|
|
451
|
-
logs.push(`找到插件依赖: ${pluginDependencies.join(
|
|
469
|
+
logs.push(`找到插件依赖: ${pluginDependencies.join(", ")}`);
|
|
452
470
|
}
|
|
453
471
|
}
|
|
454
472
|
else {
|
|
@@ -462,7 +480,7 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
462
480
|
name: pluginName,
|
|
463
481
|
libFiles: libFiles,
|
|
464
482
|
gradleDependencies: pluginDependencies,
|
|
465
|
-
manifestModifications: manifestModifications.length > 0 ? manifestModifications : undefined
|
|
483
|
+
manifestModifications: manifestModifications.length > 0 ? manifestModifications : undefined,
|
|
466
484
|
};
|
|
467
485
|
const thirdPartyResult = await integrateThirdPartyModule(projectPath, moduleDir, packageName, moduleConfig, deps);
|
|
468
486
|
logs.push(...thirdPartyResult.logs);
|
|
@@ -470,15 +488,15 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
470
488
|
return {
|
|
471
489
|
success: false,
|
|
472
490
|
error: thirdPartyResult.error,
|
|
473
|
-
logs
|
|
491
|
+
logs,
|
|
474
492
|
};
|
|
475
493
|
}
|
|
476
494
|
}
|
|
477
495
|
else {
|
|
478
|
-
logs.push(
|
|
496
|
+
logs.push("步骤 5: 跳过(未找到库文件)");
|
|
479
497
|
}
|
|
480
|
-
logs.push(
|
|
481
|
-
const androidDir = deps.join(pluginDir,
|
|
498
|
+
logs.push("步骤 6: 拷贝 android 目录下的其他文件");
|
|
499
|
+
const androidDir = deps.join(pluginDir, "android");
|
|
482
500
|
if (deps.existsSync(androidDir)) {
|
|
483
501
|
const copiedFiles = copyAndroidFilesRecursive(androidDir, projectPath, moduleDir, packageName, androidLibFiles, deps);
|
|
484
502
|
logs.push(...copiedFiles.logs);
|
|
@@ -487,10 +505,10 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
487
505
|
}
|
|
488
506
|
}
|
|
489
507
|
else {
|
|
490
|
-
logs.push(
|
|
508
|
+
logs.push("android 目录不存在,跳过其他文件拷贝");
|
|
491
509
|
}
|
|
492
|
-
logs.push(
|
|
493
|
-
const assetsDir = deps.join(projectPath, moduleDir,
|
|
510
|
+
logs.push("步骤 7: 更新 dcloud_uniplugins.json 配置");
|
|
511
|
+
const assetsDir = deps.join(projectPath, moduleDir, "src", "main", "assets");
|
|
494
512
|
let plugins = null;
|
|
495
513
|
const androidConfig = packageJson._dp_nativeplugin?.android;
|
|
496
514
|
if (androidConfig?.plugins && Array.isArray(androidConfig.plugins)) {
|
|
@@ -498,11 +516,11 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
498
516
|
}
|
|
499
517
|
if (plugins && plugins.length > 0) {
|
|
500
518
|
for (const plugin of plugins) {
|
|
501
|
-
if (plugin.type ===
|
|
519
|
+
if (plugin.type === "module" && plugin.name && plugin.class) {
|
|
502
520
|
const pluginItem = {
|
|
503
521
|
type: plugin.type,
|
|
504
522
|
name: plugin.name,
|
|
505
|
-
class: plugin.class
|
|
523
|
+
class: plugin.class,
|
|
506
524
|
};
|
|
507
525
|
const updateResult = updateUniPluginsConfig(assetsDir, pluginItem, {
|
|
508
526
|
existsSync: deps.existsSync,
|
|
@@ -510,7 +528,7 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
510
528
|
writeFileSync: deps.writeFileSync,
|
|
511
529
|
mkdirSync: deps.mkdirSync,
|
|
512
530
|
join: deps.join,
|
|
513
|
-
parse: deps.parse
|
|
531
|
+
parse: deps.parse,
|
|
514
532
|
});
|
|
515
533
|
if (updateResult.success) {
|
|
516
534
|
logs.push(updateResult.message || `已添加插件配置: ${pluginItem.name}`);
|
|
@@ -520,7 +538,8 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
520
538
|
}
|
|
521
539
|
}
|
|
522
540
|
}
|
|
523
|
-
logs.push(`dcloud_uniplugins.json 配置完成,共添加 ${plugins.filter((p) => p.type ===
|
|
541
|
+
logs.push(`dcloud_uniplugins.json 配置完成,共添加 ${plugins.filter((p) => p.type === "module" && p.name && p.class)
|
|
542
|
+
.length} 个插件`);
|
|
524
543
|
}
|
|
525
544
|
else if (pluginItem) {
|
|
526
545
|
const updateResult = updateUniPluginsConfig(assetsDir, pluginItem, {
|
|
@@ -529,30 +548,55 @@ export async function integrateUniAppNativePlugin(projectPath, moduleDir, packag
|
|
|
529
548
|
writeFileSync: deps.writeFileSync,
|
|
530
549
|
mkdirSync: deps.mkdirSync,
|
|
531
550
|
join: deps.join,
|
|
532
|
-
parse: deps.parse
|
|
551
|
+
parse: deps.parse,
|
|
533
552
|
});
|
|
534
553
|
if (updateResult.success) {
|
|
535
|
-
logs.push(updateResult.message ||
|
|
554
|
+
logs.push(updateResult.message || "dcloud_uniplugins.json 配置完成");
|
|
536
555
|
}
|
|
537
556
|
else {
|
|
538
557
|
logs.push(`警告: dcloud_uniplugins.json 配置失败: ${updateResult.error}`);
|
|
539
558
|
}
|
|
540
559
|
}
|
|
541
560
|
else {
|
|
542
|
-
logs.push(
|
|
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)}`);
|
|
543
580
|
}
|
|
544
581
|
logs.push(`UniApp 原生插件集成完成: ${pluginName}`);
|
|
545
582
|
return {
|
|
546
583
|
success: true,
|
|
547
584
|
message: `成功集成 UniApp 原生插件: ${pluginName}`,
|
|
548
|
-
logs
|
|
585
|
+
logs,
|
|
549
586
|
};
|
|
550
587
|
}
|
|
551
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 { }
|
|
552
596
|
return {
|
|
553
597
|
success: false,
|
|
554
598
|
error: `集成 UniApp 原生插件失败: ${error instanceof Error ? error.message : String(error)}`,
|
|
555
|
-
logs
|
|
599
|
+
logs,
|
|
556
600
|
};
|
|
557
601
|
}
|
|
558
602
|
}
|