Skip to content

Commit 906d3a6

Browse files
committed
Added build scripts
1 parent 19ad579 commit 906d3a6

File tree

114 files changed

+1886
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1886
-44
lines changed

app/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
### Guide
22
* Extract these files in ONE folder
3-
* Run `build.bat` to generate runnable software
3+
* Run `build_default_.bat` to quick generate runnable software (Windows x64)
4+
* Run `xxx.ps1` to build the program (linux, arm, etc.)

app/build.bat renamed to app/build_default.bat

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
cd /d "%~dp0"
44

5-
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0\build.ps1" %*
6-
7-
8-
pause
5+
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0\build_win_x64.ps1" %*

app/build_linux_arm64.ps1

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Requires PowerShell 3.0+
2+
# Script Directory
3+
$scriptDir = $PSScriptRoot
4+
$staticDir = Join-Path $scriptDir 'clash_core\linux-arm64\static'
5+
$mainDir = Join-Path $scriptDir 'main'
6+
$logoFile = Join-Path $scriptDir 'logo.ico'
7+
$outputDir = Join-Path $scriptDir 'output'
8+
$outWinDir = Join-Path $outputDir 'cfw-linux-arm64'
9+
10+
Write-Host 'Checking environment...'
11+
12+
# Checking static
13+
if (-not (Test-Path $staticDir)) {
14+
Write-Error 'Failed! "static" folder not found!'
15+
Read-Host 'Press Enter to exit'
16+
exit 1
17+
}
18+
# Checking main
19+
if (-not (Test-Path $mainDir)) {
20+
Write-Error 'Failed! "main" folder not found!'
21+
Read-Host 'Press Enter to exit'
22+
exit 1
23+
}
24+
# Checking logo.ico
25+
if (-not (Test-Path $logoFile)) {
26+
Write-Error 'Failed! "logo.ico" not found!'
27+
Read-Host 'Press Enter to exit'
28+
exit 1
29+
}
30+
31+
# Checking npm
32+
& npm --version > $null 2>&1
33+
if ($LASTEXITCODE -eq 0) {
34+
Write-Host 'npm is detected...'
35+
} else {
36+
Write-Error 'Failed! No npm command!'
37+
Write-Host 'Install Node.js might fix this.'
38+
Read-Host 'Press Enter to exit'
39+
exit 1
40+
}
41+
42+
# Checking electron-packager
43+
& npx electron-packager --version > $null 2>&1
44+
if ($LASTEXITCODE -eq 0) {
45+
Write-Host 'electron-packager is detected...'
46+
} else {
47+
Write-Warning 'Failed! No electron-packager command!'
48+
Write-Host 'But npm is detected!'
49+
Read-Host 'Press Enter to install electron-packager or Ctrl+C to exit'
50+
npm install -g electron-packager
51+
}
52+
53+
# Checking asar
54+
& npx asar --version > $null 2>&1
55+
if ($LASTEXITCODE -eq 0) {
56+
Write-Host 'asar is detected...'
57+
} else {
58+
Write-Warning 'Failed! No asar command!'
59+
Write-Host 'But npm is detected!'
60+
Read-Host 'Press Enter to install asar or Ctrl+C to exit'
61+
npm install -g asar
62+
}
63+
64+
Write-Host 'Success!'
65+
66+
# Clear old output
67+
if (Test-Path $outWinDir) {
68+
Write-Host 'Detected old output!'
69+
Read-Host 'Press Enter to delete and rebuild'
70+
Remove-Item -Recurse -Force $outWinDir
71+
Write-Host 'Success!'
72+
}
73+
74+
# Make sure output dir is existed
75+
if (-not (Test-Path $outputDir)) {
76+
New-Item -ItemType Directory -Path $outputDir | Out-Null
77+
}
78+
79+
# Start packaging
80+
Write-Host 'Starting electron-packager...'
81+
& npx electron-packager `
82+
"`"$mainDir`"" "cfw" `
83+
--platform=linux --arch=arm64 --electron-version=34.0.0 `
84+
--icon="`"$logoFile`"" --out="`"$outputDir`"" --prune=true --asar
85+
if ($LASTEXITCODE -ne 0) {
86+
Write-Error 'electron-packager Failed!'
87+
exit 1
88+
}
89+
90+
Write-Host 'Waiting app building...'
91+
Write-Host 'Note: If wait too long, it may mean that the execution has failed. Press Ctrl+C to terminate.'
92+
93+
# Wait for the program
94+
$exePath = Join-Path $outWinDir 'cfw'
95+
while (-not (Test-Path $exePath)) {
96+
Start-Sleep -Seconds 5
97+
}
98+
Write-Host 'Success!'
99+
100+
# Adding files
101+
Write-Host 'Adding proxy core files...'
102+
Start-Sleep -Seconds 1
103+
104+
$destStatic = Join-Path $outWinDir 'resources\static'
105+
106+
# Make sure resources dir is existed
107+
$resourcesDir = Split-Path $destStatic -Parent
108+
if (-not (Test-Path $resourcesDir)) {
109+
New-Item -ItemType Directory -Path $resourcesDir | Out-Null
110+
}
111+
112+
# Make sure static dir is existed
113+
if (-not (Test-Path $destStatic)) {
114+
New-Item -ItemType Directory -Path $destStatic | Out-Null
115+
}
116+
117+
# Then copy it
118+
Copy-Item -Path "$staticDir\*" -Destination $destStatic -Recurse -Force
119+
Write-Host 'Success!'
120+
121+
Write-Host 'Finish!'
122+
Read-Host 'Press Enter to exit'

app/build_linux_x64.ps1

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Requires PowerShell 3.0+
2+
# Script Directory
3+
$scriptDir = $PSScriptRoot
4+
$staticDir = Join-Path $scriptDir 'clash_core\linux-x64\static'
5+
$mainDir = Join-Path $scriptDir 'main'
6+
$logoFile = Join-Path $scriptDir 'logo.ico'
7+
$outputDir = Join-Path $scriptDir 'output'
8+
$outWinDir = Join-Path $outputDir 'cfw-linux-x64'
9+
10+
Write-Host 'Checking environment...'
11+
12+
# Checking static
13+
if (-not (Test-Path $staticDir)) {
14+
Write-Error 'Failed! "static" folder not found!'
15+
Read-Host 'Press Enter to exit'
16+
exit 1
17+
}
18+
# Checking main
19+
if (-not (Test-Path $mainDir)) {
20+
Write-Error 'Failed! "main" folder not found!'
21+
Read-Host 'Press Enter to exit'
22+
exit 1
23+
}
24+
# Checking logo.ico
25+
if (-not (Test-Path $logoFile)) {
26+
Write-Error 'Failed! "logo.ico" not found!'
27+
Read-Host 'Press Enter to exit'
28+
exit 1
29+
}
30+
31+
# Checking npm
32+
& npm --version > $null 2>&1
33+
if ($LASTEXITCODE -eq 0) {
34+
Write-Host 'npm is detected...'
35+
} else {
36+
Write-Error 'Failed! No npm command!'
37+
Write-Host 'Install Node.js might fix this.'
38+
Read-Host 'Press Enter to exit'
39+
exit 1
40+
}
41+
42+
# Checking electron-packager
43+
& npx electron-packager --version > $null 2>&1
44+
if ($LASTEXITCODE -eq 0) {
45+
Write-Host 'electron-packager is detected...'
46+
} else {
47+
Write-Warning 'Failed! No electron-packager command!'
48+
Write-Host 'But npm is detected!'
49+
Read-Host 'Press Enter to install electron-packager or Ctrl+C to exit'
50+
npm install -g electron-packager
51+
}
52+
53+
# Checking asar
54+
& npx asar --version > $null 2>&1
55+
if ($LASTEXITCODE -eq 0) {
56+
Write-Host 'asar is detected...'
57+
} else {
58+
Write-Warning 'Failed! No asar command!'
59+
Write-Host 'But npm is detected!'
60+
Read-Host 'Press Enter to install asar or Ctrl+C to exit'
61+
npm install -g asar
62+
}
63+
64+
Write-Host 'Success!'
65+
66+
# Clear old output
67+
if (Test-Path $outWinDir) {
68+
Write-Host 'Detected old output!'
69+
Read-Host 'Press Enter to delete and rebuild'
70+
Remove-Item -Recurse -Force $outWinDir
71+
Write-Host 'Success!'
72+
}
73+
74+
# Make sure output dir is existed
75+
if (-not (Test-Path $outputDir)) {
76+
New-Item -ItemType Directory -Path $outputDir | Out-Null
77+
}
78+
79+
# Start packaging
80+
Write-Host 'Starting electron-packager...'
81+
& npx electron-packager `
82+
"`"$mainDir`"" "cfw" `
83+
--platform=linux --arch=x64 --electron-version=34.0.0 `
84+
--icon="`"$logoFile`"" --out="`"$outputDir`"" --prune=true --asar
85+
if ($LASTEXITCODE -ne 0) {
86+
Write-Error 'electron-packager Failed!'
87+
exit 1
88+
}
89+
90+
Write-Host 'Waiting app building...'
91+
Write-Host 'Note: If wait too long, it may mean that the execution has failed. Press Ctrl+C to terminate.'
92+
93+
# Wait for the program
94+
$exePath = Join-Path $outWinDir 'cfw'
95+
while (-not (Test-Path $exePath)) {
96+
Start-Sleep -Seconds 5
97+
}
98+
Write-Host 'Success!'
99+
100+
# Adding files
101+
Write-Host 'Adding proxy core files...'
102+
Start-Sleep -Seconds 1
103+
104+
$destStatic = Join-Path $outWinDir 'resources\static'
105+
106+
# Make sure resources dir is existed
107+
$resourcesDir = Split-Path $destStatic -Parent
108+
if (-not (Test-Path $resourcesDir)) {
109+
New-Item -ItemType Directory -Path $resourcesDir | Out-Null
110+
}
111+
112+
# Make sure static dir is existed
113+
if (-not (Test-Path $destStatic)) {
114+
New-Item -ItemType Directory -Path $destStatic | Out-Null
115+
}
116+
117+
# Then copy it
118+
Copy-Item -Path "$staticDir\*" -Destination $destStatic -Recurse -Force
119+
Write-Host 'Success!'
120+
121+
Write-Host 'Finish!'
122+
Read-Host 'Press Enter to exit'

app/build_win32-ia32.ps1

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Requires PowerShell 3.0+
2+
# Script Directory
3+
$scriptDir = $PSScriptRoot
4+
$staticDir = Join-Path $scriptDir 'clash_core\win32-ia32\static'
5+
$mainDir = Join-Path $scriptDir 'main'
6+
$logoFile = Join-Path $scriptDir 'logo.ico'
7+
$outputDir = Join-Path $scriptDir 'output'
8+
$outWinDir = Join-Path $outputDir 'Clash for Windows-win32-ia32'
9+
10+
Write-Host 'Checking environment...'
11+
12+
# Checking static
13+
if (-not (Test-Path $staticDir)) {
14+
Write-Error 'Failed! "static" folder not found!'
15+
Read-Host 'Press Enter to exit'
16+
exit 1
17+
}
18+
# Checking main
19+
if (-not (Test-Path $mainDir)) {
20+
Write-Error 'Failed! "main" folder not found!'
21+
Read-Host 'Press Enter to exit'
22+
exit 1
23+
}
24+
# Checking logo.ico
25+
if (-not (Test-Path $logoFile)) {
26+
Write-Error 'Failed! "logo.ico" not found!'
27+
Read-Host 'Press Enter to exit'
28+
exit 1
29+
}
30+
31+
# Checking npm
32+
& npm --version > $null 2>&1
33+
if ($LASTEXITCODE -eq 0) {
34+
Write-Host 'npm is detected...'
35+
} else {
36+
Write-Error 'Failed! No npm command!'
37+
Write-Host 'Install Node.js might fix this.'
38+
Read-Host 'Press Enter to exit'
39+
exit 1
40+
}
41+
42+
# Checking electron-packager
43+
& npx electron-packager --version > $null 2>&1
44+
if ($LASTEXITCODE -eq 0) {
45+
Write-Host 'electron-packager is detected...'
46+
} else {
47+
Write-Warning 'Failed! No electron-packager command!'
48+
Write-Host 'But npm is detected!'
49+
Read-Host 'Press Enter to install electron-packager or Ctrl+C to exit'
50+
npm install -g electron-packager
51+
}
52+
53+
# Checking asar
54+
& npx asar --version > $null 2>&1
55+
if ($LASTEXITCODE -eq 0) {
56+
Write-Host 'asar is detected...'
57+
} else {
58+
Write-Warning 'Failed! No asar command!'
59+
Write-Host 'But npm is detected!'
60+
Read-Host 'Press Enter to install asar or Ctrl+C to exit'
61+
npm install -g asar
62+
}
63+
64+
Write-Host 'Success!'
65+
66+
# Clear old output
67+
if (Test-Path $outWinDir) {
68+
Write-Host 'Detected old output!'
69+
Read-Host 'Press Enter to delete and rebuild'
70+
Remove-Item -Recurse -Force $outWinDir
71+
Write-Host 'Success!'
72+
}
73+
74+
# Make sure output dir is existed
75+
if (-not (Test-Path $outputDir)) {
76+
New-Item -ItemType Directory -Path $outputDir | Out-Null
77+
}
78+
79+
# Start packaging
80+
Write-Host 'Starting electron-packager...'
81+
& npx electron-packager `
82+
"`"$mainDir`"" "Clash for Windows" `
83+
--platform=win32 --arch=ia32 --electron-version=34.0.0 `
84+
--icon="`"$logoFile`"" --out="`"$outputDir`"" --prune=true --asar
85+
if ($LASTEXITCODE -ne 0) {
86+
Write-Error 'electron-packager Failed!'
87+
exit 1
88+
}
89+
90+
Write-Host 'Waiting app building...'
91+
Write-Host 'Note: If wait too long, it may mean that the execution has failed. Press Ctrl+C to terminate.'
92+
93+
# Wait for the program
94+
$exePath = Join-Path $outWinDir 'Clash for Windows.exe'
95+
while (-not (Test-Path $exePath)) {
96+
Start-Sleep -Seconds 5
97+
}
98+
Write-Host 'Success!'
99+
100+
# Adding files
101+
Write-Host 'Adding proxy core files...'
102+
Start-Sleep -Seconds 1
103+
104+
$destStatic = Join-Path $outWinDir 'resources\static'
105+
106+
# Make sure resources dir is existed
107+
$resourcesDir = Split-Path $destStatic -Parent
108+
if (-not (Test-Path $resourcesDir)) {
109+
New-Item -ItemType Directory -Path $resourcesDir | Out-Null
110+
}
111+
112+
# Make sure static dir is existed
113+
if (-not (Test-Path $destStatic)) {
114+
New-Item -ItemType Directory -Path $destStatic | Out-Null
115+
}
116+
117+
# Then copy it
118+
Copy-Item -Path "$staticDir\*" -Destination $destStatic -Recurse -Force
119+
Write-Host 'Success!'
120+
121+
Write-Host 'Finish!'
122+
Read-Host 'Press Enter to exit'

0 commit comments

Comments
 (0)