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

How to run copyfiles synchronously? #77

Open
nangalvivek opened this issue Dec 17, 2019 · 1 comment
Open

How to run copyfiles synchronously? #77

nangalvivek opened this issue Dec 17, 2019 · 1 comment

Comments

@nangalvivek
Copy link

nangalvivek commented Dec 17, 2019

I am trying to copy some files after in a post-install script using the following code

const mappings = [{
  name:"",
  mappings: {
     from: "", to: "", up: 2
  }
}];
mappings
    .forEach(({ name, mappings: fileMappings }) => {
        process.chdir(dirname); // derived from name
        console.log("-- chdir ", dirname);
        fileMappings.forEach(({ from, to, up }) => {
            to = path.resolve(rootDir, to);
            copyfiles([from, to], {
                up: up || 0,
                verbose: true,
            }, (result) => {
                console.log(result);
            })
            console.log("-- copy files successful");
        });
    })

From the logs it appears that the copyfiles function executes asynchronously and copies all the files at the end. Since, I am changing the directory with each mapping, the last directory gets picked up for all the mappings. Is there a way to force copyfiles to run synchronously?

@calvinmetcalf
Copy link
Owner

there is not, you could try promisifying this module and rewriting your stuff to to use async/await

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

2 participants