diff --git a/README.md b/README.md index 1b95adb..923706f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The following files can be created. | | messages/version.txt | When a package is upgraded, Package Control looks through each key in the messages.json file sand shows the content of the text file that is a value of any key that is higher than the previous version of the package the user has installed. | | | messages.json | Messaging is controlled by a file named messages.json in the root of the package. | | commands | SublimePackage.sublime-commands | SublimePackage.sublime-commands is a file to register your new command / plugin for the Command Palette. | -| keymap | TODO | TODO | +| keymap | Default.sublime-keymap | Creates a Default.sublime-keymap file. Default.sublime-keymap files contain the key bindings (shortcuts) for a command. The JSON objects must contain a keys and command key, and may also contain a args key if the command requires arguments. | | macros | TODO | TODO | | menu | TODO | TODO | | plugin | SublimePackage.py | Creates a new python plugin. | diff --git a/generators/keymap/USAGE b/generators/keymap/USAGE new file mode 100644 index 0000000..b7c2ce4 --- /dev/null +++ b/generators/keymap/USAGE @@ -0,0 +1,8 @@ +Description: + Creates a Default.sublime-keymap file. Default.sublime-keymap files contain a JSON array that contains JSON objects to specify the key bindings. The JSON objects must contain a keys and command key, and may also contain a args key if the command requires arguments. + +Example: + yo sublime-package:keymap + + This will create: + Default.sublime-keymap: *.sublime-keymap files contain a JSON array that contains JSON objects to specify the key bindings. \ No newline at end of file diff --git a/generators/keymap/config.js b/generators/keymap/config.js new file mode 100644 index 0000000..2f2ab3d --- /dev/null +++ b/generators/keymap/config.js @@ -0,0 +1,23 @@ +const config = { + name: 'Keymap', + description: 'Creates a Default.sublime-keymap file. Default.sublime-keymap files contain the key bindings (shortcuts) for a command.', + priority: 4, + versions: { + '4.0.x': '', + }, + prompts: [ + { + name: 'keymap_shortcut', + message: 'What is the shortcut of your command?', + type: 'input', + default: 'super+ctrl+alt+k', + }, + { + name: 'keymap_command', + message: 'What is the name of your command?', + type: 'input', + default: '${config.package_name_pascal_case}', + }, + ], +}; +module.exports = config; \ No newline at end of file diff --git a/generators/keymap/index.js b/generators/keymap/index.js new file mode 100644 index 0000000..1d5bbb1 --- /dev/null +++ b/generators/keymap/index.js @@ -0,0 +1,73 @@ +'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, + }; + + this.renderTemplate( + this.templatePath('Default.sublime-keymap'), + this.destinationPath('Default.sublime-keymap'), + 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/keymap/templates/Default.sublime-keymap b/generators/keymap/templates/Default.sublime-keymap new file mode 100644 index 0000000..8d7f449 --- /dev/null +++ b/generators/keymap/templates/Default.sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["<%= keymap_shortcut %>"], "command": "<%= keymap_command %>" }, +] \ No newline at end of file diff --git a/generators/settings/config.js b/generators/settings/config.js index 4f27a10..ec5cf5c 100644 --- a/generators/settings/config.js +++ b/generators/settings/config.js @@ -1,7 +1,7 @@ const config = { name: 'Settings', description: 'Creates a SublimePackage.sublime-settings file to stores configuration data.', - priority: 4, + priority: 5, versions: { '4.0.x': '', }, diff --git a/generators/snippet/config.js b/generators/snippet/config.js index ce3784c..c8344c6 100644 --- a/generators/snippet/config.js +++ b/generators/snippet/config.js @@ -1,7 +1,7 @@ const config = { name: 'Snippet', description: 'Creates a Snippet file. Snippets are smart templates that will insert text for you, adapting it to their context.', - priority: 5, + priority: 6, versions: { '4.0.x': '', },