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
9 changes: 5 additions & 4 deletions lib/ember-migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var namedTypes = recast.types.namedTypes;
var builders = recast.types.builders;
var chalk = require('chalk');
var lodash = require('lodash');
var helper = require('./helper');

// Recast helpers

Expand Down Expand Up @@ -123,7 +124,7 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){
// Make sure we go to templates dir and otherwise keep subdir placement
dirs.unshift('templates');
}
var outputFile = string.dasherize(dirs.join('/'));
var outputFile = helper.dasherizePath(dirs.join('/'));
outputFile = path.join(self.outputDirectory, outputFile);
var outputFolder = path.dirname(outputFile);
if (fullPath === outputFile) {
Expand All @@ -147,14 +148,14 @@ EmberMigrator.prototype.run = function EmberMigrator_run(){
var outputFile;

if (string.endsWith(filePath, '.gitkeep')) {
outputFile = path.join(self.outputDirectory, string.dasherize(filePath));
outputFile = path.join(self.outputDirectory, helper.dasherizePath(filePath));
if (fullPath !== outputFile) {
this.writeLine(chalk.green('No Change or Move') + ' ' + fullPath);
execSync(this.moveOrCopyCmd + fullPath + " " + outputFile);
return;
}
} else {
outputFile = path.join(self.outputDirectory, 'nonjs', string.dasherize(filePath));
outputFile = path.join(self.outputDirectory, 'nonjs', helper.dasherizePath(filePath));
}
var outputFolder = path.dirname(outputFile);
if (fullPath === outputFile) {
Expand Down Expand Up @@ -338,7 +339,7 @@ EmberMigrator.prototype.splitFile = function(filePath) {
// Append any remaining non-export nodes to either first export or new export
nonExportNodes.forEach(function (node) {
if (typedExports.length === 0) {
var newFilePath = string.dasherize(filePath);
var newFilePath = helper.dasherizePath(filePath);
addTypedNode(node, newFilePath);
} else {
typedExports[0].astNodes.push(node);
Expand Down
7 changes: 7 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var string = require('underscore.string');

module.exports.dasherizePath = function (path) {
return path.split('/').map(function (dir) {
return string.dasherize(dir).replace(/^-/, '');
}).join('/');
};
2 changes: 1 addition & 1 deletion lib/migrator-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var MigratorVisitorPrototype = {
oldFileName: requirePath,
appName: this.localAppName,
outputDirectory: this.outputDirectory
})
});

var exportPath = instance.exportPath(this.rootAppName);

Expand Down
24 changes: 16 additions & 8 deletions lib/typed-export.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var path = require('path');
var string = require('underscore.string');
var helper = require('./helper');

// TODO(Tony) bring this into prototype
function TypedExport(options) {
Expand Down Expand Up @@ -33,7 +34,7 @@ TypedExport.knownTypes = [

TypedExport.pluralizeType = function(type) {
return type + 's';
}
};

TypedExport.determineType = function(filePath, className) {
// First check to see if any class matches
Expand All @@ -60,21 +61,21 @@ TypedExport.determineType = function(filePath, className) {
}, this);
}
return type;
}
};

// TODO(Tony) handle path and name
TypedExport.prototype.exportPath = function() {
return string.dasherize('/' + this.appName + '/' + this.fileName);
return helper.dasherizePath('/' + this.appName + '/' + this.fileName);
};

TypedExport.prototype.outputFolderPath = function() {
return path.join(this.outputDirectory, path.dirname(string.dasherize(this.fileName)));
return helper.dasherizePath(path.join(this.outputDirectory, path.dirname(string.dasherize(this.fileName))));
};

TypedExport.prototype.outputFilePath = function() {
var fileName = path.basename(this.fileName);
var folderPath = this.outputFolderPath();
return path.join(folderPath, string.dasherize(fileName));
return helper.dasherizePath(path.join(folderPath, string.dasherize(fileName)));
};

TypedExport.convertToOutputFilename = function(stringInput) {
Expand All @@ -89,7 +90,7 @@ TypedExport.convertToOutputFilename = function(stringInput) {
filename.push(c);
});
return filename.join('').toLowerCase();
}
};

TypedExport.filePathForClassname = function(className, type, filePath, exportFiles) {
var newFilePath;
Expand All @@ -111,7 +112,14 @@ TypedExport.filePathForClassname = function(className, type, filePath, exportFil
fileParts.pop();
}
filename = fileParts.join('-');
newFilePath = TypedExport.pluralizeType(type) + "/" + filename + ".js";
if (['controller', 'route', 'model', 'view'].indexOf(type) !== -1 && path.dirname(filePath) !== TypedExport.pluralizeType(type)) {
var subDirs = path.dirname(filePath).split('/').slice(1).map(function (dir) {
return string.dasherize(dir).replace(/^-/, '')
});
newFilePath = TypedExport.pluralizeType(type) + "/" + subDirs.join('/') + "/" + filename + ".js";
} else {
newFilePath = TypedExport.pluralizeType(type) + "/" + filename + ".js";
}
}

// Check to see if we are colliding with previous export filenames
Expand All @@ -138,6 +146,6 @@ TypedExport.filePathForClassname = function(className, type, filePath, exportFil
}
}
return newFilePath;
}
};

module.exports = TypedExport;
3 changes: 3 additions & 0 deletions test/fixtures/vanilla/input/controllers/SubFolder/sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
App.SubController = Ember.ObjectController.extend({
someControllerProperty: 'props'
});
5 changes: 5 additions & 0 deletions test/fixtures/vanilla/input/models/SubFolder/sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
App.Sub = Ember.Object.extend({
someProperty: function(){
console.log('hello');
}.property('hello')
});
2 changes: 2 additions & 0 deletions test/fixtures/vanilla/input/routes/SubFolder/sub_route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
App.SubRoute = Ember.Route.extend({
});
7 changes: 7 additions & 0 deletions test/fixtures/vanilla/output/controllers/sub-folder/sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

var SubController = Ember.ObjectController.extend({
someControllerProperty: 'props'
});

export default SubController;
9 changes: 9 additions & 0 deletions test/fixtures/vanilla/output/models/sub-folder/sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';

var Sub = Ember.Object.extend({
someProperty: function(){
console.log('hello');
}.property('hello')
});

export default Sub;
6 changes: 6 additions & 0 deletions test/fixtures/vanilla/output/routes/sub-folder/sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Ember from 'ember';

var SubRoute = Ember.Route.extend({
});

export default SubRoute;
6 changes: 6 additions & 0 deletions test/models-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ describe('migrating models', function(){
it(migrates('routes/index.js'));
});

describe('Works with nested folders', function(){
it(migrates('controllers/sub-folder/sub.js'));
it(migrates('routes/sub-folder/sub.js'));
it(migrates('models/sub-folder/sub.js'));
});

describe('Preserve comments', function(){
it(migrates('controllers/preserve-comments.js'));
});
Expand Down
5 changes: 3 additions & 2 deletions test/test_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('fs');
var inflector = require('underscore.string');
var assert = require('chai').assert;
var _ = require('lodash');
var helper = require('../lib/helper');

var tmpDir = path.join(__dirname, "../tmp");

Expand Down Expand Up @@ -37,12 +38,12 @@ function fixture(migrator, fixtureName){
}

function migratesCorrectly(inputFileName, outputFileName) {
outputFileName = outputFileName || inflector.dasherize(inputFileName);
outputFileName = outputFileName || helper.dasherizePath(inputFileName);
var spec = function(){
var migrator = this.migrator;
var underscored = inflector.underscored(inputFileName);
var expected = fixture(migrator, outputFileName);
var actual = migratorResult(migrator, inflector.dasherize(inputFileName));
var actual = migratorResult(migrator, helper.dasherizePath(inputFileName));
assert.deepEqual(actual, expected);
};
return ['migrates ' + inputFileName + ' correctly', spec];
Expand Down