Skip to content

Commit

Permalink
Adding artifact script
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Feb 4, 2025
1 parent ae7bd3e commit 12f93ba
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
86 changes: 86 additions & 0 deletions Scripts/artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/sh

# Default output location for the generated script
output_script="package_generated.sh"

echo "📝 Generating package script..."

# Create the new script
cat << 'EOF' > "$output_script"
#!/bin/sh
# Default values
swift_tools_version="6.0"
MINIMIZE=false
# Parse flags
while [ "$#" -gt 0 ]; do
case "$1" in
--version)
swift_tools_version="$2"
shift 2
;;
--minimize)
MINIMIZE=true
shift 1
;;
*)
PACKAGE_DIR="$1"
shift 1
;;
esac
done
echo "⚙️ Generating package..."
input_file=.package.source
output_file=Package.swift
cd $PACKAGE_DIR
# Hardcoded PackageDSL content
cat << 'PACKAGEDSL' > $input_file
EOF

# Add the PackageDSL content
find ../PackageDSL/Sources/PackageDSL -name '*.swift' -type f -exec cat {} + | awk '!/^[[:space:]]*(\/\/.*)?$|^import /' | sed -e 's/^[[:space:]]*//;s/[[:space:]]*$//' >> "$output_script"

# Continue with the rest of the script template
cat << 'EOF' >> "$output_script"
PACKAGEDSL
find Package/Sources -mindepth 2 -type f -name '*.swift' -not -path '*/\.*' -exec cat {} + >> $input_file
cat Package/Sources/*.swift >> $input_file
# Collect unique import statements
imports=$(awk '/^import / {imports[$0]=1} END {for (i in imports) print i}' "$input_file")
if [ "$MINIMIZE" = true ]; then
# Remove empty lines, lines containing only comments, and import statements
awk '!/^[[:space:]]*(\/\/.*)?$|^import /' "$input_file" > "$output_file.tmp"
# Remove leading and trailing whitespace from each line
sed -i '' -e 's/^[[:space:]]*//;s/[[:space:]]*$//' "$output_file.tmp"
# Append collected import statements at the beginning of the file
echo "// swift-tools-version: $swift_tools_version" > $output_file
echo "$imports" >> "$output_file"
cat "$output_file.tmp" >> "$output_file"
# Clean up temporary file
rm "$output_file.tmp"
else
# Append collected import statements at the beginning of the file
echo "// swift-tools-version: $swift_tools_version" > $output_file
# Append collected import statements at the beginning of the file
echo "$imports" >> "$output_file"
cat "$input_file" >> "$output_file"
fi
EOF

# Make the generated script executable
chmod +x "$output_script"

echo "✅ Generated package script at $output_script"
2 changes: 1 addition & 1 deletion Scripts/package.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# Default values
swift_tools_version="5.10"
swift_tools_version="6.0"
MINIMIZE=false

# Parse flags
Expand Down

0 comments on commit 12f93ba

Please sign in to comment.