-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
82 lines (69 loc) · 2.56 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const { danger, markdown } = require('danger');
function addDeployPreviewUrls() {
/**
* The incoming docsPath from danger does not start with `/`
* e.g. ['docs/data/data-grid/editing/editing.md']
*/
function formatFileToLink(docsPath) {
const url = docsPath.replace('docs/data', 'x').replace(/\/[^/]+\.md$/, '/');
return url
.replace('data-grid/', 'react-data-grid/')
.replace('date-pickers/', 'react-date-pickers/')
.replace('charts/', 'react-charts/')
.replace(/\/[^/]+\.md$/, '/');
}
const netlifyPreview = `https://deploy-preview-${danger.github.pr.number}--material-ui-x.netlify.app/`;
const files = [...danger.git.created_files, ...danger.git.modified_files];
// limit to the first 5 docs
const docs = files
.filter((file) => file.startsWith('docs/data') && file.endsWith('.md'))
.slice(0, 5);
markdown(`**Deploy preview:** <a href="${netlifyPreview}">${netlifyPreview}</a>`);
if (docs.length) {
markdown(`
**Updated pages:**
${docs
.map((docsPath) => {
const formattedUrl = formatFileToLink(docsPath);
return `- [${docsPath}](${netlifyPreview}${formattedUrl})`;
})
.join('\n')}
`);
}
}
function addL10nHelpMessage() {
const isAddingLocale = danger.git.created_files.some((file) => file.includes('/src/locales/'));
const isUpdatingLocale = danger.git.modified_files.some((file) => file.includes('/src/locales/'));
if (!isAddingLocale && !isUpdatingLocale) {
return;
}
markdown(
[
'## Localization writing tips :writing_hand:',
'',
'Seems you are updating localization :earth_africa: files.',
'',
'Thank you for contributing to the localization! :tada: To make your PR perfect, here is a list of elements to check: :heavy_check_mark:',
'- [ ] Verify if the PR title respects the release format. Here are two examples (depending if you update or add a locale file)',
' > [l10n] Improve Swedish (sv-SE) locale',
' > [l10n] Add Danish (da-DK) locale',
'- [ ] Update the documentation of supported locales by running `yarn l10n`',
...(isAddingLocale
? [
'- [ ] Verify that you have added an export line in `src/locales/index.ts` for the new locale.',
'- [ ] Run `yarn docs:api` which should add your new translation to the list of exported interfaces.',
]
: []),
'- [ ] Clean files with `yarn prettier`.',
'',
].join('\n'),
);
}
async function run() {
addL10nHelpMessage();
addDeployPreviewUrls();
}
run().catch((error) => {
console.error(error);
process.exit(1);
});