zoukankan      html  css  js  c++  java
  • 使用bat脚本部署hexo到coding和github

    因项目的不同适当的改造吧,本文以hexo为例。

    拉取coding.net的代码和github的代码到本地

    1. 确保代码能够正常的运行,commit,push
    2. 在项目的目录外新建一个push.bat文件

    快速预览

    如何一步到位提交到仓库

    脚本中的变量说明

    • artsPath 新增文章的目录
    • codingPath coding的目录
    • githubPath github的目录

    复制文章然后自动执行命令进行部署

    修改脚本中对应的路径后执行push

    xcopy F:CodingReposymhexoarts F:CodingReposymhexoyimocodingsource\_posts /Y
    cd F:CodingReposymhexoyimocoding
    call git pull
    call hexo clean
    call hexo d -g
    call git add *
    call git commit -m AddArticle
    call git push
    

    优化v1-加入变量并读取第一个参数为注释

    查阅了果然cmd是有变量的,所以提前了路径到变量中,注释也可以传入了
    使用push 修改文章,提交之后注释为update_修改文章,可省略参数

    set artsPath=F:CodingReposymhexoarts
    set codingPath=F:CodingReposymhexoyimocoding
    set githubPath=F:CodingReposymhexoyimogit.github.io
    
    xcopy %artsPath% %codingPath%source\_posts /Y
    cd /d %codingPath%
    call git pull
    call hexo clean
    call hexo d -g
    call git add *
    call git commit -m update_%1
    call git push
    

    优化v2-多个仓库的部署

    复制粘贴是最简单的了,but~ 我感觉还能再优化下
    定义变量,然后保存到字符串str中,通过赋值str后调整到for取下一个值实现一个路径的先入先出的T_T【笑哭】可以算作循环数组的方法了

    
    @echo off
    set artsPath=F:CodingReposymhexoarts
    REM coding的目录
    set codingPath=F:CodingReposymhexoyimocoding
    REM github的目录
    set githubPath=F:CodingReposymhexoyimogit.github.io
    REM 默认注释add_article,第一个参数为注释
    set notes=%1 
    if "%1"=="" set notes=add_article
    REM 拼接coding和github的目录地址,路径中不能含有空格
    set str="%codingPath% %githubPath%"
    
    :STR_START
    for /f "tokens=1,*" %%a in (%str%) do (
        REM 复制文章到此仓库
        xcopy %artsPath% %%asource\_posts /Y
        REM 重定向到此仓库
        cd /d %%a
        REM 更新推送等操作
        call git pull
        call hexo clean
        call hexo d -g
        call git add *
        call git commit -m %notes%
        call git push
        REM 重新将新字符串赋值个str,并重新开时循环新的字符串
        set str="%%b"
        goto STR_START
    )
    
    

    过去过不去的都会过去

    不愿干重复的事情~
    就是如此的懒~
    能一个脚本干完所有事简直完美~
    不知道有没有比这种方法更好的实现

  • 相关阅读:
    C#计算一段程序运行时间的三种方法
    jquery easyui combobox设置默认选中第一项
    ASP.NET Web API教程 分页查询
    ASP.NET Web Api 实现数据的分页
    开源.net 混淆器ConfuserEx介绍
    C#软件license管理(简单软件注册机制)
    MyBatis入门实例-包括实体类与数据库字段对应&CLOB字段处理
    MyBatis在insert插入操作时返回主键ID的配置
    MyBatis框架——mybatis插入数据返回主键(mysql、oracle)
    关于java中split的使用
  • 原文地址:https://www.cnblogs.com/morang/p/cmd-batch-pull-git.html
Copyright © 2011-2022 走看看