Comparing version 0.0.3 to 0.1.0
110
index.js
@@ -8,66 +8,62 @@ #! /usr/bin/env node | ||
const { safeLoad } = require('js-yaml'); | ||
const inquirer = require('inquirer'); | ||
const fieldFormatters = { | ||
contributors: (entry, { author, contributors = [] }) => { | ||
const people = [author].concat(contributors); | ||
const result = ['## Contributors\n']; | ||
result.push(people.map(({ name, id }) => `![${name}](https://avatars.githubusercontent.com/u/${id}?s=130)`).join(' | ')); | ||
result.push(people.map(() => '---').join(' | ')); | ||
result.push(people.map(({ name, url }) => `[${name}](${url})`).join(' | ')); | ||
return result.join('\n'); | ||
}, | ||
include: ({ include }) => { | ||
let result; | ||
try { | ||
result = readFileSync(include, 'utf8'); | ||
} catch (error) { | ||
process.stdout.write(`Could not read \`${include}\`!\n`); | ||
} | ||
return result; | ||
}, | ||
license: (entry, { author: { name, url }, license }) => { | ||
const result = ['## License\n']; | ||
result.push(`${license}${name && url && ` @ [${name}](${url})` || ''}`); | ||
return result.join('\n'); | ||
}, | ||
shields: ({ shields: { shields, style } }) => { | ||
const baseURL = 'https://img.shields.io/'; | ||
return `${shields.map(({ alt = '', image = '', link = '' }) => ( | ||
`[![${alt}](${baseURL}${image}${style ? `?style=${style}` : ''})](${link})` | ||
)).join('\n')}\n`; | ||
}, | ||
text: ({ text }) => `${text}\n`, | ||
title: ({ title }, { name }) => `# ${name}\n`, | ||
}; | ||
const writeREADME = content => writeFileSync('README.md', `${content}\n`); | ||
let packageJSON; | ||
const defaults = {}; | ||
let config; | ||
try { | ||
packageJSON = JSON.parse(readFileSync('package.json')); | ||
defaults.title = packageJSON.name; | ||
defaults.version = packageJSON.version; | ||
defaults.description = packageJSON.description; | ||
packageJSON = JSON.parse(readFileSync('package.json', 'utf8')); | ||
} catch (error) { | ||
process.stdout.write('You might want to run npm init first!'); | ||
process.stdout.write('You might want to run `npm init` first!\n'); | ||
} | ||
const questions = safeLoad(readFileSync(`${__dirname}/questions.yml`, 'utf8')).map(question => { | ||
let result = question; | ||
if (defaults[question.name]) { | ||
result = Object.assign(result, { | ||
default: defaults[question.name], | ||
}); | ||
try { | ||
config = safeLoad(readFileSync('./.emdaer.yml', 'utf8')).map(entry => Object.assign(entry, { | ||
type: Object.keys(entry)[0], | ||
})); | ||
} catch (error) { | ||
process.stdout.write('You need an `.emdaer.yml` to use emdaer!\n'); | ||
} | ||
const content = []; | ||
config.forEach(entry => { | ||
if (fieldFormatters[entry.type]) { | ||
content.push(fieldFormatters[entry.type](entry, packageJSON)); | ||
} else { | ||
process.stdout.write(`\`${entry.type}\` is not a supported type!\n`); | ||
} | ||
if (question.when) { | ||
result = Object.assign(result, { | ||
when: !!packageJSON[question.when], | ||
}); | ||
} | ||
return result; | ||
}); | ||
const onComplete = answers => { | ||
const output = []; | ||
if (answers.title) { | ||
output.push(`# ${answers.title}\n`); | ||
} | ||
if (answers.description) { | ||
output.push(answers.description); | ||
} | ||
if (answers.bin) { | ||
output.push('\n## CLI\n'); | ||
Object.keys(packageJSON.bin).forEach(id => { | ||
output.push('```sh'); | ||
output.push(`$ npm install -g ${packageJSON.name}`); | ||
output.push(`$ ${id}`); | ||
output.push('```'); | ||
}); | ||
} | ||
if (answers.scripts) { | ||
output.push(`\n## Scripts\n`); | ||
Object.keys(packageJSON.scripts).forEach(script => { | ||
output.push(`### ${script}\n`); | ||
output.push('```sh'); | ||
output.push(`$ npm run ${script}`); | ||
output.push('```'); | ||
}); | ||
} | ||
if (answers.scripts) { | ||
output.push(`\n## License\n`); | ||
const author = packageJSON.author.name && packageJSON.author.url | ||
&& ` @ [${packageJSON.author.name}](${packageJSON.author.url})`; | ||
output.push(`${packageJSON.license}${author || ''}`); | ||
} | ||
writeFileSync('README.md', `${output.join('\n')}\n`); | ||
}; | ||
inquirer.prompt(questions).then(onComplete); | ||
writeREADME(content.join('\n')); | ||
process.stdout.write('Ayy, wrote you a README.md!\n'); |
{ | ||
"name": "emdaer", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "does a README.md", | ||
"repository": "flipactual/emdaer", | ||
"author": { | ||
"name": "Flip", | ||
"url": "http://flipactual.com" | ||
"url": "http://github.com/flipactual", | ||
"id": 1306968 | ||
}, | ||
@@ -20,7 +22,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"inquirer": "^1.0.3", | ||
"js-yaml": "^3.6.1", | ||
"prompt": "^1.0.0" | ||
"js-yaml": "^3.6.1" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^6.0.4", | ||
"eslint": "^2.11.1", | ||
@@ -27,0 +28,0 @@ "eslint-config-airbnb-base": "^3.0.1", |
125
README.md
# emdaer | ||
[![Travis](https://img.shields.io/travis/flipactual/emdaer.svg?style=flat-square)](https://travis-ci.org/flipactual/emdaer/) | ||
[![Node](https://img.shields.io/node/v/emdaer.svg?style=flat-square)](http://npmjs.com/package/emdaer) | ||
[![NPM](https://img.shields.io/npm/v/emdaer.svg?style=flat-square)](http://npmjs.com/package/emdaer) | ||
does a README.md | ||
@@ -7,17 +11,126 @@ | ||
You can install `emdaer` globally: | ||
```sh | ||
$ npm install -g emdaer | ||
$ npm i -g emdaer | ||
$ cd ~/your-project/ | ||
$ emdaer | ||
``` | ||
## Scripts | ||
Or you can save `emdaer` to specific projects: | ||
### start | ||
```sh | ||
$ npm run start | ||
$ cd ~/your-project | ||
$ npm i -D emdaer | ||
$ ./node_modules/.bin/emdaer | ||
``` | ||
Either way, invoking `emdaer` requires the presence of a valid `.emdaer.yml` configuration file in the current directory. | ||
## Configuration | ||
```yml | ||
- title: true | ||
- shields: | ||
style: 'flat-square' | ||
shields: | ||
- alt: Travis | ||
image: 'travis/flipactual/emdaer.svg' | ||
link: 'https://travis-ci.org/flipactual/emdaer/' | ||
- text: 'does a README.md' | ||
- include: './docs/bin.md' | ||
- include: './docs/configuration.md' | ||
- license: true | ||
``` | ||
`emdaer` iterates over the array in `.emdaer.yml` and creates a `README.md` including the listed elements in the order they're provided. | ||
`.emdaer.yml` supports the following field types: | ||
#### `title` | ||
type: `boolean` | ||
If `true`, pulls title from the `name` field in the project's `package.json` and includes as a level one heading. | ||
If you'd like to use a different title, use `text` instead: | ||
```yml | ||
- text: '# My Title' | ||
``` | ||
#### `text` | ||
type: `string` | ||
A string to insert into the README. Can include markdown formatting. | ||
#### `include` | ||
type: `string` | ||
The path to a file to include in the README. | ||
#### `license` | ||
type: `string` | ||
If `true`, pulls `license` and `author` information from `package.json` to include: | ||
```md | ||
## License | ||
MIT @ [Flip](http://flipactual.com) | ||
<license> @ [<author.name>](<author.url>) | ||
``` | ||
For any other formatting, use `text` or `include`. | ||
#### `contributors` | ||
type: `boolean` | ||
If `true`, creates a table including the `author` and `contributors` from `package.json`. | ||
You must include the GitHub ID of each user: | ||
```json | ||
"author": { | ||
"name": "Flip", | ||
"url": "http://github.com/flipactual", | ||
"id": 1306968 | ||
}, | ||
``` | ||
#### `shields` | ||
type: `object` | ||
Configuration and list of [Shields](http://shields.io) to use. | ||
##### `shields.style` | ||
type: `string` | ||
The style of shields to use. Supports `plastic`, `flat`, `flat-square`, or `social`. | ||
##### `shields.shields` | ||
type: `array` | ||
A list of shields to include. | ||
###### `shields.shields[n].alt` | ||
type: `string` | ||
The alt text for the Shield. | ||
###### `shields.shields[n].image` | ||
type: `string` | ||
The path to the Shield image (eg `travis/flipactual/emdaer.svg`). | ||
###### `shields.shields[n].link` | ||
type: `string` | ||
The link to open when clicking the Shield. | ||
## Contributors | ||
![Flip](https://avatars.githubusercontent.com/u/1306968?s=130) | ||
--- | ||
[Flip](http://github.com/flipactual) | ||
## License | ||
MIT @ [Flip](http://github.com/flipactual) |
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8708
1
8
136
4
63
- Removedinquirer@^1.0.3
- Removedprompt@^1.0.0
- Removed@colors/colors@1.5.0(transitive)
- Removedansi-escapes@1.4.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedasync@2.6.43.2.3(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcli-cursor@1.0.2(transitive)
- Removedcli-width@2.2.1(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcolors@1.0.3(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedexit-hook@1.1.1(transitive)
- Removedextend@3.0.2(transitive)
- Removedexternal-editor@1.1.1(transitive)
- Removedeyes@0.1.8(transitive)
- Removedfigures@1.7.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinquirer@1.2.3(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmute-stream@0.0.6(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonetime@1.1.0(transitive)
- Removedos-shim@0.1.3(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedprompt@1.3.0(transitive)
- Removedread@1.0.7(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedrestore-cursor@1.0.1(transitive)
- Removedrevalidator@0.1.8(transitive)
- Removedrun-async@2.4.1(transitive)
- Removedrx@4.1.0(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedspawn-sync@1.0.15(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtmp@0.0.29(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwinston@2.4.7(transitive)