Skip to content

Commit

Permalink
✨ Adding some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck committed Jun 12, 2019
1 parent 772d536 commit 6850244
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 17 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@

`readme-md-generator` is able to read your environment (package.json, git config...) to suggest you default answers during the `README.md` creation process :

<img width="700" src="https://user-images.githubusercontent.com/9840435/59162633-8f291b80-8af4-11e9-9985-b0f768cbc2b1.gif" alt="demo"/>
<div align="center">
<img width="700" align="center" src="https://user-images.githubusercontent.com/9840435/59162633-8f291b80-8af4-11e9-9985-b0f768cbc2b1.gif" alt="demo"/>
</div>

Generated `README.md` :

<img width="700" src="https://user-images.githubusercontent.com/9840435/59162884-02cd2780-8af9-11e9-9765-e1af31fd8bc2.jpg" alt="cli output"/>
<div align="center">
<img width="700" src="https://user-images.githubusercontent.com/9840435/59162884-02cd2780-8af9-11e9-9765-e1af31fd8bc2.jpg" alt="cli output"/>
</div>

Example of `package.json` with good meta data :

Expand Down
9 changes: 8 additions & 1 deletion src/project-infos.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const getProjectName = require('project-name')
const isNil = require('lodash/isNil')
const get = require('lodash/get')
const has = require('lodash/has')
const ora = require('ora')
const { execSync } = require('child_process')

Expand Down Expand Up @@ -109,6 +110,10 @@ const getProjectInfos = async () => {
const version = get(packageJson, 'version', undefined)
const licenseName = get(packageJson, 'license', undefined)
const homepage = get(packageJson, 'homepage', undefined)
const usage = has(packageJson, 'scripts.start') ? 'npm run start' : undefined
const testCommand = has(packageJson, 'scripts.test')
? 'npm run test'
: undefined
const repositoryUrl = await getReposUrl(packageJson)
const contributingUrl = await getReposIssuesUrl(packageJson)
const isGithubRepos = isGithubRepository(repositoryUrl)
Expand Down Expand Up @@ -137,7 +142,9 @@ const getProjectInfos = async () => {
licenseName,
licenseUrl,
documentationUrl,
isGithubRepos
isGithubRepos,
usage,
testCommand
}
}

Expand Down
24 changes: 18 additions & 6 deletions src/project-infos.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ describe('projectInfos', () => {
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE',
documentationUrl:
'https://github.com/kefranabg/readme-md-generator#readme',
isGithubRepos: true
isGithubRepos: true,
usage: undefined,
testCommand: undefined
})
})

Expand Down Expand Up @@ -127,7 +129,9 @@ describe('projectInfos', () => {
licenseName: 'MIT',
licenseUrl: undefined,
documentationUrl: undefined,
isGithubRepos: false
isGithubRepos: false,
usage: undefined,
testCommand: undefined
})
})

Expand Down Expand Up @@ -155,7 +159,9 @@ describe('projectInfos', () => {
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE',
documentationUrl:
'https://github.com/kefranabg/readme-md-generator#readme',
isGithubRepos: true
isGithubRepos: true,
usage: undefined,
testCommand: undefined
})
})

Expand All @@ -181,7 +187,9 @@ describe('projectInfos', () => {
licenseName: undefined,
licenseUrl: undefined,
documentationUrl: undefined,
isGithubRepos: false
isGithubRepos: false,
usage: undefined,
testCommand: undefined
})
})

Expand All @@ -206,7 +214,9 @@ describe('projectInfos', () => {
licenseName: undefined,
licenseUrl: undefined,
documentationUrl: undefined,
isGithubRepos: false
isGithubRepos: false,
usage: undefined,
testCommand: undefined
})
})

Expand Down Expand Up @@ -256,7 +266,9 @@ describe('projectInfos', () => {
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE',
documentationUrl:
'https://github.com/kefranabg/readme-md-generator#readme',
isGithubRepos: true
isGithubRepos: true,
usage: undefined,
testCommand: undefined
})
})
})
Expand Down
5 changes: 4 additions & 1 deletion src/questions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ module.exports = {
askProjectPrerequisites: require('./project-prerequisites'),
askLicenseName: require('./license-name'),
askLicenseUrl: require('./license-url'),
askContributing: require('./contributing')
askContributing: require('./contributing'),
askInstallCommand: require('./install-command'),
askUsage: require('./usage'),
askTestCommand: require('./test-command')
}
5 changes: 4 additions & 1 deletion src/questions/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('questions', () => {
'askProjectPrerequisites',
'askLicenseName',
'askLicenseUrl',
'askContributing'
'askContributing',
'askInstallCommand',
'askUsage',
'askTestCommand'
])
})
})
6 changes: 6 additions & 0 deletions src/questions/install-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = () => ({
type: 'input',
message: 'πŸ“¦ Install command (use empty value to skip)',
name: 'installCommand',
default: 'npm install'
})
14 changes: 14 additions & 0 deletions src/questions/install-command.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const askInstallCommand = require('./install-command')

describe('askInstallCommand', () => {
it('should return correct question format', () => {
const result = askInstallCommand()

expect(result).toEqual({
type: 'input',
message: 'πŸ“¦ Install command (use empty value to skip)',
name: 'installCommand',
default: 'npm install'
})
})
})
6 changes: 6 additions & 0 deletions src/questions/test-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = projectInfos => ({
type: 'input',
message: 'βœ… Test command (use empty value to skip)',
name: 'testCommand',
default: projectInfos.testCommand
})
17 changes: 17 additions & 0 deletions src/questions/test-command.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const askTestCommand = require('./test-command')

describe('askTestCommand', () => {
it('should return correct question format', () => {
const testCommand = 'npm run test'
const projectInfos = { testCommand }

const result = askTestCommand(projectInfos)

expect(result).toEqual({
type: 'input',
message: 'βœ… Test command (use empty value to skip)',
name: 'testCommand',
default: testCommand
})
})
})
6 changes: 6 additions & 0 deletions src/questions/usage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = projectInfos => ({
type: 'input',
message: 'πŸš€ Usage command or instruction (use empty value to skip)',
name: 'usage',
default: projectInfos.usage
})
17 changes: 17 additions & 0 deletions src/questions/usage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const askUsage = require('./usage')

describe('askUsage', () => {
it('should return correct question format', () => {
const usage = 'npm start'
const projectInfos = { usage }

const result = askUsage(projectInfos)

expect(result).toEqual({
type: 'input',
message: 'πŸš€ Usage command or instruction (use empty value to skip)',
name: 'usage',
default: usage
})
})
})
10 changes: 7 additions & 3 deletions src/readme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ describe('readme', () => {
licenseName: 'MIT',
licenseUrl:
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE',
contributingUrl: 'https://github.com/kefranabg/readme-md-generator/issues'
contributingUrl:
'https://github.com/kefranabg/readme-md-generator/issues',
installCommand: 'npm install',
usage: 'npm start',
testCommand: 'npm run test'
}

afterEach(() => {
Expand Down Expand Up @@ -130,13 +134,13 @@ describe('readme', () => {
## πŸ“¦ Install
\`\`\`sh
npm i
npm install
\`\`\`
## πŸš€ Usage
\`\`\`sh
npm run start
npm start
\`\`\`
## βœ… Run tests
Expand Down
12 changes: 9 additions & 3 deletions templates/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,30 @@

- <%= projectPrerequisites.join("\n- "); %>
<% } -%>
<% if (installCommand) { -%>

## πŸ“¦ Install

```sh
npm i
<%= installCommand %>
```
<% } -%>
<% if (usage) { -%>

## πŸš€ Usage

```sh
npm run start
<%= usage %>
```
<% } -%>
<% if (testCommand) { -%>

## βœ… Run tests

```sh
npm run test
<%= testCommand %>
```
<% } -%>
<% if (contributingUrl) { -%>

## 🀝 Contributing
Expand Down

0 comments on commit 6850244

Please sign in to comment.