From 5ba0e179781ba770cb62c2ef07819e3c88ab9420 Mon Sep 17 00:00:00 2001 From: tshino Date: Mon, 20 Dec 2021 21:23:15 +0900 Subject: [PATCH 1/3] Add header to autogenerated keymap wrappers --- generator/gen_keymap_wrapper.js | 15 +++++++++++++-- generator/gen_wrapper_util.js | 11 ++++++++--- keymap-wrapper/ms-vscode.sublime-keybindings.json | 2 ++ keymap-wrapper/tshino.vz-like-keymap.json | 2 ++ keymap-wrapper/tuttieee.emacs-mcx.json | 2 ++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/generator/gen_keymap_wrapper.js b/generator/gen_keymap_wrapper.js index 8ba8bf0d..f254d930 100644 --- a/generator/gen_keymap_wrapper.js +++ b/generator/gen_keymap_wrapper.js @@ -50,7 +50,9 @@ async function makeKeymapWrapper(configPath, commonConfig) { const id = path.basename(configPath, '.config.json'); const packageJsonPath = path.resolve(dirname, 'tmp/' + id + '.package.json'); const packageJson = await genWrapperUtil.readJSON(packageJsonPath); - console.log('** generating keymap wrapper for', { id, displayName: packageJson['displayName'] }); + const displayName = packageJson['displayName']; + const version = packageJson['version']; + console.log('** generating keymap wrapper for', { id, displayName, version }); const config = await genWrapperUtil.readJSON(configPath); @@ -102,7 +104,16 @@ async function makeKeymapWrapper(configPath, commonConfig) { ); const wrapperPath = path.resolve(dirname, id + '.json'); - await genWrapperUtil.writeCompactKeybindingsJSON(wrapperPath, wrapperKeybindings); + const compactJson = genWrapperUtil.makeCompactKeybindingsJSON(wrapperKeybindings); + const fileContent = compactJson.replace( + /^\[\n/, + ( + '[\n' + + `\t// Keymap wrapper for ${displayName} v${version}\n` + + '\t// (required by Keyboard Macro Beta)\n' + ) + ) + '\n'; + await genWrapperUtil.writeFile(wrapperPath, fileContent); console.log('...done (' + id + '.json)'); } diff --git a/generator/gen_wrapper_util.js b/generator/gen_wrapper_util.js index c3c1919b..80e0164f 100644 --- a/generator/gen_wrapper_util.js +++ b/generator/gen_wrapper_util.js @@ -18,7 +18,11 @@ async function writeJSON(path, value) { await fsPromises.writeFile(path, json + '\n'); } -async function writeCompactKeybindingsJSON(path, keybindings) { +async function writeFile(path, content) { + await fsPromises.writeFile(path, content); +} + +function makeCompactKeybindingsJSON(keybindings) { const json = JSON.stringify(keybindings, null, '\t'); const compactJson = json.replace( /,\n\s+"(?!when)/gm, ', "' @@ -31,7 +35,7 @@ async function writeCompactKeybindingsJSON(path, keybindings) { ).replace( /\s*\n\s+}/gm, ' }' ); - await fsPromises.writeFile(path, compactJson + '\n'); + return compactJson; } function addWhenContext(when, context) { @@ -226,7 +230,8 @@ function makeWrapper(keybinding, awaitOption) { module.exports = { readJSON, writeJSON, - writeCompactKeybindingsJSON, + writeFile, + makeCompactKeybindingsJSON, addWhenContext, copyKeybinding, removeOSSpecificKeys, diff --git a/keymap-wrapper/ms-vscode.sublime-keybindings.json b/keymap-wrapper/ms-vscode.sublime-keybindings.json index e5105a17..93d75c5d 100644 --- a/keymap-wrapper/ms-vscode.sublime-keybindings.json +++ b/keymap-wrapper/ms-vscode.sublime-keybindings.json @@ -1,4 +1,6 @@ [ + // Keymap wrapper for Sublime Text Keymap and Settings Importer v4.0.10 + // (required by Keyboard Macro Beta) { "key": "cmd+y", "command": "kb-macro.wrap", "args": { "command": "redo" }, "when": "kb-macro.recording && isMac && editorTextFocus && !editorReadonly" }, { "key": "ctrl+y", "command": "kb-macro.wrap", "args": { "command": "redo" }, diff --git a/keymap-wrapper/tshino.vz-like-keymap.json b/keymap-wrapper/tshino.vz-like-keymap.json index 62d1ff0c..24d028ff 100644 --- a/keymap-wrapper/tshino.vz-like-keymap.json +++ b/keymap-wrapper/tshino.vz-like-keymap.json @@ -1,4 +1,6 @@ [ + // Keymap wrapper for Vz Keymap v0.18.0 + // (required by Keyboard Macro Beta) { "key": "ctrl+s", "command": "", "when": "kb-macro.recording && editorFocus" }, { "key": "ctrl+s", "command": "kb-macro.wrap", "args": { "command": "vz.cursorLeft", "await": "selection" }, diff --git a/keymap-wrapper/tuttieee.emacs-mcx.json b/keymap-wrapper/tuttieee.emacs-mcx.json index efbd9eb6..c54d6a87 100644 --- a/keymap-wrapper/tuttieee.emacs-mcx.json +++ b/keymap-wrapper/tuttieee.emacs-mcx.json @@ -1,4 +1,6 @@ [ + // Keymap wrapper for Awesome Emacs Keymap v0.36.6 + // (required by Keyboard Macro Beta) { "key": "ctrl+u", "command": "kb-macro.wrap", "args": { "command": "emacs-mcx.universalArgument" }, "when": "kb-macro.recording && editorTextFocus" }, { "key": "0", "command": "kb-macro.wrap", "args": { "command": "emacs-mcx.universalArgumentDigit", "args": [ 0 ] }, From 9b101bbdcc488ab04350a1dcaf532b5af6839885 Mon Sep 17 00:00:00 2001 From: tshino Date: Mon, 20 Dec 2021 21:29:17 +0900 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2366510..d6a48c63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Keyboard Macro Bata extension will be documented in this file. +### [Unreleased] +- Update + - Added comment lines to keymap wrapper files to describe keymap name and its version. + ### [0.6.0] - 2021-12-19 - New - Added Sublime Text Keymap support. [#18](https://github.com/tshino/vscode-kb-macro/issues/18) From 8449a202989ab2d7ed46efa23a5fa38a069f4cd2 Mon Sep 17 00:00:00 2001 From: tshino Date: Mon, 20 Dec 2021 21:37:09 +0900 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6a48c63..91714ca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to the Keyboard Macro Bata extension will be documented in t ### [Unreleased] - Update - - Added comment lines to keymap wrapper files to describe keymap name and its version. + - Added comment lines to keymap wrapper files to describe keymap name and its version. [#20](https://github.com/tshino/vscode-kb-macro/pull/20) ### [0.6.0] - 2021-12-19 - New