diff --git a/.test-profiles/simple-profile/data/User/settings.json b/.test-profiles/simple-profile/data/User/settings.json index 693f064..57208bb 100755 --- a/.test-profiles/simple-profile/data/User/settings.json +++ b/.test-profiles/simple-profile/data/User/settings.json @@ -1,112 +1,12 @@ { - "editor.fontSize": 24, - "profileSwitcher.profiles": ["Default"], + "editor.fontSize": 14, + "profileSwitcher.profiles": ["Default", "Big Font"], "profileSwitcher.storage": { "Default": { - "sync.gist": "40c333588d64df34c6f36f196010e5ee", - "sync.lastUpload": "", - "sync.autoDownload": false, - "sync.autoUpload": false, - "sync.lastDownload": "2017-11-03T04:41:33.893Z", - "sync.forceDownload": false, - "sync.anonymousGist": false, - "sync.host": "", - "sync.pathPrefix": "", - "sync.quietSync": false, - "sync.askGistName": false, - "workbench.colorTheme": "1984 - Light", - "files.autoSave": "afterDelay", - "editor.renderWhitespace": "all", - "editor.fontFamily": "Fira Code", - "editor.fontLigatures": true, - "workbench.startupEditor": "newUntitledFile", - "files.autoSaveDelay": 5000, - "sync.removeExtensions": true, - "sync.syncExtensions": true, - "team.showWelcomeMessage": false, - "terminal.integrated.rendererType": "auto", - "explorer.confirmDelete": false, - "window.zoomLevel": 0, - "azureStorage.preview.staticWebsites": true, - "breadcrumbs.enabled": true, - "powershell.powerShellExePath": "C:\\WINDOWS\\SysWow64\\WindowsPowerShell\\v1.0\\powershell.exe", - "FSharp.enableReferenceCodeLens": true, - "FSharp.fsacRuntime": "netcore", - "workbench.iconTheme": "vscode-icons", - "peacock.favoriteColors": [ - { - "name": "Angular Red", - "value": "#b52e31" - }, - { - "name": "Auth0 Orange", - "value": "#eb5424" - }, - { - "name": "Azure Blue", - "value": "#007fff" - }, - { - "name": "C# Purple", - "value": "#68217A" - }, - { - "name": "Gatsby Purple", - "value": "#639" - }, - { - "name": "Go Cyan", - "value": "#5dc9e2" - }, - { - "name": "Java Blue-Gray", - "value": "#557c9b" - }, - { - "name": "JavaScript Yellow", - "value": "#f9e64f" - }, - { - "name": "Mandalorian Blue", - "value": "#1857a4" - }, - { - "name": "Node Green", - "value": "#215732" - }, - { - "name": "React Blue", - "value": "#00b3e6" - }, - { - "name": "Something Different", - "value": "#832561" - }, - { - "name": "Vue Green", - "value": "#42b883" - } - ], - "[javascript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[jsonc]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "editor.fontSize": 14, - "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "editor.formatOnSave": true, - "[typescriptreact]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "profileSwitcher.profiles": ["test1"], - "profileSwitcher.storage": { - "test1": { - "foo": "bar" - } - } + "editor.fontSize": 14 + }, + "Big Font": { + "editor.fontSize": 24 } }, "profileSwitcher.extensions": { @@ -118,6 +18,7 @@ "version": "1.9.0", "name": "prettier-vscode" } - ] + ], + "Big Font": [] } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c8ada..64f5e24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,17 @@ All notable changes to the "vscode-profile-switcher" extension will be documente Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -## [0.3.0] - Unreleased +## [0.3.0] - 2019-07-03 ### Added - Working on support for enable/disable extensions as you change profiles (Issue [#2](https://github.com/aaronpowell/vscode-profile-switcher/issues/2)) - Add support for setting a Live Share profile that is auto-activated (PR [#4](https://github.com/aaronpowell/vscode-profile-switcher/pull/4)) +### Changed + +- Using [`jsonc`](https://npmjs.org/package/jsonc) for parsing the `settings.json` file so it won't fail if there are comments (see [#3](https://github.com/aaronpowell/vscode-profile-switcher/issues/3)) + ## [0.2.0] - 2019-06-28 ### Added diff --git a/package-lock.json b/package-lock.json index 71db575..a6dec46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -471,6 +471,14 @@ "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", "dev": true }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "requires": { + "is-arrayish": "^0.2.1" + } + }, "es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", @@ -672,6 +680,11 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fast-safe-stringify": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz", + "integrity": "sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg==" + }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", @@ -963,6 +976,11 @@ } } }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -1036,6 +1054,11 @@ "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "dev": true }, + "json-parse-better-errors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", + "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==" + }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", @@ -1060,6 +1083,26 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "jsonc": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jsonc/-/jsonc-2.0.0.tgz", + "integrity": "sha512-B281bLCT2TRMQa+AQUQY5AGcqSOXBOKaYGP4wDzoA/+QswUfN8sODektbPEs9Baq7LGKun5jQbNFpzwGuVYKhw==", + "requires": { + "fast-safe-stringify": "^2.0.6", + "graceful-fs": "^4.1.15", + "mkdirp": "^0.5.1", + "parse-json": "^4.0.0", + "strip-bom": "^4.0.0", + "strip-json-comments": "^3.0.1" + }, + "dependencies": { + "strip-json-comments": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", + "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==" + } + } + }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -1135,14 +1178,12 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, "requires": { "minimist": "0.0.8" } @@ -1295,6 +1336,15 @@ "callsites": "^3.0.0" } }, + "parse-json": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", + "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "requires": { + "error-ex": "^1.3.1", + "json-parse-better-errors": "^1.0.1" + } + }, "path-dirname": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", @@ -1567,6 +1617,11 @@ "ansi-regex": "^3.0.0" } }, + "strip-bom": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", + "integrity": "sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==" + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", diff --git a/package.json b/package.json index 3db492f..9637e9b 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,7 @@ }, "dependencies": { "fs-extra": "^8.0.1", + "jsonc": "^2.0.0", "vsls": "^0.3.1291" } } diff --git a/src/settingsHelper.ts b/src/settingsHelper.ts index 0dc5983..456715a 100755 --- a/src/settingsHelper.ts +++ b/src/settingsHelper.ts @@ -3,6 +3,7 @@ import * as vscode from "vscode"; import * as os from "os"; import * as path from "path"; import { Settings } from "./services/config"; +import { jsonc } from "jsonc"; export enum OsType { Windows = 1, @@ -113,7 +114,9 @@ export default class SettingsHelper { return {}; } - return await fs.readJSON(settingsPath, { encoding: "utf8" }); + let fileContents = await fs.readFile(settingsPath, { encoding: "utf8" }); + + return jsonc.parse(fileContents); } public async updateUserSettings(update: Settings) { @@ -121,9 +124,10 @@ export default class SettingsHelper { let newSettings = Object.assign({}, existingSettings, update); - await fs.writeJSON(this.getSettingsPath(), newSettings, { - encoding: "utf8", - spaces: 4 + let settingsAsJson = jsonc.stringify(newSettings, { space: 4 }); + + await fs.writeFile(this.getSettingsPath(), settingsAsJson, { + encoding: "utf8" }); }