我正在处理一个 Node.js 文件以自动创建一个新的 Github 存储库。
当我curl -u 'BretCameron' https://api.github.com/user/repos -d '{"name":"test_repo"}'
在终端中运行时,它会询问我的 GitHub 密码,然后创建新的存储库。
但我无法让它在 Node 中工作,即使git
我的示例代码中的命令运行良好:
const { exec, execSync } = require('child_process');
function run(func) {
console.log(execSync(func).toString())
}
run('touch README.md');
run('git init');
run('git add README.md');
run('git commit -m "First commit"');
exec(`curl -u 'BretCameron' https://api.github.com/user/repos -d '{"name":"test_repo"}'`));
我已尝试使用模块中的exec
andexecSync
函数child_process
,并将其放入我的辅助函数run
中。任何人都可以提供一些建议吗?