From 7c348bd19a8d77d7b5fb0b21a89c866e0a33d33d Mon Sep 17 00:00:00 2001 From: Julien Date: Sun, 28 May 2023 22:47:40 +0200 Subject: [PATCH] scripts: support different path patterns --- scripts/copyHooks.mjs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/copyHooks.mjs b/scripts/copyHooks.mjs index 075b7664..25a8b066 100644 --- a/scripts/copyHooks.mjs +++ b/scripts/copyHooks.mjs @@ -94,16 +94,19 @@ function copyFile({ source, dest, useSandbox, toMarkdown }) { } if (toMarkdown) { - // rename import from "from '..'" to "from 'usehooks-ts'" - const regex = new RegExp("from '..'$") - - const transform = line => { - return regex.test(line) - ? line.replace("from '..'", "from 'usehooks-ts'") - : line - } - - data = data.split('\n').map(transform).join('\n') + data = data + .split('\n') + .map(line => { + return new RegExp("from '..'$").test(line) + ? line.replace("from '..'", "from 'usehooks-ts'") + : line + }) + .map(line => { + return new RegExp(`from './${name}'$`).test(line) + ? line.replace(`from './${name}'`, "from 'usehooks-ts'") + : line + }) + .join('\n') // wrap code into markdown code tags data = preCode + '\r' + data + '```\r'