Skip to content

Commit b6acf50

Browse files
authored
feat: Add support for executeInTerminal for IntelliJ run configs (#857)
## 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
1 parent 50b102b commit b6acf50

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

docs/configuration/overview.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ collisions with other IntelliJ modules you may already have in place.
119119

120120
The default is 'melos\_'.
121121

122+
### executeInTerminal
123+
124+
Whether to execute the script in a terminal.
125+
126+
The default is `true`.
127+
128+
```yaml
129+
melos:
130+
ide:
131+
intellij:
132+
executeInTerminal: false
133+
```
134+
122135
## scripts
123136

124137
Define custom scripts that can be executed in the workspace via the

packages/melos/lib/src/common/intellij_project.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class IntellijProject {
143143
'fileurl="file://\$PROJECT_DIR\$/$imlPath" '
144144
'filepath="\$PROJECT_DIR\$/$imlPath" '
145145
'/>';
146-
// Pad to preserve formatting on generated file. Indent x6.
147-
return ' $module';
146+
// Pad to preserve formatting on generated file.
147+
return module.padLeft(6);
148148
}
149149

150150
Future<void> forceWriteToFile(String filePath, String fileContents) async {
@@ -265,6 +265,8 @@ class IntellijProject {
265265
'scriptName': scriptName,
266266
'scriptArgs': scriptArgs,
267267
'scriptPath': getMelosBinForIde(),
268+
'executeInTerminal':
269+
_workspace.config.ide.intelliJ.executeInTerminal.toString(),
268270
});
269271

270272
final outputFile = p.join(

packages/melos/lib/src/workspace_config.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class IntelliJConfig {
6565
const IntelliJConfig({
6666
this.enabled = _defaultEnabled,
6767
this.moduleNamePrefix = _defaultModuleNamePrefix,
68+
this.executeInTerminal = _defaultExecuteInTerminal,
6869
});
6970

7071
factory IntelliJConfig.fromYaml(Object? yaml) {
@@ -79,9 +80,17 @@ class IntelliJConfig {
7980
final enabled = yaml.containsKey('enabled')
8081
? assertKeyIsA<bool>(key: 'enabled', map: yaml, path: 'ide/intellij')
8182
: _defaultEnabled;
83+
final executeInTerminal = yaml.containsKey('executeInTerminal')
84+
? assertKeyIsA<bool>(
85+
key: 'executeInTerminal',
86+
map: yaml,
87+
path: 'ide/intellij',
88+
)
89+
: _defaultExecuteInTerminal;
8290
return IntelliJConfig(
8391
enabled: enabled,
8492
moduleNamePrefix: moduleNamePrefix,
93+
executeInTerminal: executeInTerminal,
8594
);
8695
} else {
8796
final enabled = assertIsA<bool>(
@@ -96,15 +105,19 @@ class IntelliJConfig {
96105
static const empty = IntelliJConfig();
97106
static const _defaultModuleNamePrefix = 'melos_';
98107
static const _defaultEnabled = true;
108+
static const _defaultExecuteInTerminal = true;
99109

100110
final bool enabled;
101111

102112
final String moduleNamePrefix;
103113

114+
final bool executeInTerminal;
115+
104116
Object? toJson() {
105117
return {
106118
'enabled': enabled,
107119
'moduleNamePrefix': moduleNamePrefix,
120+
'executeInTerminal': executeInTerminal,
108121
};
109122
}
110123

@@ -113,18 +126,23 @@ class IntelliJConfig {
113126
other is IntelliJConfig &&
114127
runtimeType == other.runtimeType &&
115128
other.enabled == enabled &&
116-
other.moduleNamePrefix == moduleNamePrefix;
129+
other.moduleNamePrefix == moduleNamePrefix &&
130+
other.executeInTerminal == executeInTerminal;
117131

118132
@override
119133
int get hashCode =>
120-
runtimeType.hashCode ^ enabled.hashCode ^ moduleNamePrefix.hashCode;
134+
runtimeType.hashCode ^
135+
enabled.hashCode ^
136+
moduleNamePrefix.hashCode ^
137+
executeInTerminal.hashCode;
121138

122139
@override
123140
String toString() {
124141
return '''
125142
IntelliJConfig(
126143
enabled: $enabled,
127144
moduleNamePrefix: $moduleNamePrefix,
145+
executeInTerminal: $executeInTerminal,
128146
)
129147
''';
130148
}

packages/melos/templates/intellij/runConfigurations/shell_script.xml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="false" />
77
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
88
<option name="SCRIPT_TEXT" value="melos {{#scriptArgs}}" />
9+
<option name="EXECUTE_IN_TERMINAL" value="{{#executeInTerminal}}"/>
910
<method v="2" />
1011
</configuration>
1112
</component>

packages/melos/test/workspace_config_test.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,24 @@ void main() {
337337
);
338338
});
339339

340+
test('executeInTerminal is true by default', () {
341+
expect(
342+
IDEConfigs.empty.intelliJ.executeInTerminal,
343+
true,
344+
);
345+
});
346+
340347
group('fromYaml', () {
341348
test('supports empty map', () {
342349
expect(
343350
IDEConfigs.fromYaml(const {}),
344351
isA<IDEConfigs>()
345-
.having((e) => e.intelliJ.enabled, 'intelliJ.enabled', true),
352+
.having((e) => e.intelliJ.enabled, 'intelliJ.enabled', true)
353+
.having(
354+
(e) => e.intelliJ.executeInTerminal,
355+
'intelliJ.executeInTerminal',
356+
true,
357+
),
346358
);
347359
});
348360

0 commit comments

Comments
 (0)