Comparing version 1.0.0-5 to 1.0.0-6
@@ -20,2 +20,3 @@ const EventEmitter = require('events').EventEmitter | ||
* @param {string} [options.replace] - The replace string. If omitted, defaults to a empty string. The special token `{{index}}` will insert a number, incremented each time a file is replaced. | ||
* @param {string} [options.pathElement] - The path element to rename, valid values are "base" (the default), "name" and "ext". | ||
* @emits module:renamer#rename-start | ||
@@ -22,0 +23,0 @@ */ |
@@ -75,3 +75,3 @@ const cliOptions = require('../lib/cli-options') | ||
this.log('Before:'.padEnd(8), result.from) | ||
this.log('After:'.padEnd(8), result.to) | ||
if (result.to) this.log('After:'.padEnd(8), result.to) | ||
this.log('--------') | ||
@@ -95,4 +95,4 @@ } else if (view === 'diff') { | ||
this.log('Before:'.padEnd(8), result.from) | ||
this.log('After:'.padEnd(8), result.to) | ||
this.log('Diff:'.padEnd(8), data.join('')) | ||
if (result.to) this.log('After:'.padEnd(8), result.to) | ||
if (data.length) this.log('Diff:'.padEnd(8), data.join('')) | ||
this.log('--------') | ||
@@ -99,0 +99,0 @@ } else { |
@@ -50,6 +50,6 @@ exports.optionDefinitions = [ | ||
exports.usageSections = function (optionDefinitions, plugins) { | ||
exports.usageSections = function (allOptionDefinitions, plugins) { | ||
const util = require('./util') | ||
plugins = util.loadPlugins(plugins) | ||
return [ | ||
const sections = [ | ||
{ | ||
@@ -66,17 +66,29 @@ header: 'renamer', | ||
content: plugins.length | ||
? plugins.map(mw => ({ | ||
name: '↓ ' + mw.constructor.name, | ||
desc: mw.description && mw.description() | ||
? plugins.map(p => ({ | ||
name: '↓ ' + p.constructor.name, | ||
desc: p.description && p.description() | ||
})) | ||
: '{italic Stack empty, supply one or more middlewares using --stack.}' | ||
: '{italic Replace chain empty, supply one or more plugins using --plugin.}' | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: optionDefinitions, | ||
header: 'General options', | ||
optionList: exports.optionDefinitions, | ||
hide: 'files' | ||
}, | ||
{ | ||
content: 'for more detailed instructions, visit {underline https://github.com/75lb/renamer}' | ||
} | ||
] | ||
for (const plugin of plugins) { | ||
const pluginDefinitions = plugin.optionDefinitions() | ||
if (pluginDefinitions.length) { | ||
sections.push({ | ||
header: 'Plugin: ' + plugin.constructor.name, | ||
optionList: pluginDefinitions | ||
}) | ||
} | ||
} | ||
sections.push({ | ||
content: 'For detailed instructions, visit {underline https://github.com/75lb/renamer}' | ||
}) | ||
return sections | ||
} |
@@ -67,3 +67,3 @@ /** | ||
} | ||
if (!t.isFunction(createPlugin)) { | ||
if (!(t.isFunction(createPlugin) && !t.isClass(createPlugin))) { | ||
throw new Error('Invalid plugin: plugin module must export a function') | ||
@@ -70,0 +70,0 @@ } |
{ | ||
"name": "renamer", | ||
"description": "Rename files in bulk", | ||
"version": "1.0.0-5", | ||
"version": "1.0.0-6", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
@@ -29,3 +29,3 @@ "bin": "bin/cli.js", | ||
"docs": "jsdoc2md index.js > docs/API.md", | ||
"cover": "nyc --reporter=text-lcov test-runner test/*.js | coveralls" | ||
"cover": "nyc test-runner test/*.js && nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
@@ -32,0 +32,0 @@ "dependencies": { |
@@ -11,3 +11,3 @@ [![view on npm](http://img.shields.io/npm/v/renamer/next.svg)](https://www.npmjs.org/package/renamer) | ||
# renamer | ||
Renamer is a command-line utility to help rename files and folders in bulk. It is flexible and extensible via plugins. | ||
Renamer is a command-line utility to help rename files and folders. It is flexible and extensible via plugins. | ||
@@ -20,8 +20,9 @@ ## Disclaimer | ||
As input, renamer takes a list of filenames or glob patterns plus some options describing how you would like the files to be renamed. If no filesnames/patterns are specified, renamer will look for a newline-separated list of filenames on standard input. | ||
As input, renamer takes a list of filenames or glob patterns plus some options describing how you would like the files to be renamed. | ||
<pre><code>$ renamer [options] [<u>file</u> <u>...</u>] | ||
</pre></code> | ||
``` | ||
$ renamer [options] [file...] | ||
``` | ||
Trivial example. It will replace the text `jpeg` with `jpg` in all file or folder names in the current directory. | ||
Trivial example. It will replace the text `jpeg` with `jpg` in all file and directory names in the current directory. | ||
@@ -38,3 +39,3 @@ ``` | ||
Same operation but on a filename list supplied via stdin. This approach is useful for crafting a more specific input list using tools like `find`. This example operates on files modified less than 20 minutes ago. | ||
If no filesnames/patterns are specified, renamer will look for a newline-separated list of filenames on standard input. This approach is useful for crafting a more specific input list using tools like `find`. This example operates on files modified less than 20 minutes ago. | ||
@@ -82,54 +83,5 @@ ``` | ||
The full set of command-line options. | ||
``` | ||
-d, --dry-run Used for test runs. Set this to do everything but rename the file. | ||
--force If the target path already exists, overwrite it. Use with caution. | ||
--view detail|diff The default view outputs one line per rename. Set `--view detail` to see a | ||
longer, less condensed view and `--view diff` to include a diff. | ||
-p, --plugin string One or more replacer plugins to use, set the `--plugin` option multiple times | ||
to build a chain. For each value, supply either a) a path to a plugin file | ||
b) a path to a plugin package c) the name of a plugin package installed in | ||
the current working directory or above. The default plugin chain is `default` | ||
then `index`, be sure to set `-p default -p index` before your plugin if you | ||
wish to extend default behaviour. | ||
-v, --verbose In the output, also include names of files that were not renamed. | ||
-h, --help Print usage instructions. | ||
-f, --find string Optional find string (e.g. `one`) or regular expression literal (e.g. | ||
`/one/i`). If omitted, the whole filename will be matched and replaced. | ||
-r, --replace string The replace string. If omitted, defaults to a empty string. The special token | ||
`{{index}}` will insert a number, incremented each time a file is replaced. | ||
--index-format The format of the number to replace `{{index}}` with. Specify a standard | ||
printf format string, e.g `%03d`. Defaults to `%d`. | ||
``` | ||
For more information on Regular Expressions, see [this useful guide](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions). | ||
## Globbing | ||
Renamer comes with globbing support built in supporting all special characters [described here](https://github.com/isaacs/node-glob#glob-primer). | ||
For example, this command operates on all `js` files in the current directory: | ||
``` | ||
$ renamer --find this --replace that "*.js" | ||
``` | ||
This command operates on all `js` files, recursively: | ||
``` | ||
$ renamer --find this --replace that "**/*.js" | ||
``` | ||
this command operates on all `js` files from the `lib` directory downward: | ||
``` | ||
$ renamer --find this --replace that "lib/**/*.js" | ||
``` | ||
**Bash users without globstar will need to enclose the glob expression in quotes to prevent native file expansion**, i.e. `"**/*.js"` | ||
## Further reading | ||
Please see [the wiki](https://github.com/75lb/renamer/wiki) for more documentation and examples. | ||
Please see [the wiki](https://github.com/75lb/renamer/wiki) for more documentation and examples. For the full list of command-line options, see [here](https://github.com/75lb/renamer/wiki/Renamer-CLI-docs). For more information on Regular Expressions, see [this useful guide](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions). | ||
@@ -136,0 +88,0 @@ ## Install |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
471
22918
93