Skip to content

Commit 3df4cbe

Browse files
committed
添加Windows版脚本
1 parent 2d30bbf commit 3df4cbe

File tree

4 files changed

+101
-22
lines changed

4 files changed

+101
-22
lines changed

cg

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ set -e
66
# https://github.com/excel-code-generator/code-generator
77
CG_PATH=$HOME/.cg/bin/cg.jar
88

9-
if [ ! -f $CG_PATH ];then
10-
echo "`tput setaf 1`ERROR: The file \"$CG_PATH\" does not exist.`tput sgr0`"
11-
echo
12-
echo "For more information about the cg.jar, please vist the following page:"
13-
echo "`tput setaf 4`https://github.com/excel-code-generator/code-generator `tput sgr0`"
14-
exit 1
15-
fi
16-
179
# update
1810
do_update () {
1911
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/excel-code-generator/code-generator/master/install.sh)"
@@ -25,4 +17,13 @@ if [ "update" = "$1" ];then
2517
exit 0
2618
fi
2719

20+
if [ ! -f $CG_PATH ];then
21+
echo "`tput setaf 1`ERROR: The file \"$CG_PATH\" does not exist.`tput sgr0`"
22+
echo "run \``tput setaf 2`cg update`tput sgr0`\` command to reinstall."
23+
echo
24+
echo "For more information about the cg.jar, please vist the following page:"
25+
echo "`tput setaf 4`https://github.com/excel-code-generator/code-generator `tput sgr0`"
26+
exit 1
27+
fi
28+
2829
java -jar $CG_PATH $@

cg.bat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
3+
REM For more information about the cg.jar, please vist the following page:
4+
REM https://github.com/excel-code-generator/code-generator
5+
set CG_PATH=%APPDATA%\cg\bin\cg.jar
6+
7+
REM update
8+
if "update" == "%1" (
9+
echo update code generator
10+
powershell "iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/excel-code-generator/code-generator/master/install.ps1'))"
11+
12+
exit /B %ERRORLEVEL%
13+
)
14+
15+
if not exist %CG_PATH% (
16+
echo ERROR: The file %CG_PATH% does not exist.
17+
echo run `cg update` command to reinstall.
18+
echo=
19+
echo For more information about the cg.jar, please vist the following page:
20+
echo https://github.com/excel-code-generator/code-generator
21+
exit /B 1
22+
)
23+
24+
java -jar %CG_PATH% %*

install.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Set-StrictMode -Version Latest
2+
$ErrorActionPreference = "Stop"
3+
$PSDefaultParameterValues['*:ErrorAction']='Stop'
4+
5+
# Always download the latest version
6+
# For more information about the cg.jar, please vist the following page:
7+
# https://github.com/excel-code-generator/code-generator
8+
9+
$repo="excel-code-generator/code-generator"
10+
$repoPath="https://github.com/$repo"
11+
$rawPath="https://raw.githubusercontent.com/$repo"
12+
13+
# latest version
14+
echo "Get the latest version"
15+
$releasesUri = "https://api.github.com/repos/$repo/releases/latest"
16+
$tag = (Invoke-WebRequest $releasesUri | ConvertFrom-Json)[0].tag_name
17+
echo "Latest version: $tag"
18+
19+
# download
20+
echo "Downloading..."
21+
function download_file($name, $path) {
22+
echo "Download file $path "
23+
if ( Test-Path "$env:TEMP\$name" ) {
24+
del "$env:TEMP\$name"
25+
}
26+
27+
Invoke-WebRequest $path -Out "$env:TEMP\$name"
28+
}
29+
download_file cg "$rawPath/$tag/LICENSE"
30+
download_file cg.bat "$rawPath/$tag/cg.bat"
31+
download_file cg.jar "$repoPath/releases/download/$tag/cg.jar"
32+
echo "Download success."
33+
34+
# move file
35+
$cgPath = "$env:APPDATA\cg\bin"
36+
$existDir = Test-Path $cgPath
37+
if ($existDir -eq $False) {
38+
mkdir -p $cgPath
39+
}
40+
41+
mv "$env:TEMP\cg" $cgPath
42+
mv "$env:TEMP\cg.bat" $cgPath
43+
mv "$env:TEMP\cg.jar" $cgPath
44+
45+
# set environment
46+
echo "setting environment."
47+
$alreadyAdded = $False
48+
$path = [environment]::GetEnvironmentvariable("PATH", "User")
49+
$path.Split(";") | ForEach-Object -Process {if ($_ -eq $cgPath) { $alreadyAdded = $True }}
50+
51+
if (! $alreadyAdded) {
52+
$path = $path + ";" + $cgPath
53+
$path = [environment]::SetEnvironmentvariable("PATH", $path, "User")
54+
}
55+
56+
echo "Install success!"
57+
cg -v

install.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,33 @@ set -e
55
# For more information about the cg.jar, please vist the following page:
66
# https://github.com/excel-code-generator/code-generator
77

8-
CG_PATH="excel-code-generator/code-generator"
9-
BASE_PATH="https://github.com/$CG_PATH"
10-
RAW_PATH="https://raw.githubusercontent.com/$CG_PATH"
8+
repo="excel-code-generator/code-generator"
9+
repoPath="https://github.com/$repo"
10+
rawPath="https://raw.githubusercontent.com/$repo"
1111

1212
# latest version
1313
echo "Get the latest version"
14-
VER=`curl --silent "$BASE_PATH/releases/latest" | sed 's#.*tag/\(.*\)".*#\1#'`
15-
echo "Latest version: $VER"
14+
tag=`curl --silent "$repoPath/releases/latest" | sed 's#.*tag/\(.*\)".*#\1#'`
15+
echo "Latest version: $tag"
1616

1717
# download
18-
SH_FILE="$RAW_PATH/$VER/cg"
19-
JAR_FILE="$BASE_PATH/releases/download/$VER/cg.jar"
20-
2118
download_file() {
2219
echo "Download file `tput setaf 4`$2`tput sgr0`"
2320
curl -Lfo /tmp/$1 $2
2421
}
2522
echo "Downloading..."
26-
download_file cg $SH_FILE
27-
download_file cg.jar $JAR_FILE
23+
download_file cg "$rawPath/$tag/cg"
24+
download_file cg.jar "$repoPath/releases/download/$tag/cg.jar"
2825

2926
echo "Download success."
3027

3128
# move file
32-
CG_DIR=$HOME/.cg/bin
33-
mkdir -p $CG_DIR
29+
cgDir=$HOME/.cg/bin
30+
mkdir -p $cgDir
3431

3532
chmod +x /tmp/cg
36-
mv /tmp/cg /usr/local/bin/
37-
mv /tmp/cg.jar $CG_DIR/
33+
mv /tmp/cg /usr/bin/
34+
mv /tmp/cg.jar $cgDir/
3835

3936
echo "Install success!"
4037
cg -v

0 commit comments

Comments
 (0)