I hope someone can clarify how the yorn spawnCommand () method works. I am working on a generator and I would like it to initialize the git repository, commit and push the generated application at the end.
I got the impression that the second parameter is an array, this is an array of commands that will be executed in the process. So, something like this will start 'git init', followed by 'git remote add origin', etc.
end: function () { if(this.repo !== '') { this.spawnCommand('git', ['init', 'remote add origin ' + this.repo, 'add --all', 'commit -m "initial commit from generator"', 'push -u origin master'] ); } console.log(yosay('I believe we\'re done here.')); }
Unfortunately, it just causes a usage error:
usage: git init [-q | --quiet] [--bare] ...
So, I tried doing init myself, and then the rest:
end: function () { if(this.repo !== '') { this.spawnCommand('git', ['init']); this.spawnCommand('git', ['remote add origin ' + this.repo, 'add --all', 'commit -m "initial commit from generator"', 'push -u origin master'] ); } console.log(yosay('I believe we\'re done here.')); }
The result then changes the meaning a bit:
git: 'remote add origin {URL}' is not a git command. See 'git --help'. Initialized empty Git repository in /my/project/.git/
This makes me think that they work asynchronously, which may be the cause of the failure of the remote source, but otherwise I am very confused.
Is there any other way to get the generator to click on git, or am I better off trying to automate the initial push?
EDIT:
Running each command as its own spawnCommand () also does not work.
this.spawnCommand('git', ['init']); this.spawnCommand('git', ['remote add origin ', this.repo]); this.spawnCommand('git', ['add --all']); this.spawnCommand('git', ['commit -m "initial commit from generator"']); this.spawnCommand('git', ['push -u origin master']);
Conclusion:
error: invalid key: pager.remote add origin error: invalid key: pager.add --all error: invalid key: alias.remote add origin error: invalid key: alias.add --all error: invalid key: pager.commit -m "initial commit from generator" error: invalid key: pager.push -u origin master Initialized empty Git repository in /my/project/.git/ error: invalid key: alias.commit -m "initial commit from generator" error: invalid key: alias.push -u origin master git: 'remote add origin ' is not a git command. See 'git --help'. git: 'push -u origin master' is not a git command. See 'git --help'. git: 'add --all' is not a git command. See 'git --help'. git: 'commit -m "initial commit from generator"' is not a git command. See 'git --help'.
Believing that this is not the best way to do this.