Files
react-native-devtools-frontend/scripts/deps/sync-vscode-settings.js
T
Eric Leese 30df387ba8 Better VSCode debugging support
- Default build task is set up
 - Can launch unit tests and e2e tests under the debugger
 - When using JavaScript Debug Terminal, skip attaching to tsc as
   this slows down builds

Bug: None
Change-Id: I4cd627b186b799e148393008fef50fac647aa5a9
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3366667
Reviewed-by: Tim Van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Eric Leese <leese@chromium.org>
2022-01-19 12:53:26 +00:00

61 lines
2.3 KiB
JavaScript

// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const path = require('path');
const fs = require('fs');
// JSON files under .vscode/ synced by this script
const VSCODE_SETTINGS_TO_MERGE = [
{settingsFile: 'settings.json'}, {settingsFile: 'tasks.json', mergeField: 'tasks', byField: 'label'},
{settingsFile: 'launch.json', mergeField: 'configurations', byField: 'name'}
];
// If the user has opted out of updates, return and do nothing.
if (Boolean(process.env['SKIP_VSCODE_SETTINGS_SYNC'])) {
return;
}
for (const {settingsFile, mergeField, byField} of VSCODE_SETTINGS_TO_MERGE) {
const vscodeSettingsLocation = path.join(process.cwd(), '.vscode', settingsFile);
const devtoolsSettingsLocation = path.join(process.cwd(), '.vscode', 'devtools-workspace-' + settingsFile);
// If there are no settings to copy and paste, skip.
if (!fs.existsSync(devtoolsSettingsLocation)) {
continue;
}
try {
const devtoolsSettings = require(devtoolsSettingsLocation);
let preExistingSettings = {};
if (fs.existsSync(vscodeSettingsLocation)) {
preExistingSettings = require(vscodeSettingsLocation);
}
const updatedSettings = {
...devtoolsSettings,
// Any setting specified by the engineer will always take precedence over the defaults
...preExistingSettings,
};
if (mergeField && byField && preExistingSettings[mergeField] && devtoolsSettings[mergeField]) {
// We need to merge two lists in a field. The list items have a unique
// id specified by byField. If an entry is found in devtoolsSettings we
// assume it should be updated when the devtools settings file is updated,
// otherwise we keep the preexisting setting.
const mergedList = [...devtoolsSettings[mergeField]];
const doNotDuplicate = new Set(mergedList.map(item => item[byField]));
for (const item of preExistingSettings[mergeField]) {
if (!doNotDuplicate.has(item[byField])) {
mergedList.push(item);
}
}
updatedSettings[mergeField] = mergedList;
}
fs.writeFileSync(vscodeSettingsLocation, JSON.stringify(updatedSettings, null, 2));
} catch (err) {
console.warn('Unable to update VSCode settings - skipping');
console.warn(err.stack);
}
}