common-copier
Copy and maintain identical boilerplate across projects
Last updated 3 months ago by laggingreflex .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install common-copier 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.8.0                                ...           latest (3 months ago)

13 Versions

  • 0.8.0                                ...           3 months ago
  • 0.7.2                                ...           3 months ago
  • 0.7.1                                ...           4 months ago
  • 0.7.0                                ...           4 months ago
  • 0.6.0                                ...           4 months ago
  • 0.5.0                                ...           4 months ago
  • 0.4.0                                ...           4 months ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 0
Last Month 4
Dependencies (5)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |