@@ -15,6 +15,9 @@ const {
15
15
canaryChannelLabel,
16
16
rcNumber,
17
17
} = require ( '../../ReactVersions' ) ;
18
+ const yargs = require ( 'yargs' ) ;
19
+ const Bundles = require ( './bundles' ) ;
20
+ const { buildEverything} = require ( './build-ghaction' ) ;
18
21
19
22
// Runs the build script for both stable and experimental release channels,
20
23
// by configuring an environment variable.
@@ -53,44 +56,87 @@ fs.writeFileSync(
53
56
`export default '${ PLACEHOLDER_REACT_VERSION } ';\n`
54
57
) ;
55
58
56
- if ( process . env . CIRCLE_NODE_TOTAL ) {
57
- // In CI, we use multiple concurrent processes. Allocate half the processes to
58
- // build the stable channel, and the other half for experimental. Override
59
- // the environment variables to "trick" the underlying build script.
60
- const total = parseInt ( process . env . CIRCLE_NODE_TOTAL , 10 ) ;
61
- const halfTotal = Math . floor ( total / 2 ) ;
62
- const index = parseInt ( process . env . CIRCLE_NODE_INDEX , 10 ) ;
63
- if ( index < halfTotal ) {
64
- const nodeTotal = halfTotal ;
65
- const nodeIndex = index ;
66
- buildForChannel ( 'stable' , nodeTotal , nodeIndex ) ;
67
- processStable ( './build' ) ;
59
+ const argv = yargs . wrap ( yargs . terminalWidth ( ) ) . options ( {
60
+ releaseChannel : {
61
+ alias : 'r' ,
62
+ describe : 'Build the given release channel.' ,
63
+ requiresArg : true ,
64
+ type : 'string' ,
65
+ default : 'experimental' ,
66
+ choices : [ 'experimental' , 'stable' ] ,
67
+ } ,
68
+ bundleType : {
69
+ alias : 'b' ,
70
+ describe : 'Build the given bundle type.' ,
71
+ requiresArg : true ,
72
+ type : 'string' ,
73
+ choices : Object . values ( Bundles . bundleTypes ) ,
74
+ } ,
75
+ ci : {
76
+ describe : 'Run tests in CI' ,
77
+ requiresArg : false ,
78
+ type : 'choices' ,
79
+ choices : [ 'circleci' , 'github' ] ,
80
+ } ,
81
+ } ) . argv ;
82
+
83
+ async function main ( ) {
84
+ if ( argv . ci === 'github' ) {
85
+ // ./scripts/rollup/build was being used by spawning a new process and passing via ENV variables
86
+ // so let's just preserve this for now and rewrite it later to just take a function arg
87
+ process . env . RELEASE_CHANNEL = argv . releaseChannel ;
88
+ await buildEverything ( argv . bundleType ) ;
89
+ switch ( argv . releaseChannel ) {
90
+ case 'stable' : {
91
+ processStable ( './build' ) ;
92
+ break ;
93
+ }
94
+ case 'experimental' : {
95
+ processExperimental ( './build' ) ;
96
+ break ;
97
+ }
98
+ default :
99
+ throw new Error ( `Unknown release channel ${ argv . releaseChannel } ` ) ;
100
+ }
101
+ } else if ( argv . ci === 'circleci' ) {
102
+ // In CI, we use multiple concurrent processes. Allocate half the processes to
103
+ // build the stable channel, and the other half for experimental. Override
104
+ // the environment variables to "trick" the underlying build script.
105
+ const total = parseInt ( process . env . CIRCLE_NODE_TOTAL , 10 ) ;
106
+ const halfTotal = Math . floor ( total / 2 ) ;
107
+ const index = parseInt ( process . env . CIRCLE_NODE_INDEX , 10 ) ;
108
+ if ( index < halfTotal ) {
109
+ const nodeTotal = halfTotal ;
110
+ const nodeIndex = index ;
111
+ buildForChannel ( 'stable' , nodeTotal , nodeIndex ) ;
112
+ processStable ( './build' ) ;
113
+ } else {
114
+ const nodeTotal = total - halfTotal ;
115
+ const nodeIndex = index - halfTotal ;
116
+ buildForChannel ( 'experimental' , nodeTotal , nodeIndex ) ;
117
+ processExperimental ( './build' ) ;
118
+ }
68
119
} else {
69
- const nodeTotal = total - halfTotal ;
70
- const nodeIndex = index - halfTotal ;
71
- buildForChannel ( 'experimental' , nodeTotal , nodeIndex ) ;
72
- processExperimental ( './build' ) ;
120
+ // Running locally, no concurrency. Move each channel's build artifacts into
121
+ // a temporary directory so that they don't conflict.
122
+ buildForChannel ( 'stable' , '' , '' ) ;
123
+ const stableDir = tmp . dirSync ( ) . name ;
124
+ crossDeviceRenameSync ( './build' , stableDir ) ;
125
+ processStable ( stableDir ) ;
126
+ buildForChannel ( 'experimental' , '' , '' ) ;
127
+ const experimentalDir = tmp . dirSync ( ) . name ;
128
+ crossDeviceRenameSync ( './build' , experimentalDir ) ;
129
+ processExperimental ( experimentalDir ) ;
130
+
131
+ // Then merge the experimental folder into the stable one. processExperimental
132
+ // will have already removed conflicting files.
133
+ //
134
+ // In CI, merging is handled automatically by CircleCI's workspace feature.
135
+ mergeDirsSync ( experimentalDir + '/' , stableDir + '/' ) ;
136
+
137
+ // Now restore the combined directory back to its original name
138
+ crossDeviceRenameSync ( stableDir , './build' ) ;
73
139
}
74
- } else {
75
- // Running locally, no concurrency. Move each channel's build artifacts into
76
- // a temporary directory so that they don't conflict.
77
- buildForChannel ( 'stable' , '' , '' ) ;
78
- const stableDir = tmp . dirSync ( ) . name ;
79
- crossDeviceRenameSync ( './build' , stableDir ) ;
80
- processStable ( stableDir ) ;
81
- buildForChannel ( 'experimental' , '' , '' ) ;
82
- const experimentalDir = tmp . dirSync ( ) . name ;
83
- crossDeviceRenameSync ( './build' , experimentalDir ) ;
84
- processExperimental ( experimentalDir ) ;
85
-
86
- // Then merge the experimental folder into the stable one. processExperimental
87
- // will have already removed conflicting files.
88
- //
89
- // In CI, merging is handled automatically by CircleCI's workspace feature.
90
- mergeDirsSync ( experimentalDir + '/' , stableDir + '/' ) ;
91
-
92
- // Now restore the combined directory back to its original name
93
- crossDeviceRenameSync ( stableDir , './build' ) ;
94
140
}
95
141
96
142
function buildForChannel ( channel , nodeTotal , nodeIndex ) {
@@ -457,3 +503,5 @@ function mergeDirsSync(source, destination) {
457
503
}
458
504
}
459
505
}
506
+
507
+ main ( ) ;
0 commit comments