|
1 | 1 | // @ts-check |
2 | 2 |
|
3 | | -const { releaseVersionGenerator } = require('@nx/js/src/generators/release-version/release-version'); |
| 3 | +const {REPO_ROOT} = require('../../scripts/consts'); |
| 4 | +const JsVersionActions = require('@nx/js/src/release/version-actions').default; |
4 | 5 | const fs = require('node:fs'); |
5 | 6 | const path = require('node:path'); |
6 | | -const { REPO_ROOT } = require('../../scripts/consts'); |
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * @returns {Promise<string[]>} |
10 | 10 | */ |
11 | 11 | async function runSetVersion() { |
12 | | - const rnmPkgJson = require.resolve('react-native-macos/package.json'); |
13 | | - const { updateReactNativeArtifacts } = require('../../scripts/releases/set-rn-artifacts-version'); |
| 12 | + const rnmPkgJsonPath = path.join(REPO_ROOT, 'packages', 'react-native', 'package.json'); |
| 13 | + const {updateReactNativeArtifacts} = require('../../scripts/releases/set-rn-artifacts-version'); |
14 | 14 |
|
15 | | - const manifest = fs.readFileSync(rnmPkgJson, { encoding: 'utf-8' }); |
16 | | - const { version } = JSON.parse(manifest); |
| 15 | + const manifest = fs.readFileSync(rnmPkgJsonPath, {encoding: 'utf-8'}); |
| 16 | + const {version} = JSON.parse(manifest); |
17 | 17 |
|
18 | 18 | await updateReactNativeArtifacts(version); |
19 | 19 |
|
@@ -66,23 +66,59 @@ async function runSetVersion() { |
66 | 66 | ]; |
67 | 67 | } |
68 | 68 |
|
69 | | -/** @type {typeof releaseVersionGenerator} */ |
70 | | -module.exports = async function(tree, options) { |
71 | | - const { data, callback } = await releaseVersionGenerator(tree, options); |
72 | | - return { |
73 | | - data, |
74 | | - callback: async (tree, options) => { |
75 | | - const result = await callback(tree, options); |
| 69 | +/** |
| 70 | + * Custom Version Actions for React Native macOS |
| 71 | + * Extends the built-in JsVersionActions to add React Native artifact updates |
| 72 | + */ |
| 73 | +class ReactNativeMacOSVersionActions extends JsVersionActions { |
| 74 | + /** |
| 75 | + * @override |
| 76 | + * Override updateProjectVersion to include React Native artifact updates |
| 77 | + * @param {import('@nx/devkit').Tree} tree |
| 78 | + * @param {string} newVersion |
| 79 | + * @returns {Promise<string[]>} |
| 80 | + */ |
| 81 | + async updateProjectVersion(tree, newVersion) { |
| 82 | + // First, run the standard JS version update (package.json, etc.) |
| 83 | + const standardLogMessages = await super.updateProjectVersion(tree, newVersion); |
76 | 84 |
|
77 | | - // Only update artifacts if there were changes |
78 | | - const changedFiles = Array.isArray(result) ? result : result.changedFiles; |
79 | | - if (changedFiles.length > 0) { |
80 | | - fs.writeFile(path.join(REPO_ROOT, '.rnm-publish'), '', () => null); |
| 85 | + // Only update React Native artifacts for the react-native-macos project |
| 86 | + if (this.projectGraphNode.name === 'react-native-macos') { |
| 87 | + try { |
| 88 | + // Create the .rnm-publish file to indicate versioning has occurred |
| 89 | + fs.writeFileSync(path.join(REPO_ROOT, '.rnm-publish'), ''); |
| 90 | + |
| 91 | + // Update React Native artifacts |
81 | 92 | const versionedFiles = await runSetVersion(); |
82 | | - changedFiles.push(...versionedFiles); |
| 93 | + |
| 94 | + // Add the versioned files to the tree so they are tracked by Nx |
| 95 | + for (const filePath of versionedFiles) { |
| 96 | + if (fs.existsSync(filePath)) { |
| 97 | + const content = fs.readFileSync(filePath, 'utf-8'); |
| 98 | + const relativePath = path.relative(REPO_ROOT, filePath); |
| 99 | + tree.write(relativePath, content); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + return [ |
| 104 | + ...standardLogMessages, |
| 105 | + `✅ Updated React Native platform artifacts for version ${newVersion}`, |
| 106 | + `📁 Updated ${versionedFiles.length} platform-specific files`, |
| 107 | + '🏷️ Created .rnm-publish marker file', |
| 108 | + ]; |
| 109 | + } catch (error) { |
| 110 | + console.error('Failed to update React Native artifacts:', error); |
| 111 | + const errorMessage = error instanceof Error ? error.message : String(error); |
| 112 | + return [ |
| 113 | + ...standardLogMessages, |
| 114 | + `❌ Failed to update React Native artifacts: ${errorMessage}`, |
| 115 | + ]; |
83 | 116 | } |
| 117 | + } |
| 118 | + |
| 119 | + return standardLogMessages; |
| 120 | + } |
| 121 | +} |
84 | 122 |
|
85 | | - return result; |
86 | | - }, |
87 | | - }; |
88 | | -}; |
| 123 | +module.exports = ReactNativeMacOSVersionActions; |
| 124 | +module.exports.default = ReactNativeMacOSVersionActions; |
0 commit comments