Skip to content
Merged
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
29 changes: 26 additions & 3 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,16 @@ export function addTasksJsonIfNecessary(generator: AssetGenerator, operations: O
return resolve();
}

// Read existing Tasks configuration
const tasksConfigs = vscode.workspace.getConfiguration('tasks');
let existingTaskConfigs = tasksConfigs.get<Array<tasks.TaskDescription>>('tasks');
Copy link
Contributor

Choose a reason for hiding this comment

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

@vishrutshah thanks for sending this! One question on this - did you test the behavior if you do NOT already have a tasks.json, or if the task.json has no real content to see if you need additional if statements there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've verified with having no task.json at all but let me also verify if tasks.json is having empty content :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. So after testing both the scenarios, looks like we do not need addition if statements around

let existingTaskConfigs = tasksConfigs.get<Array<tasks.TaskDescription>>('tasks');

Case 1: When we do not have tasks.json then getConfiguration returns an object on which we call get<T> which returns undefined
Case 2: When we have tasks.json with empty array of tasks then we do not visit this path as we existing logic resolve({ updateTasksJson: buildTasks.length === 0 }); would prevent from modifying the tasks.json

Let me know your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vishrutshah your analysis sounds correct to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. Let me know if any more changes are required. Happy to do it :)

const tasksJson = generator.createTasksConfiguration();
const tasksJsonText = JSON.stringify(tasksJson, null, ' ');

if (existingTaskConfigs) {
tasksJson['tasks'] = tasksJson['tasks'].concat(existingTaskConfigs);
}

const tasksJsonText = JSON.stringify(tasksJson, null, ' ');
fs.writeFile(generator.tasksJsonPath, tasksJsonText, err => {
if (err) {
return reject(err);
Expand All @@ -442,11 +449,27 @@ function addLaunchJsonIfNecessary(generator: AssetGenerator, operations: Operati
return resolve();
}

// Read existing launch configuration
const launchConfigs = vscode.workspace.getConfiguration('launch');
let existingLaunchConfigs = launchConfigs.get<{}[]>('configurations');

const isWebProject = generator.hasWebServerDependency();
const launchJson: string = generator.createLaunchJson(isWebProject);
let launchJson: string = generator.createLaunchJson(isWebProject);

if (existingLaunchConfigs) {
let existingLaunchConfigsString = JSON.stringify(existingLaunchConfigs, null, ' ');
const lastBracket = launchJson.lastIndexOf(']');
const lastBracketInExistingConfig = existingLaunchConfigsString.lastIndexOf(']');
const firstBracketInExistingConfig = existingLaunchConfigsString.indexOf('[');

if (lastBracket !== -1 && lastBracketInExistingConfig !== -1 && firstBracketInExistingConfig !== -1) {
launchJson = launchJson.substring(0, lastBracket);
existingLaunchConfigsString = existingLaunchConfigsString.substring(firstBracketInExistingConfig + 1, lastBracketInExistingConfig);
launchJson = `${launchJson},${existingLaunchConfigsString}]`;
}
}

const configurationsMassaged: string = indentJsonString(launchJson);

const launchJsonText = `
{
// Use IntelliSense to find out which attributes exist for C# debugging
Expand Down