From 62d523d1169eb7f374edd611dda923a255eb557d Mon Sep 17 00:00:00 2001 From: Mujahid Khan <106528609+mujahidkay@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:27:56 +0500 Subject: [PATCH] chore: adjust custom lint script --- ...-linter.mjs => markdown-js-snippets-linter.cjs} | 14 ++++++-------- scripts/run-linter.mjs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) rename scripts/{markdown-js-snippets-linter.mjs => markdown-js-snippets-linter.cjs} (97%) create mode 100644 scripts/run-linter.mjs diff --git a/scripts/markdown-js-snippets-linter.mjs b/scripts/markdown-js-snippets-linter.cjs similarity index 97% rename from scripts/markdown-js-snippets-linter.mjs rename to scripts/markdown-js-snippets-linter.cjs index 123e56606..4c4fee13a 100644 --- a/scripts/markdown-js-snippets-linter.mjs +++ b/scripts/markdown-js-snippets-linter.cjs @@ -1,6 +1,7 @@ -import { promises as fs } from 'fs'; -import { glob } from 'glob'; - +const fs = require('fs').promises; +const glob = require('glob'); +const util = require('util'); +const globPromise = util.promisify(glob); const extractJsSnippets = (markdownContent) => { const pattern = /```(?:js|javascript)\n([\s\S]*?)```/g; @@ -163,7 +164,7 @@ const lintMarkdownFile = async (filePath, fix = false) => { }; const processFiles = async (globPattern, fix = false) => { try { - const files = await glob(globPattern); + const files = await globPromise(globPattern); if (files.length === 0) { console.error('No files found matching the pattern.'); process.exit(1); @@ -231,7 +232,4 @@ const main = async () => { await processFiles(globPattern, fix); }; -main().catch(error => { - console.error(`Unhandled error: ${error.message}`); - process.exit(1); -}); +module.exports = main; diff --git a/scripts/run-linter.mjs b/scripts/run-linter.mjs new file mode 100644 index 000000000..8d77889a9 --- /dev/null +++ b/scripts/run-linter.mjs @@ -0,0 +1,13 @@ +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; +import main from './markdown-js-snippets-linter.cjs'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const linterPath = join(__dirname, 'markdown-js-snippets-linter.mjs'); + +main().catch(error => { + console.error(`Unhandled error: ${error.message}`); + process.exit(1); +});