-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Allow user to choose a non HTML README template (#80)
- Loading branch information
Showing
11 changed files
with
358 additions
and
102 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
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,33 @@ | ||
const inquirer = require('inquirer') | ||
const path = require('path') | ||
|
||
module.exports = async useDefaultAnswers => { | ||
const defaultTemplate = path.resolve(__dirname, '../templates/default.md') | ||
const defaultNoHtmlTemplate = path.resolve( | ||
__dirname, | ||
'../templates/default-no-html.md' | ||
) | ||
|
||
if (useDefaultAnswers) return defaultTemplate | ||
|
||
const question = { | ||
type: 'list', | ||
message: | ||
'🎨 Use HTML in your README.md for a nicer rendering? (not supported everywhere. ex: Bitbucket)', | ||
name: 'templatePath', | ||
choices: [ | ||
{ | ||
name: 'Yes ', | ||
value: defaultTemplate | ||
}, | ||
{ | ||
name: 'No', | ||
value: defaultNoHtmlTemplate | ||
} | ||
] | ||
} | ||
|
||
const { templatePath } = await inquirer.prompt([question]) | ||
|
||
return templatePath | ||
} |
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,51 @@ | ||
const inquirer = require('inquirer') | ||
const path = require('path') | ||
|
||
const chooseTemplate = require('./choose-template') | ||
|
||
const defaultTemplatePath = path.resolve(__dirname, '../templates/default.md') | ||
const defaultNoHtmlTemplatePath = path.resolve( | ||
__dirname, | ||
'../templates/default-no-html.md' | ||
) | ||
|
||
inquirer.prompt = jest.fn(() => | ||
Promise.resolve({ templatePath: defaultTemplatePath }) | ||
) | ||
|
||
describe('choose-template', () => { | ||
it('should return user choice', async () => { | ||
const result = await chooseTemplate(false) | ||
|
||
expect(result).toEqual(defaultTemplatePath) | ||
}) | ||
|
||
it('should return default template', async () => { | ||
const result = await chooseTemplate(true) | ||
|
||
expect(result).toEqual(defaultTemplatePath) | ||
}) | ||
|
||
it('should call prompt with correct parameters', async () => { | ||
await chooseTemplate(false) | ||
|
||
expect(inquirer.prompt).toHaveBeenNthCalledWith(1, [ | ||
{ | ||
type: 'list', | ||
message: | ||
'🎨 Use HTML in your README.md for a nicer rendering? (not supported everywhere. ex: Bitbucket)', | ||
name: 'templatePath', | ||
choices: [ | ||
{ | ||
name: 'Yes ', | ||
value: defaultTemplatePath | ||
}, | ||
{ | ||
name: 'No', | ||
value: defaultNoHtmlTemplatePath | ||
} | ||
] | ||
} | ||
]) | ||
}) | ||
}) |
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
Oops, something went wrong.