fixed issue with globing pattern, allow glob pattern

This commit is contained in:
ido 2017-01-04 14:24:06 +02:00
parent 3eb8df60b3
commit 6c5ea9e3a1
4 changed files with 28 additions and 4 deletions

View File

@ -7,7 +7,7 @@ npm install react-templates -g
## Usage
```shell
rt [file.rt|dir]* [options]
rt [file.rt|glob]* [options]
```
Such as:
@ -15,6 +15,15 @@ Such as:
rt dir/file.rt
```
Please note that when passing a glob as a parameter, it will be expanded by your shell.
The results of the expansion can vary depending on your shell, and its configuration.
If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:
```shell
rt 'src/**/*.rt'
```
## Options
The command line utility has several options. You can view the options by running `rt -h`.

View File

@ -35,6 +35,7 @@
"css": "2.2.1",
"escodegen": "1.8.1",
"esprima": "3.1.3",
"glob": "7.1.1",
"lodash": "4.17.4",
"normalize-html-whitespace": "0.2.0",
"optionator": "0.8.2",

View File

@ -2,6 +2,7 @@
'use strict';
const _ = require('lodash');
const path = require('path');
// const fs = require('fs');
const api = require('./api');
const context = require('./context');
const shell = require('./shell');
@ -10,6 +11,7 @@ const options = require('./options');
const reactDOMSupport = require('./reactDOMSupport');
const reactTemplates = require('./reactTemplates');
const rtStyle = require('./rtStyle');
const glob = require('glob');
/**
* @param {Options} currentOptions
@ -31,7 +33,19 @@ function executeOptions(currentOptions) {
} else if (currentOptions.listTargetVersion) {
printVersions(currentOptions);
} else if (files.length) {
_.forEach(files, handleSingleFile.bind(this, currentOptions));
// console.log(files);
// console.log(files.length);
// const allFiles = _.flatMap(files, f => {
// const fp = path.resolve(context.cwd, f);
// if (fs.statSync(fp).isDirectory()) {
// // TODO: consider removing glob and simply walk the directory
// return glob.sync(`${fp}/**/*.rt`, {cwd: context.cwd});
// }
// return fp;
// });
const allFiles = _.flatMap(files, f => glob.sync(f, {cwd: context.cwd}));
// console.log(allFiles.length);
_.forEach(allFiles, handleSingleFile.bind(this, currentOptions));
ret = shell.printResults(context);
} else {
console.log(options.generateHelp());

View File

@ -24,7 +24,7 @@ module.exports = optionator({
${pkg.description}
Usage:
$ rt <filename> [<filename> ...] [<args>]`,
$ rt <filename|glob> [<filename|glob> ...] [<args>]`,
concatRepeatedArrays: true,
mergeRepeatedObjects: true,
options: [{
@ -114,7 +114,7 @@ $ rt <filename> [<filename> ...] [<args>]`,
alias: 'rnv',
type: 'String',
enum: Object.keys(reactNativeSupport),
default: reactNativeSupport.default,
default: reactNativeSupport.default,
description: `React native version to generate code for (${Object.keys(reactNativeSupport).join(', ')})`
}, {
option: 'normalize-html-whitespace',