diff --git a/.gitignore b/.gitignore index 639b06e..f8d64a6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ node_modules .vscode-test/ *.vsix src/symbol-icon-theme.modified.json -.DS_Store \ No newline at end of file +.DS_Store + +/variants \ No newline at end of file diff --git a/package.json b/package.json index 152c0bd..79aab48 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "publisher": "miguelsolorio", "icon": "symbols.png", "preview": true, - "main": "./src/extension.js", "engines": { "vscode": "^1.70.0" }, @@ -30,34 +29,24 @@ "author": { "name": "Miguel Solorio" }, - "activationEvents": [ - "onStartupFinished" - ], "contributes": { "iconThemes": [ { "id": "symbols", "label": "Symbol Icons", - "path": "./src/symbol-icon-theme.modified.json" - } - ], - "configuration": { - "type": "object", - "title": "Symbols", - "properties": { - "symbols.hidesExplorerArrows": { - "type": "boolean", - "default": false, - "description": "Hide arrow icons in the explorer section." - } + "path": "./variants/symbol-icon-theme.json" + }, + { + "id": "symbols-no-folder-arrows", + "label": "Symbol Icons (No Folder Arrows)", + "path": "./variants/symbol-icon-theme.no-arrows.json" } - } + ] }, "scripts": { "release": "release-it" }, "devDependencies": { - "@types/vscode": "^1.70.0", "release-it": "^15.3.0" } } diff --git a/scripts/generate.js b/scripts/generate.js new file mode 100755 index 0000000..44200ff --- /dev/null +++ b/scripts/generate.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node + +const path = require("path"); +const fs = require("fs"); + +const basePath = path.resolve(__dirname); + +const sourceThemePath = path.join( + basePath, + "..", + "src", + "symbol-icon-theme.json" +); + +const sourcethemeJSON = require(sourceThemePath); + +// make variant directory +const outPath = path.join(basePath, "..", "variants"); +fs.mkdirSync(outPath, { recursive: true }); + + +// replace paths with relative paths +Object.keys(sourcethemeJSON.iconDefinitions).forEach(iconDef=>{ + const ogPath = path.join("src",sourcethemeJSON.iconDefinitions[iconDef].iconPath) + const relativePath = path.relative(outPath,ogPath) + sourcethemeJSON.iconDefinitions[iconDef].iconPath = relativePath +}) + + +const variants = { + default: { + name: "symbol-icon-theme.json", + theme: { ...sourcethemeJSON }, + }, +}; + +variants.noFolderArrows = { + name: "symbol-icon-theme.no-arrows.json", + theme: { + ...sourcethemeJSON, + hidesExplorerArrows: true, + }, +}; + +// write to files +Object.keys(variants).forEach((key) => { + fs.writeFileSync( + path.join(outPath, variants[key].name), + JSON.stringify(variants[key].theme, null, 2) + ); +}); diff --git a/src/extension.js b/src/extension.js deleted file mode 100644 index 793d266..0000000 --- a/src/extension.js +++ /dev/null @@ -1,29 +0,0 @@ -const vscode = require("vscode"); -const { monitorConfigChanges } = require("./lib/change-listener"); -const { syncOriginal } = require("./lib/theme"); - -/** - * @param {vscode.ExtensionContext} context - */ -async function activate(context) { - console.log("miguelsolorio.symbols activated"); - - await syncOriginal(); - monitorConfigChanges(); - - vscode.workspace.onDidChangeConfiguration(monitorConfigChanges); - - vscode.window.onDidChangeWindowState((state) => { - if (state.focused) { - monitorConfigChanges(); - } - }); -} - -function deactivate() {} - -// eslint-disable-next-line no-undef -module.exports = { - activate, - deactivate, -}; diff --git a/src/lib/change-listener.js b/src/lib/change-listener.js deleted file mode 100644 index 49ef93b..0000000 --- a/src/lib/change-listener.js +++ /dev/null @@ -1,26 +0,0 @@ -const { - themeJSONToConfig, - getWorkspaceConfiguration, - updateConfig, -} = require("./config"); -const { getThemeFile } = require("./theme"); - -function monitorConfigChanges() { - const themeJSON = getThemeFile(); - const currentState = themeJSONToConfig(themeJSON); - const workspaceState = getWorkspaceConfiguration(); - - const updatedKeys = {}; - - for (let currentKey in currentState) { - if (currentState[currentKey] != workspaceState[currentKey]) { - updatedKeys[currentKey] = workspaceState[currentKey]; - } - } - - updateConfig(updatedKeys); -} - -module.exports = { - monitorConfigChanges, -}; diff --git a/src/lib/config.js b/src/lib/config.js deleted file mode 100644 index bded517..0000000 --- a/src/lib/config.js +++ /dev/null @@ -1,77 +0,0 @@ -const vscode = require("vscode"); - -const defaultConfig = require("../symbol-icon-theme.json"); -const pkgConfig = require("../../package.json"); -const { getThemeFile, writeThemeFile } = require("./theme"); -const {PKG_PROP_MAP} = require("./constants") - - - -// get the configuration definition from the package.json -// and also the default state of the theme to act as fallback -// values for the configs -const configDef = pkgConfig.contributes.configuration; -const configKeys = Object.keys(configDef.properties); -const defaultState = themeJSONToConfig(defaultConfig); - -/** - * @description will get the current **workspace** configuration - */ -function getWorkspaceConfiguration() { - const config = {}; - for (let key of configKeys) { - if (!PKG_PROP_MAP[key]) { - continue; - } - - const valueGroup = vscode.workspace - .getConfiguration("symbols") - .inspect(PKG_PROP_MAP[key]); - - config[PKG_PROP_MAP[key]] = - valueGroup.workspaceValue || - valueGroup.globalValue || - defaultState[PKG_PROP_MAP[key]]; - } - - return config; -} - -/** - * @description normalize a theme definition json to only have - * keys that are defined in the configuration section of the package.json - */ -function themeJSONToConfig(themeDef) { - const result = {}; - - for (let key of configKeys) { - if (!PKG_PROP_MAP[key]) { - continue; - } - result[PKG_PROP_MAP[key]] = themeDef[PKG_PROP_MAP[key]]; - } - - return result; -} - -/** - * @description update the changed property in the global settings and - * in the theme definition file - */ -function updateConfig(config) { - const themeJSON = getThemeFile(); - - for (let key in config) { - console.log(`symbols.${key} changed, updating to ${config[key]}`); - vscode.workspace.getConfiguration("symbols").update(key, config[key], true); - themeJSON.hidesExplorerArrows = config[key]; - } - - writeThemeFile(themeJSON); -} - -module.exports = { - getWorkspaceConfiguration, - themeJSONToConfig, - updateConfig -}; diff --git a/src/lib/constants.js b/src/lib/constants.js deleted file mode 100644 index e78bf60..0000000 --- a/src/lib/constants.js +++ /dev/null @@ -1,14 +0,0 @@ -// mapped properties for keys in package.json vs keys in vscode -const PKG_PROP_MAP = { - "symbols.hidesExplorerArrows": "hidesExplorerArrows", -}; - -const MESSAGES = { - needsReloadToSync: "A Reload is needed to sync with the updated settings", - reloadButton: "Reload", -}; - -module.exports = { - PKG_PROP_MAP, - MESSAGES, -}; diff --git a/src/lib/theme.js b/src/lib/theme.js deleted file mode 100644 index dc7a3b1..0000000 --- a/src/lib/theme.js +++ /dev/null @@ -1,122 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const { PKG_PROP_MAP } = require("./constants"); -const { confirmReload } = require("./window"); - -const THEME_FILE = "symbol-icon-theme.modified.json"; -const DEFAULT_THEME_FILE = "symbol-icon-theme.json"; - -// getPath and getDefaultPath are seperated in -// case we decide to change the path at which the -// modified theme is kept - -/** - * @description get the path for the theme definition - * (or the theme file that vscode looks for) - */ -function getPath() { - if (__dirname === "src") { - return path.join(__dirname, THEME_FILE); - } else { - // relative to the current file aka theme.js - return path.join(__dirname, "..", THEME_FILE); - } -} - -/** - * @description get the path for the default theme file (or the source code theme) - */ -function getDefaultFilePath() { - if (__dirname === "src") { - return path.join(__dirname, DEFAULT_THEME_FILE); - } else { - // relative to the current file aka theme.js - return path.join(__dirname, "..", DEFAULT_THEME_FILE); - } -} - -/** - * @description check if the theme source exists, - * if not, create one and then send the path - */ -function resolveOrCreateTheme() { - const themeFile = getPath(); - if (!fs.existsSync(themeFile)) { - fs.copyFileSync(getDefaultFilePath(), themeFile); - } - return themeFile; -} - -/** - * @description get the theme json, either from the modified one - * or the default one - */ -function getThemeFile() { - return JSON.parse(fs.readFileSync(resolveOrCreateTheme(), "utf-8")); -} - -/** - * @description get the source theme json - */ -function getSoureFile() { - return JSON.parse(fs.readFileSync(getDefaultFilePath(), "utf-8")); -} - -// write the theme data file to the **modified** theme -// file -function writeThemeFile(data) { - fs.writeFileSync(getPath(), JSON.stringify(data, null, 2)); -} - -/** - * @description, force clone the original to modified theme - * to make sure updates are merged to it - * - * Note: kept seperate from the - * resolveOrCreateTheme if we wish to move this into a deeper diffing based - * sync later (unnecessary right now since the themeFile is small) - */ -async function syncOriginal() { - let themePath = getPath(); - let themeJSON = getThemeFile(); - let originalJSON = getSoureFile(); - - let needsSync = false; - - const configurableKeys = Object.values(PKG_PROP_MAP); - - // shallow check - for (const key in originalJSON) { - if (configurableKeys.indexOf(key) > -1) { - continue; - } - - const stringifiedSource = JSON.stringify(originalJSON[key]); - if (!themeJSON[key]) { - needsSync = true; - break; - } - - const stringifiedTheme = JSON.stringify(themeJSON[key]); - if (stringifiedSource != stringifiedTheme) { - console.log({ - stringifiedSource, - stringifiedTheme, - }); - needsSync = true; - break; - } - } - - if (needsSync) { - await confirmReload(); - fs.unlinkSync(themePath); - fs.copyFileSync(getDefaultFilePath(), themePath); - } -} - -module.exports = { - getThemeFile, - writeThemeFile, - syncOriginal, -}; diff --git a/src/lib/window.js b/src/lib/window.js deleted file mode 100644 index 91d4b04..0000000 --- a/src/lib/window.js +++ /dev/null @@ -1,20 +0,0 @@ -const vscode = require("vscode"); -const { MESSAGES } = require("./constants"); - -async function confirmReload() { - const response = await vscode.window.showInformationMessage( - MESSAGES.needsReloadToSync, - MESSAGES.reloadButton - ); - - if (response != MESSAGES.reloadButton) { - return false; - } - - vscode.commands.executeCommand("workbench.action.reloadWindow"); - return true; -} - -module.exports = { - confirmReload, -};