Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/ember-cli-migrator
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = './';
Expand All @@ -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();
17 changes: 15 additions & 2 deletions lib/ember-migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down