-
-
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
1ad2034
commit 62ea0bd
Showing
12 changed files
with
167 additions
and
6 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
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,50 @@ | ||
const path = require('path'); | ||
const helpers = require('yeoman-test'); | ||
|
||
describe('generators:macro', () => { | ||
describe('creates files', () => { | ||
let runResult; | ||
|
||
const config = { | ||
// generator_data | ||
macro_file_name: 'SublimePackage', | ||
|
||
// 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 = [ | ||
'macros/SublimePackage.sublime-macro', | ||
]; | ||
|
||
const expectedContent = [ | ||
[ 'macros/SublimePackage.sublime-macro', 'hardeol' ], | ||
]; | ||
|
||
beforeEach(async () => { | ||
runResult = await helpers | ||
.run(path.join(process.env.INIT_CWD, '/generators/macro')) | ||
.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,8 @@ | ||
Description: | ||
Creates a Default.sublime-macro file. Macros are a basic automation facility comprising sequences of commands. Use them whenever you need to repeat the exact same steps to perform an operation. | ||
|
||
Example: | ||
yo sublime-package:macro | ||
|
||
This will create: | ||
macros/SublimePackage.sublime-macro: Macro files are JSON files with the extension .sublime-macro. |
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,17 @@ | ||
const config = { | ||
name: 'Macro', | ||
description: 'Creates a Default.sublime-macro file. Macros are a basic automation facility comprising sequences of commands. Use them whenever you need to repeat the exact same steps to perform an operation.', | ||
priority: 60, | ||
versions: { | ||
'4.0.x': '', | ||
}, | ||
prompts: [ | ||
{ | ||
name: 'macro_file_name', | ||
message: 'What is the name of your new macro file (macro file name)?', | ||
type: 'input', | ||
default: '${config.package_name_pascal_case}', | ||
}, | ||
], | ||
}; | ||
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,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('macro.sublime-macro'), | ||
this.destinationPath(`macros/${data.macro_file_name}.sublime-macro`), | ||
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,4 @@ | ||
[ | ||
{"command": "move_to", "args": {"to": "hardeol"}}, | ||
{"command": "insert", "args": {"characters": "\n"}} | ||
] |
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
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
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