Skip to content

Commit cae0276

Browse files
committed
Add support for custom port for task
1 parent b0af38e commit cae0276

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

src/project/tasks.js

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ export class ProjectTasks {
1818
{
1919
name: 'Upload',
2020
args: ['run', '--target', 'upload'],
21+
optionalPortArgs: ['--upload-port'],
2122
multienv: true,
2223
},
2324
{
2425
name: 'Monitor',
2526
args: ['device', 'monitor'],
27+
optionalPortArgs: ['--port'],
2628
multienv: true,
2729
},
2830
{
2931
name: 'Upload and Monitor',
3032
args: ['run', '--target', 'upload', '--target', 'monitor'],
33+
optionalPortArgs: ['--upload-port', '--monitor-port'],
3134
multienv: true,
3235
},
3336
{
@@ -66,6 +69,7 @@ export class ProjectTasks {
6669
{
6770
name: 'Test',
6871
args: ['test'],
72+
optionalPortArgs: ['--upload-port', '--test-port'],
6973
group: 'Advanced',
7074
multienv: true,
7175
},
@@ -91,6 +95,7 @@ export class ProjectTasks {
9195
{
9296
name: 'Verbose Upload',
9397
args: ['run', '--verbose', '--target', 'upload'],
98+
optionalPortArgs: ['--upload-port'],
9499
group: 'Advanced',
95100
multienv: true,
96101
},
@@ -144,25 +149,21 @@ export class ProjectTasks {
144149

145150
async getDefaultTasks() {
146151
// General tasks
147-
const result = ProjectTasks.generalTasks.map(
148-
(task) =>
149-
new TaskItem(
150-
task.name,
151-
task.description,
152-
task.args.slice(0),
153-
task.group,
154-
task.multienv
155-
)
156-
);
152+
const result = ProjectTasks.generalTasks.map((task) => {
153+
const item = new TaskItem(task.name, task.args.slice(0), task.group);
154+
item.description = task.description;
155+
item.multienv = !!task.multienv;
156+
item.optionalPortArgs = task.optionalPortArgs;
157+
return item;
158+
});
157159
// Miscellaneous tasks
158160
result.push(
159161
new TaskItem(
160162
'Rebuild IntelliSense Index',
161-
undefined,
162163
['project', 'init', '--ide', this.ide],
163164
'Miscellaneous'
164165
),
165-
new TaskItem('Upgrade PlatformIO Core', undefined, ['upgrade'], 'Miscellaneous')
166+
new TaskItem('Upgrade PlatformIO Core', ['upgrade'], 'Miscellaneous')
166167
);
167168
return result;
168169
}
@@ -175,31 +176,30 @@ export class ProjectTasks {
175176
continue;
176177
}
177178
usedTitles.push(task.name);
178-
result.push(
179-
new TaskItem(
180-
task.name,
181-
task.description,
182-
[...task.args.slice(0), '--environment', name],
183-
task.group,
184-
true
185-
)
179+
const item = new TaskItem(
180+
task.name,
181+
[...task.args.slice(0), '--environment', name],
182+
task.group
186183
);
184+
item.description = task.description;
185+
item.multienv = true;
186+
item.optionalPortArgs = task.optionalPortArgs;
187+
result.push(item);
187188
}
188189
// dev-platform targets
189190
try {
190191
for (const target of await this.fetchEnvTargets(name)) {
191192
if (usedTitles.includes(target.title)) {
192193
continue;
193194
}
194-
result.push(
195-
new TaskItem(
196-
target.title || target.name,
197-
target.description,
198-
['run', '--target', target.name, '--environment', name],
199-
target.group,
200-
true
201-
)
195+
const item = new TaskItem(
196+
target.title || target.name,
197+
['run', '--target', target.name, '--environment', name],
198+
target.group
202199
);
200+
item.description = target.description;
201+
item.multienv = true;
202+
result.push(item);
203203
}
204204
} catch (err) {
205205
console.error(
@@ -226,12 +226,25 @@ print(json.dumps(load_build_metadata(os.getcwd(), '${name}', cache=True)["target
226226
}
227227

228228
export class TaskItem {
229-
constructor(name, description, args, group = 'General', multienv = false) {
229+
constructor(name, args, group = 'General') {
230230
this.name = name;
231-
this.description = description;
232231
this.args = args;
233232
this.group = group;
234-
this.multienv = multienv;
233+
this.description = undefined;
234+
this.multienv = false;
235+
this.optionalPortArgs = undefined;
236+
}
237+
238+
isBuild() {
239+
return this.name.startsWith('Build');
240+
}
241+
242+
isClean() {
243+
return this.name.startsWith('Clean');
244+
}
245+
246+
isTest() {
247+
return this.name.startsWith('Test');
235248
}
236249

237250
get coreTarget() {
@@ -258,15 +271,14 @@ export class TaskItem {
258271
return env ? `${title} (${env})` : title;
259272
}
260273

261-
isBuild() {
262-
return this.name.startsWith('Build');
263-
}
264-
265-
isClean() {
266-
return this.name.startsWith('Clean');
267-
}
268-
269-
isTest() {
270-
return this.name.startsWith('Test');
274+
getCoreArgs(options = {}) {
275+
const args = this.args.slice(0);
276+
if (this.optionalPortArgs && options.port) {
277+
this.optionalPortArgs.forEach((arg) => {
278+
args.push(arg);
279+
args.push(options.port);
280+
});
281+
}
282+
return args;
271283
}
272284
}

0 commit comments

Comments
 (0)