├── CHANGELOG.md ├── LICENSE ├── README.md ├── config.json ├── img ├── example1.png └── example2.png ├── index.js ├── lib ├── cli.js ├── config.js ├── gitParser.js ├── parser.js ├── prompter.js ├── qExtensions.js ├── reporter.js ├── updater.js └── utils.js ├── package.json ├── test ├── ConfigSpec.js ├── FilteringSpec.js ├── FixedHtmlFileSpec.js ├── FixedModuleFileSpec.js ├── MovedHTMLFileSpec.js ├── MovedModuleFileSpec.js ├── OriginalHtmlFilesSpec.js ├── OriginalModuleFilesSpec.js ├── OutsideWcdSpec.js ├── ReportSpec.js ├── files │ ├── .reffixrc │ ├── filtering │ │ ├── .dir-to-ignore │ │ │ └── file1.js │ │ ├── bar_file1.jsx │ │ ├── file1.js │ │ ├── file1.txt │ │ ├── file2.js │ │ ├── foo_file1.jsx │ │ └── foo_file2.js │ ├── html │ │ └── original │ │ │ ├── css │ │ │ └── file1.css │ │ │ ├── file with spaces in name.js │ │ │ ├── file1.html │ │ │ ├── images │ │ │ └── file1.png │ │ │ ├── index.html │ │ │ └── level1 │ │ │ └── file2.js │ ├── modules │ │ └── original │ │ │ ├── file-with-references.js │ │ │ ├── file1.conf │ │ │ ├── file1.html │ │ │ ├── file1.js.bak │ │ │ ├── file1.json │ │ │ ├── file1.txt │ │ │ ├── file2.js │ │ │ ├── level1a │ │ │ ├── file-with-references.jsx │ │ │ ├── file3.js │ │ │ ├── file3.jsx │ │ │ ├── file5.js │ │ │ └── level2a │ │ │ │ ├── file6.js │ │ │ │ └── level3a │ │ │ │ ├── file2.txt │ │ │ │ └── file8.js │ │ │ ├── level1b │ │ │ ├── file1.css │ │ │ ├── file4.js │ │ │ └── level2b │ │ │ │ ├── file2.json │ │ │ │ ├── file2.jsx │ │ │ │ └── file7.js │ │ │ ├── rootfile with spaces in name 2.js │ │ │ ├── rootfile1.js │ │ │ ├── rootfile3.js │ │ │ └── rootfile4.js │ ├── outside-cwd │ │ └── file1.js │ └── ref-outside-cwd │ │ └── referencing-file.js ├── fixtures │ ├── htmlFilesToMove.json │ └── moduleFilesToMove.json └── helpers │ └── fileMover.js └── vendor └── xregexp-all.js /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### v0.1.1 (2016-07-27) 2 | 3 | - By default exclude comments from HTML files 4 | 5 | ### v0.1.2 (2016-07-29) 6 | 7 | - Improved accuracy of handling duplicate filenames when using git status. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2016 Robert Kendall 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # reffix 3 | 4 | **Reference Fixer** -- the easy fix for broken file path references. Analyze and batch-repair broken references across an entire project from the command line. 5 | 6 | ## Features 7 | 8 | - Fixes broken `require` and `import` statements in JavaScript files 9 | - Fixes broken `src` and `href` attributes in HTML files 10 | - Customizable to support other types of references 11 | - Expands references you type into your files 12 | - Generates detailed reports about all the file path dependencies in a project 13 | - Comprehensive filtering options 14 | - Extremely fast asynchronous performance 15 | 16 | ## Install 17 | 18 | `npm install --global reffix` 19 | 20 | ## Command Line Usage 21 | 22 | `$ ref` 23 | or 24 | `$ reffix` 25 | 26 | Fixing broken references couldn't be easier. By default, **reffix** will generate a report of broken module references (`require` and `import` statements) by recursing through all the files in the directory in which it is launched. Use the `-m html` option to parse HTML files instead. **reffix** will list the broken and corrected paths and prompt you to update the files to fix them. Just hit `Enter` to make the repairs. All reports list absolute paths, but relative paths will be used to update the files. 27 | 28 | ![Command line output](img/example1.png) 29 | 30 | If git version control is available for the files being parsed, **reffix** will use data from git status to fix references broken when files were renamed or moved. If git is unavailable, the program can repair references broken as a result of files being moved but not as a result of files being renamed. If a broken reference refers to a filename that is shared by mutliple files in different locations, reffix may not be able to determine which path to use and will prompt you to select the correct one. 31 | 32 | ![Prompt to choose file](img/example2.png) 33 | 34 | Using the command-line options described below, you can generate reports showing which files contain references and which files they refer to. You can filter the parsed files via command line options or configuration settings in a `.reffixrc` configuration file. Edit the configuration file to add support for additional types of file path references. 35 | 36 | ## Path Expansion 37 | 38 | When you type a reference into your code but don't know offhand the full path of the relevant file, use **reffix** to automatically expand the filename into a full-path reference. 39 | 40 | Type this into your code: 41 | `'./myFile.js'` 42 | Run **reffix** and you'll see this when you reload the file: 43 | `'../../full/path/of/myFile.js'`. 44 | 45 | ## Command Line Options 46 | 47 | ### General Usage 48 | 49 | `ref [options] [--] [working_directory]` 50 | 51 | Each option has a short (`-o`) and a long (`--option`) version that you can use interchangeably. Short options can be combined into a single argument (for example, `-ste`). `working_directory` is the starting path to use for parsing files. It defaults to the directory from which the command is executed. If `working_directory` is preceded by option arguments, it must be immediately preceded by `--`. 52 | 53 | ### Error Correction 54 | 55 | - `-e --errors` - List broken references and files containing them, then prompt to fix the errors. This option is engaged by default if none of the reporting options below are engaged. 56 | - `-m --mode` - The type of references to work with. Specify the argument `default` to parse `import` and `require` statements in JavaScript files. Specify `html` to parse `href` and `src` attributes in HTML files. If `-m` is omitted, the `default` mode is used. 57 | - `-n --no-prompts` - Fix errors without prompting (unless overridden by `-r`). 58 | - `-r --report-only` - Don't fix errors, just show the report. (Overrides `-n`.) 59 | 60 | ### Filtering 61 | 62 | All lists of names or globs, as described below, must be separated by commas. If a pattern contains a `*`, the pattern should be should be enclosed in quotes, or the `*` should be escaped (`\*`). 63 | 64 | - `-d --dirs ` - Exclude specified directories from parsing. Provide a list of directory names or globs to exclude. The names are added to the default list of `'.*,node_modules,build'`. 65 | - `-f --files [target_globs]` - Filter the files that are analyzed and repaired. Provide a glob or list of globs to specify the source (referencing) and target (referenced) files that should be included or excluded. For example, `'!*Spec.js,*.js'`. Overrides the default filter, which is `'*.js,*.jsx' '*.*'`. `source_globs` is required. If you wish to filter only target files, enter `''` for `source_globs`. 66 | - `-c --config ` - Load a custom configuration file located at the specified path. This can specify more-advanced parsing options (see below). 67 | 68 | ### Reporting 69 | 70 | When one of the following switches is set, you won't be prompted to repair files unless you include `-e`. 71 | 72 | - `-s --sources` - List files that contain (are sources of) references. 73 | - `-t --targets` - List files that are referenced by (targets of) other files. 74 | 75 | ### Help 76 | 77 | - `-V --version` - Displays the software version. 78 | - `-h --help` - Produces the following display. 79 | ``` 80 | -h, --help output usage information 81 | -V, --version output the version number 82 | -c, --config path of custom configuration file 83 | -m, --mode type of references to look for, JS import/require (default) or HTML href/src (html) 84 | -f, --files [target_globs] filter the source (referencing) and target (referenced) files parsed (e.g., '*1.js,*2.js' 'file.js') 85 | -d, --dirs exclude from sources the specified directories (e.g., 'test,bin') 86 | -e, --errors list broken references and prompt to fix them 87 | -s, --sources list files (sources of references) containing references to other files 88 | -t, --targets list files (targets of references) referenced by other files 89 | -n, --no-prompts fix broken references without prompting (unless -r) 90 | -r, --report-only don't fix broken references, just display reports 91 | ``` 92 | 93 | ## Examples 94 | 95 | `$ ref` 96 | List all broken references and prompt you to fix them. 97 | 98 | `$ ref ../` 99 | Begin parsing in the parent directory and list all broken references and prompt you to fix them. 100 | 101 | `$ ref -ret -d 'test' -f '!*Test.js,!*Spec.js'` 102 | Don't repair files, list errors and all references (targets), and filter out test files and directories. 103 | 104 | `$ ref -n -f '' '**/examples/*Widget.*,**/examples/*Module.*' -- ../src` 105 | Repair files without prompting. Fix only references to widgets and modules in `examples` directory. Set the working directory to `../src`. 106 | 107 | ## Customization 108 | 109 | ### Configuration File 110 | 111 | You can also specify filtering and parsing options by creating a `.reffixrc` file. Place it in your `$home` or `/etc` directory, or specify its path using the command-line option `-c --config`. The file will be merged into the following default settings and must use the same JSON format. You can add as many modes as you want and select them from the command line using the `-m` switch. Each new mode will be merged with `default`, so you need only include the properties you wish to overrride. 112 | 113 | ```javascript 114 | { 115 | "default": { 116 | "workingDirectory": ".", 117 | "directoriesToExclude": [ 118 | ".*", 119 | "node_modules", 120 | "build" 121 | ], 122 | "referencingFileFilter": [ 123 | "*.js", 124 | "*.jsx" 125 | ], 126 | "referencedFileFilter": [ 127 | "*.*" 128 | ], 129 | "searchPatterns": [ 130 | "(^|\\s)import\\s+([\\w\\-\\{\\}\\,\\*\\$\\s]+\\s+)?(['\"]){{valuePattern}}\\3", 131 | "(^|[^\\w-])require *\\( *(['\"]){{valuePattern}}\\2 *\\)" 132 | ], 133 | "valuePattern": "\\.+/[^'\"]+", 134 | "currentDirectoryPrefix": "./", 135 | "textToExclude": [ 136 | "// *[^\\n]+\\n", 137 | "/\\*[\\s\\S]+?\\*/" 138 | ] 139 | }, 140 | "html": { 141 | "referencingFileFilter": [ 142 | "*.html", 143 | "*.js" 144 | ], 145 | "referencedFileFilter": [ 146 | "*.*" 147 | ], 148 | "searchPatterns": [ 149 | "]*href=(['\"]){{valuePattern}}\\1[^>]*>", 150 | "]*href=(['\"]){{valuePattern}}\\1[^>]*>", 151 | "'); 45 | expect(content).to.contain(''); 46 | expect(content).to.contain('link'); 47 | expect(content).to.contain('image'); 48 | done(); 49 | }); 50 | }) 51 | }); 52 | 53 | }); -------------------------------------------------------------------------------- /test/FixedModuleFileSpec.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var expect = require('chai').expect; 4 | var mv = require('mv'); 5 | 6 | var fileMover = require('./helpers/fileMover'); 7 | var config = require('../lib/config'); 8 | var updater = require('../lib/updater'); 9 | 10 | var filesToMove = require('./fixtures/moduleFilesToMove.json'); 11 | 12 | describe('File Repair for Modules', function() { 13 | var testBaseDir = 'test/files/modules/moved'; 14 | var testDir = 'modules'; 15 | var options = { 16 | workingDirectory: testBaseDir 17 | }; 18 | var baseDir = path.resolve(testBaseDir) + '/'; 19 | before(function(done) { 20 | fileMover.moveFiles(testDir, filesToMove, done); 21 | }); 22 | after(function(done) { 23 | fileMover.deleteMovedFiles(testDir, done); 24 | }); 25 | describe('References', function() { 26 | var files; 27 | var pathOfFileWithReferences = path.join(baseDir, 'level1c/level2c/file-with-references.js'); 28 | beforeEach(function(done) { 29 | config.forceSet(options); 30 | updater.fixReferences().then(function(result) { 31 | files = result; 32 | done(); 33 | }) 34 | }); 35 | it('Should fix correct files', function() { 36 | expect(files).to.have.length(2); 37 | expect(files[0]).to.equal(path.join(baseDir, 'level1a/file-with-references.jsx')); 38 | expect(files[1]).to.equal(pathOfFileWithReferences); 39 | }); 40 | it('Should correctly update file content', function(done) { 41 | fs.readFile(pathOfFileWithReferences, 'utf8', function(err, content) { 42 | expect(content).to.contain("import module1 from '../../level1a/file-with-references.jsx';"); 43 | expect(content).to.contain("const module4 = require('../../level1a/file4.js');"); 44 | expect(content).to.contain("let module6 = require( '../../file7.js' ).someMethod;"); 45 | done(); 46 | }); 47 | }) 48 | }); 49 | 50 | }); -------------------------------------------------------------------------------- /test/MovedHTMLFileSpec.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var expect = require('chai').expect; 3 | 4 | var fileMover = require('./helpers/fileMover'); 5 | var config = require('../lib/config'); 6 | var parser = require('../lib/parser'); 7 | 8 | var filesToMove = require('./fixtures/htmlFilesToMove.json'); 9 | 10 | describe('Moved HMTL Files', function() { 11 | 12 | var testBaseDir = 'test/files/html/moved'; 13 | var testDir = 'html'; 14 | var fullBasePath = path.resolve(testBaseDir) + '/'; 15 | 16 | before(function(done) { 17 | fileMover.moveFiles(testDir, filesToMove, done); 18 | }); 19 | after(function(done) { 20 | fileMover.deleteMovedFiles(testDir, done); 21 | }); 22 | 23 | describe('Broken References', function() { 24 | var brokenReferences; 25 | var options = { 26 | mode: 'html', 27 | workingDirectory: testBaseDir 28 | }; 29 | beforeEach(function(done) { 30 | config.reset(); 31 | config.set(options); 32 | parser.getBrokenReferences(options) 33 | .then(function(result) { 34 | brokenReferences = result.brokenReferences; 35 | done(); 36 | }) 37 | }); 38 | afterEach(function() { 39 | config.reset(); 40 | }); 41 | it('Should find correct number of broken references', function() { 42 | expect(brokenReferences).to.have.length(5); 43 | }); 44 | 45 | it('Should correctly identify broken references, referencers, and correct paths', function() { 46 | 47 | var result1 = brokenReferences.find(function(brokenReference) { 48 | if (brokenReference.referencedFile === fullBasePath + 'level1/css/file1.css') { 49 | return true; 50 | } 51 | }); 52 | expect(result1).to.be.ok; 53 | expect(result1.referencingFiles).to.contain(fullBasePath + 'level1/index.html'); 54 | expect(result1.correctPath).to.equal(fullBasePath + 'css/file1.css'); 55 | 56 | var result2 = brokenReferences.find(function(brokenReference) { 57 | if (brokenReference.referencedFile.indexOf(fullBasePath + '' + 'level1/file1.html') !== -1) { 58 | return true; 59 | } 60 | }); 61 | expect(result2).to.be.ok; 62 | expect(result2.referencingFiles).to.contain(fullBasePath + 'level1/index.html'); 63 | expect(result2.correctPath).to.equal(fullBasePath + 'file1.html'); 64 | 65 | var result3 = brokenReferences.find(function(brokenReference) { 66 | if (brokenReference.referencedFile.indexOf(fullBasePath + 'level1/file with spaces in name.js') !== -1) { 67 | return true; 68 | } 69 | }); 70 | expect(result3).to.be.ok; 71 | expect(result3.referencingFiles).to.contain(fullBasePath + 'level1/index.html'); 72 | expect(result3.correctPath).to.equal(fullBasePath + 'file with spaces in name.js'); 73 | 74 | }); 75 | 76 | }); 77 | 78 | }); -------------------------------------------------------------------------------- /test/MovedModuleFileSpec.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var expect = require('chai').expect; 3 | 4 | var fileMover = require('./helpers/fileMover'); 5 | var config = require('../lib/config'); 6 | var parser = require('../lib/parser'); 7 | 8 | var filesToMove = require('./fixtures/moduleFilesToMove.json'); 9 | 10 | describe('Moved Files', function() { 11 | 12 | var testBaseDir = 'test/files/modules/moved'; 13 | var testDir = 'modules'; 14 | var fullBasePath = path.resolve(testBaseDir) + '/'; 15 | 16 | before(function(done) { 17 | fileMover.moveFiles(testDir, filesToMove, done); 18 | }); 19 | after(function(done) { 20 | fileMover.deleteMovedFiles(testDir, done); 21 | }); 22 | 23 | describe('Broken References', function() { 24 | var brokenReferences; 25 | var options = { 26 | workingDirectory: testBaseDir 27 | }; 28 | beforeEach(function(done) { 29 | config.reset(); 30 | config.forceSet(options); 31 | parser.getBrokenReferences(options) 32 | .then(function(result) { 33 | brokenReferences = result.brokenReferences; 34 | done(); 35 | }) 36 | }); 37 | afterEach(function() { 38 | config.reset(); 39 | }); 40 | it('Should find correct number of broken references', function() { 41 | expect(brokenReferences).to.have.length(13); 42 | }); 43 | it('Should correctly identify broken references, referencers, and correct paths', function() { 44 | var result1 = brokenReferences.find(function(brokenReference) { 45 | if (brokenReference.referencedFile === fullBasePath + 'level1c/level2c/level1a/file-with-references.jsx') { 46 | return true; 47 | } 48 | }); 49 | expect(result1).to.be.ok; 50 | expect(result1.referencingFiles).to.contain(fullBasePath + 'level1c/level2c/file-with-references.js'); 51 | expect(result1.correctPath).to.equal(fullBasePath + 'level1a/file-with-references.jsx'); 52 | 53 | var result2 = brokenReferences.find(function(brokenReference) { 54 | if (brokenReference.referencedFile.indexOf(fullBasePath + 'level1c/level2c/level1b/file4.js') !== -1) { 55 | return true; 56 | } 57 | }); 58 | expect(result2).to.be.ok; 59 | expect(result2.referencingFiles).to.contain(fullBasePath + 'level1c/level2c/file-with-references.js'); 60 | expect(result2.correctPath).to.equal(fullBasePath + 'level1a/file4.js'); 61 | 62 | var result3 = brokenReferences.find(function(brokenReference) { 63 | if (brokenReference.referencedFile.indexOf(fullBasePath + 'level1c/level2c/level1b/level2b/file7.js') !== -1) { 64 | return true; 65 | } 66 | }); 67 | expect(result3).to.be.ok; 68 | expect(result3.referencingFiles).to.contain(fullBasePath + 'level1c/level2c/file-with-references.js'); 69 | expect(result3.correctPath).to.equal(fullBasePath + 'file7.js'); 70 | }); 71 | 72 | }); 73 | 74 | }); -------------------------------------------------------------------------------- /test/OriginalHtmlFilesSpec.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var expect = require('chai').expect; 3 | 4 | var config = require('../lib/config'); 5 | var parser = require('../lib/parser'); 6 | 7 | describe('Original HTML Files', function() { 8 | 9 | var testWorkingDir = 'test/files/html/original'; 10 | 11 | describe('References', function() { 12 | var files; 13 | var options = { 14 | mode: 'html', 15 | workingDirectory: testWorkingDir 16 | }; 17 | beforeEach(function(done) { 18 | config.reset(); 19 | config.set(options); 20 | parser.getReferences().then(function(result) { 21 | files = result; 22 | done(); 23 | }); 24 | }); 25 | afterEach(function() { 26 | config.reset(); 27 | }); 28 | it('Should get correct number of files', function() { 29 | expect(Object.keys(files.existingFiles)).to.have.length(6); 30 | }); 31 | it('Should get correct number of referencing files', function() { 32 | expect(Object.keys(files.referencingFiles)).to.have.length(1); 33 | }); 34 | it('Should get correct file paths', function() { 35 | expect(files.referencingFiles).to.have.property(path.resolve(options.workingDirectory, 'index.html')); 36 | }); 37 | it('Should get correct number of references within files', function() { 38 | expect(Object.keys(files.referencedFiles)).to.have.length(5); 39 | }); 40 | it('Should get correct file paths', function() { 41 | expect(files.referencedFiles).to.have.property(path.resolve(options.workingDirectory, 'level1/file2.js')); 42 | }); 43 | }); 44 | 45 | describe('Filtered References for CSS only', function() { 46 | var files; 47 | var options = { 48 | mode: 'html', 49 | workingDirectory: testWorkingDir, 50 | referencedFileFilter: ['*.css'] 51 | }; 52 | beforeEach(function(done) { 53 | config.set(options); 54 | parser.getReferences().then(function(result) { 55 | files = result; 56 | done(); 57 | }) 58 | }); 59 | it('Should get correct number of references within files', function() { 60 | expect(Object.keys(files.referencedFiles)).to.have.length(1); 61 | }) 62 | }); 63 | 64 | describe('Broken References', function() { 65 | var brokenReferences; 66 | var options = { 67 | workingDirectory: testWorkingDir 68 | }; 69 | beforeEach(function(done) { 70 | config.forceSet(options); 71 | parser.getBrokenReferences().then(function(result) { 72 | brokenReferences = result.brokenReferences; 73 | done(); 74 | }) 75 | }); 76 | it('Should find no broken references', function() { 77 | expect(Object.keys(brokenReferences)).to.have.length(0); 78 | }); 79 | }); 80 | 81 | }); -------------------------------------------------------------------------------- /test/OriginalModuleFilesSpec.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var expect = require('chai').expect; 3 | 4 | var config = require('../lib/config'); 5 | var parser = require('../lib/parser'); 6 | 7 | describe('Original Files', function() { 8 | 9 | var testWorkingDir = 'test/files/modules/original'; 10 | 11 | describe('References', function() { 12 | var files; 13 | var options = { 14 | workingDirectory: testWorkingDir 15 | }; 16 | beforeEach(function(done) { 17 | config.reset(); 18 | config.set(options); 19 | parser.getReferences().then(function(result) { 20 | files = result; 21 | done(); 22 | }); 23 | }); 24 | afterEach(function() { 25 | config.reset(); 26 | }); 27 | it('Should get correct number of files', function() { 28 | expect(Object.keys(files.existingFiles)).to.have.length(23); 29 | }); 30 | it('Should get correct number of referencing files', function() { 31 | expect(Object.keys(files.referencingFiles)).to.have.length(2); 32 | }); 33 | it('Should get correct file paths', function() { 34 | expect(files.existingFiles).to.have.property(path.join(process.cwd(), options.workingDirectory, 'file1.json')); 35 | expect(files.existingFiles).to.have.property(path.join(process.cwd(), options.workingDirectory, 'level1a/file-with-references.jsx')); 36 | expect(files.existingFiles).to.have.property(path.join(process.cwd(), options.workingDirectory, 'level1a/level2a/level3a/file8.js')); 37 | }); 38 | it('Should get correct number of references within files', function() { 39 | expect(Object.keys(files.referencedFiles)).to.have.length(12); 40 | }) 41 | }); 42 | 43 | describe('Filtered References with one glob', function() { 44 | var files; 45 | var options = { 46 | workingDirectory: testWorkingDir, 47 | referencingFileFilter: ['*.js'], 48 | referencedFileFilter: ['*.js'] 49 | }; 50 | beforeEach(function(done) { 51 | config.forceSet(options); 52 | parser.getReferences().then(function(result) { 53 | files = result; 54 | done(); 55 | }) 56 | }); 57 | it('Should get correct number of existing files', function() { 58 | expect(Object.keys(files.existingFiles)).to.have.length(12); 59 | }); 60 | it('Should get correct number of references within files', function() { 61 | expect(Object.keys(files.referencedFiles)).to.have.length(9); 62 | }) 63 | }); 64 | 65 | describe('Filtered References with two globs', function() { 66 | var files; 67 | var options = { 68 | workingDirectory: testWorkingDir, 69 | referencingFileFilter: ['*.js', '*.jsx'], 70 | referencedFileFilter: ['*.js', '*.jsx'] 71 | }; 72 | beforeEach(function(done) { 73 | config.forceSet(options); 74 | parser.getReferences().then(function(result) { 75 | files = result; 76 | done(); 77 | }) 78 | }); 79 | it('Should get correct number of existing files', function() { 80 | expect(Object.keys(files.existingFiles)).to.have.length(15); 81 | }); 82 | it('Should get correct number of references within files', function() { 83 | expect(Object.keys(files.referencedFiles)).to.have.length(12); 84 | }) 85 | }); 86 | 87 | describe('Broken References', function() { 88 | var brokenReferences; 89 | var options = { 90 | workingDirectory: testWorkingDir 91 | }; 92 | beforeEach(function(done) { 93 | config.forceSet(options); 94 | parser.getBrokenReferences().then(function(result) { 95 | brokenReferences = result.brokenReferences; 96 | done(); 97 | }) 98 | }); 99 | it('Should find no broken references', function() { 100 | expect(Object.keys(brokenReferences)).to.have.length(0); 101 | }); 102 | }); 103 | 104 | }); -------------------------------------------------------------------------------- /test/OutsideWcdSpec.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var expect = require('chai').expect; 3 | 4 | var config = require('../lib/config'); 5 | var parser = require('../lib/parser'); 6 | 7 | describe('Outside CWD', function() { 8 | 9 | var testWorkingDir = 'test/files/ref-outside-cwd'; 10 | 11 | describe('References', function() { 12 | var files; 13 | var options = { 14 | workingDirectory: testWorkingDir 15 | }; 16 | beforeEach(function(done) { 17 | config.reset(); 18 | config.forceSet(options); 19 | parser.getReferences().then(function(result) { 20 | files = result; 21 | done(); 22 | }); 23 | }); 24 | it('Should find file outside of CWD', function() { 25 | expect(Object.keys(files.referencedFiles)).to.have.length(1); 26 | expect(files.referencedFiles).to.have.property(path.join(process.cwd(), 'test/files/outside-cwd/file1.js')); 27 | }); 28 | 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /test/ReportSpec.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | var config = require('../lib/config'); 4 | var parser = require('../lib/parser'); 5 | var reporter = require('../lib/reporter'); 6 | 7 | describe('Reports', function() { 8 | var filesCheckedReport; 9 | var referencingFilesReport; 10 | var options = { 11 | workingDirectory: 'test/files/modules/original', 12 | referencingFileFilter: ['*.js'], 13 | referencedFileFilter: ['*.js'] 14 | }; 15 | beforeEach(function(done) { 16 | config.forceSet(options); 17 | parser.getAll() 18 | .then(function(fileData) { 19 | filesCheckedReport = reporter.reportFilesChecked(fileData); 20 | var reportOptions = {referencingFiles: true}; 21 | referencingFilesReport = reporter.getReport(fileData, reportOptions); 22 | done(); 23 | }); 24 | }); 25 | it('Should report correct number of files checked', function() { 26 | expect(filesCheckedReport).to.contain('12 files'); 27 | }); 28 | 29 | }); -------------------------------------------------------------------------------- /test/files/.reffixrc: -------------------------------------------------------------------------------- 1 | { 2 | "test": { 3 | "referencingFileFilter": [ 4 | "test.*" 5 | ], 6 | "referencedFileFilter": [ 7 | "test_test.*" 8 | ] 9 | } 10 | } -------------------------------------------------------------------------------- /test/files/filtering/.dir-to-ignore/file1.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/filtering/.dir-to-ignore/file1.js -------------------------------------------------------------------------------- /test/files/filtering/bar_file1.jsx: -------------------------------------------------------------------------------- 1 | import module1 from './file1'; -------------------------------------------------------------------------------- /test/files/filtering/file1.js: -------------------------------------------------------------------------------- 1 | import module1 from './foo_file1.jsx'; 2 | import module1 from './bar_file1.jsx'; -------------------------------------------------------------------------------- /test/files/filtering/file1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/filtering/file1.txt -------------------------------------------------------------------------------- /test/files/filtering/file2.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/filtering/file2.js -------------------------------------------------------------------------------- /test/files/filtering/foo_file1.jsx: -------------------------------------------------------------------------------- 1 | import module1 from './file1'; -------------------------------------------------------------------------------- /test/files/filtering/foo_file2.js: -------------------------------------------------------------------------------- 1 | import module1 from './file1'; -------------------------------------------------------------------------------- /test/files/html/original/css/file1.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/html/original/css/file1.css -------------------------------------------------------------------------------- /test/files/html/original/file with spaces in name.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/html/original/file with spaces in name.js -------------------------------------------------------------------------------- /test/files/html/original/file1.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/html/original/file1.html -------------------------------------------------------------------------------- /test/files/html/original/images/file1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/html/original/images/file1.png -------------------------------------------------------------------------------- /test/files/html/original/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | link 13 | image 14 | 15 | -------------------------------------------------------------------------------- /test/files/html/original/level1/file2.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/html/original/level1/file2.js -------------------------------------------------------------------------------- /test/files/modules/original/file-with-references.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import module1 from './level1a/file-with-references.jsx'; 4 | import $ from './file2.js'; 5 | 6 | /* 7 | * import module1 from './file12.js'; 8 | * 9 | */ 10 | 11 | import { member1, member2 } from './level1a/level2a/file6'; 12 | import * as name from "./rootfile1"; 13 | import defaultMember, { member1, member2 } 14 | from "./rootfile with spaces in name 2"; 15 | import defaultMember, * as name from "./rootfile3"; 16 | import './rootfile4.js' 17 | // import module2a from './file12.js'; 18 | 19 | 20 | var module3 = require('./level1a/file3.jsx'); 21 | const module4 = require('./level1b/file4.js'); 22 | const module5 = require ("./level1b/level2b/file2.jsx"); 23 | 24 | let module6 = require( './level1b/level2b/file7' ).someMethod; 25 | var module7 = require("./level1a/file5.js")(); 26 | 27 | // var module8 = require('./file10.js'); 28 | 29 | /* 30 | * import module9 from './file11.js'; 31 | * 32 | */ 33 | 34 | let foo = bar; -------------------------------------------------------------------------------- /test/files/modules/original/file1.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/file1.conf -------------------------------------------------------------------------------- /test/files/modules/original/file1.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/file1.html -------------------------------------------------------------------------------- /test/files/modules/original/file1.js.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/file1.js.bak -------------------------------------------------------------------------------- /test/files/modules/original/file1.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/file1.json -------------------------------------------------------------------------------- /test/files/modules/original/file1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/file1.txt -------------------------------------------------------------------------------- /test/files/modules/original/file2.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/file2.js -------------------------------------------------------------------------------- /test/files/modules/original/level1a/file-with-references.jsx: -------------------------------------------------------------------------------- 1 | import module from '../level1b/file4'; -------------------------------------------------------------------------------- /test/files/modules/original/level1a/file3.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1a/file3.js -------------------------------------------------------------------------------- /test/files/modules/original/level1a/file3.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1a/file3.jsx -------------------------------------------------------------------------------- /test/files/modules/original/level1a/file5.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1a/file5.js -------------------------------------------------------------------------------- /test/files/modules/original/level1a/level2a/file6.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1a/level2a/file6.js -------------------------------------------------------------------------------- /test/files/modules/original/level1a/level2a/level3a/file2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1a/level2a/level3a/file2.txt -------------------------------------------------------------------------------- /test/files/modules/original/level1a/level2a/level3a/file8.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1a/level2a/level3a/file8.js -------------------------------------------------------------------------------- /test/files/modules/original/level1b/file1.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1b/file1.css -------------------------------------------------------------------------------- /test/files/modules/original/level1b/file4.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1b/file4.js -------------------------------------------------------------------------------- /test/files/modules/original/level1b/level2b/file2.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1b/level2b/file2.json -------------------------------------------------------------------------------- /test/files/modules/original/level1b/level2b/file2.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1b/level2b/file2.jsx -------------------------------------------------------------------------------- /test/files/modules/original/level1b/level2b/file7.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/level1b/level2b/file7.js -------------------------------------------------------------------------------- /test/files/modules/original/rootfile with spaces in name 2.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/rootfile with spaces in name 2.js -------------------------------------------------------------------------------- /test/files/modules/original/rootfile1.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/rootfile1.js -------------------------------------------------------------------------------- /test/files/modules/original/rootfile3.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/rootfile3.js -------------------------------------------------------------------------------- /test/files/modules/original/rootfile4.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/modules/original/rootfile4.js -------------------------------------------------------------------------------- /test/files/outside-cwd/file1.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkendall/reffix/eb07f00864eca0add18063c00dd8c2872cef04cf/test/files/outside-cwd/file1.js -------------------------------------------------------------------------------- /test/files/ref-outside-cwd/referencing-file.js: -------------------------------------------------------------------------------- 1 | import module1 from '../outside-cwd/file1.js'; -------------------------------------------------------------------------------- /test/fixtures/htmlFilesToMove.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | "index.html", 4 | "level1/index.html" 5 | ] 6 | ] -------------------------------------------------------------------------------- /test/fixtures/moduleFilesToMove.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | "file-with-references.js", 4 | "level1c/level2c/file-with-references.js" 5 | ], 6 | [ 7 | "level1b/file4.js", 8 | "level1a/file4.js" 9 | ], 10 | [ 11 | "level1b/level2b/file7.js", 12 | "file7.js" 13 | ] 14 | ] -------------------------------------------------------------------------------- /test/helpers/fileMover.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fse = require('fs-extra'); 3 | var Q = require('q'); 4 | var qe = require('../../lib/qExtensions'); 5 | var mv = require('mv'); 6 | 7 | var fileMover = { 8 | 9 | moveFiles: function(dir, files, done) { 10 | var workingDir = this.getFullTestPath(dir); 11 | var movedDir = workingDir + 'moved/'; 12 | return Q.nfcall(fse.emptyDir, movedDir) 13 | .then(function() { 14 | return Q.nfcall(fse.copy, 15 | workingDir + 'original/', 16 | movedDir 17 | ); 18 | }) 19 | .then(function() { 20 | console.log('Test files copied'); 21 | var fileMovePromises = files.map(function(filenames) { 22 | return Q.nfcall(fse.move, 23 | movedDir + filenames[0], 24 | movedDir + filenames[1] 25 | ) 26 | .handleError(); 27 | }); 28 | return Q.all(fileMovePromises); 29 | }) 30 | .then(function() { 31 | console.log('File structure prepared for tests'); 32 | done(); 33 | }) 34 | .handleError(); 35 | }, 36 | 37 | deleteMovedFiles: function(dir, done) { 38 | var movedDir = this.getFullTestPath(dir) + 'moved'; 39 | fse.remove(movedDir, function(err) { 40 | if (!err) { 41 | console.log('Test files removed'); 42 | done(); 43 | } else { 44 | console.error(err); 45 | done(err); 46 | } 47 | }) 48 | 49 | }, 50 | 51 | getFullTestPath: function(dir) { 52 | return path.resolve('test/files/', dir) + '/'; 53 | } 54 | 55 | }; 56 | 57 | module.exports = { 58 | moveFiles: fileMover.moveFiles.bind(fileMover), 59 | deleteMovedFiles: fileMover.deleteMovedFiles.bind(fileMover) 60 | }; 61 | --------------------------------------------------------------------------------