Skip to content

Commit

Permalink
Switch to export components only
Browse files Browse the repository at this point in the history
  • Loading branch information
rianbotha committed May 5, 2019
1 parent a1246f6 commit ebc22bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The props table in the file needs to be wrapped between `<!-- props-table-start

### Options

* `--toConsole` will write the props table to the terminal instead of the file.
* `--to-console` will write the props table to the terminal instead of the file.
* `--force` will write the props table at the end of the readme if no table wrapped by comments is found. The readme.md will be created if it doesn't exist.
* `--help` or `-h` display usage options
* `--version` or `-v` display version information
2 changes: 1 addition & 1 deletion build-props-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const addLine = require('./add-line');
const buildPropsTable = (filename) => {
try {
const content = fs.readFileSync(path.resolve(process.cwd(), filename), 'utf-8');
const components = reactDocs.parse(content, reactDocs.resolver.findAllComponentDefinitions);
const components = reactDocs.parse(content, reactDocs.resolver.findAllExportedComponentDefinitions);

let propsTable = '';

Expand Down
17 changes: 8 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ const buildPropsTable = require('./build-props-table');
const writeReadme = require('./write-readme');
const argv = require('yargs')
.usage('Usage: $0 <filename> [options]')
.boolean(['toConsole', 'force'])
.describe('toConsole', 'Outputs props table to command line instead of readme')
.boolean(['to-console', 'force'])
.describe('to-console', 'Outputs props table to command line instead of readme')
.describe('force', 'Add props table at end of file if no table is found to be replaced. A new readme.md will be created if it does not exist.')
.demandCommand(1, 'You need to provide a file to extract the props table from.')
.alias('h', 'help')
.alias('v', 'version')
.argv

const filename = argv._[0];
const toConsole = argv.toConsole;
const toConsole = argv['to-console'];
const force = argv.force;
const readme = path.dirname(filename) + '/readme.md';
const regex = /<!-- props-table-start -->[\s\S]*<!-- props-table-end -->/m;

const propsTable = buildPropsTable(filename);

if (toConsole) {
console.log('<!-- props-table-start -->\n' + propsTable + '<!-- props-table-end -->');
process.exit(1);
}

if (propsTable) {
writeReadme(readme, propsTable, regex, force);
if (toConsole) {
console.log('<!-- props-table-start -->\n' + propsTable + '<!-- props-table-end -->');
} else {
writeReadme(readme, propsTable, regex, force);
}
}

0 comments on commit ebc22bc

Please sign in to comment.