1const puppeteer = require('puppeteer'); 2 3const url = process.argv[2]; 4 5if (!url) { 6 console.error(`You need to provide the base URL for links as a parameter.`); 7 process.exit(-1); 8} 9 10const externalLinks = [ 11 '/versions/latest/workflow/expo-cli/', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/README.md and https://github.com/expo/expo-cli/blob/master/README.md 12 '/versions/latest/workflow/configuration/', // https://github.com/expo/expo-cli/blob/master/CONTRIBUTING.md and https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/init.js and https://github.com/expo/expo-cli/blob/master/packages/xdl/src/project/Doctor.js 13 // https://github.com/expo/expo-cli/blob/4e16a55e98e0612f71685ed16b3b5f8405219d4a/packages/xdl/README.md#xdl [Documentation](https://docs.expo.dev/versions/devdocs/index.html) 14 '/versions/latest/distribution/building-standalone-apps/#switch-to-push-notification-key-on-ios', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/build/ios/credentials/constants.js 15 '/versions/latest/distribution/building-standalone-apps/#2-configure-appjson', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/build/AndroidBuilder.js 16 '/versions/latest/distribution/building-standalone-apps/#if-you-choose-to-build-for-android', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/build/AndroidBuilder.js 17 '/versions/latest/distribution/uploading-apps/', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/upload/BaseUploader.js 18 '/versions/latest/workflow/linking/', // https://github.com/expo/expo-cli/blob/master/packages/xdl/src/detach/Detach.js 19 '/versions/latest/workflow/configuration/#ios', // https://github.com/expo/expo-cli/blob/master/packages/xdl/src/detach/Detach.js 20 '/versions/latest/guides/splash-screens/#differences-between-environments---android', // https://github.com/expo/expo-cli/blob/master/packages/xdl/src/Android.js 21 '/versions/latest/sdk/overview/', // https://github.com/expo/expo-cli/blob/master/packages/xdl/src/project/Convert.js 22 '/versions/latest/distribution/building-standalone-apps/#2-configure-appjson', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/build/ios/IOSBuilder.js 23 '/versions/latest/guides/configuring-updates/', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/build/BaseBuilder.js 24 '/versions/latest/expokit/eject/', // https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/commands/eject/Eject.js 25 '/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo', // https://github.com/expo/expo-cli/blob/master/packages/xdl/src/logs/PackagerLogsStream.js 26 '/versions/latest/guides/offline-support/', // https://github.com/expo/expo-cli/tree/master/packages/xdl/caches 27]; 28 29(async () => { 30 try { 31 const notFound = []; 32 const redirectsFailed = []; 33 34 const browser = await puppeteer.launch(); 35 const page = await browser.newPage(); 36 37 for (const link of externalLinks) { 38 const response = await page.goto(`${url}${link}`); 39 if (response.status() === 404) { 40 await page.waitForFunction( 41 () => document.querySelector('#redirect-link') || document.querySelector('#__not_found'), 42 { timeout: 500 } 43 ); 44 if (await page.$('#redirect-link')) { 45 await Promise.all([page.waitForNavigation(), page.click('#redirect-link')]); 46 console.info(`Redirected from ${link} to ${await page.url()}`); 47 try { 48 await page.waitForFunction( 49 () => 50 document.querySelector('#__redirect_failed') || 51 document.querySelector('#__not_found'), 52 { timeout: 500 } 53 ); 54 console.debug(`Redirect failed`); 55 redirectsFailed.push(link); 56 } catch { 57 console.debug(`Redirect successful`); 58 } 59 } else { 60 console.debug(`Couldn't find ${link}`); 61 notFound.push(link); 62 } 63 } 64 } 65 await browser.close(); 66 67 if (notFound.length || redirectsFailed.length) { 68 if (notFound.length) { 69 console.error(`Pages not found for links: ${notFound.join(',')}`); 70 } else if (redirectsFailed.length) { 71 console.error(`Redirects failed for links: ${redirectsFailed.join(',')}`); 72 } 73 process.exit(-1); 74 } 75 } catch (e) { 76 console.error(e); 77 process.exit(-1); 78 } 79})(); 80