Comparing version 1.0.0-2 to 1.0.0-3
@@ -102,3 +102,3 @@ const cliOptions = require('../lib/cli-options') | ||
halt (err) { | ||
this.log(chalk.red(err.stack)) | ||
this.log(chalk.red(err.message)) | ||
process.exitCode = 1 | ||
@@ -105,0 +105,0 @@ } |
@@ -62,3 +62,3 @@ exports.optionDefinitions = [ | ||
header: 'Options', | ||
optionList: optionDefinitions || exports.optionDefinitions, | ||
optionList: optionDefinitions, | ||
hide: 'files' | ||
@@ -65,0 +65,0 @@ }, |
@@ -1,3 +0,1 @@ | ||
const path = require('path') | ||
module.exports = PluginBase => class RenamerIndex extends PluginBase { | ||
@@ -9,7 +7,15 @@ constructor () { | ||
optionDefinitions () { | ||
return [ | ||
{ name: 'index-format', description: 'The format of the number to replace `\\{\\{index\\}\\}` with. Specify a standard printf format string, e.g `%03d`. Defaults to `%d`.' } | ||
] | ||
} | ||
replace (file, options) { | ||
if (/{{index}}/.test(file)) { | ||
const path = require('path') | ||
const basename = path.basename(file) | ||
const dirname = path.dirname(file) | ||
return path.join(dirname, this.replaceIndexToken(basename, this.matchCount++)) | ||
const newBasename = this.replaceIndexToken(basename, this.matchCount++, options.indexFormat || '%d') | ||
return path.join(dirname, newBasename) | ||
} else { | ||
@@ -20,5 +26,6 @@ return file | ||
replaceIndexToken (file, index) { | ||
return file.replace(/{{index}}/g, index) | ||
replaceIndexToken (file, index, format) { | ||
const sprintf = require('printj').sprintf | ||
return file.replace(/{{index}}/g, sprintf(format, index)) | ||
} | ||
} |
{ | ||
"name": "renamer", | ||
"description": "Rename files in bulk", | ||
"version": "1.0.0-2", | ||
"version": "1.0.0-3", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
@@ -40,2 +40,3 @@ "bin": "bin/cli.js", | ||
"load-module": "^1.0.0", | ||
"printj": "^1.1.2", | ||
"reduce-flatten": "^2.0.0", | ||
@@ -42,0 +43,0 @@ "reduce-unique": "^2.0.1", |
@@ -1,4 +0,4 @@ | ||
[![view on npm](http://img.shields.io/npm/v/renamer.svg)](https://www.npmjs.org/package/renamer) | ||
[![view on npm](http://img.shields.io/npm/v/renamer/next.svg)](https://www.npmjs.org/package/renamer) | ||
[![npm module downloads](http://img.shields.io/npm/dt/renamer.svg)](https://www.npmjs.org/package/renamer) | ||
[![Build Status](https://travis-ci.org/75lb/renamer.svg?branch=master)](https://travis-ci.org/75lb/renamer) | ||
[![Build Status](https://travis-ci.org/75lb/renamer.svg?branch=next)](https://travis-ci.org/75lb/renamer?branch=next) | ||
[![Coverage Status](https://coveralls.io/repos/github/75lb/renamer/badge.svg?branch=next)](https://coveralls.io/github/75lb/renamer?branch=next) | ||
@@ -59,3 +59,3 @@ [![Dependency Status](https://david-dm.org/75lb/renamer.svg)](https://david-dm.org/75lb/renamer) | ||
``` | ||
$ renamer --find '/one/i' --replace 'two' ONE.jpg | ||
$ renamer --find "/one/i" --replace "two" ONE.jpg | ||
``` | ||
@@ -66,12 +66,20 @@ | ||
``` | ||
-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. | ||
-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 string The default view outputs one line per rename. Set `--view detail` to see more | ||
info including a diff. | ||
--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`. | ||
``` | ||
@@ -88,3 +96,3 @@ | ||
``` | ||
$ renamer --find this --replace that '*.js' | ||
$ renamer --find this --replace that "*.js" | ||
``` | ||
@@ -95,3 +103,3 @@ | ||
``` | ||
$ renamer --find this --replace that '**/*.js' | ||
$ renamer --find this --replace that "**/*.js" | ||
``` | ||
@@ -102,6 +110,6 @@ | ||
``` | ||
$ renamer --find this --replace that 'lib/**/*.js' | ||
$ 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'` | ||
**Bash users without globstar will need to enclose the glob expression in quotes to prevent native file expansion**, i.e. `"**/*.js"` | ||
@@ -108,0 +116,0 @@ ## Further reading |
20341
396
124
12
+ Addedprintj@^1.1.2
+ Addedprintj@1.3.1(transitive)