ldcp
v0.1.6
Published
low dependency cp
Readme
ldcp (low dependency cp)
Why? Because a popular cp clone in node is 46k lines of JavaScript and 197 dependencies!
This one is 148 lines and has no dependencies.
It tries to do the same as cp though it only supports the -R option.
What's the point?
I needed to copy a file as part of my build. I can't use cp because that's not
cross platform (doesn't work on Windows). I'm usually on MacOS but I also run
Windows and have friends that do dev on Windows. I could have used grunt and
grunt-contrib-copy or some other giant build framework but I just wanted to
add an inline script in package.json like
"scripts": {
"build": "rollup && ldcp somefile dist/somefile"
}I went looking for an existing solution. I'm sure it exists but the first one I
found was very popular and also 450k lines of dependencies. Ridiculous! I
actually solved the issue, copying a single file, with a 4 line .js file but
just for fun I thought I'd see how much work it would be to write a small cp
clone. This is result.
Installation
npm install ldcpUsage
ldcp [-R] src_file dst_file
lcdp [-R] src_file ... dst_directoryoptions
-Rrecursive copy--dry-runshow what it would do--verboseprint what it's doing
Like cp
with just 2 arguments, copies a single file from src to dst
with
-Rif the source ends with/it copies the contents of sourceIn other words assume you have
+-abc | +-def.txt | +-ghi.txt +-xyzthen
ldcp -R abc xyzresults in
+-abc | +-def.txt | +-ghi.txt xyz +--abc +--def.txt +--ghi.txtwhere as
ldcp -R abc/ xyzresults in
+-abc | +-def.txt | +-ghi.txt +-xyz +--def.txt +--ghi.txtif
xyzdoes not existthen
ldcp -R abc xyzresults in
+-abc | +-def.txt | +-ghi.txt xyz +--def.txt +--ghi.txtwhere as
ldcp -R abc/ xyzresults in
+-abc | +-def.txt | +-ghi.txt +-xyz +--def.txt +--ghi.txt
API
const ldcp = require('ldcp');
ldcp(['src'], 'dst', {recurse: true});or
const fs = require('fs');
const ldcp = require('ldcp');
const api = {
copyFileSync(...args) { return fs.copyFileSync(...args) },
mkdirSync(...args) { return fs.mkdirSync(...args); },
statSync(...args) { return fs.statSync(...args); },
readdirSync(...args) { return fs.readdirSync(...args); },
log(..args) { console.log(...args); },
};
ldcp(['src'], 'dst', {recurse: true}, api);