Skip to content

Commit 07da0fc

Browse files
committed
Release v2.0.2: Merge branch 'dev'
2 parents 8fa35f2 + bec0435 commit 07da0fc

1 file changed

Lines changed: 60 additions & 55 deletions

File tree

src/Compile-SourceScript/Public/Compile-SourceScript.ps1

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,68 +41,73 @@ function Compile-SourceScript {
4141
)
4242

4343
begin {
44-
$ErrorActionPreference = 'Stop'
45-
"Starting Compile-SourceScript" | Write-Host -ForegroundColor Cyan
44+
try {
45+
$ErrorActionPreference = 'Stop'
46+
"Starting Compile-SourceScript" | Write-Host -ForegroundColor Cyan
4647

47-
# Verify the specified item's type and extension
48-
$sourceFile = Get-Item -Path $PSBoundParameters['File']
49-
if (!(Test-Path -Path $sourceFile.FullName -PathType Leaf)) {
50-
throw "The item is not a file."
51-
}
52-
$MOD_NAME = if ($sourceFile.Extension -eq '.sp') { 'sourcemod' }
53-
elseif ($sourceFile.Extension -eq '.sma') { 'amxmodx' }
54-
if (!$MOD_NAME) {
55-
throw "File is not a '.sp' or '.sma' source file."
56-
}
48+
# Verify the specified item's type and extension
49+
$sourceFile = Get-Item -Path $PSBoundParameters['File']
50+
if (!(Test-Path -Path $sourceFile.FullName -PathType Leaf)) {
51+
throw "The item is not a file."
52+
}
53+
$MOD_NAME = if ($sourceFile.Extension -eq '.sp') { 'sourcemod' }
54+
elseif ($sourceFile.Extension -eq '.sma') { 'amxmodx' }
55+
if (!$MOD_NAME) {
56+
throw "File is not a '.sp' or '.sma' source file."
57+
}
5758

58-
# Initialize variables
59-
$MOD = @{
60-
sourcemod = @{
61-
script_ext = '.sp'
62-
plugin_ext = '.smx'
63-
compiled_dir_name = 'compiled'
64-
plugins_dir_name = 'plugins'
65-
compiler = @{
66-
windows = @{
67-
wrapper = 'compile.exe'
68-
bin = 'spcomp.exe'
69-
}
70-
others = @{
71-
wrapper = 'compile.sh'
72-
bin = 'spcomp'
59+
# Initialize variables
60+
$MOD = @{
61+
sourcemod = @{
62+
script_ext = '.sp'
63+
plugin_ext = '.smx'
64+
compiled_dir_name = 'compiled'
65+
plugins_dir_name = 'plugins'
66+
compiler = @{
67+
windows = @{
68+
wrapper = 'compile.exe'
69+
bin = 'spcomp.exe'
70+
}
71+
others = @{
72+
wrapper = 'compile.sh'
73+
bin = 'spcomp'
74+
}
7375
}
7476
}
75-
}
76-
amxmodx = @{
77-
script_ext = '.sma'
78-
plugin_ext = '.amxx'
79-
compiled_dir_name = 'compiled'
80-
plugins_dir_name = 'plugins'
81-
compiler = @{
82-
windows = @{
83-
wrapper = 'compile.exe'
84-
bin = 'amxxpc.exe'
85-
}
86-
others = @{
87-
wrapper = 'compile.sh'
88-
bin = 'amxxpc'
77+
amxmodx = @{
78+
script_ext = '.sma'
79+
plugin_ext = '.amxx'
80+
compiled_dir_name = 'compiled'
81+
plugins_dir_name = 'plugins'
82+
compiler = @{
83+
windows = @{
84+
wrapper = 'compile.exe'
85+
bin = 'amxxpc.exe'
86+
}
87+
others = @{
88+
wrapper = 'compile.sh'
89+
bin = 'amxxpc'
90+
}
8991
}
9092
}
9193
}
92-
}
93-
$COMPILER_NAME = if ($env:OS) {
94-
if ($PSBoundParameters['SkipWrapper']) { $MOD[$MOD_NAME]['compiler']['windows']['bin'] }
95-
else { $MOD[$MOD_NAME]['compiler']['windows']['wrapper'] }
96-
}else {
97-
if ($PSBoundParameters['SkipWrapper']) { $MOD[$MOD_NAME]['compiler']['others']['bin'] }
98-
else { $MOD[$MOD_NAME]['compiler']['others']['wrapper'] }
99-
}
100-
$SCRIPTING_DIR = $sourceFile.DirectoryName
101-
$COMPILED_DIR = Join-Path $SCRIPTING_DIR $MOD[$MOD_NAME]['compiled_dir_name']
102-
$PLUGINS_DIR = Join-Path (Split-Path $SCRIPTING_DIR -Parent) $MOD[$MOD_NAME]['plugins_dir_name']
94+
$COMPILER_NAME = if ($env:OS) {
95+
if ($PSBoundParameters['SkipWrapper']) { $MOD[$MOD_NAME]['compiler']['windows']['bin'] }
96+
else { $MOD[$MOD_NAME]['compiler']['windows']['wrapper'] }
97+
}else {
98+
if ($PSBoundParameters['SkipWrapper']) { $MOD[$MOD_NAME]['compiler']['others']['bin'] }
99+
else { $MOD[$MOD_NAME]['compiler']['others']['wrapper'] }
100+
}
101+
$SCRIPTING_DIR = $sourceFile.DirectoryName
102+
$COMPILED_DIR = Join-Path $SCRIPTING_DIR $MOD[$MOD_NAME]['compiled_dir_name']
103+
$PLUGINS_DIR = Join-Path (Split-Path $SCRIPTING_DIR -Parent) $MOD[$MOD_NAME]['plugins_dir_name']
103104

104-
# Verify the presence of the compiler item
105-
$compiler = Get-Item -Path (Join-Path $SCRIPTING_DIR $COMPILER_NAME)
105+
# Verify the presence of the compiler item
106+
$compiler = Get-Item -Path (Join-Path $SCRIPTING_DIR $COMPILER_NAME)
107+
108+
}catch {
109+
Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject
110+
}
106111

107112
}process {
108113
try {
@@ -216,7 +221,7 @@ function Compile-SourceScript {
216221
}
217222

218223
}catch {
219-
throw
224+
Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject
220225
}finally {
221226
# Cleanup
222227
if ($stdInFile) {

0 commit comments

Comments
 (0)