Skip to content

Commit

Permalink
feat: write merged dist-workspace.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Dec 19, 2024
1 parent fb9771d commit 46ce241
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use axoasset::toml_edit;
use axoasset::{toml_edit, LocalAsset};
use axoproject::{WorkspaceGraph, WorkspaceInfo, WorkspaceKind};
use camino::Utf8PathBuf;
use cargo_dist_schema::TripleNameRef;
Expand Down Expand Up @@ -162,23 +162,39 @@ fn do_migrate_from_dist_toml() -> DistResult<()> {

// OK, now we know we have a root-level dist.toml. Time to fix that.
let workspace_toml = config::load_toml(&root_workspace.manifest_path)?;
let mut original_workspace_toml = workspace_toml.clone();

eprintln!("Migrating tables");
// Init a generic workspace with the appropriate members
let mut new_workspace_toml = new_generic_workspace();
// Copy the [dist] section
// First copy the [package] section
if let Some(package) = workspace_toml.get("package") {
let mut package = package.clone();
// Ensures we have whitespace between the end of [workspace] and
// the start of [package]
if let Some(table) = package.as_table_mut() {
let decor = table.decor_mut();
// Try to keep existing comments if we can
if let Some(desc) = decor.prefix().and_then(|p| p.as_str()) {
if !desc.starts_with('\n') {
decor.set_prefix(&format!("\n{desc}"));
}
} else {
decor.set_prefix("\n");
}
}
new_workspace_toml.insert("package", package.to_owned());
}
// ...then copy the [dist] section
if let Some(dist) = workspace_toml.get("dist") {
new_workspace_toml.insert("dist", dist.to_owned());
}
// Then prune it from the old copy
original_workspace_toml.remove("dist");

// Finally, write out the new config...
let filename = "dist-workspace.toml";
let destination = root_workspace.workspace_dir.join(filename);
config::write_toml(&destination, new_workspace_toml)?;
// ...and write the modified config
config::write_toml(&root_workspace.manifest_path, original_workspace_toml)?;
// ...and delete the old config
LocalAsset::remove_file(&root_workspace.manifest_path)?;

Ok(())
}
Expand Down

0 comments on commit 46ce241

Please sign in to comment.