-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
723c690
commit d1ef9ff
Showing
7 changed files
with
234 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}, | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters