hcordova 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hcordova",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Cordova CLI with HarmonyOS support",
5
5
  "main": "src/base-cli.js",
6
6
  "bin": {
@@ -120,6 +120,9 @@ class PlatformProject {
120
120
 
121
121
  // 下载 cordova-openharmony HAR 工程源码
122
122
  async downloadHarSourceCode(platformUrl, platformTag) {
123
+ if(!platformUrl.startsWith("http")) {
124
+ return await this.downloadNpmHarSourceCode(platformUrl, platformTag);
125
+ }
123
126
  // 检查git是否可用
124
127
  try {
125
128
  execSync('git --version', { stdio: 'pipe' });
@@ -186,6 +189,55 @@ class PlatformProject {
186
189
  }
187
190
  }
188
191
 
192
+ // 下载 cordova-openharmony HAR 工程源码
193
+ async downloadNpmHarSourceCode(platformUrl, platformTag) {
194
+ const organization = "@cordova-ohos";
195
+ const tempDir = path.join(os.tmpdir(), 'cordova-openharmony-har-' + Date.now());
196
+ try {
197
+ // 创建临时目录
198
+ if (!fs.existsSync(tempDir)) {
199
+ fs.mkdirSync(tempDir, { recursive: true });
200
+ }
201
+
202
+ const fetcher = new ReleaseFetcher({ verbose: true });
203
+ const latestTag = fetcher.getNpmVersion(`${organization}/${platformUrl}`, platformTag);
204
+
205
+ let commandNpm = `npm --prefix ${tempDir} install ${organization}/${platformUrl}`;
206
+ if(latestTag != null) {
207
+ commandNpm += `@${latestTag}`;
208
+ }
209
+
210
+ console.log(commandNpm);
211
+ try {
212
+ execSync(commandNpm, { stdio: 'inherit' });
213
+ } catch(error) {
214
+ throw new Error(`${commandNpm} exec failed`);
215
+ }
216
+
217
+ // 验证 HAR 工程结构
218
+ const requiredFiles = [
219
+ 'src/main/ets/',
220
+ 'src/main/module.json5',
221
+ 'oh-package.json5'
222
+ ];
223
+
224
+ const fullPath = path.join(tempDir, 'node_modules', organization, platformUrl);
225
+ for (const file of requiredFiles) {
226
+ if (!fs.existsSync(path.join(fullPath, file))) {
227
+ throw new Error(`Invalid HAR project structure: ${file} not found`);
228
+ }
229
+ }
230
+
231
+ console.log('HAR source code downloaded successfully');
232
+ return fullPath;
233
+
234
+ } catch (error) {
235
+ // 清理临时文件
236
+ this.cleanupTempFiles(tempDir);
237
+ throw new Error(`Failed to download HAR source code: ${error.message}`);
238
+ }
239
+ }
240
+
189
241
  // 下载 openssl 源码
190
242
  async downloadOpensslSourceCode() {
191
243
  // 检查git是否可用
@@ -132,18 +132,15 @@ class PluginDownloader {
132
132
  }
133
133
 
134
134
  try {
135
- let lastestTag = null;
136
- const fetcher = new ReleaseFetcher({ verbose: true });
137
- const tagInfo = await fetcher.getLatestReleaseTag(gitUrl, options.gitRef);
138
- if(tagInfo.found) {
139
- lastestTag = tagInfo.latestTag;
140
- } else if(tagInfo.allTags.length > 0) {
141
- lastestTag = tagInfo.allTags[0];
142
- }
143
-
144
- let commandGit = `git clone ${gitUrl} ${pluginDir}`;
145
- if(lastestTag != null) {
146
- commandGit += ` --branch ${lastestTag} --single-branch`;
135
+ let lastestTag = "master";
136
+ if (options.gitRef != null && options.gitRef != "" && options.gitRef !== undefined) {
137
+ const fetcher = new ReleaseFetcher({ verbose: true });
138
+ const tagInfo = await fetcher.getLatestReleaseTag(gitUrl, options.gitRef);
139
+ if (tagInfo.found) {
140
+ lastestTag = tagInfo.latestTag;
141
+ } else if (tagInfo.allTags.length > 0) {
142
+ lastestTag = tagInfo.allTags[0];
143
+ }
147
144
  }
148
145
 
149
146
  let commandGit = `git clone ${gitUrl} ${pluginDir}`;
@@ -49,7 +49,6 @@ class ReleaseFetcher {
49
49
  stdio: 'pipe',
50
50
  timeout: 5000
51
51
  });
52
- this.log('Git is available');
53
52
  } catch (error) {
54
53
  throw new Error(`Git is not installed: ${error.message}`);
55
54
  }
@@ -177,6 +176,8 @@ class ReleaseFetcher {
177
176
  throw new Error(`Failed to fetch branches: ${error.message}`);
178
177
  }
179
178
  }
179
+
180
+
180
181
 
181
182
  /**
182
183
  * 获取所有发行版标签(按语义化版本排序)
@@ -266,6 +267,46 @@ class ReleaseFetcher {
266
267
  repoUrl:repoUrl
267
268
  };
268
269
  }
270
+
271
+ /**
272
+ * 获取NPM包版本 - 如果指定版本存在则返回该版本,否则返回最新版本
273
+ * @param {string} packageName - NPM包名
274
+ * @param {string} version - 期望的版本号
275
+ * @returns {string} 最终版本号
276
+ */
277
+ getNpmVersion(packageName, version) {
278
+ try {
279
+ // 如果是 latest,直接返回最新版本
280
+ if (version === 'latest') {
281
+ return execSync(`npm view ${packageName} dist-tags.latest`, {
282
+ encoding: 'utf-8'
283
+ }).trim();
284
+ }
285
+
286
+ // 检查指定版本是否存在
287
+ if (version != "" && version != null && version != undefined) {
288
+ try {
289
+ const result = execSync(`npm view ${packageName}@${version} version`, {
290
+ encoding: 'utf-8'
291
+ }).trim();
292
+
293
+ if (result === version) {
294
+ return version;
295
+ }
296
+ } catch (e) {
297
+ this.log("Install the latest version");
298
+ }
299
+ }
300
+
301
+ // 返回最新版本
302
+ return execSync(`npm view ${packageName} dist-tags.latest`, {
303
+ encoding: 'utf-8'
304
+ }).trim();
305
+
306
+ } catch (error) {
307
+ throw new Error(`获取版本失败: ${error.message}`);
308
+ }
309
+ }
269
310
 
270
311
  /**
271
312
  * 根据版本范围过滤标签