I am writing a promise, where the first part of my promise is doing a git clone
in shelljs (node.js app). The second part of the promise is doing a git pull
and more. But many times the promise starts the clone and then before that is over, jumps into the function holding other shell.js executions like git pull
. But then it does not find the repo. What am I missing here?
My code:
let myPromise = new Promise((rev, err) => {
console.log('create promise');
rev();
});
myPromise.then(() => {
shell.cd(' ..');
shell.cd('git_folder');
fs.access('git_repo', function(error) {
if (error) {
console.log("Directory does not exist.")
shell.exec(`git clone the_git_repo && echo "cloned"`);
} else console.log("Directory exists.");
})
}).then(() => nextFunc());
const nextFunc = () => {
shell.cd('git_repo');
shell.exec('git pull');
//other git commands
}
Sometimes my promise runs in order, and other times, it starts the clone and goes into the nextFunc
function but does not find the git_repo
folder. Is there anyway to finish the clone and only then execute nextFunc
.