diff --git a/package.json b/package.json index 7bba9c8..3de7afe 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,12 @@ "mkdirp": "^0.5.1", "yeoman-generator": "^1.1.1" }, + "jest": { + "testPathIgnorePatterns": [ + "/node_modules/", + "/app/src/templates/src/" + ] + }, "config": { "commitizen": { "path": "cz-conventional-changelog" diff --git a/src/app/index.js b/src/app/index.js index d044ed1..54d54ac 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -14,6 +14,13 @@ function makeGeneratorName(name) { name = name.indexOf(PLUGIN_PREFIX) === 0 ? name : PLUGIN_PREFIX + name return name } + +function makePluginFunctionName(name) { + const functionName = _.camelCase( + name.substring(PLUGIN_PREFIX.length, name.length) + ) + return `${functionName}()` +} export default class extends Generator { initializing() { this.props = {} @@ -118,6 +125,18 @@ export default class extends Generator { ) this.fs.copy(this.templatePath('babelrc'), this.destinationPath('.babelrc')) + + this.fs.copyTpl( + this.templatePath('src/index'), + this.destinationPath('src/index.js'), + { pluginFunctionName: makePluginFunctionName(this.props.pluginName) } + ) + + this.fs.copyTpl( + this.templatePath('src/index.test'), + this.destinationPath('src/index.test.js'), + { pluginFunctionName: makePluginFunctionName(this.props.pluginName) } + ) } install() { diff --git a/src/app/index.test.js b/src/app/index.test.js index 611ba7d..6280df1 100644 --- a/src/app/index.test.js +++ b/src/app/index.test.js @@ -30,8 +30,30 @@ describe('generator:app', () => { '.gitignore', '.npmignore', '.esdoc.json', + 'src/index.js', + 'src/index.test.js', ]) }) + describe('src/', () => { + it('generates source file based on plugin name', async () => { + await helpers.run(__dirname).withPrompts({ + pluginName: 'danger-plugin-fun-time', + description: 'Danger plugin that tells you to have a fun time', + authorName: 'Macklin Underdown', + authorEmail: 'email@example.com', + }) + assert.fileContent('src/index.js', 'funTime()') + }) + it('generates source file based on plugin name', async () => { + await helpers.run(__dirname).withPrompts({ + pluginName: 'danger-plugin-fun-time', + description: 'Danger plugin that tells you to have a fun time', + authorName: 'Macklin Underdown', + authorEmail: 'email@example.com', + }) + assert.fileContent('src/index.test.js', 'funTime()') + }) + }) describe('CODE_OF_CONDUCT.md', () => { it('contains author email', async () => { await helpers.run(__dirname).withPrompts({ diff --git a/src/app/templates/src/index b/src/app/templates/src/index new file mode 100644 index 0000000..3a7c5b5 --- /dev/null +++ b/src/app/templates/src/index @@ -0,0 +1,3 @@ +export default function <%= pluginFunctionName %> { + +} diff --git a/src/app/templates/src/index.test b/src/app/templates/src/index.test new file mode 100644 index 0000000..d0950a1 --- /dev/null +++ b/src/app/templates/src/index.test @@ -0,0 +1,3 @@ +describe('<%= pluginFunctionName %>', () => { + it('does something') +})