Skip to content

Commit 1a90e7d

Browse files
committed
feat: add redirect support for plugin rename
Though code references do not change in a plugin rename, content references will change as the root package element for plugin content is the name of the plugin. This commit adds support to the rename plugin workflow for redirects (adding a new one and updating existing ones) to prevent breakage on rename.
1 parent d8c5058 commit 1a90e7d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/workflows/rename_plugin/changeset.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use crate::{
4-
changes::{Change, RenameFile, ReplaceInFile},
4+
changes::{AppendIniEntry, Change, RenameFile, ReplaceInFile},
55
unreal::Plugin,
66
};
77

@@ -36,6 +36,8 @@ pub fn generate_changeset(context: &Context) -> Vec<Change> {
3636
old_name,
3737
new_name,
3838
));
39+
changeset.push(update_existing_redirects(project_root, old_name, new_name));
40+
changeset.push(append_plugin_redirect(project_root, old_name, new_name));
3941

4042
changeset
4143
}
@@ -84,3 +86,29 @@ fn rename_plugin_references_in_plugin(plugin: &Plugin, old_name: &str, new_name:
8486
format!(r#""{new_name}""#),
8587
))
8688
}
89+
90+
fn update_existing_redirects(project_root: &Path, old_name: &str, new_name: &str) -> Change {
91+
Change::ReplaceInFile(ReplaceInFile::new(
92+
project_root.join("Config").join("DefaultEngine.ini"),
93+
format!(
94+
r#"\(OldName="/(?P<old>.+?)/",\s*NewName="/{}/",\s*MatchSubstring=true\)"#,
95+
old_name
96+
),
97+
format!(
98+
r#"(OldName="/$old/",NewName="/{}/",MatchSubstring=true)"#,
99+
new_name
100+
),
101+
))
102+
}
103+
104+
fn append_plugin_redirect(project_root: &Path, old_name: &str, new_name: &str) -> Change {
105+
Change::AppendIniEntry(AppendIniEntry::new(
106+
project_root.join("Config").join("DefaultEngine.ini"),
107+
"CoreRedirects",
108+
"+PackageRedirects",
109+
format!(
110+
r#"(OldName="/{}/",NewName="/{}/",MatchSubstring=true)"#,
111+
old_name, new_name
112+
),
113+
))
114+
}

0 commit comments

Comments
 (0)