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

feat: Add support for executeInTerminal for IntelliJ run configs #857

Merged
merged 3 commits into from
Feb 1, 2025
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
13 changes: 13 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ collisions with other IntelliJ modules you may already have in place.

The default is 'melos\_'.

### executeInTerminal

Whether to execute the script in a terminal.

The default is `true`.

```yaml
melos:
ide:
intellij:
executeInTerminal: false
```

## scripts

Define custom scripts that can be executed in the workspace via the
Expand Down
6 changes: 4 additions & 2 deletions packages/melos/lib/src/common/intellij_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class IntellijProject {
'fileurl="file://\$PROJECT_DIR\$/$imlPath" '
'filepath="\$PROJECT_DIR\$/$imlPath" '
'/>';
// Pad to preserve formatting on generated file. Indent x6.
return ' $module';
// Pad to preserve formatting on generated file.
return module.padLeft(6);
}

Future<void> forceWriteToFile(String filePath, String fileContents) async {
Expand Down Expand Up @@ -265,6 +265,8 @@ class IntellijProject {
'scriptName': scriptName,
'scriptArgs': scriptArgs,
'scriptPath': getMelosBinForIde(),
'executeInTerminal':
_workspace.config.ide.intelliJ.executeInTerminal.toString(),
});

final outputFile = p.join(
Expand Down
22 changes: 20 additions & 2 deletions packages/melos/lib/src/workspace_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class IntelliJConfig {
const IntelliJConfig({
this.enabled = _defaultEnabled,
this.moduleNamePrefix = _defaultModuleNamePrefix,
this.executeInTerminal = _defaultExecuteInTerminal,
});

factory IntelliJConfig.fromYaml(Object? yaml) {
Expand All @@ -79,9 +80,17 @@ class IntelliJConfig {
final enabled = yaml.containsKey('enabled')
? assertKeyIsA<bool>(key: 'enabled', map: yaml, path: 'ide/intellij')
: _defaultEnabled;
final executeInTerminal = yaml.containsKey('executeInTerminal')
? assertKeyIsA<bool>(
key: 'executeInTerminal',
map: yaml,
path: 'ide/intellij',
)
: _defaultExecuteInTerminal;
return IntelliJConfig(
enabled: enabled,
moduleNamePrefix: moduleNamePrefix,
executeInTerminal: executeInTerminal,
);
} else {
final enabled = assertIsA<bool>(
Expand All @@ -96,15 +105,19 @@ class IntelliJConfig {
static const empty = IntelliJConfig();
static const _defaultModuleNamePrefix = 'melos_';
static const _defaultEnabled = true;
static const _defaultExecuteInTerminal = true;

final bool enabled;

final String moduleNamePrefix;

final bool executeInTerminal;

Object? toJson() {
return {
'enabled': enabled,
'moduleNamePrefix': moduleNamePrefix,
'executeInTerminal': executeInTerminal,
};
}

Expand All @@ -113,18 +126,23 @@ class IntelliJConfig {
other is IntelliJConfig &&
runtimeType == other.runtimeType &&
other.enabled == enabled &&
other.moduleNamePrefix == moduleNamePrefix;
other.moduleNamePrefix == moduleNamePrefix &&
other.executeInTerminal == executeInTerminal;

@override
int get hashCode =>
runtimeType.hashCode ^ enabled.hashCode ^ moduleNamePrefix.hashCode;
runtimeType.hashCode ^
enabled.hashCode ^
moduleNamePrefix.hashCode ^
executeInTerminal.hashCode;

@override
String toString() {
return '''
IntelliJConfig(
enabled: $enabled,
moduleNamePrefix: $moduleNamePrefix,
executeInTerminal: $executeInTerminal,
)
''';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="false" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="SCRIPT_TEXT" value="melos {{#scriptArgs}}" />
<option name="EXECUTE_IN_TERMINAL" value="{{#executeInTerminal}}"/>
<method v="2" />
</configuration>
</component>
14 changes: 13 additions & 1 deletion packages/melos/test/workspace_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,24 @@ void main() {
);
});

test('executeInTerminal is true by default', () {
expect(
IDEConfigs.empty.intelliJ.executeInTerminal,
true,
);
});

group('fromYaml', () {
test('supports empty map', () {
expect(
IDEConfigs.fromYaml(const {}),
isA<IDEConfigs>()
.having((e) => e.intelliJ.enabled, 'intelliJ.enabled', true),
.having((e) => e.intelliJ.enabled, 'intelliJ.enabled', true)
.having(
(e) => e.intelliJ.executeInTerminal,
'intelliJ.executeInTerminal',
true,
),
);
});

Expand Down
Loading