Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programic API #28

Open
jnthnjns opened this issue Aug 30, 2017 · 10 comments
Open

Programic API #28

jnthnjns opened this issue Aug 30, 2017 · 10 comments

Comments

@jnthnjns
Copy link

jnthnjns commented Aug 30, 2017

Desperate need for documentation here.

I have been an advocate for npm scripting of build processes for many departments at my work and I sold them a group of npm packages to get the job done, copyfiles being one of them. We have recently converted from npm scripts within package.json to writing out a node build file.

We are going to have to switch away from copyfiles do to the lack of documentation and below.

takes an array of paths, last one is the destination path...

On the command line that makes sense, programatically it is nonsensical. I can't explain to other developers why the "last item in the array is the destination" and any new developer coming on board would have to get taught that as well.

This npm package has been great to me, I would love to see more documentation on "programmatic" usage as well an additional parameter when calling copyfiles in that environment.

Something like:


copyfiles(path, dest [, opts] [, callback])

Example

var copyfiles = require('copyfiles');

copyfiles(["./src/**/*.html"], "./dist/", function (err) {
    if (err) console.error(err);
});

Example w/opts

var copyfiles = require('copyfiles');

// I honestly don't understand how you are taking options here because it isn't documented.
copyfiles(["./src/**/*.html"], "./dist/", "-u", function (err) {
    if (err) console.error(err);
});
@calvinmetcalf
Copy link
Owner

yeah I can try to add some more details on the programmatic api, I'm not sure when I'm going to get to it, I'm kinda swamped with some stuff right now so pull requests would always help

@BioPhoton
Copy link

@calvinmetcalf Great job!

I would also need more information.
I need to use the -u 3 options programmatically. A quick explanation in a comment would help.

cheers!

@calvinmetcalf
Copy link
Owner

the signature is

copyfiles(paths, opts, callback);

with paths being an array of the input paths and the output being the last path and config being an object where the names correspond to the flags so you'd want it to be {up: 3}

@BioPhoton
Copy link

THX @calvinmetcalf for your answer!

Here is some source code as documentation for the options:

 .option('-u, --up [levels]', 'slice a path off the bottom of the paths', parseInt)
 .option('-a --all', 'include files and directories whose names begin with a dot (.)')
 .option('-f, --flat', 'flatten the output')
 .option('-e, --exclude [pattern]', 'pattern or glob to exclude')
 .option('-s, --soft', 'do not overwrite destination files if they exist')

as the key in the options object corresponds to the flags i guess i would be able to use short and long version. So i could use {up: 3} and {u: 3}

@calvinmetcalf
Copy link
Owner

no just the long option, so you can have 'all', 'flat', 'exclude' and 'soft'

@spenoir
Copy link

spenoir commented Feb 14, 2018

Actually in my case where I wanted to flatten while copying Programmatically I had to do this:

copyfiles(["./src/**/*.html", "./dist/"], true, function (err) {
    if (err) console.error(err);
});

I found this out by checking your tests. This really needs to be documented

@topalavlad
Copy link

topalavlad commented Jul 3, 2019

I know this issue is pretty old but using true as the second parameter stops you from adding other parameters like error or verbose.

After looking through the code I saw that flat = true is actually transformed into up = true so for anyone who wants to use multiple parameters one of which is flat, the following will do the trick:

copyfiles(["./src/**/*.html", "./dist/"], {up: true, error: true, verbose: true}, function (err) {
    if (err) console.error(err);
});

@calvinmetcalf might be worth allowing people to use flat in the parameters object since the Read.me says:

if it is an object it is a hash of the various options (the long version e.g. up, all, flat, exclude, error, verbose and soft)

If you agree, I can create a PR.

@BehnooshShiva
Copy link

BehnooshShiva commented Jan 7, 2020

hello,
How can I transfer this node script :
copyfiles file.json ../ --flat
I trayed several ways but always nothing
var copyfiles= require('copyfiles'); copyfiles(['file.json', '../'], true, function (err) { if (err) console.error(err); }); copyfiles(['file', '../'], -flat, function (err) { if (err) console.error(err); });

@nolimitdev
Copy link

Actually in my case where I wanted to flatten while copying Programmatically I had to do this:

copyfiles(["./src/**/*.html", "./dist/"], true, function (err) {
    if (err) console.error(err);
});

I found this out by checking your tests. This really needs to be documented

Yes docs is very poor and lies that copyfiles([paths], opt, callback) opt is optional. Both opt callback and must be used.

@nolimitdev
Copy link

nolimitdev commented May 29, 2020

How can I transfer this node script :
copyfiles file.json ../ --flat

Your copy operation is very simple, so I recommend NodeJS built in fs module.

require('fs').copyFileSync('file.json', '../file.json');

Or you can use async alternative copyFile().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants