cjs-rename
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -10,6 +10,7 @@ 'use strict'; | ||
var MODE_PATH = 'path'; | ||
var MODE_SEARCH = 'search'; | ||
var MODE_PATH = 'path'; | ||
var MODE_SEARCH = 'search'; | ||
var MODE_DEFAULT = MODE_PATH; | ||
/* | ||
@@ -57,5 +58,11 @@ * App | ||
* | ||
* Start the rename process. | ||
* Runs all the code. | ||
* | ||
* - [fn] (function) : callback | ||
* 1. Read the source folder | ||
* 2. Scan the filelist for matching 'from' paths | ||
* 3. Rename any files that reference those files | ||
* 4. Save changes (unless in drymode) | ||
* 5. Resolve callback | ||
* | ||
* - [fn] (function) : optional node style callback | ||
* > promise > this.changes | ||
@@ -99,3 +106,3 @@ */ | ||
App.prototype.save = function save () { | ||
App.prototype.save = function save (fn) { | ||
return Promise.map(this.changes, function (file) { | ||
@@ -102,0 +109,0 @@ return fs.write(file.path, file.contents); |
{ | ||
"name": "cjs-rename", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Rename a CJS file thing", | ||
@@ -10,3 +10,3 @@ "main": "lib/index.js", | ||
"bin": { | ||
"cjs-rename": "./bin/cjs-rename" | ||
"cjs-rename": "./bin/cjs-rename.js" | ||
}, | ||
@@ -13,0 +13,0 @@ "author": "George Czabania <george@czabania.com>", |
178
README.md
@@ -5,11 +5,14 @@ # cjs-rename | ||
Given a module a bad name? Used all over your codebase and tests? Sounds like you want to rename a CJS module, and this here module can do that for you: | ||
Given a module a bad name that is used all over your codebase and tests? Sounds like you want to rename a CJS module, and this here module can do that for you: | ||
```shell | ||
> cjs-rename src/some-bad-name.js src/some-good-name.js | ||
Renaming: | ||
- moved test/some-bad-name.js to test/some-good-name.js | ||
- src/foo/bad.js fixed 2 require()s | ||
- src/foo/qux.js fixed 3 require()s | ||
- test/foo/bar.js fixed 1 require()s | ||
> cjs-rename lib/some-bad-name.js lib/some-good-name.js | ||
Moving: | ||
- moved lib/some-bad-name.js to lib/some-good-name.js | ||
Fixing: | ||
- [1] lib/foo/bad.js | ||
- [1] lib/foo/qux.js | ||
- [1] test/foo/bar.js | ||
``` | ||
@@ -20,3 +23,3 @@ | ||
```javascript | ||
require('../../src/some-bad-name'); | ||
require('../../lib/some-bad-name'); | ||
``` | ||
@@ -27,17 +30,44 @@ | ||
```javascript | ||
require('../../src/some-good-name'); | ||
require('../../lib/some-good-name'); | ||
``` | ||
**Search Example** | ||
**Search by filename** | ||
Don't want to type out filepaths? Then add the `-s` flag to do a search. | ||
Notice how it moves both files in the `lib` and `test` folders. | ||
```shell | ||
> cjs-rename -s some-bad-name some-good-name | ||
Renaming: | ||
Moving: | ||
- moved lib/some-bad-name.js to lib/some-good-name.js | ||
- moved test/some-bad-name.js to test/some-good-name.js | ||
- src/foo/bad.js fixed 2 require()s | ||
- src/foo/qux.js fixed 3 require()s | ||
- test/foo/bar.js fixed 1 require()s | ||
Fixing: | ||
- [1] lib/foo/bad.js | ||
- [1] lib/foo/qux.js | ||
- [1] test/foo/bar.js | ||
``` | ||
**Drymode** | ||
Drymode will show you the affect the command will have, without actually saving | ||
any changes. Just add the `-d` flag. | ||
```shell | ||
cjs-rename -s -d old new | ||
Drymode: Will not save changes | ||
Moving: | ||
- moved lib/folder/old.js to lib/folder/new.js | ||
-moved test/old.js to test/new.js | ||
Fixing: | ||
- [1] lib/folder/foo.js | ||
- [1] test/foo.js | ||
``` | ||
## Install | ||
@@ -58,3 +88,3 @@ | ||
* cjs-rename [from] [to] [source...] | ||
* cjs-rename from to [source] | ||
@@ -73,14 +103,27 @@ Options: | ||
- `to`: path to the file has been moved to | ||
- `folder`: (optional). Which files to search through. Uses cwd by default. | ||
- `source`: (optional). Which folder to search through. Uses the current folder | ||
by default. | ||
**Example:** | ||
**Example using current working directory** | ||
```shell | ||
> cjs-rename source/template.js source/view.js | ||
Renaming: | ||
- source/core.js fixed 1 require()s | ||
- source/utils.js fixed 1 require()s | ||
- test/template.js fixed 1 requires()s | ||
Fixing: | ||
- [1] source/core.js | ||
- [1] source/utils.js | ||
- [1] test/template.js | ||
``` | ||
**Example using custom source directory** | ||
```shell | ||
> cjs-rename template.js view.js source | ||
Fixing: | ||
- [1] source/core.js | ||
- [1] source/utils.js | ||
- [1] test/template.js | ||
``` | ||
## Module Usage | ||
@@ -92,8 +135,9 @@ | ||
var rename = new Rename({ | ||
to: '...', | ||
from: '...', | ||
folder: '...', | ||
cwd: '...', // optional | ||
dryrun: false, // optional | ||
mode: 'search' // optional | ||
from: './source/path', | ||
to: './where/to/move/to', | ||
// optional | ||
cwd: proces.cwd(), | ||
dryrun: false, | ||
mode: 'path', | ||
}); | ||
@@ -116,2 +160,69 @@ | ||
### Rename constructor | ||
Create a new Rename instance. | ||
Can be called with or without `new`. | ||
**Parameters:** | ||
- `options` (object) | ||
- `from` (string) required | ||
- `to` (string) required | ||
- `cwd` (string) | ||
- `dryrun` (boolean) | ||
- `mode` (string) | ||
**Example:** | ||
```javascript | ||
var rename = Rename({ | ||
from: 'old', | ||
to: 'new', | ||
cwd: '/home/project/folder', | ||
mode: 'search' | ||
}); | ||
``` | ||
### rename.run | ||
Will move and rename files. Will automatically call `rename.save` unless you | ||
specify `drymode: true` in the options. | ||
**Parameters:** | ||
- `[fn]` (function) : optional callback with signature `fn(err, changes)` | ||
**Example:** | ||
```javascript | ||
rename.run(function (err, changes) { | ||
if (err) { | ||
console.log('Error', err); | ||
} else { | ||
console.log(changes); | ||
} | ||
}); | ||
``` | ||
### rename.save | ||
Save changes to disk. | ||
**Paramters:** | ||
- `[fn]` (function) : optional callback with signature `fn(err)` | ||
**Example:** | ||
```javascript | ||
rename.save(function (err) { | ||
if (err) { | ||
console.log('Error', err); | ||
} else { | ||
console.log('Saved changes'); | ||
} | ||
}); | ||
``` | ||
## Important Notes | ||
@@ -122,10 +233,9 @@ | ||
## Todo | ||
## Changelog | ||
- Improve command line interface | ||
- Move files | ||
### 0.0.6 | ||
## Changelog | ||
- Improve docs | ||
## 0.0.5 | ||
### 0.0.5 | ||
@@ -139,3 +249,3 @@ - Color output of `cjs-rename` command | ||
## 0.0.4 | ||
### 0.0.4 | ||
@@ -147,3 +257,3 @@ - Add support for coffeescript files | ||
## 0.0.3 | ||
### 0.0.3 | ||
@@ -150,0 +260,0 @@ - Improve command line interface. |
40165
1150
289