在执行 node 时,需要从 github 下载源码。就找到了网上了有一个库 download-git-repo ,可以用于从 github clone 或者下载代码。

download-git-repo 文档 https://www.npmjs.com/package/download-git-repo

下面代码用到了 download-git-reporimraf 两个第三方库

npm install download-git-repo rimraf

使用 clone 时,路径

GitHub - github:owner/name or simply owner/name
GitLab - gitlab:owner/name
Bitbucket - bitbucket:owner/name

后面也可以用 # 添加分支

const download = require("download-git-repo");
const path = require("path");
const rimraf = require("rimraf");const dir = path.join(process.cwd(), "test"); //这里可以自定义下载的地址rimraf.sync(dir, {});  //在下载前需要保证路径下没有同名文件download("github:billmian/react-webpack-template#main", dir,{ clone: true },function (err) {console.log(err ? "Error" : "Success", err);}
);

如果仅仅是想下载,路径需要使用 zip 文件的路径

const download = require("download-git-repo");
const path = require("path");
const rimraf = require("rimraf");const dir = path.join(process.cwd(), "test");rimraf.sync(dir, {});download("direct:https://codeload.github.com/billmian/react-webpack-template/zip/main",dir,function (err) {console.log(err ? "Error" : "Success", err);}
);

node 使用 download-git-repo 下载 github 代码相关推荐

  1. ubuntu使用git下载github代码

    目前国内访问github经常时断时续,网页阅读不能随心所欲,可以下载代码后,根据作者的Readme来学习作者的代码,有时即使无法访问github网站,也可通过git命令下载项目代码: 首先安装git: ...

  2. 在linux下载github代码,linux 定时下载github最新代码

    场景:网站的代码在github上托管,静态网站部署在服务器上,每次自己修改完本地代码后,提交到github上,需要自己去服务器上执行git pull 拉取最新代码, 为了解决这种操作,自己再服务器上  ...

  3. 如何通过linux下载github代码

    [linux]如何通过linux下载github代码 1.在linux下生成SSH-Key的命令 首先通过root访问虚拟机. cd root 2.查看是否已经存在SSH-Key 如果.ssh内存在内 ...

  4. 下载github代码到服务器

    一.下载github代码到服务器 1.进入你想存放文件的目录: chf@user-System:~/Project$ 右键单击 Download ZIP 复制下载地址,在终端输入: wget 下载地址 ...

  5. 批量下载GitHub代码

    批量下载GitHub代码 华为被特朗普政府针对,连GitHub.Apache都瑟瑟发抖. 为了保存GitHub上开源项目,批量下载GitHub代码如下 1.第一个代码,用于获取目标对象所有开源项目网址 ...

  6. ubuntu18.04.4 中 下载 github 代码 并创建 python 虚拟环境virtualenv

    文章目录 ubuntu18.04.4 中 下载 github 代码 并创建 python 虚拟环境virtualenv 1 安装virtualenv和virtualenvwrapper 2 githu ...

  7. Ubuntu18.04系统快速下载Github代码

    1.打开终端,输入: sudo gedit /etc/host 然后就出来一个host的文本编辑 2.用浏览器访问 IPAddress.com or http://tool.chinaz.com 使用 ...

  8. 如何快速下载github代码

    如何快速下载github代码 注册一个gitee账号:gitee网址 登陆后:点击下图右上角"+"号来添加仓库: 出现如下界面:点击右上角的"点击导入": 出现 ...

  9. 用git来下载github项目代码

    最近要进行课程设计,但是查看代码时想把github的代码下载下来直接导入怎么下载 这就要用到我们的git代码托管了 只需要下载这个git git连接下载 选择一个版本进行下载 选择下面带有时间的进行新 ...

最新文章

  1. Hyperic HQ HQU 插件开发指南
  2. dreamweaver中的JSP的编程环境配置
  3. html自动执行的事件,js自执行事件
  4. Android隐藏EditText长按菜单中分享功能探索
  5. 第七季1:MP4文件格式解析
  6. tex文件用什么软件打开_pdf怎么打开?用什么软件打开pdf?
  7. 区块链每日一问 | 数字货币的场内交易和场外交易各指什么?各有哪些特点?...
  8. JSON.stringify()实现原理
  9. NSA漏洞预防,关闭有漏洞的端口
  10. Linux c/c++ IDE(开发环境)
  11. quickpcb添加pcb库_QuickPcb元件库下载
  12. 生物信息数据格式:fastq格式
  13. 有向图的深度优先遍历
  14. python 抖音短视频 去水印_如何去除抖音快手等短视频平台的水印?(工具+原理)...
  15. mysql,sqlserver查询表所有字段名
  16. Life:怎样提高睡眠质量?
  17. 【解决方案】Error response from daemon: Conflict. The container name /mongo is already in use by contain
  18. 有哪些地图编辑平台?制作地图软件哪个最好?
  19. MATLAB未找到支持的编译器或 sdk 解决方案
  20. JS - Array - 在数组的指定下标添加或替换元素 。 也可删除指定下标的元素

热门文章

  1. Keras中几个重要函数用法
  2. matlab计时,暂停
  3. 59 Celery架构
  4. unity球体添加光源_Unity渲染路径——光源种类
  5. python考试题库 pcap_使用Python修改PCAP
  6. linux qt检测u盘热插拔,【QT】动态监测U盘插拔
  7. php 负载监控_PHP监控linux服务器负载
  8. linux启动phpstudy,phpstudy启动不了解决方法
  9. 算法分析 载货问题_协会发布 | 汽车市场走势分析及2021年预测报告
  10. composer update报错: The https://packagist.phpcomposer.com/p/xxx file could not be downloaded