Skip to content

Commit e80d407

Browse files
committed
Only write a new settings file if the settings have changed
1 parent e216328 commit e80d407

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

packages/app/src/app/overmind/effects/vscode/initializers.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,40 @@ export function initializeSettings() {
5656
const settings = JSON5.parse(
5757
fs.readFileSync('/vscode/settings.json').toString()
5858
);
59-
settings['javascript.autoClosingTags'] = false;
60-
settings['typescript.autoClosingTags'] = false;
61-
settings['html.autoClosingTags'] = false;
62-
settings['typescript.tsserver.useSeparateSyntaxServer'] = false;
59+
60+
let settingsChanged = false;
61+
const changeIfNeeded = (field: string, value: unknown) => {
62+
if (settings[field] !== value) {
63+
settings[field] = value;
64+
return true;
65+
}
66+
return settingsChanged || false;
67+
};
68+
69+
settingsChanged = changeIfNeeded('javascript.autoClosingTags', false);
70+
settingsChanged = changeIfNeeded('typescript.autoClosingTags', false);
71+
settingsChanged = changeIfNeeded('html.autoClosingTags', false);
72+
settingsChanged = changeIfNeeded(
73+
'typescript.tsserver.useSeparateSyntaxServer',
74+
false
75+
);
6376

6477
if (!settings['workbench.colorTheme']) {
6578
// if you have not changed the theme ever,
6679
// we set codesandbox black as the theme for you
67-
settings['workbench.colorTheme'] = 'CodeSandbox Black';
80+
81+
settingsChanged = changeIfNeeded(
82+
'workbench.colorTheme',
83+
'CodeSandbox Black'
84+
);
6885
}
6986

70-
fs.writeFileSync(
71-
'/vscode/settings.json',
72-
JSON.stringify(settings, null, 2)
73-
);
87+
if (settingsChanged) {
88+
fs.writeFileSync(
89+
'/vscode/settings.json',
90+
JSON5.stringify(settings, { quote: '"', space: 2, replacer: null })
91+
);
92+
}
7493
} catch (e) {
7594
console.warn(e);
7695
}

0 commit comments

Comments
 (0)