Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

renamer

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

renamer - npm Package Compare versions

Comparing version 1.0.0-0 to 1.0.0-1

8

index.js
const EventEmitter = require('events').EventEmitter
/**
* Rename files in bulk.
* @module renamer

@@ -18,2 +19,3 @@ */

* @param {boolean} [options.force]
* @param {string} [options.view] - The default view outputs one line per rename. Set `--view detail` to see more info including a diff.
* @param {string[]} [options.plugin]

@@ -37,4 +39,5 @@ * @emits module:renamer#rename-start

* @type {object}
* @property {string} from
* @property {string} to
* @property {string} from - The filename before rename.
* @property {string} to - The filename after rename.
* @property {boolean} renamed - True if the file was renamed.
*/

@@ -44,3 +47,2 @@ this.emit('rename-start', replaceResult)

renameFile(replaceResult.from, replaceResult.to, { force: options.force, dryRun: options.dryRun })
this.emit('rename-end', replaceResult)
}

@@ -47,0 +49,0 @@ }

@@ -25,7 +25,4 @@ const cliOptions = require('../lib/cli-options')

renamer.on('rename-start', replaceResult => {
this.logReplace(options.verbose, replaceResult)
this.writeOutput(options.verbose, options.view, replaceResult)
})
renamer.on('rename-end', replaceResult => {
// this.logReplace(options.verbose, replaceResult)
})
try {

@@ -48,7 +45,7 @@ if (options.dryRun) {

log (msg) {
console.log(msg)
log (...args) {
console.log(...args)
}
logReplace (verbose, result) {
writeOutput (verbose, view, result) {
/* Only log not-renamed files if --verbose is set */

@@ -59,7 +56,28 @@ if (!result.renamed && !verbose) return

const symbol = chalk`{${result.renamed ? 'green' : 'red'} ${result.renamed ? tick : cross}}`
// TODO: diff
const desc = result.from + (result.to ? ' -> ' + result.to : '')
const errDesc = result.error ? chalk`({red ${result.error}})` : ''
this.log(chalk`${symbol} ${desc} ${errDesc}`)
if (view === 'detail') {
const fastDiff = require('fast-diff')
this.log('Renamed:'.padEnd(8), symbol)
this.log('Before:'.padEnd(8), result.from)
if (result.to) {
this.log('After:'.padEnd(8), result.to)
const diff = fastDiff(result.from, result.to)
process.stdout.write('Diff:'.padEnd(9))
for (const [code, hunk] of diff) {
if (code === 0) {
process.stdout.write(hunk)
} if (code === -1) {
process.stdout.write(chalk.bgRed(hunk))
} if (code === 1) {
process.stdout.write(chalk.green(hunk))
}
}
process.stdout.write('\n')
}
this.log('⎻⎻⎻⎻⎻⎻⎻')
} else {
const desc = result.from + (result.to ? chalk.bold(' → ') + result.to : '')
this.log(chalk`${symbol} ${desc} ${errDesc}`)
}
}

@@ -66,0 +84,0 @@

@@ -34,2 +34,7 @@ exports.optionDefinitions = [

},
{
name: 'view',
type: String,
description: 'The default view outputs one line per rename. Set `--view detail` to see more info including a diff.'
},
// {

@@ -64,3 +69,3 @@ // name: 'plugin',

header: 'Synopsis',
content: '$ renamer [options] <files>'
content: '$ renamer [options] [{underline file} ...]'
},

@@ -67,0 +72,0 @@ {

@@ -5,18 +5,4 @@ 'use strict'

constructor (pluginNames) {
const path = require('path')
const util = require('./util')
this.plugins = []
pluginNames = pluginNames || [ require('./plugin/default'), require('./plugin/index') ]
for (const pluginName of pluginNames) {
let createPlugin
if (typeof pluginName === 'string') {
createPlugin = util.loadModule(pluginName, { paths: [
process.cwd(), path.resolve(__dirname, 'plugin')
]})
} else {
createPlugin = pluginName
}
const Plugin = createPlugin(require('./plugin-base'))
this.plugins.push(new Plugin())
}
this.plugins = util.loadPlugins(pluginNames)
}

@@ -23,0 +9,0 @@

@@ -21,8 +21,2 @@ /**

function escapeRegExp (string) {
return string
? string.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1')
: ''
}
function loadModule (moduleId, options) {

@@ -66,4 +60,21 @@ options = Object.assign({ paths: [ process.cwd() ] }, options)

function loadPlugins (pluginNames) {
const path = require('path')
pluginNames = pluginNames || [ require('./plugin/default'), require('./plugin/index') ]
return pluginNames.map(pluginName => {
let createPlugin
if (typeof pluginName === 'string') {
createPlugin = loadModule(pluginName, { paths: [
process.cwd(), path.resolve(__dirname, 'plugin')
]})
} else {
createPlugin = pluginName
}
const Plugin = createPlugin(require('./plugin-base'))
return new Plugin()
})
}
exports.regExpBuilder = regExpBuilder
exports.escapeRegExp = escapeRegExp
exports.loadModule = loadModule

@@ -73,1 +84,2 @@ exports.expandGlobPatterns = expandGlobPatterns

exports.depthFirstCompare = depthFirstCompare
exports.loadPlugins = loadPlugins
{
"name": "renamer",
"description": "Rename files in bulk",
"version": "1.0.0-0",
"version": "1.0.0-1",
"author": "Lloyd Brookes <75pound@gmail.com>",

@@ -35,2 +35,3 @@ "bin": "bin/cli.js",

"command-line-usage": "^5.0.5",
"fast-diff": "^1.1.2",
"glob": "^7.1.2",

@@ -37,0 +38,0 @@ "reduce-flatten": "^2.0.0",

@@ -11,3 +11,3 @@ [![view on npm](http://img.shields.io/npm/v/renamer.svg)](https://www.npmjs.org/package/renamer)

# renamer
Renamer is a command-line utility intended 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 in bulk. It is flexible and extensible via plugins.

@@ -25,3 +25,3 @@ ## Disclaimer

Trivial example. It will replace the text `jpeg` with `jpg` in all files or folders in the current directory.
Trivial example. It will replace the text `jpeg` with `jpg` in all file or folder names in the current directory.

@@ -67,10 +67,12 @@ ```

```
-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.
-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.
-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.
-v, --verbose In the output, also include names of files that were not renamed.
-h, --help Print usage instructions.
```

@@ -77,0 +79,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc