@@ -8,10 +8,11 @@ const NX_CONFIG_FILE = "nx.json";
8
8
9
9
const NPM_TAG_NEXT = "next" ;
10
10
const NPM_TAG_NIGHTLY = "nightly" ;
11
+ const RNMACOS_LATEST = "react-native-macos@latest" ;
11
12
12
13
/**
13
14
* @typedef {typeof import("../../nx.json") } NxConfig
14
- * @typedef {{ tag?: string; update?: boolean; } } Options
15
+ * @typedef {{ tag?: string; update?: boolean; verbose?: boolean; } } Options
15
16
*/
16
17
17
18
/**
@@ -33,6 +34,14 @@ function error(message) {
33
34
console . error ( "❌" , message ) ;
34
35
}
35
36
37
+ /**
38
+ * Logs an informational message to the console.
39
+ * @param {string } message
40
+ */
41
+ function info ( message ) {
42
+ console . log ( "ℹ️" , message ) ;
43
+ }
44
+
36
45
/**
37
46
* Returns whether the given branch is considered main branch.
38
47
* @param {string } branch
@@ -94,7 +103,7 @@ function getCurrentBranch() {
94
103
* @returns {number }
95
104
*/
96
105
function getLatestVersion ( ) {
97
- const { stdout } = spawnSync ( "npm" , [ "view" , "react-native-macos@latest" , "version" ] ) ;
106
+ const { stdout } = spawnSync ( "npm" , [ "view" , RNMACOS_LATEST , "version" ] ) ;
98
107
return versionToNumber ( stdout . toString ( ) . trim ( ) ) ;
99
108
}
100
109
@@ -108,35 +117,62 @@ function getLatestVersion() {
108
117
*
109
118
* @param {string } branch
110
119
* @param {Options } options
120
+ * @param {typeof info } log
111
121
* @returns {{ npmTag: string; prerelease?: string; } }
112
122
*/
113
- function getTagForStableBranch ( branch , { tag } ) {
123
+ function getTagForStableBranch ( branch , { tag } , log ) {
114
124
if ( ! isStableBranch ( branch ) ) {
115
125
throw new Error ( "Expected a stable branch" ) ;
116
126
}
117
127
118
128
const latestVersion = getLatestVersion ( ) ;
119
129
const currentVersion = versionToNumber ( branch ) ;
120
130
131
+ log ( `${ RNMACOS_LATEST } : ${ latestVersion } ` ) ;
132
+ log ( `Current version: ${ currentVersion } ` ) ;
133
+
121
134
// Patching latest version
122
135
if ( currentVersion === latestVersion ) {
123
- return { npmTag : "latest" } ;
136
+ const npmTag = "latest" ;
137
+ log ( `Expected npm tag: ${ npmTag } ` ) ;
138
+ return { npmTag } ;
124
139
}
125
140
126
141
// Patching an older stable version
127
142
if ( currentVersion < latestVersion ) {
128
- return { npmTag : "v" + branch } ;
143
+ const npmTag = "v" + branch ;
144
+ log ( `Expected npm tag: ${ npmTag } ` ) ;
145
+ return { npmTag } ;
129
146
}
130
147
131
148
// Publishing a new latest version
132
149
if ( tag === "latest" ) {
150
+ log ( `Expected npm tag: ${ tag } ` ) ;
133
151
return { npmTag : tag } ;
134
152
}
135
153
136
154
// Publishing a release candidate
155
+ log ( `Expected npm tag: ${ NPM_TAG_NEXT } ` ) ;
137
156
return { npmTag : NPM_TAG_NEXT , prerelease : "rc" } ;
138
157
}
139
158
159
+ /**
160
+ * @param {string } file
161
+ * @param {string } tag
162
+ * @returns {void }
163
+ */
164
+ function verifyPublishPipeline ( file , tag ) {
165
+ const data = fs . readFileSync ( file , { encoding : "utf-8" } ) ;
166
+ const m = data . match ( / p u b l i s h T a g : ' ( \w * ?) ' / ) ;
167
+ if ( ! m ) {
168
+ throw new Error ( `${ file } : Could not find npm publish tag` ) ;
169
+ }
170
+
171
+ if ( m [ 1 ] !== tag ) {
172
+ throw new Error ( `${ file } : 'publishTag' needs to be set to '${ tag } '` ) ;
173
+ }
174
+ }
175
+
140
176
/**
141
177
* Verifies the configuration and enables publishing on CI.
142
178
* @param {NxConfig } config
@@ -182,30 +218,10 @@ function enablePublishing(config, currentBranch, tag, prerelease) {
182
218
throw new Error ( "Nx Release is not correctly configured for the current branch" ) ;
183
219
}
184
220
221
+ verifyPublishPipeline ( ADO_PUBLISH_PIPELINE , tag ) ;
185
222
enablePublishingOnAzurePipelines ( ) ;
186
223
}
187
224
188
- /**
189
- * @param {string } file
190
- * @param {string } tag
191
- * @returns {boolean }
192
- */
193
- function verifyPublishPipeline ( file , tag ) {
194
- const data = fs . readFileSync ( file , { encoding : "utf-8" } ) ;
195
- const m = data . match ( / p u b l i s h T a g : ' ( \w * ?) ' / ) ;
196
- if ( ! m ) {
197
- error ( `${ file } : Could not find npm publish tag` ) ;
198
- return false ;
199
- }
200
-
201
- if ( m [ 1 ] !== tag ) {
202
- error ( `${ file } : 'publishTag' needs to be set to '${ tag } '` ) ;
203
- return false ;
204
- }
205
-
206
- return true ;
207
- }
208
-
209
225
/**
210
226
* @param {Options } options
211
227
* @returns {number }
@@ -217,16 +233,14 @@ function main(options) {
217
233
return 1 ;
218
234
}
219
235
220
- if ( ! verifyPublishPipeline ( ADO_PUBLISH_PIPELINE , options . tag || NPM_TAG_NEXT ) ) {
221
- return 1 ;
222
- }
236
+ const logger = options . verbose ? info : ( ) => undefined ;
223
237
224
238
const config = loadNxConfig ( NX_CONFIG_FILE ) ;
225
239
try {
226
240
if ( isMainBranch ( branch ) ) {
227
241
enablePublishing ( config , branch , NPM_TAG_NIGHTLY , NPM_TAG_NIGHTLY ) ;
228
242
} else if ( isStableBranch ( branch ) ) {
229
- const { npmTag, prerelease } = getTagForStableBranch ( branch , options ) ;
243
+ const { npmTag, prerelease } = getTagForStableBranch ( branch , options , logger ) ;
230
244
enablePublishing ( config , branch , npmTag , prerelease ) ;
231
245
}
232
246
} catch ( e ) {
@@ -236,7 +250,7 @@ function main(options) {
236
250
fs . writeSync ( fd , "\n" ) ;
237
251
fs . closeSync ( fd )
238
252
} else {
239
- console . error ( `${ e } ` ) ;
253
+ error ( `${ e . message } ` ) ;
240
254
}
241
255
return 1 ;
242
256
}
@@ -255,6 +269,10 @@ const { values } = util.parseArgs({
255
269
type : "boolean" ,
256
270
default : false ,
257
271
} ,
272
+ verbose : {
273
+ type : "boolean" ,
274
+ default : false ,
275
+ } ,
258
276
} ,
259
277
strict : true ,
260
278
} ) ;
0 commit comments