1import { warn } from 'danger'; 2const fs = require('fs'); 3 4function warnIfOnlyOneVersionChanged() { 5 const LATEST_VERSION = JSON.parse(fs.readFileSync('./package.json')).version; 6 7 function getPageName(path) { 8 let version = getVersionFromPath(path); 9 return path.replace('docs/pages/versions/', '').replace(`${version}/`, ''); 10 } 11 12 function getVersionFromPath(path) { 13 return path.replace('docs/pages/versions/', '').split('/')[0]; 14 } 15 16 let pages = danger.git.modified_files.filter( 17 file => file.startsWith('docs/pages') && file.endsWith('.mdx') 18 ); 19 20 let groupedByName = pages.reduce((all, path) => { 21 let pageName = getPageName(path); 22 all[pageName] = all[pageName] || []; 23 all[pageName].push(path); 24 return all; 25 }, {}); 26 27 function getSuggestion(version, name) { 28 if (version === 'unversioned') { 29 let path = `docs/pages/versions/v${LATEST_VERSION}/${name}`; 30 let url = `https://github.com/expo/expo/tree/main/${path}`; 31 return `Please consider copying the changes to the [latest released version](${url}) if applicable.`; 32 } else if (version === `v${LATEST_VERSION}`) { 33 let path = `docs/pages/versions/unversioned/${name}`; 34 let url = `https://github.com/expo/expo/tree/main/${path}`; 35 return `Please make sure this change won't be lost on the next SDK release by updating the [unversioned copy](${url}).`; 36 } else { 37 return `You may also want to make these changes to other versions of the documentation, where applicable, in the [docs/pages/versions](https://github.com/expo/expo/tree/main/docs/pages/versions) directory.`; 38 } 39 } 40 41 Object.keys(groupedByName).forEach(name => { 42 let changes = groupedByName[name]; 43 if (changes.length === 1) { 44 let version = getVersionFromPath(changes[0]); 45 warn( 46 `You modified \`${name}\` in the \`${version}\` directory. ${getSuggestion(version, name)}` 47 ); 48 } 49 }); 50} 51 52// Skip this for now 53// warnIfOnlyOneVersionChanged(); 54