-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy path-addon-import.js
54 lines (47 loc) · 1.7 KB
/
-addon-import.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-env node */
var stringUtil = require('ember-cli-string-utils');
var path = require('path');
var inflector = require('inflection');
module.exports = {
description: 'Generates an import wrapper.',
fileMapTokens: function() {
return {
__name__: function(options) {
if (options.pod && options.hasPathToken) {
return options.locals.blueprintName;
}
return options.dasherizedModuleName;
},
__path__: function(options) {
if (options.pod && options.hasPathToken) {
return path.join(options.podPath, options.dasherizedModuleName);
}
return inflector.pluralize(options.locals.blueprintName);
},
__root__: function(options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
}
};
},
locals: function(options) {
var addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
var addonName = stringUtil.dasherize(addonRawName);
var fileName = stringUtil.dasherize(options.entity.name);
var blueprintName = options.originBlueprintName;
var modulePathSegments = [addonName, inflector.pluralize(options.originBlueprintName), fileName];
if (blueprintName.match(/-addon/)) {
blueprintName = blueprintName.substr(0, blueprintName.indexOf('-addon'));
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
}
if (options.pod) {
modulePathSegments = [addonName, fileName, blueprintName];
}
return {
modulePath: modulePathSegments.join('/'),
blueprintName: blueprintName
};
}
};