33/**
44 * Dependencies
55 */
6+ const chalk = require ( 'chalk' ) ;
67const parseConfig = require ( './helpers/parse-config' ) ;
78const getPathsSync = require ( './helpers/get-paths-sync' ) ;
89const getPathsAsync = require ( './helpers/get-paths-async' ) ;
@@ -28,14 +29,20 @@ function replaceInFile(config, cb) {
2829 //Get config
2930 const {
3031 files, from, to, encoding, ignore, allowEmptyPaths, disableGlobs,
32+ dry, verbose,
3133 } = config ;
3234
35+ //Dry run?
36+ if ( dry && verbose ) {
37+ console . log ( chalk . yellow ( 'Dry run, not making actual changes' ) ) ;
38+ }
39+
3340 //Find paths
3441 return getPathsAsync ( files , ignore , disableGlobs , allowEmptyPaths )
3542
3643 //Make replacements
3744 . then ( paths => Promise . all ( paths . map ( file => {
38- return replaceAsync ( file , from , to , encoding ) ;
45+ return replaceAsync ( file , from , to , encoding , dry ) ;
3946 } ) ) )
4047
4148 //Convert results to array of changed files
@@ -73,13 +80,20 @@ replaceInFile.sync = function(config) {
7380 config = parseConfig ( config ) ;
7481
7582 //Get config, paths, and initialize changed files
76- const { files, from, to, encoding, ignore, disableGlobs} = config ;
83+ const {
84+ files, from, to, encoding, ignore, disableGlobs, dry, verbose,
85+ } = config ;
7786 const paths = getPathsSync ( files , ignore , disableGlobs ) ;
7887 const changedFiles = [ ] ;
7988
89+ //Dry run?
90+ if ( dry && verbose ) {
91+ console . log ( chalk . yellow ( 'Dry run, not making any changes' ) ) ;
92+ }
93+
8094 //Process synchronously
8195 paths . forEach ( path => {
82- if ( replaceSync ( path , from , to , encoding ) ) {
96+ if ( replaceSync ( path , from , to , encoding , dry ) ) {
8397 changedFiles . push ( path ) ;
8498 }
8599 } ) ;
0 commit comments