@@ -12,19 +12,16 @@ const cp = require('child_process');
1212const readline = require ( 'readline' ) ;
1313const { promisify } = require ( 'util' ) ;
1414
15- /*::
16- type ExecFilePromiseResult = {|
17- stdout: string | Buffer,
18- stderr: string | Buffer
19- |};
20-
21- type ExecFile = (
22- command: string,
23- args?: string[]
24- ) => Promise<ExecFilePromiseResult>;
25- */
15+ /**
16+ * @typeef {Object} ExecFilePromiseResult
17+ * @property {string | Buffer } stdout
18+ * @property {string | Buffer } stderr
19+ */
2620
27- const execFile /*: ExecFile */ = promisify ( cp . execFile ) ;
21+ /**
22+ * @type {(command: string, args?: string[]) => Promise<ExecFilePromiseResult> }
23+ */
24+ const execFile = promisify ( cp . execFile ) ;
2825
2926const DATE_FORMAT = new Intl . DateTimeFormat ( 'en-US' , {
3027 month : 'long' ,
@@ -39,12 +36,12 @@ const MERGE_COMMIT_MESSAGE = '🔃 Daily sync: main -> l10n';
3936 * Logs the command to be executed first, and spawns a shell then executes the
4037 * command. Returns the stdout of the executed command.
4138 *
39+ * @param {string } executable
40+ * @param {...string } args
41+ * @returns {Promise<ExecFilePromiseResult> }
4242 * @throws Will throw an error if executed command fails.
4343 */
44- async function logAndExec (
45- executable /*: string */ ,
46- ...args /*: string[] */
47- ) /*: Promise<ExecFilePromiseResult> */ {
44+ async function logAndExec ( executable , ...args ) {
4845 console . log ( '[exec]' , executable , args . join ( ' ' ) ) ;
4946 const result = await execFile ( executable , args ) ;
5047
@@ -64,9 +61,11 @@ async function logAndExec(
6461 * and pipes the stdout of them to the next one. In the end, returns the stdout
6562 * of the last piped command.
6663 *
64+ * @param {...string[] } commands
65+ * @returns {string }
6766 * @throws Will throw an error if one of the executed commands fails.
6867 */
69- function logAndPipeExec ( ...commands /*: string[][] */ ) /*: string */ {
68+ function logAndPipeExec ( ...commands ) {
7069 console . log (
7170 '[exec]' ,
7271 commands . map ( ( command ) => command . join ( ' ' ) ) . join ( ' | ' )
@@ -90,10 +89,11 @@ function logAndPipeExec(...commands /*: string[][] */) /*: string */ {
9089 * Pause with a message and wait for the enter as a confirmation.
9190 * The prompt will not be displayed if the `-y` argument is given to the script.
9291 * This is mainly used by the GitHub Actions automation.
92+ *
93+ * @param {string } [message='']
94+ * @returns {Promise<void> }
9395 */
94- async function pauseWithMessageIfNecessary (
95- message /*: string */ = ''
96- ) /*: Promise<void> */ {
96+ async function pauseWithMessageIfNecessary ( message = '' ) {
9797 if ( SKIP_PROMPTS ) {
9898 return ;
9999 }
@@ -115,9 +115,10 @@ async function pauseWithMessageIfNecessary(
115115/**
116116 * Check if Git workspace is clean.
117117 *
118+ * @returns {Promise<void> }
118119 * @throws Will throw an error if workspace is not clean.
119120 */
120- async function checkIfWorkspaceClean ( ) /*: Promise<void> */ {
121+ async function checkIfWorkspaceClean ( ) {
121122 console . log ( '>>> Checking if the workspace is clean for the operations.' ) ;
122123 // git status --porcelain --ignore-submodules -unormal
123124 const statusResult = await logAndExec (
@@ -140,9 +141,10 @@ async function checkIfWorkspaceClean() /*: Promise<void> */ {
140141/**
141142 * Finds the Git upstream remote and returns it.
142143 *
144+ * @returns {Promise<string> }
143145 * @throws Will throw an error if it can't find an upstream remote.
144146 */
145- async function findUpstream ( ) /*: Promise<string> */ {
147+ async function findUpstream ( ) {
146148 console . log ( '>>> Finding the upstream remote.' ) ;
147149 try {
148150 const gitRemoteResult = await logAndExec ( 'git' , 'remote' , '-v' ) ;
@@ -178,19 +180,21 @@ async function findUpstream() /*: Promise<string> */ {
178180 * Fails if the `compareBranch` has changes from the files that doesn't match
179181 * the `allowedRegexp`.
180182 *
183+ * @param {Object } options
184+ * @param {string } options.upstream
185+ * @param {string } options.compareBranch
186+ * @param {string } options.baseBranch
187+ * @param {RegExp } options.allowedRegexp
188+ * @returns {Promise<void> }
181189 * @throws Will throw an error if `compareBranch` has changes from the files
182190 * that doesn't match the `allowedRegexp`.
183191 */
184- async function checkAllowedPaths (
185- { upstream, compareBranch, baseBranch, allowedRegexp } /*:
186- {|
187- upstream: string,
188- compareBranch: string,
189- baseBranch: string ,
190- allowedRegexp: RegExp
191- |}
192- */
193- ) {
192+ async function checkAllowedPaths ( {
193+ upstream,
194+ compareBranch,
195+ baseBranch,
196+ allowedRegexp,
197+ } ) {
194198 console . log (
195199 `>>> Checking if ${ compareBranch } branch has changes from the files that are not allowed.`
196200 ) ;
@@ -224,8 +228,11 @@ async function checkAllowedPaths(
224228 * It's a pretty simple hack and would be good to have a more sophisticated
225229 * (localized?) API function. But it's not really worth for a deployment only
226230 * script.
231+ *
232+ * @param {number } count
233+ * @returns {string }
227234 */
228- function fewTimes ( count /*: number */ ) /*: string */ {
235+ function fewTimes ( count ) {
229236 switch ( count ) {
230237 case 1 :
231238 return 'once' ;
@@ -239,9 +246,11 @@ function fewTimes(count /*: number */) /*: string */ {
239246/**
240247 * Tries to sync the l10n branch and retries for 3 times if it fails to sync.
241248 *
249+ * @param {string } upstream
250+ * @returns {Promise<void> }
242251 * @throws Will throw an error if it fails to sync for more than 3 times.
243252 */
244- async function tryToSync ( upstream /*: string */ ) /*: Promise<void> */ {
253+ async function tryToSync ( upstream ) {
245254 console . log ( '>>> Syncing the l10n branch with main.' ) ;
246255 // RegExp for matching only the vendored locales.
247256 // It matches the files in `locales` directory but excludes `en-US` which is the
@@ -268,7 +277,8 @@ async function tryToSync(upstream /*: string */) /*: Promise<void> */ {
268277 // changes and try again. Nevertheless, we should have a hard cap on the try
269278 // count for safety.
270279 const totalTryCount = 3 ;
271- let error /*: Error | null */ = null ;
280+ /** @type {Error | null } */
281+ let error = null ;
272282 let tryCount = 0 ;
273283
274284 // Try to sync and retry for `totalTryCount` times if it fails.
@@ -341,9 +351,10 @@ async function tryToSync(upstream /*: string */) /*: Promise<void> */ {
341351/**
342352 * Main function to be executed in the global scope.
343353 *
354+ * @returns {Promise<void> }
344355 * @throws Will throw an error if any of the functions it calls throw.
345356 */
346- async function main ( ) /*: Promise<void> */ {
357+ async function main ( ) {
347358 const args = process . argv . slice ( 2 ) ;
348359
349360 if ( args . includes ( '-y' ) ) {
@@ -363,8 +374,13 @@ async function main() /*: Promise<void> */ {
363374 console . log ( '>>> Done!' ) ;
364375}
365376
366- main ( ) . catch ( ( error /*: Error */ ) => {
367- // Print the error to the console and exit if an error is caught.
368- console . error ( error ) ;
369- process . exitCode = 1 ;
370- } ) ;
377+ main ( ) . catch (
378+ /**
379+ * @param {Error } error
380+ */
381+ ( error ) => {
382+ // Print the error to the console and exit if an error is caught.
383+ console . error ( error ) ;
384+ process . exitCode = 1 ;
385+ }
386+ ) ;
0 commit comments