Skip to content

Commit

Permalink
move readme-file into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit authored and tmcw committed May 22, 2018
1 parent f70961d commit 0c48198
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -39,7 +39,6 @@
"parse-filepath": "^1.0.2",
"pify": "^3.0.0",
"read-pkg-up": "^3.0.0",
"readme-file": "^0.2.0",
"remark": "^9.0.0",
"remark-html": "7.0.0",
"remark-reference-links": "^4.0.1",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/readme.js
Expand Up @@ -8,14 +8,14 @@ const sharedOptions = require('./shared_options');
const inject = require('mdast-util-inject');
const chalk = require('chalk');
const disparity = require('disparity');
const getReadmeFile = require('readme-file');
const getReadmeFile = require('../get-readme-file');

module.exports.command = 'readme [input..]';
module.exports.description = 'inject documentation into your README.md';

let DEFAULT_README_FILE = 'README.md';
let defaultReadmeFile = 'README.md';
try {
DEFAULT_README_FILE = getReadmeFile('.');
defaultReadmeFile = getReadmeFile('.');
} catch (err) {
// ignore and use default README.md
}
Expand All @@ -33,7 +33,7 @@ module.exports.builder = Object.assign(
{
'readme-file': {
describe: 'The markdown file into which to inject documentation',
default: DEFAULT_README_FILE
default: defaultReadmeFile
},
section: {
alias: 's',
Expand Down
25 changes: 25 additions & 0 deletions src/get-readme-file.js
@@ -0,0 +1,25 @@
/* @flow */

const fs = require('fs');
const path = require('path');

module.exports = function findReadme(dir: string) {
const readmeFilenames = [
'README',
'README.markdown',
'README.md',
'README.txt',
'Readme.md',
'readme.markdown',
'readme.md',
'readme.txt'
];

const readmeFile = fs.readdirSync(dir).find(function(filename) {
return readmeFilenames.indexOf(filename) >= 0;
});

if (readmeFile) {
return path.join(fs.realpathSync(dir), readmeFile);
}
};
10 changes: 0 additions & 10 deletions yarn.lock
Expand Up @@ -5173,16 +5173,6 @@ readdirp@^2.0.0:
readable-stream "^2.0.2"
set-immediate-shim "^1.0.1"

readme-file@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/readme-file/-/readme-file-0.2.0.tgz#4ce8f43d756f53740f39b7a9121469d7fb0508fc"
dependencies:
readme-filenames "^1.0.1"

readme-filenames@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/readme-filenames/-/readme-filenames-1.0.1.tgz#9c125c69839c3741edf4f0b4b46ba51e1a3a4bf8"

realpath-native@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-1.0.0.tgz#7885721a83b43bd5327609f0ddecb2482305fdf0"
Expand Down

0 comments on commit 0c48198

Please sign in to comment.