From d1ef9ff80538859d5902334508905559f5d7110c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denny=20Korsuk=C3=A9witz?= Date: Wed, 3 Jan 2024 09:55:25 +0100 Subject: [PATCH] Added mousemap --- __tests__/generators/mousemap.test.js | 54 +++++++++++++ generators/mousemap/USAGE | 13 ++++ generators/mousemap/config.js | 33 ++++++++ generators/mousemap/index.js | 76 +++++++++++++++++++ .../templates/Default.sublime-mousemap | 56 ++++++++++++++ generators/project/config.js | 2 +- generators/setting/config.js | 2 +- 7 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 __tests__/generators/mousemap.test.js create mode 100644 generators/mousemap/USAGE create mode 100644 generators/mousemap/config.js create mode 100644 generators/mousemap/index.js create mode 100644 generators/mousemap/templates/Default.sublime-mousemap diff --git a/__tests__/generators/mousemap.test.js b/__tests__/generators/mousemap.test.js new file mode 100644 index 0000000..5d57ba9 --- /dev/null +++ b/__tests__/generators/mousemap.test.js @@ -0,0 +1,54 @@ +const path = require('path'); +const helpers = require('yeoman-test'); + +describe('generators:mousemap', () => { + describe('creates files', () => { + let runResult; + + const config = { + // generator_data + mousemap_os: ['Default (Windows)', 'Default (OSX)', 'Default (Linux)'], + + // package_data + sublime_version: '4.0.x', + package_name: 'Sublime-Package', + package_description: 'My description.', + github_username: 'dennykorsukewitz', + github_fullname: 'Denny Korsukéwitz', + }; + + const expectedFiles = [ + 'mousemaps/Default (Linux).sublime-mousemap', + 'mousemaps/Default (OSX).sublime-mousemap', + 'mousemaps/Default (Windows).sublime-mousemap', + ]; + + const expectedContent = [ + [ 'mousemaps/Default (Linux).sublime-mousemap', 'drag_select' ], + [ 'mousemaps/Default (OSX).sublime-mousemap', 'drag_select' ], + [ 'mousemaps/Default (Windows).sublime-mousemap', 'drag_select' ], + ]; + + beforeEach(async () => { + runResult = await helpers + .run(path.join(process.env.INIT_CWD, '/generators/mousemap')) + .withPrompts(config) + .withLocalConfig(config); + }); + + afterEach(() => { + if (runResult) { + runResult.restore(); + } + }); + + it('expected files', () => { + runResult.assertFile(expectedFiles); + }); + + it('expected content', () => { + runResult.assertFileContent(expectedContent); + }); + + }); +}); diff --git a/generators/mousemap/USAGE b/generators/mousemap/USAGE new file mode 100644 index 0000000..15e223f --- /dev/null +++ b/generators/mousemap/USAGE @@ -0,0 +1,13 @@ +Description: + Creates a Default.sublime-mousemap file. + The mousemap files (which have the extension .sublime-mousemap) control what commands are executed when a user performs an action with a mouse, e.g. clicking a mouse button, scrolling the scroll wheel, etc. + +Example: + yo sublime-package:mousemap + + This will create: + mousemaps/Default.sublime-mousemap: *.sublime-mousemap files contain a JSON array that contains JSON objects to specify the key bindings. + + mousemaps/Default (Linux).sublime-mousemap + mousemaps/Default (OSX).sublime-mousemap + mousemaps/Default (Windows).sublime-mousemap \ No newline at end of file diff --git a/generators/mousemap/config.js b/generators/mousemap/config.js new file mode 100644 index 0000000..b47505d --- /dev/null +++ b/generators/mousemap/config.js @@ -0,0 +1,33 @@ +const config = { + name: 'Mousemap', + description: 'Creates a Default.sublime-mousemap file. Default.sublime-mousemap files contain the key bindings (shortcuts) for a command.', + priority: 70, + versions: { + '4.0.x': '', + }, + prompts: [ + { + name: 'mousemap_os', + message: 'For which operating system do you need a mousemap?', + type: 'checkbox', + choices: [ + { + name: 'Windows', + value: 'Default (Windows)', + checked: true, + }, + { + name: 'OSX', + value: 'Default (OSX)', + checked: true, + }, + { + name: 'Linux', + value: 'Default (Linux)', + checked: true, + }, + ], + }, + ], +}; +module.exports = config; \ No newline at end of file diff --git a/generators/mousemap/index.js b/generators/mousemap/index.js new file mode 100644 index 0000000..fc92297 --- /dev/null +++ b/generators/mousemap/index.js @@ -0,0 +1,76 @@ +'use strict'; +/* eslint no-empty-function: ["error", { "allow": ["methods"] }] */ + +const Generator = require('yeoman-generator'); +const chalk = require('chalk'); +const yosay = require('yosay'); +const path = require('path'); +const helper = require('./../../src/helper.js'); +const generator = path.basename(__dirname); +const generator_config = require('./config.js'); + +let config = {}; +let answers = {}; + +module.exports = class extends Generator { + // initializing - Your initialization methods (checking current project state, getting configs, etc) + async initializing() { + + // create or update config + await helper.InitConfig(this, generator_config); + + // get current config + config = this.config.getAll(); + config.generator_name = generator_config.name || generator; + config.generator_description = '\n' + generator_config.description || ''; + } + + // prompting - Where you prompt users for options (where you’d call this.prompt()) + async prompting() { + this.log( + yosay( + `${chalk.green(config.generator_name)} ${config.generator_description}`, + ), + ); + + generator_config.prompts = helper.InterpolatePrompts(this, config, generator_config.prompts); + answers = await this.prompt(generator_config.prompts); + } + + // configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files) + configuring() {} + + // default - If the method name doesn’t match a priority, it will be pushed to this group. + default() {} + + // writing - Where you write the generator specific files (routes, controllers, etc) + writing() { + + // merge data + const data = { + ...config, + ...answers, + }; + + answers.mousemap_os.forEach(os => { + this.renderTemplate( + this.templatePath('Default.sublime-mousemap'), + this.destinationPath(`mousemaps/${os}.sublime-mousemap`), + data, + ); + }); + + } + + // conflicts - Where conflicts are handled (used internally) + conflicts() { } + + // install - Where installations are run (npm, bower) + install() {} + + // end - Called last, cleanup, say good bye, etc + end() { + helper.End(this, config); + } +}; + diff --git a/generators/mousemap/templates/Default.sublime-mousemap b/generators/mousemap/templates/Default.sublime-mousemap new file mode 100644 index 0000000..26c7a7b --- /dev/null +++ b/generators/mousemap/templates/Default.sublime-mousemap @@ -0,0 +1,56 @@ +[ + + // button: The name of the button. + // This defines the name of the button. There can be upto 16 buttons, button1 to button16 along with scroll_up & scroll_down for the scroll wheel. + + // modifiers: A list of modifier keys. + // This defines a list of modifiers keys that have to be pressed simultaneously (along with the corresponding button click) for the command to be triggered, e.g. ["ctrl", "alt"]. A list of all the modifier keys can be found in the keybindings section on Modifiers. + + // count: The count of the button press. + // This defines the number of times the button has to be pressed for the corresponding command to trigger. Defaults to 1. + + // command: The command to execute. + // This defines the command to be executed when the corresponding button is released. + + // args: The arguments for command. + // This is a mapping of arguments to be passed on to the command. + + // press_command: The press_command to execute. + // This defines the command to be executed when the corresponding button is pressed. + + // press_args: The arguments for press_command. + // This is a mapping of arguments to be passed on to the press_command. + + // --- + // Examples: + // --- + + // Basic drag select + { + "button": "button1", "count": 1, + "press_command": "drag_select" + }, + { + "button": "button1", "count": 1, "modifiers": ["ctrl"], + "press_command": "drag_select", + "press_args": {"additive": true} + }, + { + "button": "button1", "count": 1, "modifiers": ["alt"], + "press_command": "drag_select", + "press_args": {"subtractive": true} + }, + + // Save all with click on scroll wheel + { + "button": "button3", "count": 1, + "press_command": "save_all", + }, + + // Double left click on scroll wheel opens a new window + { + "button": "button3", "count": 2, + "press_command": "new_window", + }, + +] \ No newline at end of file diff --git a/generators/project/config.js b/generators/project/config.js index 85312de..e081888 100644 --- a/generators/project/config.js +++ b/generators/project/config.js @@ -1,7 +1,7 @@ const config = { name: 'Project', description: 'Creates a SublimePackage.sublime-project file to register a collection of files and folders, which are shown in Sidebar.', - priority: 70, + priority: 80, versions: { '4.0.x': '', }, diff --git a/generators/setting/config.js b/generators/setting/config.js index 3e19b97..c212031 100644 --- a/generators/setting/config.js +++ b/generators/setting/config.js @@ -1,7 +1,7 @@ const config = { name: 'Setting', description: 'Creates a SublimePackage.sublime-settings file to stores configuration data.', - priority: 80, + priority: 90, versions: { '4.0.x': '', },