Skip to content

Commit

Permalink
scripts: support different path patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Jun 6, 2023
1 parent 78771fa commit 7c348bd
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions scripts/copyHooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 7c348bd

Please sign in to comment.