@@ -17,6 +17,7 @@ var lodash = require('lodash');
1717// Recast helpers
1818
1919function EmberMigrator ( options ) {
20+ this . debugging = options . debug || false ;
2021 this . testing = options . testing || false ;
2122 // Directory to process
2223 this . inputDirectory = options . inputDirectory ;
@@ -53,6 +54,15 @@ function EmberMigrator(options){
5354
5455EmberMigrator . prototype = Object . create ( null ) ;
5556
57+ EmberMigrator . prototype . debug = function ( message , condition ) {
58+ if ( arguments . length === 1 ) {
59+ condition = true ;
60+ }
61+ if ( condition && this . debugging ) {
62+ this . writeLine ( chalk . yellow ( 'DEBUG: ' + message ) ) ;
63+ }
64+ } ;
65+
5666EmberMigrator . prototype . run = function EmberMigrator_run ( ) {
5767 var self = this ;
5868 var files = walk ( this . inputDirectory ) ;
@@ -63,6 +73,7 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){
6373 // Here is where we control what files we will process in the input directory
6474 files . forEach ( function ( file ) {
6575 var fullPath = path . join ( self . inputDirectory , file ) ;
76+ self . debug ( 'Processing file: ' + file ) ;
6677 var isDir = fs . lstatSync ( fullPath ) . isDirectory ( ) ;
6778 var isJS = string . endsWith ( file , '.js' ) ;
6879 var isHbs = string . endsWith ( file , '.handlebars' ) || string . endsWith ( file , '.hbs' ) ;
@@ -108,6 +119,7 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){
108119 } , this ) ;
109120
110121 hbsFiles . forEach ( function ( filePath ) {
122+
111123 var fullPath = path . join ( self . inputDirectory , filePath ) ;
112124 var dirs = filePath . split ( '/' ) ;
113125 if ( dirs [ 0 ] !== 'templates' ) {
@@ -169,10 +181,10 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){
169181 execSync ( "git commit -m \"auto-commit from ember-cli-migrator\"" ) ;
170182 }
171183 Object . keys ( this . splitFiles ) . forEach ( function ( key ) {
184+ self . debug ( 'Processing split file: ' + key ) ;
172185 self . processFile ( self . splitFiles [ key ] ) ;
173186 } ) ;
174187
175- console . log ( 'flush' ) ;
176188 this . flushConvertedFiles ( this . splitFiles ) ;
177189
178190 if ( ! this . testing ) {
@@ -373,7 +385,7 @@ EmberMigrator.prototype.convertFile = function(typedExport){
373385
374386 // for some reason there is a rogue semicolon
375387 code = code . replace ( / \n ; \n / , '\n' ) ;
376-
388+
377389 code = code . replace ( new RegExp ( this . rootAppName + "\\." , 'g' ) , '' ) ;
378390 code = code . replace ( / E m \. / g, 'Ember.' ) ;
379391 // For any module imported that used to be a window global
@@ -392,6 +404,7 @@ EmberMigrator.prototype.convertFile = function(typedExport){
392404EmberMigrator . prototype . flushConvertedFiles = function ( splitFiles ) {
393405 //Create directory for every path in our app including unknown folders
394406 Object . keys ( splitFiles ) . forEach ( function ( file ) {
407+ this . debug ( 'flushing converted file: ' + file ) ;
395408 var typedExport = splitFiles [ file ] ;
396409 var folder = typedExport . outputFolderPath ( ) ;
397410 mkdirp . sync ( folder ) ;
0 commit comments