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