From 6c5ea9e3a1a20d8272883f981bc1e5f7c3d993d0 Mon Sep 17 00:00:00 2001 From: ido Date: Wed, 4 Jan 2017 14:24:06 +0200 Subject: [PATCH] fixed issue with globing pattern, allow glob pattern --- docs/cli.md | 11 ++++++++++- package.json | 1 + src/cli.js | 16 +++++++++++++++- src/options.js | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 8e00d86..9a3676e 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -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`. diff --git a/package.json b/package.json index dc24b53..d50a9c3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli.js b/src/cli.js index c7dc089..8720621 100755 --- a/src/cli.js +++ b/src/cli.js @@ -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()); diff --git a/src/options.js b/src/options.js index 1195f26..f70c584 100644 --- a/src/options.js +++ b/src/options.js @@ -24,7 +24,7 @@ module.exports = optionator({ ${pkg.description} Usage: -$ rt [ ...] []`, +$ rt [ ...] []`, concatRepeatedArrays: true, mergeRepeatedObjects: true, options: [{ @@ -114,7 +114,7 @@ $ rt [ ...] []`, 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',