diff --git a/index.js b/index.js deleted file mode 100644 index 0eb5140..0000000 --- a/index.js +++ /dev/null @@ -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); - }, -} \ No newline at end of file diff --git a/netlify-plugin-check-html-links/index.js b/netlify-plugin-check-html-links/index.js new file mode 100644 index 0000000..9bd26c2 --- /dev/null +++ b/netlify-plugin-check-html-links/index.js @@ -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(); + }, +} \ No newline at end of file diff --git a/manifest.yml b/netlify-plugin-check-html-links/manifest.yml similarity index 100% rename from manifest.yml rename to netlify-plugin-check-html-links/manifest.yml diff --git a/package.json b/netlify-plugin-check-html-links/package.json similarity index 93% rename from package.json rename to netlify-plugin-check-html-links/package.json index c02bbaa..5e6d450 100644 --- a/package.json +++ b/netlify-plugin-check-html-links/package.json @@ -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" } } diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..8028c8c --- /dev/null +++ b/netlify.toml @@ -0,0 +1,6 @@ +[[plugins]] +package = "..\\netlify-plugin-check-html-links\\" + + [plugins.inputs] + docfolder = dist + docplop = dist2 \ No newline at end of file