mirror of
https://github.com/jlengrand/check-html-links-netlify-plugin.git
synced 2026-03-10 00:01:17 +00:00
test
This commit is contained in:
62
index.js
62
index.js
@@ -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);
|
||||
},
|
||||
}
|
||||
9
netlify-plugin-check-html-links/index.js
Normal file
9
netlify-plugin-check-html-links/index.js
Normal 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();
|
||||
},
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"chalk": "^4.1.0",
|
||||
"check-html-links": "^0.1.2",
|
||||
"check-html-links": "^0.2.0",
|
||||
"path": "^0.12.7"
|
||||
}
|
||||
}
|
||||
6
netlify.toml
Normal file
6
netlify.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[[plugins]]
|
||||
package = "..\\netlify-plugin-check-html-links\\"
|
||||
|
||||
[plugins.inputs]
|
||||
docfolder = dist
|
||||
docplop = dist2
|
||||
Reference in New Issue
Block a user