【发布时间】:2015-08-09 15:48:19
【问题描述】:
我正在为 Flask-Bootstrap 框架编写自己的 yeoman 生成器。创建所有目录后,复制/模板化所有文件,理想情况下,我想创建一个本地 git 存储库(我可以这样做),然后初始化一个远程存储库并将第一个提交推送到它。
到了创建本地仓库、进行第一次本地提交并添加远程源的地步,但在尝试推送到源主机时被挂断了。
顺便说一句,我还没有找到关于 Yeoman 的 exec() 函数的可靠文档,谁能指出我正确的方向。
input.js
...
git: function(){
var done = this.async();
// create git repository and start remote github repository
exec('cd ' + this.appName + ' && git init', function(err, stdout) {
console.log('Initialized local git repository\n', stdout);
});
exec('cd ' + this.appName + ' && curl -u ' + this.githubUsername + ' https://api.github.com/user/repos -d \'{"name":"' + this.appName + '"}\'', function(err, stdout) {
console.log('Initialized remote github repository!\n', stdout);
});
exec('cd ' + this.appName + ' && git remote add origin git@github.com:' + this.githubUsername + '/' + this.appName + '.git', function(err, stdout) {
console.log('Added github remote origin\n', stdout);
});
exec('cd ' + this.appName + ' && git add .', function(err, stdout) {
console.log('Added all files to git staging area\n', stdout);
});
exec('cd ' + this.appName + ' && git commit -m "init commit"', function(err, stdout) {
console.log('Made first commit!\n', stdout);
});
exec('cd ' + this.appName + ' && git push origin master', function(err, stdout) {
console.log('Pushed first commit to github\n', stdout);
});
done();
},
...
输出
...
Initialized local git repository
Initialized empty Git repository in /Users/joey/Desktop/trippity/.git/
Made first commit!
Added all files to git staging area
Added github remote origin
//Never prints line corresponding to pushing to the remote
...
我引用了this SO 关于从 CLI 创建远程 GitHub 存储库的问题。
更新
所以我尝试在测试存储库上使用 GitHub API 来尝试从 CLI 创建远程存储库。使用 curl 后,系统会提示您输入 github 密码(这是有道理的)。我在 yeoman 生成器中没有看到输入密码的提示,这可能是它被挂断的原因,关于如何向用户显示此提示的任何想法?
joey@JoeyOrlandoMacBookAir:~/Desktop/trippity$ curl -u joeyorlando https://api.github.com/user/repos -d '{"name":"trippity"}'
Enter host password for user 'joeyorlando':
【问题讨论】:
-
我看不到使用 yeoman 命令来使用 git 的意义。为什么不直接使用 git 命令呢?并让用户使用 svn 或 mercurial 或其他任何他喜欢的东西?
-
我最感兴趣的是创建这个生成器供个人使用,我只使用 git
标签: git github yeoman yeoman-generator