-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
-addon-import.js
48 lines (42 loc) · 1.36 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
'use strict';
const stringUtil = require('ember-cli-string-utils');
const path = require('path');
const inflector = require('inflection');
module.exports = {
description: 'Generates an import wrapper.',
fileMapTokens: function () {
return {
__name__: function (options) {
return options.dasherizedModuleName;
},
__path__: function (options) {
return inflector.pluralize(options.locals.blueprintName);
},
__root__: function (options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
},
};
},
locals: function (options) {
let addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
let addonName = stringUtil.dasherize(addonRawName);
let fileName = stringUtil.dasherize(options.entity.name);
let blueprintName = options.originBlueprintName;
let modulePathSegments = [
addonName,
inflector.pluralize(options.originBlueprintName),
fileName,
];
if (blueprintName.match(/-addon/)) {
blueprintName = blueprintName.substr(0, blueprintName.indexOf('-addon'));
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
}
return {
modulePath: modulePathSegments.join('/'),
blueprintName: blueprintName,
};
},
};