|
| 1 | +/* eslint-env node */ |
| 2 | + |
| 3 | +var stringUtil = require('ember-cli-string-utils'); |
| 4 | +var validComponentName = require('ember-cli-valid-component-name'); |
| 5 | +var getPathOption = require('ember-cli-get-component-path-option'); |
| 6 | +var path = require('path'); |
| 7 | +var normalizeEntityName = require('ember-cli-normalize-entity-name'); |
| 8 | + |
| 9 | +module.exports = { |
| 10 | + description: 'Generates a component. Name must contain a hyphen.', |
| 11 | + |
| 12 | + fileMapTokens: function() { |
| 13 | + return { |
| 14 | + __path__: function(options) { |
| 15 | + if (options.pod) { |
| 16 | + return path.join(options.podPath, options.locals.path, options.dasherizedModuleName); |
| 17 | + } |
| 18 | + return 'components'; |
| 19 | + }, |
| 20 | + __name__: function(options) { |
| 21 | + if (options.pod) { |
| 22 | + return 'component'; |
| 23 | + } |
| 24 | + return options.dasherizedModuleName; |
| 25 | + }, |
| 26 | + __root__: function(options) { |
| 27 | + if (options.inRepoAddon) { |
| 28 | + return path.join('lib', options.inRepoAddon, 'app'); |
| 29 | + } |
| 30 | + return 'app'; |
| 31 | + } |
| 32 | + }; |
| 33 | + }, |
| 34 | + |
| 35 | + normalizeEntityName: function(entityName) { |
| 36 | + entityName = normalizeEntityName(entityName); |
| 37 | + |
| 38 | + return validComponentName(entityName); |
| 39 | + }, |
| 40 | + |
| 41 | + locals: function(options) { |
| 42 | + var addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name(); |
| 43 | + var addonName = stringUtil.dasherize(addonRawName); |
| 44 | + var fileName = stringUtil.dasherize(options.entity.name); |
| 45 | + var importPathName = [addonName, 'components', fileName].join('/'); |
| 46 | + |
| 47 | + if (options.pod) { |
| 48 | + importPathName = [addonName, 'components', fileName, 'component'].join('/'); |
| 49 | + } |
| 50 | + |
| 51 | + return { |
| 52 | + modulePath: importPathName, |
| 53 | + path: getPathOption(options) |
| 54 | + }; |
| 55 | + } |
| 56 | +}; |
0 commit comments