Skip to content

Commit

Permalink
Add uninstall hook script (cleanUp) (vscode-icons#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimiC authored and robertohuertasm committed Mar 22, 2018
1 parent 7cb8fe2 commit 8ad15a4
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"posttest": "nyc report -r lcov",
"test:vs": "node ./node_modules/vscode/bin/test",
"vscode:prepublish": "npm run build",
"vscode:uninstall": "node ./out/src/uninstall.js",
"precompile": "rimraf ./out",
"compile": "tsc",
"compile:w": "npm run compile -- -w",
Expand Down
52 changes: 52 additions & 0 deletions src/cleanUp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { readFile, writeFile, unlink } from 'fs';
import { constants } from '../constants';
import { vscodePath as getAppPath, parseJSON, pathUnixJoin } from '../utils';

export function getAppUserPath(dirPath: string): string {
const isDev = /oss-dev/i.test(dirPath);
const isOSS = !isDev && /oss/i.test(dirPath);
const isInsiders = /insiders/i.test(dirPath);
const vscodeAppName = isInsiders ? 'Code - Insiders' : isOSS ? 'Code - OSS' : isDev ? 'code-oss-dev' : 'Code';
return pathUnixJoin(getAppPath(), vscodeAppName, 'User');
}

export function removeVSIconsSettings(settings: {}): void {
Reflect.ownKeys(settings)
.map(key => key.toString())
.filter(key => /^vsicons\..+/.test(key))
.forEach(key => delete settings[key]);
}

export function resetThemeSetting(settings: {}): void {
if (settings[constants.vscode.iconThemeSetting] === constants.extensionName) {
settings[constants.vscode.iconThemeSetting] = null;
}
}

export function cleanUpVSCodeSettings(): void {
const saveSettings = content => {
const settings = JSON.stringify(content, null, 4);
writeFile(settingsFilePath, settings, err => console.error(err));
};
const cleanUpSettings = (err, content) => {
if (err) {
console.error(err);
return;
}
const settings = parseJSON(content);
if (!settings) { return; }

removeVSIconsSettings(settings);

resetThemeSetting(settings);

saveSettings(settings);
};
const settingsFilePath = pathUnixJoin(getAppUserPath(__dirname), 'settings.json');
readFile(settingsFilePath, 'utf8', cleanUpSettings);
}

export function cleanUpVSIconsSettings(): void {
unlink(pathUnixJoin(getAppUserPath(__dirname), 'vsicons.settings.json'),
err => console.error(err));
}
4 changes: 4 additions & 0 deletions src/uninstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { cleanUpVSCodeSettings, cleanUpVSIconsSettings } from './cleanUp';

cleanUpVSIconsSettings();
cleanUpVSCodeSettings();
Loading

0 comments on commit 8ad15a4

Please sign in to comment.