Skip to content

Commit e0201d3

Browse files
committed
fix hvigor plugin
1 parent ba5b358 commit e0201d3

File tree

5 files changed

+51
-44
lines changed

5 files changed

+51
-44
lines changed
Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,9 @@
1-
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
2-
import fs from 'fs';
3-
import path from 'path';
4-
5-
export function generatePushyBuildTime(str?: string) {
6-
return {
7-
pluginId: 'PushyBuildTimePlugin',
8-
apply(pluginContext) {
9-
pluginContext.registerTask({
10-
name: 'pushy_build_time',
11-
run: (taskContext) => {
12-
const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json');
13-
const dirPath = path.dirname(metaFilePath);
14-
if (!fs.existsSync(dirPath)) {
15-
fs.mkdirSync(dirPath, { recursive: true });
16-
}
17-
const moduleJsonPath = path.resolve(__dirname, '../AppScope/app.json5');
18-
let versionName = '';
19-
if (fs.existsSync(moduleJsonPath)) {
20-
const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8');
21-
const versionMatch = moduleContent.match(/"versionName":\s*"([^"]+)"/);
22-
if (versionMatch && versionMatch[1]) {
23-
versionName = versionMatch[1];
24-
}
25-
}
26-
const buildTime = new Date().toISOString();
27-
const metaContent = {
28-
pushy_build_time: buildTime,
29-
versionName: versionName
30-
};
31-
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
32-
console.log(`Build time written to ${metaFilePath}`);
33-
},
34-
dependencies: [],
35-
postDependencies: ['default@BuildJS']
36-
})
37-
}
38-
}
39-
}
1+
import {hapTasks} from '@ohos/hvigor-ohos-plugin';
2+
import {reactNativeUpdatePlugin} from 'pushy/hvigor-plugin';
403

414
export default {
42-
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
43-
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
44-
}
5+
system: hapTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
6+
plugins: [
7+
reactNativeUpdatePlugin(),
8+
] /* Custom plugin to extend the functionality of Hvigor. */,
9+
};

Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"modelVersion": "5.0.0",
33
"dependencies": {
4+
pushy: 'file:../../node_modules/react-native-update/harmony/pushy'
45
},
56
"execution": {
67
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */

Example/harmony_use_pushy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"lint": "eslint .",
99
"start": "npm run codegen && hdc rport tcp:8081 tcp:8081 && react-native start",
1010
"codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/react_native_openharmony",
11-
"build": "pushy bundle --platform harmony",
11+
"build": "pushy bundle --platform harmony --no-interactive",
1212
"test": "jest",
1313
"hdiffFromPPK": "pushy hdiffFromPPK .pushy/output/harmony.1735052610653.ppk .pushy/output/harmony.1735052678646.ppk .pushy/output/hdiff.ppk-patch",
1414
"hdiffFromApp": "pushy hdiffFromApp .pushy/output/version-1.0.0.app .pushy/output/harmony.1735052610653.ppk .pushy/output/hdiff.app-patch",

harmony/pushy/hvigor-plugin.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
export function reactNativeUpdatePlugin() {
5+
return {
6+
pluginId: 'reactNativeUpdatePlugin',
7+
apply(node) {
8+
node.registerTask({
9+
name: 'reactNativeUpdatePlugin',
10+
run: () => {
11+
const cwd = process.cwd();
12+
const metaFilePath = path.resolve(
13+
cwd,
14+
'entry/src/main/resources/rawfile/meta.json',
15+
);
16+
fs.mkdirSync(path.dirname(metaFilePath), { recursive: true });
17+
18+
const moduleJsonPath = path.resolve(cwd, 'AppScope/app.json5');
19+
let versionName = '';
20+
if (fs.existsSync(moduleJsonPath)) {
21+
const content = fs.readFileSync(moduleJsonPath, 'utf-8');
22+
const match = content.match(
23+
/(?:"versionName"|versionName):\s*["']([^"']+)["']/,
24+
);
25+
versionName = match?.[1] || '';
26+
}
27+
28+
const metaContent = {
29+
pushy_build_time: new Date().toISOString(),
30+
versionName,
31+
};
32+
33+
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
34+
console.log(`Build time written to ${metaFilePath}`);
35+
},
36+
dependencies: [],
37+
postDependencies: ['default@BuildJS'],
38+
});
39+
},
40+
};
41+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update",
3-
"version": "10.35.2",
3+
"version": "10.35.3",
44
"description": "react-native hot update",
55
"main": "src/index",
66
"scripts": {

0 commit comments

Comments
 (0)