hcordova 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.
Files changed (55) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +346 -0
  3. package/bin/hcordova +27 -0
  4. package/package.json +39 -0
  5. package/src/base-cli.js +1181 -0
  6. package/src/utils/DependencyChecker.js +382 -0
  7. package/src/utils/PlatformProject.js +452 -0
  8. package/src/utils/PluginConfigParser.js +408 -0
  9. package/src/utils/PluginDownloader.js +181 -0
  10. package/src/utils/PluginHandler.js +1097 -0
  11. package/src/utils/VariableValidator.js +369 -0
  12. package/src/utils/args-processor.js +79 -0
  13. package/templates/project/AppScope/app.json5 +10 -0
  14. package/templates/project/AppScope/resources/base/element/string.json +8 -0
  15. package/templates/project/AppScope/resources/base/media/background.png +0 -0
  16. package/templates/project/AppScope/resources/base/media/foreground.png +0 -0
  17. package/templates/project/AppScope/resources/base/media/layered_image.json +7 -0
  18. package/templates/project/build-profile.json5 +46 -0
  19. package/templates/project/code-linter.json5 +32 -0
  20. package/templates/project/entry/build-profile.json5 +28 -0
  21. package/templates/project/entry/hvigorfile.ts +6 -0
  22. package/templates/project/entry/obfuscation-rules.txt +23 -0
  23. package/templates/project/entry/oh-package.json5 +12 -0
  24. package/templates/project/entry/src/main/ets/entryability/EntryAbility.ets +62 -0
  25. package/templates/project/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +32 -0
  26. package/templates/project/entry/src/main/ets/pages/Index.ets +40 -0
  27. package/templates/project/entry/src/main/module.json5 +52 -0
  28. package/templates/project/entry/src/main/resources/base/element/color.json +8 -0
  29. package/templates/project/entry/src/main/resources/base/element/float.json +8 -0
  30. package/templates/project/entry/src/main/resources/base/element/string.json +16 -0
  31. package/templates/project/entry/src/main/resources/base/media/background.png +0 -0
  32. package/templates/project/entry/src/main/resources/base/media/foreground.png +0 -0
  33. package/templates/project/entry/src/main/resources/base/media/layered_image.json +7 -0
  34. package/templates/project/entry/src/main/resources/base/media/startIcon.png +0 -0
  35. package/templates/project/entry/src/main/resources/base/profile/backup_config.json +3 -0
  36. package/templates/project/entry/src/main/resources/base/profile/main_pages.json +5 -0
  37. package/templates/project/entry/src/main/resources/dark/element/color.json +8 -0
  38. package/templates/project/entry/src/main/resources/rawfile/config.xml +26 -0
  39. package/templates/project/entry/src/main/resources/rawfile/www/cordova.js +1925 -0
  40. package/templates/project/entry/src/main/resources/rawfile/www/css/index.css +158 -0
  41. package/templates/project/entry/src/main/resources/rawfile/www/img/cordova.png +0 -0
  42. package/templates/project/entry/src/main/resources/rawfile/www/img/logo.png +0 -0
  43. package/templates/project/entry/src/main/resources/rawfile/www/index.html +110 -0
  44. package/templates/project/entry/src/main/resources/rawfile/www/js/index.js +68 -0
  45. package/templates/project/entry/src/mock/mock-config.json5 +2 -0
  46. package/templates/project/entry/src/ohosTest/ets/test/Ability.test.ets +35 -0
  47. package/templates/project/entry/src/ohosTest/ets/test/List.test.ets +5 -0
  48. package/templates/project/entry/src/ohosTest/module.json5 +13 -0
  49. package/templates/project/entry/src/test/List.test.ets +5 -0
  50. package/templates/project/entry/src/test/LocalUnit.test.ets +33 -0
  51. package/templates/project/hvigor/hvigor-config.json5 +22 -0
  52. package/templates/project/hvigorfile.ts +6 -0
  53. package/templates/project/local.properties +9 -0
  54. package/templates/project/oh-package-lock.json5 +27 -0
  55. package/templates/project/oh-package.json5 +10 -0
@@ -0,0 +1,158 @@
1
+
2
+ /*
3
+ * Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /* 基础样式 */
19
+ * {
20
+ margin: 0;
21
+ padding: 0;
22
+ box-sizing: border-box;
23
+ }
24
+
25
+ body {
26
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
27
+ line-height: 1.6;
28
+ color: #333;
29
+ background-color: #f5f7fa;
30
+ }
31
+
32
+ /* 头部样式 */
33
+ header {
34
+ background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
35
+ color: white;
36
+ text-align: center;
37
+ padding: 2rem 1rem;
38
+ margin-bottom: 2rem;
39
+ }
40
+
41
+ header h1 {
42
+ font-size: 2.5rem;
43
+ margin-bottom: 0.5rem;
44
+ }
45
+
46
+ header p {
47
+ font-size: 1.2rem;
48
+ opacity: 0.9;
49
+ }
50
+
51
+ /* 主内容区域 */
52
+ main {
53
+ max-width: 1200px;
54
+ margin: 0 auto;
55
+ padding: 0 1rem;
56
+ }
57
+
58
+ section {
59
+ margin-bottom: 2rem;
60
+ }
61
+
62
+ section h2 {
63
+ font-size: 1.8rem;
64
+ color: #2c3e50;
65
+ margin-bottom: 1rem;
66
+ padding-bottom: 0.5rem;
67
+ border-bottom: 2px solid #3498db;
68
+ }
69
+
70
+ /* 卡片样式 */
71
+ .card {
72
+ background: white;
73
+ border-radius: 8px;
74
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
75
+ padding: 1.5rem;
76
+ transition: transform 0.3s ease, box-shadow 0.3s ease;
77
+ }
78
+
79
+ .card:hover {
80
+ transform: translateY(-5px);
81
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
82
+ }
83
+
84
+ .card h3 {
85
+ color: #2980b9;
86
+ margin: 1rem 0 0.5rem;
87
+ }
88
+
89
+ .card h3:first-child {
90
+ margin-top: 0;
91
+ }
92
+
93
+ .card p {
94
+ margin-bottom: 1rem;
95
+ }
96
+
97
+ /* 代码块样式 */
98
+ pre {
99
+ background: #2d3a4b;
100
+ color: #e2e8f0;
101
+ padding: 1rem;
102
+ border-radius: 4px;
103
+ overflow-x: auto;
104
+ margin: 1rem 0;
105
+ font-family: 'Courier New', Courier, monospace;
106
+ }
107
+
108
+ code {
109
+ background: #f1f5f9;
110
+ padding: 0.2rem 0.4rem;
111
+ border-radius: 3px;
112
+ font-family: 'Courier New', Courier, monospace;
113
+ color: #2d3748;
114
+ }
115
+
116
+ pre code {
117
+ background: none;
118
+ padding: 0;
119
+ color: inherit;
120
+ }
121
+
122
+ /* 列表样式 */
123
+ ul {
124
+ padding-left: 1.5rem;
125
+ margin: 1rem 0;
126
+ }
127
+
128
+ li {
129
+ margin-bottom: 0.5rem;
130
+ }
131
+
132
+ /* 页脚样式 */
133
+ footer {
134
+ background: #2c3e50;
135
+ color: white;
136
+ text-align: center;
137
+ padding: 1.5rem;
138
+ margin-top: 2rem;
139
+ }
140
+
141
+ /* 响应式设计 */
142
+ @media (max-width: 768px) {
143
+ header h1 {
144
+ font-size: 2rem;
145
+ }
146
+
147
+ header p {
148
+ font-size: 1rem;
149
+ }
150
+
151
+ section h2 {
152
+ font-size: 1.5rem;
153
+ }
154
+
155
+ .card {
156
+ padding: 1rem;
157
+ }
158
+ }
@@ -0,0 +1,110 @@
1
+ <!--
2
+
3
+ Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ -->
17
+
18
+ <!DOCTYPE html>
19
+ <html lang="zh-CN">
20
+ <head>
21
+ <meta charset="UTF-8">
22
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
23
+ <title>Harmony Cordova使用指南</title>
24
+ <link rel="stylesheet" href="css/index.css">
25
+ </head>
26
+ <body>
27
+ <header>
28
+ <h1>Harmony Cordova使用指南</h1>
29
+ <p>使用Harmony Cordova将Web应用转换为移动应用</p>
30
+ </header>
31
+
32
+ <main>
33
+ <section id="intro">
34
+ <h2>什么是Cordova?</h2>
35
+ <div class="card">
36
+ <p>Apache Cordova是一个开源的移动开发框架,允许您使用标准的Web技术(HTML5, CSS3和JavaScript)进行跨平台开发。</p>
37
+ <p>使用Harmony Cordova,您可以构建一个鸿蒙应用程序。</p>
38
+ </div>
39
+ </section>
40
+
41
+ <section id="installation">
42
+ <h2>安装与设置</h2>
43
+ <div class="card">
44
+ <h3>安装Node.js</h3>
45
+ <p>首先需要安装Node.js,因为Cordova是基于Node.js构建的。</p>
46
+
47
+ <h3>安装Cordova CLI</h3>
48
+ <p>使用npm安装Cordova命令行工具:</p>
49
+ <pre><code>npm install -g hcordova</code></pre>
50
+
51
+ <h3>创建新项目</h3>
52
+ <p>使用以下命令创建新的Cordova项目:</p>
53
+ <pre><code>hcordova create MyApp com.example.myapp MyApp</code></pre>
54
+ </div>
55
+ </section>
56
+
57
+ <section id="platforms">
58
+ <h2>添加平台</h2>
59
+ <div class="card">
60
+ <p>进入项目目录并添加目标平台:</p>
61
+ <pre><code>cd MyApp
62
+ hcordova platform add harmonyos
63
+ hcordova platform add android</code></pre>
64
+ <p>您可以根据需要添加其他平台。</p>
65
+ </div>
66
+ </section>
67
+
68
+ <section id="plugins">
69
+ <h2>使用插件</h2>
70
+ <div class="card">
71
+ <p>Cordova插件提供了访问设备原生功能的API:</p>
72
+ <pre><code>hcordova plugin add cordova-plugin-camera
73
+ hcordova plugin add cordova-plugin-geolocation</code></pre>
74
+ <p>在JavaScript代码中使用插件:</p>
75
+ <pre><code>navigator.camera.getPicture(onSuccess, onFail, {
76
+ quality: 50,
77
+ destinationType: Camera.DestinationType.DATA_URL
78
+ });</code></pre>
79
+ </div>
80
+ </section>
81
+
82
+ <section id="advantages">
83
+ <h2>优势与局限</h2>
84
+ <div class="card">
85
+ <h3>优势</h3>
86
+ <ul>
87
+ <li>跨平台开发,节省时间和成本</li>
88
+ <li>使用熟悉的Web技术</li>
89
+ <li>丰富的插件生态系统</li>
90
+ <li>易于维护和更新</li>
91
+ </ul>
92
+
93
+ <h3>局限</h3>
94
+ <ul>
95
+ <li>性能可能不如原生应用</li>
96
+ <li>访问某些设备功能可能受限</li>
97
+ <li>应用商店审核可能更严格</li>
98
+ </ul>
99
+ </div>
100
+ </section>
101
+ </main>
102
+
103
+ <footer>
104
+ <p>&copy; 2025 Cordova指南 | 使用Web技术构建移动应用</p>
105
+ </footer>
106
+
107
+ <script type="text/javascript" src="js/index.js"></script>
108
+ <script type="text/javascript" src="cordova.js"></script>
109
+ </body>
110
+ </html>
@@ -0,0 +1,68 @@
1
+ // 页面加载完成后执行
2
+ document.addEventListener('DOMContentLoaded', function() {
3
+ // 为所有卡片添加点击效果
4
+ const cards = document.querySelectorAll('.card');
5
+
6
+ cards.forEach(card => {
7
+ card.addEventListener('click', function() {
8
+ this.style.backgroundColor = '#f8f9fa';
9
+ setTimeout(() => {
10
+ this.style.backgroundColor = '';
11
+ }, 300);
12
+ });
13
+ });
14
+
15
+ // 为代码块添加复制功能
16
+ const codeBlocks = document.querySelectorAll('pre');
17
+
18
+ codeBlocks.forEach(block => {
19
+ block.addEventListener('click', function() {
20
+ const text = this.innerText;
21
+ copyToClipboard(text);
22
+ showCopyNotification();
23
+ });
24
+ });
25
+
26
+ // 复制文本到剪贴板
27
+ function copyToClipboard(text) {
28
+ const textarea = document.createElement('textarea');
29
+ textarea.value = text;
30
+ document.body.appendChild(textarea);
31
+ textarea.select();
32
+ document.execCommand('copy');
33
+ document.body.removeChild(textarea);
34
+ }
35
+
36
+ // 显示复制成功通知
37
+ function showCopyNotification() {
38
+ const notification = document.createElement('div');
39
+ notification.textContent = '代码已复制到剪贴板!';
40
+ notification.style.cssText = `
41
+ position: fixed;
42
+ top: 20px;
43
+ right: 20px;
44
+ background: #4CAF50;
45
+ color: white;
46
+ padding: 10px 15px;
47
+ border-radius: 4px;
48
+ z-index: 1000;
49
+ box-shadow: 0 2px 5px rgba(0,0,0,0.2);
50
+ `;
51
+
52
+ document.body.appendChild(notification);
53
+
54
+ setTimeout(() => {
55
+ document.body.removeChild(notification);
56
+ }, 2000);
57
+ }
58
+
59
+ // 添加滚动效果
60
+ window.addEventListener('scroll', function() {
61
+ const header = document.querySelector('header');
62
+ if (window.scrollY > 50) {
63
+ header.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
64
+ } else {
65
+ header.style.boxShadow = 'none';
66
+ }
67
+ });
68
+ });
@@ -0,0 +1,35 @@
1
+ import { hilog } from '@kit.PerformanceAnalysisKit';
2
+ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
3
+
4
+ export default function abilityTest() {
5
+ describe('ActsAbilityTest', () => {
6
+ // Defines a test suite. Two parameters are supported: test suite name and test suite function.
7
+ beforeAll(() => {
8
+ // Presets an action, which is performed only once before all test cases of the test suite start.
9
+ // This API supports only one parameter: preset action function.
10
+ })
11
+ beforeEach(() => {
12
+ // Presets an action, which is performed before each unit test case starts.
13
+ // The number of execution times is the same as the number of test cases defined by **it**.
14
+ // This API supports only one parameter: preset action function.
15
+ })
16
+ afterEach(() => {
17
+ // Presets a clear action, which is performed after each unit test case ends.
18
+ // The number of execution times is the same as the number of test cases defined by **it**.
19
+ // This API supports only one parameter: clear action function.
20
+ })
21
+ afterAll(() => {
22
+ // Presets a clear action, which is performed after all test cases of the test suite end.
23
+ // This API supports only one parameter: clear action function.
24
+ })
25
+ it('assertContain', 0, () => {
26
+ // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
27
+ hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
28
+ let a = 'abc';
29
+ let b = 'b';
30
+ // Defines a variety of assertion methods, which are used to declare expected boolean conditions.
31
+ expect(a).assertContain(b);
32
+ expect(a).assertEqual(a);
33
+ })
34
+ })
35
+ }
@@ -0,0 +1,5 @@
1
+ import abilityTest from './Ability.test';
2
+
3
+ export default function testsuite() {
4
+ abilityTest();
5
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "module": {
3
+ "name": "entry_test",
4
+ "type": "feature",
5
+ "deviceTypes": [
6
+ "phone",
7
+ "tablet",
8
+ "2in1"
9
+ ],
10
+ "deliveryWithInstall": true,
11
+ "installationFree": false
12
+ }
13
+ }
@@ -0,0 +1,5 @@
1
+ import localUnitTest from './LocalUnit.test';
2
+
3
+ export default function testsuite() {
4
+ localUnitTest();
5
+ }
@@ -0,0 +1,33 @@
1
+ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
2
+
3
+ export default function localUnitTest() {
4
+ describe('localUnitTest', () => {
5
+ // Defines a test suite. Two parameters are supported: test suite name and test suite function.
6
+ beforeAll(() => {
7
+ // Presets an action, which is performed only once before all test cases of the test suite start.
8
+ // This API supports only one parameter: preset action function.
9
+ });
10
+ beforeEach(() => {
11
+ // Presets an action, which is performed before each unit test case starts.
12
+ // The number of execution times is the same as the number of test cases defined by **it**.
13
+ // This API supports only one parameter: preset action function.
14
+ });
15
+ afterEach(() => {
16
+ // Presets a clear action, which is performed after each unit test case ends.
17
+ // The number of execution times is the same as the number of test cases defined by **it**.
18
+ // This API supports only one parameter: clear action function.
19
+ });
20
+ afterAll(() => {
21
+ // Presets a clear action, which is performed after all test cases of the test suite end.
22
+ // This API supports only one parameter: clear action function.
23
+ });
24
+ it('assertContain', 0, () => {
25
+ // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
26
+ let a = 'abc';
27
+ let b = 'b';
28
+ // Defines a variety of assertion methods, which are used to declare expected boolean conditions.
29
+ expect(a).assertContain(b);
30
+ expect(a).assertEqual(a);
31
+ });
32
+ });
33
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "modelVersion": "5.0.5",
3
+ "dependencies": {
4
+ },
5
+ "execution": {
6
+ // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
7
+ // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
8
+ // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
9
+ // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
10
+ // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
11
+ },
12
+ "logging": {
13
+ // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
14
+ },
15
+ "debugging": {
16
+ // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
17
+ },
18
+ "nodeOptions": {
19
+ // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
20
+ // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
21
+ }
22
+ }
@@ -0,0 +1,6 @@
1
+ import { appTasks } from '@ohos/hvigor-ohos-plugin';
2
+
3
+ export default {
4
+ system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
6
+ }
@@ -0,0 +1,9 @@
1
+ # This file is automatically generated by DevEco Studio.
2
+ # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3
+ #
4
+ # This file should *NOT* be checked into Version Control Systems,
5
+ # as it contains information specific to your local configuration.
6
+ #
7
+ # For customization when using a Version Control System, please read the header note.
8
+
9
+
@@ -0,0 +1,27 @@
1
+ {
2
+ "meta": {
3
+ "stableOrder": true
4
+ },
5
+ "lockfileVersion": 3,
6
+ "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
7
+ "specifiers": {
8
+ "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0",
9
+ "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21"
10
+ },
11
+ "packages": {
12
+ "@ohos/hamock@1.0.0": {
13
+ "name": "@ohos/hamock",
14
+ "version": "1.0.0",
15
+ "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==",
16
+ "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har",
17
+ "registryType": "ohpm"
18
+ },
19
+ "@ohos/hypium@1.0.21": {
20
+ "name": "@ohos/hypium",
21
+ "version": "1.0.21",
22
+ "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==",
23
+ "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.21.har",
24
+ "registryType": "ohpm"
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "modelVersion": "5.0.5",
3
+ "description": "Please describe the basic information.",
4
+ "dependencies": {
5
+ },
6
+ "devDependencies": {
7
+ "@ohos/hypium": "1.0.21",
8
+ "@ohos/hamock": "1.0.0"
9
+ }
10
+ }