Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't override Intellij module config files #351

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/commands/clean.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ These files include;
- `{packageRoot}/.dart_tool/package_config.json`
- `{packageRoot}/.dart_tool/package_config_subset`
- `{packageRoot}/.dart_tool/version`
- `{packageRoot}/melos_{packageName}.iml`
- `{workspaceRoot}/melos_{workspaceName}.iml`
- `{workspaceRoot}/.idea/runConfigurations/melos_*.xml`

This can be useful to give your workspace a 'fresh start', e.g.;
Expand Down
39 changes: 31 additions & 8 deletions packages/melos/lib/src/common/intellij_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class IntellijProject {
return joinAll([package.path, 'melos_${package.name}.iml']);
}

String pathWorkspaceModuleIml() {
final workspaceModuleName = _workspace.config.name.toLowerCase();
return joinAll([_workspace.path, 'melos_$workspaceModuleName.iml']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need changing after #349

}

String injectTemplateVariable({
required String template,
required String variableName,
Expand Down Expand Up @@ -167,21 +172,43 @@ class IntellijProject {
}

Future<void> writePackageModule(Package package) async {
final path = pathPackageModuleIml(package);
if (fileExists(path)) {
// The user might have modified the module, so we don't want to overwrite
// them.
return;
}

final template = await readFileTemplate(
moduleTemplateFileForPackageType(package.type),
templateCategory: 'modules',
);
return forceWriteToFile(pathPackageModuleIml(package), template);

return forceWriteToFile(path, template);
}

Future<void> writePackageModules() async {
await Future.forEach(
_workspace.filteredPackages.values,
writePackageModule,
);
}

Future<void> writeWorkspaceModule() async {
final path = pathWorkspaceModuleIml();
if (fileExists(path)) {
// The user might have modified the module, so we don't want to overwrite
// them.
return;
}

final ideaWorkspaceModuleImlTemplate = await readFileTemplate(
'workspace_root_module.iml',
templateCategory: 'modules',
);
final workspaceModuleName = _workspace.config.name.toLowerCase();

return forceWriteToFile(
joinAll([_workspace.path, 'melos_$workspaceModuleName.iml']),
path,
ideaWorkspaceModuleImlTemplate,
);
}
Expand Down Expand Up @@ -312,11 +339,7 @@ class IntellijProject {
await writeNameFile();

// <WORKSPACE_ROOT>/<PACKAGE_DIR>/<PACKAGE_NAME>.iml

await Future.forEach(_workspace.filteredPackages.values,
(Package package) async {
await writePackageModule(package);
});
await writePackageModules();

// <WORKSPACE_ROOT>/<WORKSPACE_NAME>.iml
await writeWorkspaceModule();
Expand Down