用自制的脚手架下载远程仓库代码

介绍

需要用到一个npm包download-git-repo

npm install download-git-repo

然后引入这个包使用

使用
download(repository, destination, options, callback)
const download = require('download-git-repo')
download('direct:https://gitee.com/haonanhu/vue3-vite-van-ui.git', './xxx', {clone: true}, (err) => {
    console.log(err)
})

参数解释:

repository

 这是你要下载的Git仓库的URL。它可以是GitHub、GitLab或Bitbucket等平台上的仓库地址。

destination

这是你想要下载并解压仓库内容的目标目录路径。如果该目录不存在,download-git-repo会尝试创建它。

options

这是一个对象,包含了一些额外的配置选项

  • clone: 默认为true,表示使用git clone命令来下载仓库。设置为false时,会使用git archive命令,这可能会更快,但不包括.git目录。
  • depth: 如果clonetrue,可以设置depth选项以进行浅克隆,即只获取最近的几次提交。
  • progress: 如果设置为true,则在下载过程中显示进度条。
  • recursive: 如果为true,则下载子模块。

callback

:这是一个回调函数,在下载过程结束后被调用。它接受一个错误对象作为参数,如果没有错误,则为null,否则会包含错误详情。

将它集成到我们自己的脚手架项目中

var inquirer = require('inquirer')
const download =  require('download-git-repo')
var config = require('../../../config')
const myAction = function (project, args) {
    {
        inquirer.prompt([{
            type: 'list',
            name: 'framwork',
            choices: config.framwork,
            message: '请选择你所使用的框架',
        }
        ]).then((answers) => {
            console.log(answers)
            console.log(config.framworkUrl[config.framwork])
            download(`direct:${config.framworkUrl[answers.framwork]}`, project,  (err) => {
                console.log(err)
            })
        })
    }
}
module.exports = myAction;

在action中写入然后全局mycli调用就可以

选完就可以克隆到本地

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值