This commit is contained in:
Julien Lengrand-Lambert
2021-02-09 13:18:25 +01:00
parent 2455c02ff0
commit f3b5d023b2
5 changed files with 16 additions and 63 deletions

View File

@@ -1,62 +0,0 @@
import path from 'path';
import chalk from 'chalk';
import { validateFiles } from 'check-html-links/validateFolder.js';
import { formatErrors } from 'check-html-links/formatErrors.js';
import { listFiles } from 'check-html-links/listFiles.js';
module.exports = {
onPostBuild: ({inputs}) => {
console.log('Hello world from onPreBuild event!')
console.log(inputs.docfolder)
async function main(userRootDir) {
const rootDir = userRootDir ? path.resolve(userRootDir) : process.cwd();
console.log(rootDir);
const performanceStart = process.hrtime();
console.log('👀 Checking if all internal links work...');
const files = await listFiles('**/*.html', rootDir);
const filesOutput =
files.length == 0
? '🧐 No files to check. Did you select the correct folder?'
: `🔥 Found a total of ${chalk.green.bold(files.length)} files to check!`;
console.log(filesOutput);
const { errors, numberLinks } = await validateFiles(files, rootDir);
console.log(`🔗 Found a total of ${chalk.green.bold(numberLinks)} links to validate!\n`);
const performance = process.hrtime(performanceStart);
if (errors.length > 0) {
let referenceCount = 0;
for (const error of errors) {
referenceCount += error.usage.length;
}
const output = [
`❌ Found ${chalk.red.bold(
errors.length.toString(),
)} missing reference targets (used by ${referenceCount} links) while checking ${
files.length
} files:`,
...formatErrors(errors)
.split('\n')
.map(line => ` ${line}`),
`Checking links duration: ${performance[0]}s ${performance[1] / 1000000}ms`,
];
console.error(output.join('\n'));
process.exit(1);
} else {
console.log(
`✅ All internal links are valid. (executed in %ds %dms)`,
performance[0],
performance[1] / 1000000,
);
}
}
main(inputs.docfolder);
},
}

View File

@@ -0,0 +1,9 @@
module.exports = {
onPostBuild: ({inputs}) => {
console.log('Hello world from onPreBuild event!')
console.log(inputs.docfolder)
const cli = new CheckHtmlLinksCli();
cli.run();
},
}

View File

@@ -13,7 +13,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"chalk": "^4.1.0", "chalk": "^4.1.0",
"check-html-links": "^0.1.2", "check-html-links": "^0.2.0",
"path": "^0.12.7" "path": "^0.12.7"
} }
} }

6
netlify.toml Normal file
View File

@@ -0,0 +1,6 @@
[[plugins]]
package = "..\\netlify-plugin-check-html-links\\"
[plugins.inputs]
docfolder = dist
docplop = dist2