2020-04-13 10:15:18 -04:00
|
|
|
const fs = require('fs-extra');
|
2020-11-11 02:46:43 -05:00
|
|
|
const helper = require('./common');
|
2020-04-13 10:15:18 -04:00
|
|
|
|
|
|
|
console.log({
|
2020-11-11 02:46:43 -05:00
|
|
|
DEBUG: process.env.DEBUG || false,
|
2020-04-13 10:15:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const README = 'README.md';
|
|
|
|
|
|
|
|
async function main() {
|
2020-11-11 02:46:43 -05:00
|
|
|
const has_error = {
|
|
|
|
show: false,
|
|
|
|
duplicates: '',
|
|
|
|
other_links_error: '',
|
|
|
|
};
|
|
|
|
const markdown = await fs.readFile(README, 'utf8');
|
|
|
|
let links = helper.extract_all_links(markdown);
|
|
|
|
links = links.filter((l) => !helper.exclude_from_list(l)); // exclude websites
|
|
|
|
helper.LOG.debug_string({ links });
|
2020-04-13 13:59:09 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
console.log(`total links to check ${links.length}`);
|
2020-04-13 13:59:09 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
console.log('checking for duplicates links...');
|
2020-04-13 13:59:09 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
const duplicates = helper.find_duplicates(links);
|
|
|
|
if (duplicates.length > 0) {
|
|
|
|
has_error.show = true;
|
|
|
|
has_error.duplicates = duplicates;
|
|
|
|
}
|
|
|
|
helper.LOG.debug_string({ duplicates });
|
|
|
|
const [github_links, external_links] = helper.partition(links, (link) =>
|
|
|
|
link.startsWith('https://github.com'),
|
|
|
|
);
|
2020-04-13 10:15:18 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
console.log(`checking ${external_links.length} external links...`);
|
2020-04-13 13:59:09 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
const external_links_error = await helper.batch_fetch({
|
|
|
|
arr: external_links,
|
|
|
|
get: helper.fetch_link,
|
|
|
|
post_filter_func: (x) => !x[1].ok,
|
|
|
|
BATCH_SIZE: 8,
|
|
|
|
});
|
|
|
|
if (external_links_error.length > 0) {
|
|
|
|
has_error.show = true;
|
|
|
|
has_error.other_links_error = external_links_error;
|
|
|
|
}
|
2020-04-13 10:15:18 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
console.log(`checking ${github_links.length} GitHub repositories...`);
|
2020-04-13 13:59:09 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
console.log(
|
|
|
|
`skipping GitHub repository check. Run "npm run test" to execute them manually.`,
|
|
|
|
);
|
2020-11-09 13:30:28 -05:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
console.log({
|
|
|
|
TEST_PASSED: !has_error.show,
|
|
|
|
EXTERNAL_LINKS: external_links.length,
|
|
|
|
});
|
2020-04-13 13:59:09 -04:00
|
|
|
|
2020-11-11 02:46:43 -05:00
|
|
|
if (has_error.show) {
|
|
|
|
helper.LOG.error_string(has_error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-04-13 10:15:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('starting...');
|
|
|
|
main();
|