-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add LICENSE file to all published packages
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# Check if LICENSE file exists in the root directory | ||
if [ ! -f LICENSE ]; then | ||
echo "LICENSE file not found in the root directory." | ||
exit 1 | ||
fi | ||
|
||
# Check if .gitignore file exists | ||
if [ ! -f .gitignore ]; then | ||
echo ".gitignore file not found in the root directory." | ||
exit 1 | ||
fi | ||
|
||
# Read .gitignore into an array, ignoring comments and empty lines | ||
gitignore_patterns=() | ||
while IFS= read -r line; do | ||
# Ignore comments and empty lines | ||
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue | ||
gitignore_patterns+=("$line") | ||
done <.gitignore | ||
|
||
# Create an array to keep track of created LICENSE files | ||
created_files=() | ||
|
||
# Function to check if a path matches any .gitignore pattern | ||
is_ignored() { | ||
local path=$1 | ||
for pattern in "${gitignore_patterns[@]}"; do | ||
if [[ $path == $pattern || $path == $pattern/* ]]; then | ||
return 0 | ||
fi | ||
done | ||
return 1 | ||
} | ||
|
||
# Find all directories containing a package.json file | ||
while IFS= read -r -d '' package_json; do | ||
dir=$(dirname "$package_json") | ||
# Check if directory is ignored | ||
if ! is_ignored "$dir"; then | ||
# Check if LICENSE file already exists in the directory | ||
if [ ! -f "$dir/LICENSE" ]; then | ||
# Copy the LICENSE file to the directory | ||
cp LICENSE "$dir" | ||
created_files+=("$dir/LICENSE") | ||
echo "Copied LICENSE to $dir" | ||
fi | ||
fi | ||
done < <(find . -name package.json -type f -not -path "*/node_modules/*" -print0) | ||
|
||
yarn workspaces foreach -At --no-private npm publish --access public --tag snapshot --tolerate-republish | ||
|
||
# Delete only the created LICENSE files | ||
for file in "${created_files[@]}"; do | ||
if [ -f "$file" ]; then | ||
rm "$file" | ||
echo "Deleted $file" | ||
fi | ||
done |