Skip to content

Commit

Permalink
feat: Add support for executeInTerminal for IntelliJ run configs (#857)
Browse files Browse the repository at this point in the history
## Description

This PR aims to add support for `executeInTerminal` for IntelliJ run
configurations allowing scripts to be ran in the "Run" panel instead of
the terminal

## Type of Change

- [x] ✨ `feat` -- New feature (non-breaking change which adds
functionality)
- [ ] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 `refactor` -- Code refactor
- [ ] ✅ `ci` -- Build configuration change
- [ ] 📝 `docs` -- Documentation
- [ ] 🗑️ `chore` -- Chore
  • Loading branch information
exaby73 authored Feb 1, 2025
1 parent 50b102b commit b6acf50
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
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

0 comments on commit b6acf50

Please sign in to comment.