Skip to content

Commit 32662bf

Browse files
author
Stanley Stuart
committed
add debug option
1 parent fab2737 commit 32662bf

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

bin/ember-cli-migrator

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
var program = require('commander');
88
var EmberMigrator = require('../lib/ember-migrator');
99
var path = require('path');
10-
var package = require('../package')
10+
var package = require('../package');
1111

1212
program
1313
.version(package.version)
@@ -17,6 +17,7 @@ program
1717
.option('-t, --target [target_directory]', 'Directory to output result of migration')
1818
.option('-f, --force', 'Migrate even if output files exist')
1919
.option('--ignore-subdirs [comma_separated_dirs]', 'Sub-directories in source to ignore')
20+
.option('-d, --debug', 'print debugging information')
2021
.parse(process.argv);
2122

2223
var curDir = './';
@@ -28,7 +29,8 @@ var migrator = new EmberMigrator({
2829
forceOutput: program.force,
2930
ignoreDirs: program.ignoreSubdirs,
3031
appName: program.emberCliAppName,
31-
rootAppName: program.global
32+
rootAppName: program.global,
33+
debug: program.debug
3234
});
3335

3436
migrator.run();

lib/ember-migrator.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var lodash = require('lodash');
1717
// Recast helpers
1818

1919
function 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

5455
EmberMigrator.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+
5666
EmberMigrator.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(/Em\./g, 'Ember.');
379391
// For any module imported that used to be a window global
@@ -392,6 +404,7 @@ EmberMigrator.prototype.convertFile = function(typedExport){
392404
EmberMigrator.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

Comments
 (0)