diff --git a/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts b/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts index da601f2..8ab866b 100644 --- a/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts +++ b/Example/harmony_use_pushy/harmony/entry/hvigorfile.ts @@ -1,44 +1,9 @@ -import { hapTasks } from '@ohos/hvigor-ohos-plugin'; -import fs from 'fs'; -import path from 'path'; - -export function generatePushyBuildTime(str?: string) { - return { - pluginId: 'PushyBuildTimePlugin', - apply(pluginContext) { - pluginContext.registerTask({ - name: 'pushy_build_time', - run: (taskContext) => { - const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json'); - const dirPath = path.dirname(metaFilePath); - if (!fs.existsSync(dirPath)) { - fs.mkdirSync(dirPath, { recursive: true }); - } - const moduleJsonPath = path.resolve(__dirname, '../AppScope/app.json5'); - let versionName = ''; - if (fs.existsSync(moduleJsonPath)) { - const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8'); - const versionMatch = moduleContent.match(/"versionName":\s*"([^"]+)"/); - if (versionMatch && versionMatch[1]) { - versionName = versionMatch[1]; - } - } - const buildTime = new Date().toISOString(); - const metaContent = { - pushy_build_time: buildTime, - versionName: versionName - }; - fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4)); - console.log(`Build time written to ${metaFilePath}`); - }, - dependencies: [], - postDependencies: ['default@BuildJS'] - }) - } - } -} +import {hapTasks} from '@ohos/hvigor-ohos-plugin'; +import {reactNativeUpdatePlugin} from 'pushy/hvigor-plugin'; export default { - system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */ -} \ No newline at end of file + system: hapTasks /* Built-in plugin of Hvigor. It cannot be modified. */, + plugins: [ + reactNativeUpdatePlugin(), + ] /* Custom plugin to extend the functionality of Hvigor. */, +}; diff --git a/Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5 b/Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5 index 06b2783..f643787 100644 --- a/Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5 +++ b/Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5 @@ -1,6 +1,7 @@ { "modelVersion": "5.0.0", "dependencies": { + pushy: 'file:../../node_modules/react-native-update/harmony/pushy' }, "execution": { // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ diff --git a/Example/harmony_use_pushy/package.json b/Example/harmony_use_pushy/package.json index 86af81f..1fce1d5 100644 --- a/Example/harmony_use_pushy/package.json +++ b/Example/harmony_use_pushy/package.json @@ -8,7 +8,7 @@ "lint": "eslint .", "start": "npm run codegen && hdc rport tcp:8081 tcp:8081 && react-native start", "codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/react_native_openharmony", - "build": "pushy bundle --platform harmony", + "build": "pushy bundle --platform harmony --no-interactive", "test": "jest", "hdiffFromPPK": "pushy hdiffFromPPK .pushy/output/harmony.1735052610653.ppk .pushy/output/harmony.1735052678646.ppk .pushy/output/hdiff.ppk-patch", "hdiffFromApp": "pushy hdiffFromApp .pushy/output/version-1.0.0.app .pushy/output/harmony.1735052610653.ppk .pushy/output/hdiff.app-patch", diff --git a/harmony/pushy/hvigor-plugin.ts b/harmony/pushy/hvigor-plugin.ts new file mode 100644 index 0000000..b298823 --- /dev/null +++ b/harmony/pushy/hvigor-plugin.ts @@ -0,0 +1,41 @@ +import fs from 'fs'; +import path from 'path'; + +export function reactNativeUpdatePlugin() { + return { + pluginId: 'reactNativeUpdatePlugin', + apply(node) { + node.registerTask({ + name: 'reactNativeUpdatePlugin', + run: () => { + const cwd = process.cwd(); + const metaFilePath = path.resolve( + cwd, + 'entry/src/main/resources/rawfile/meta.json', + ); + fs.mkdirSync(path.dirname(metaFilePath), { recursive: true }); + + const moduleJsonPath = path.resolve(cwd, 'AppScope/app.json5'); + let versionName = ''; + if (fs.existsSync(moduleJsonPath)) { + const content = fs.readFileSync(moduleJsonPath, 'utf-8'); + const match = content.match( + /(?:"versionName"|versionName):\s*["']([^"']+)["']/, + ); + versionName = match?.[1] || ''; + } + + const metaContent = { + pushy_build_time: new Date().toISOString(), + versionName, + }; + + fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4)); + console.log(`Build time written to ${metaFilePath}`); + }, + dependencies: [], + postDependencies: ['default@BuildJS'], + }); + }, + }; +} diff --git a/package.json b/package.json index 9d36ec9..f4b0f4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update", - "version": "10.35.2", + "version": "10.35.3", "description": "react-native hot update", "main": "src/index", "scripts": {