npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

common-copier

v0.8.0

Published

Copy and maintain identical boilerplate across projects

Downloads

3

Readme

Common Copier

Copy and maintain identical common code across different projects.

Install

npm i -g common-copier

Usage

common-copier [command]

Commands:
  common-copier link <commonDir> [projectDir=.]  Link files from commonDir to projectDir
  common-copier unlink [projectDir=.]            Dereference all symlinks

Options:
  --help, -h     Show help  [boolean]
  --version      Show version number  [boolean]
  --commonDir    (From) common folder  [string]
  --projectDir   (To) project folder  [string] [default: "."]
  --fileLimit    Limit on number of files  [number] [default: 500]
  --ignored, -i  dir(s)/file(s) to ignore (glob/wildcard)  [array] [default: [".git","*node_modules*","dist"]]
  --gitignore    .gitignore(-like) files  [array] [default: ["~/.gitignore",".gitignore"]]
  --yes, -y      Assume 'yes' for all prompts  [boolean]
  --dry, -d      Do not make any changes (dry run)  [boolean]
  --dirty        Don't check for uncommitted local changes  [boolean]
  --config       Config files to load settings from  [array] [default: ["~/.common-copier",".common-copier"]]
  --cwd          Current working directory  [string] [default: "<cwd>"]
  --silent, -s   Don't log unnecessarily  [boolean]
  --debug, -d    Log debug messages  [boolean]

Example

Let's say you have a boilerplate and 2 projects based off of it:

./common-dir
└── utils.js  ─────┐
                   │
./project-dir1     │
├── index.js       │
└── utils.js  ─────┤ common "utils.js" file
                   │
./project-dir2     │
├── index.js       │
└── utils.js  ─────┘

By doing this:

common-copier ./common-dir ./project-dir1
common-copier ./common-dir ./project-dir2

You'll get:

./common-dir
└── utils.js  ═════╗
                   ║
./project-dir1     ║
├── index.js       ║
└── utils.js  ═════╣ <hard-linked>
                   ║
./project-dir2     ║
├── index.js       ║
└── utils.js  ═════╝

./common-dir/utils.js has been hardlinked across both projects. But index.js in either of the projects has stayed the same (because they were different).

Now you can manage the same utils.js from either your boilerplate (common-dir) or either of the project-dirs.

If at some point you decide you want your utils.js to be different in project-dir1, just destroy the hardlink and make your changes, then when you run it again it won't copy it anymore.

cp ./project-dir1/utils.js ./project-dir1/utils.tmp
rm ./project-dir1/utils.js
mv ./project-dir1/utils.tmp ./project-dir1/utils.js
echo changed >> ./project-dir1/utils.js

common-copier ./common-dir ./project-dir1
common-copier ./common-dir ./project-dir2

./project-dir1
├── index.js
└── utils.js // doesn't hardlinks now because it changed

./project-dir2
├── index.js // console.log('this is project 2')
└── utils.js << hardlink >> // still hardlinks because this one didn't change

./common-dir
└── utils.js << hardlink >>

In summary, it copies (makes hardlinks) of files* from common-dir to the project-dir(s) if:

  • both files are identical
  • file doesn't exist in project-dir

Warnings

Checking out files from Git may destroy hardlinks. Run common-copier again to maintain hardlinks.

Tested on Windows only. Uses fs.link