Skip to content

Commit

Permalink
feat(generator): create src/
Browse files Browse the repository at this point in the history
  • Loading branch information
macklinu committed May 17, 2017
1 parent e34de96 commit bc33e4e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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() {
Expand Down
22 changes: 22 additions & 0 deletions src/app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]',
})
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 protected]',
})
assert.fileContent('src/index.test.js', 'funTime()')
})
})
describe('CODE_OF_CONDUCT.md', () => {
it('contains author email', async () => {
await helpers.run(__dirname).withPrompts({
Expand Down
3 changes: 3 additions & 0 deletions src/app/templates/src/index
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function <%= pluginFunctionName %> {

}
3 changes: 3 additions & 0 deletions src/app/templates/src/index.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('<%= pluginFunctionName %>', () => {
it('does something')
})

0 comments on commit bc33e4e

Please sign in to comment.