-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathpush.ps1
65 lines (61 loc) · 1.62 KB
/
push.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<##
# Author: Cyanashi([email protected])
# Version: 1.0.2
# Last_Updated: 2020-03-31
# Description: 一键push
#>
$debug = $false
$curtime = Get-Date
if ([String]::IsNullOrEmpty($args[0])) {
$commitWithMessage = "Updated@$($curtime)"
}
else {
$extraMsg = [String]$args[0]
For ($i = 1; $i -lt $args.Count; $i++) {
$extraMsg += " $($args[$i])"
}
$commitWithMessage = "Updated@$($curtime) $($extraMsg.Trim())"
}
$script:workspace = Split-Path -Parent $MyInvocation.MyCommand.Definition
$script:autoDelete = "" # 需要删除的文件夹写在这里即可 比如 \public
$script:commandString = @"
git add .
git commit -m`"$($commitWithMessage)`"
git push -u origin
git push gitee
"@
<##
# @func Initialize-WorkingDirectory
# @desc 初始化工作 在执行$script:commandString前运行
#>
function Initialize-WorkingDirectory {
Set-Location $script:workspace
if (-not [String]::IsNullOrEmpty($script:autoDelete)) {
$public = $script:workspace + $script:autoDelete
if (Test-Path $public -and $public -ne $script:workspace) {
Remove-Item $public -Recurse
}
}
}
<##
# @func Invoke-Command
# @desc 执行设定的指令
# @param {Boolean} $is_debug 是否为调试模式
#>
function Invoke-Command {
[CmdletBinding()]
param (
[Boolean]$is_debug = $true
)
if ($is_debug) {
$debugInfo = "[DEBUG] Try to exec this command:`n" + $script:commandString
Write-Host $debugInfo
}
else {
$command = [scriptblock]::Create($script:commandString)
& $command
}
}
Initialize-WorkingDirectory
#$debug = $true
Invoke-Command($debug)