symlink-rewriter

0.1.1 • Public • Published

Symlink Rewriter

Have you ever had a big ol' batch of symlinks and then you change the folder location and they all break? Sometimes they only require a sight adjustment to the path, but they all require this adjustment and it takes forever to fix. Fear not, Symlink Rewriter™️ is here to save the day! With its innovative symlink batch rewriting technology, it can solve your batch symlink changing tasks with ease! Backed by over 30 entire lines of hand-crafted javascript code ✨

Usage

Let's say that you changed a containing folder's name from foo to bar and all your symlinks broke. Easy fix!

const symlinkRewriter = require('symlink-rewriter')

const rootPath = __dirname
symlinkRewriter(rootPath, (symlinkDestination, filePath) => {
  return symlinkDestination.replace(/\/foo/, '/bar')
})

You may be nervous about running this bulk operation, because what if you did your regex wrong and then all your files are messed up? Fair enough - just pass the dry option into the third argument, and it won't do anything other than logging out the set of changes it plans to make, like this:

const symlinkRewriter = require('symlink-rewriter')

const rootPath = __dirname
symlinkRewriter(
  rootPath,
  (symlinkDestination, filePath) => {
    return symlinkDestination.replace(/\/foo/, '/bar')
  },
  { dry: true }
)

Do you have nested directories you need to make changes to? That's ok as well, just pass in the recursive option and you're all set:

const symlinkRewriter = require('symlink-rewriter')

const rootPath = __dirname
symlinkRewriter(
  rootPath,
  (symlinkDestination, filePath) => {
    return symlinkDestination.replace(/\/foo/, '/bar')
  },
  { recursive: true }
)

That's all there is to it! Happy symlink rewriting 😀

Package Sidebar

Install

npm i symlink-rewriter

Weekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

4.98 kB

Total Files

9

Last publish

Collaborators

  • jescalan