Skip to content
Merged
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
61 changes: 44 additions & 17 deletions blueprints/route-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const useTestFrameworkDetector = require('../test-framework-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = useTestFrameworkDetector({
description: 'Generates a route unit test.',
Expand All @@ -15,23 +16,49 @@ module.exports = useTestFrameworkDetector({
],

fileMapTokens: function() {
return {
__test__: function(options) {
let moduleName = options.locals.moduleName;

if (options.pod) {
moduleName = 'route';
}

return `${moduleName}-test`;
},
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.moduleName);
}
return 'routes';
},
};
if (isModuleUnificationProject(this.project)) {
return {
__test__() {
return 'route-test';
},
__root__(options) {
if (options.inRepoAddon) {
return path.join('packages', options.inRepoAddon, 'src');
}
return 'src';
},
__testType__() {
return '';
},
__path__(options) {
return path.join('ui', 'routes', options.dasherizedModuleName);
},
};
} else {
return {
__root__() {
return 'tests';
},
__testType__() {
return 'unit';
},
__test__: function(options) {
let moduleName = options.locals.moduleName;

if (options.pod) {
moduleName = 'route';
}

return `${moduleName}-test`;
},
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.moduleName);
}
return 'routes';
},
};
}
},

locals: function(options) {
Expand Down
110 changes: 69 additions & 41 deletions blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const chalk = require('chalk');
const stringUtil = require('ember-cli-string-utils');
const EmberRouterGenerator = require('ember-router-generator');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = {
description: 'Generates a route and a template, and registers the route with the router.',
Expand All @@ -27,47 +28,73 @@ module.exports = {
],

fileMapTokens: function() {
return {
__name__: function(options) {
if (options.pod) {
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}
if (options.inDummy) {
return path.join('tests', 'dummy', 'src');
}
return 'src';
},
__path__(options) {
return path.join('ui', 'routes', options.dasherizedModuleName);
},
__name__() {
return 'route';
}
return options.locals.moduleName;
},
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.moduleName);
}
return 'routes';
},
__templatepath__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.moduleName);
}
return 'templates';
},
__templatename__: function(options) {
if (options.pod) {
},
__templatepath__(options) {
return path.join('ui', 'routes', options.dasherizedModuleName);
},
__templatename__() {
return 'template';
}
return options.locals.moduleName;
},
__root__: function(options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'addon');
}

if (options.inDummy) {
return path.join('tests', 'dummy', 'app');
}

if (options.inAddon) {
return 'addon';
}

return 'app';
},
};
},
};
} else {
return {
__name__(options) {
if (options.pod) {
return 'route';
}
return options.locals.moduleName;
},
__path__(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.moduleName);
}
return 'routes';
},
__templatepath__(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.moduleName);
}
return 'templates';
},
__templatename__(options) {
if (options.pod) {
return 'template';
}
return options.locals.moduleName;
},
__root__(options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'addon');
}

if (options.inDummy) {
return path.join('tests', 'dummy', 'app');
}

if (options.inAddon) {
return 'addon';
}

return 'app';
},
};
}
},

locals: function(options) {
Expand Down Expand Up @@ -132,11 +159,12 @@ function updateRouter(action, options) {

function findRouter(options) {
let routerPathParts = [options.project.root];
let root = isModuleUnificationProject(options.project) ? 'src' : 'app';

if (options.dummy && options.project.isEmberCLIAddon()) {
routerPathParts = routerPathParts.concat(['tests', 'dummy', 'app', 'router.js']);
routerPathParts = routerPathParts.concat(['tests', 'dummy', root, 'router.js']);
} else {
routerPathParts = routerPathParts.concat(['app', 'router.js']);
routerPathParts = routerPathParts.concat([root, 'router.js']);
}

return routerPathParts;
Expand Down
Loading