如何使用node.js克隆github仓库 [英] How to clone github repo using node.js

查看:399
本文介绍了如何使用node.js克隆github仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种可靠的方法来克隆github存储库,并使用node.js和任何必要的npm软件包将其粘贴到本地目录中。

I need a reliable way to clone a github repo and paste it into a local directory using node.js and any necessary npm packages.

此代码使用了nodegit库,无法克隆github存储库。它会创建一个名为.git的文件夹,并且不会从存储库中复制任何文件。我尝试了几个库,其中大多数库的代码非常复杂或无法正常工作。这以前曾经有过,但现在没有了。 (它随心所欲地打开和关闭)。请帮助,我需要一个可靠的代码来从url中克隆github存储库,并将其粘贴到本地目录中。谢谢。

This code is using the nodegit library and doesn't work to clone a github repo. it creates a single folder named .git and copies none of the files from the repo. I have tried several libraries most of which have extremely complicated code or don't work. This was working before but now isn't. (it goes on and off as it pleases). pls help, I need a reliable code that clones a github repo from url and pastes it into a local directory. Thank you.

var nodegit = require('nodegit'),
    path = require('path');

var url = "https://github.com/atomicptr/dauntless-builder", //also tried https://github.com/atomicptr/dauntless-builder.git
    local = "C:/data",
    cloneOpts = {};

nodegit.Clone(url, local, cloneOpts).then(function (repo) {
    console.log("cloning succesful!");
    console.log("Cloned " + path.basename(url) + " to " + repo.workdir());
}).catch(function (err) {
    console.log(err);
});

此代码未显示错误,但实际上无法克隆存储库。

this code shows no errors, yet doesn't actually work to clone the repo.

推荐答案

您可以使用 shelljs

You can use shelljs for this.

const shell = require('shelljs')
const path = 'absolute/path/to/folder'
shell.cd(path)
shell.exec('git clone https://github.com/atomicptr/dauntless-builder')

这篇关于如何使用node.js克隆github仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆