| 5 | return { |
| 6 | pluginId: 'reactNativeUpdatePlugin', |
| 7 | apply() { |
| 8 | const cwd = process.cwd(); |
| 9 | const metaFilePath = path.resolve( |
| 10 | cwd, |
| 11 | 'entry/src/main/resources/rawfile/meta.json', |
| 12 | ); |
| 13 | fs.mkdirSync(path.dirname(metaFilePath), { recursive: true }); |
| 14 | |
| 15 | const moduleJsonPath = path.resolve(cwd, 'AppScope/app.json5'); |
| 16 | let versionName = ''; |
| 17 | if (fs.existsSync(moduleJsonPath)) { |
| 18 | const content = fs.readFileSync(moduleJsonPath, 'utf-8'); |
| 19 | const match = content.match( |
| 20 | /(?:"versionName"|versionName):\s*["']([^"']+)["']/, |
| 21 | ); |
| 22 | versionName = match?.[1] || ''; |
| 23 | } |
| 24 | |
| 25 | const metaContent = { |
| 26 | pushy_build_time: String(Date.now()), |
| 27 | versionName, |
| 28 | }; |
| 29 | |
| 30 | fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 2)); |
| 31 | console.log(`Build time written to ${metaFilePath}`); |
| 32 | }, |
| 33 | }; |
| 34 | } |