diff --git a/bin/ember-cli-migrator b/bin/ember-cli-migrator index b0c3a27..4b3ae4a 100755 --- a/bin/ember-cli-migrator +++ b/bin/ember-cli-migrator @@ -7,7 +7,7 @@ var program = require('commander'); var EmberMigrator = require('../lib/ember-migrator'); var path = require('path'); -var package = require('../package') +var package = require('../package'); program .version(package.version) @@ -17,6 +17,7 @@ program .option('-t, --target [target_directory]', 'Directory to output result of migration') .option('-f, --force', 'Migrate even if output files exist') .option('--ignore-subdirs [comma_separated_dirs]', 'Sub-directories in source to ignore') + .option('-d, --debug', 'print debugging information') .parse(process.argv); var curDir = './'; @@ -28,7 +29,8 @@ var migrator = new EmberMigrator({ forceOutput: program.force, ignoreDirs: program.ignoreSubdirs, appName: program.emberCliAppName, - rootAppName: program.global + rootAppName: program.global, + debug: program.debug }); migrator.run(); diff --git a/lib/ember-migrator.js b/lib/ember-migrator.js index 149f885..c35dc61 100644 --- a/lib/ember-migrator.js +++ b/lib/ember-migrator.js @@ -17,6 +17,7 @@ var lodash = require('lodash'); // Recast helpers function EmberMigrator(options){ + this.debugging = options.debug || false; this.testing = options.testing || false; // Directory to process this.inputDirectory = options.inputDirectory; @@ -53,6 +54,15 @@ function EmberMigrator(options){ EmberMigrator.prototype = Object.create(null); +EmberMigrator.prototype.debug = function(message, condition) { + if (arguments.length === 1) { + condition = true; + } + if (condition && this.debugging) { + this.writeLine(chalk.yellow('DEBUG: ' + message)); + } +}; + EmberMigrator.prototype.run = function EmberMigrator_run(){ var self = this; var files = walk(this.inputDirectory); @@ -63,6 +73,7 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){ // Here is where we control what files we will process in the input directory files.forEach(function (file) { var fullPath = path.join(self.inputDirectory, file); + self.debug('Processing file: ' + file); var isDir = fs.lstatSync(fullPath).isDirectory(); var isJS = string.endsWith(file, '.js'); var isHbs = string.endsWith(file, '.handlebars') || string.endsWith(file, '.hbs'); @@ -108,6 +119,7 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){ }, this); hbsFiles.forEach(function (filePath) { + var fullPath = path.join(self.inputDirectory, filePath); var dirs = filePath.split('/'); if (dirs[0] !== 'templates') { @@ -169,10 +181,10 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){ execSync("git commit -m \"auto-commit from ember-cli-migrator\""); } Object.keys(this.splitFiles).forEach(function(key) { + self.debug('Processing split file: ' + key); self.processFile(self.splitFiles[key]); }); - console.log('flush'); this.flushConvertedFiles(this.splitFiles); if (!this.testing) { @@ -373,7 +385,7 @@ EmberMigrator.prototype.convertFile = function(typedExport){ // for some reason there is a rogue semicolon code = code.replace(/\n;\n/, '\n'); - + code = code.replace(new RegExp(this.rootAppName + "\\.", 'g'), ''); code = code.replace(/Em\./g, 'Ember.'); // For any module imported that used to be a window global @@ -392,6 +404,7 @@ EmberMigrator.prototype.convertFile = function(typedExport){ EmberMigrator.prototype.flushConvertedFiles = function(splitFiles){ //Create directory for every path in our app including unknown folders Object.keys(splitFiles).forEach(function(file) { + this.debug('flushing converted file: ' + file); var typedExport = splitFiles[file]; var folder = typedExport.outputFolderPath(); mkdirp.sync(folder);