|
20 | 20 |
|
21 | 21 | echo "Migrating $COMPOSER_FILE from WPackagist to WP Composer..." |
22 | 22 |
|
| 23 | +# Detect indent: find first indented line and count leading spaces |
| 24 | +INDENT=$(awk '/^[ \t]+[^ \t]/ { match($0, /^[ \t]+/); print RLENGTH; exit }' "$COMPOSER_FILE") |
| 25 | +if [[ -z "$INDENT" || "$INDENT" -lt 1 ]]; then |
| 26 | + INDENT=4 |
| 27 | +fi |
| 28 | + |
23 | 29 | # Rename wpackagist-plugin/* → wp-plugin/* and wpackagist-theme/* → wp-theme/* |
24 | | -# in both require and require-dev, then swap the repository entry |
25 | | -jq ' |
| 30 | +# in require, require-dev, and extra.patches, then swap the repository entry |
| 31 | +jq --indent "$INDENT" ' |
26 | 32 | # Rename package keys in a given object |
27 | 33 | def rename_packages: |
28 | 34 | to_entries | map( |
|
40 | 46 | # Rename packages in require-dev |
41 | 47 | (if .["require-dev"] then .["require-dev"] |= rename_packages else . end) | |
42 | 48 |
|
43 | | - # Replace wpackagist repository with wp-composer |
| 49 | + # Rename packages in extra.patches (composer-patches plugin) |
| 50 | + (if .extra.patches then .extra.patches |= rename_packages else . end) | |
| 51 | +
|
| 52 | + # Filter out wpackagist repo entry |
| 53 | + def is_wpackagist: |
| 54 | + (.url // "" | test("wpackagist\\.org")) or ((.name // "") == "wpackagist"); |
| 55 | +
|
| 56 | + # WP Composer repo entry |
| 57 | + def wp_composer_repo: |
| 58 | + { |
| 59 | + "name": "wp-composer", |
| 60 | + "type": "composer", |
| 61 | + "url": "https://wp-composer.com", |
| 62 | + "only": ["wp-plugin/*", "wp-theme/*"] |
| 63 | + }; |
| 64 | +
|
| 65 | + # Replace wpackagist repository with wp-composer (handles both array and object formats) |
44 | 66 | (if .repositories then |
45 | | - .repositories = [ |
46 | | - (.repositories[] | select( |
47 | | - (.url // "" | test("wpackagist\\.org") | not) and |
48 | | - ((.name // "") != "wpackagist") |
49 | | - )), |
50 | | - { |
51 | | - "name": "wp-composer", |
52 | | - "type": "composer", |
53 | | - "url": "https://wp-composer.com", |
54 | | - "only": ["wp-plugin/*", "wp-theme/*"] |
55 | | - } |
56 | | - ] |
| 67 | + if (.repositories | type) == "array" then |
| 68 | + .repositories = [(.repositories[] | select(is_wpackagist | not)), wp_composer_repo] |
| 69 | + else |
| 70 | + # Object format: remove wpackagist entries by key, add wp-composer |
| 71 | + .repositories |= ( |
| 72 | + to_entries |
| 73 | + | map(select(.value | is_wpackagist | not)) |
| 74 | + | from_entries |
| 75 | + ) |
| 76 | + | .repositories["wp-composer"] = (wp_composer_repo | del(.name)) |
| 77 | + end |
57 | 78 | else . end) |
58 | 79 | ' "$COMPOSER_FILE" > "${COMPOSER_FILE}.tmp" && mv "${COMPOSER_FILE}.tmp" "$COMPOSER_FILE" |
59 | 80 |
|
60 | 81 | echo "Done! Changes made to $COMPOSER_FILE:" |
61 | 82 | echo " - Renamed wpackagist-plugin/* → wp-plugin/*" |
62 | 83 | echo " - Renamed wpackagist-theme/* → wp-theme/*" |
| 84 | +echo " - Renamed wpackagist-plugin/*, wpackagist-theme/* in extra.patches" |
63 | 85 | echo " - Replaced WPackagist repository with WP Composer" |
64 | 86 | echo "" |
65 | 87 | echo "Run 'composer update' to install packages from WP Composer." |
0 commit comments