Skip to content

Commit 503830f

Browse files
authored
Merge pull request #160 from jamescdavis/add-addon-blueprints
Add -addon blueprints that generate .ts files
2 parents d9e11c6 + e22c3fd commit 503830f

File tree

19 files changed

+339
-0
lines changed

19 files changed

+339
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1010

1111
* Blueprint (and tests) to generate in-repo addons configured for TypeScript
1212
* @ts-ignore component template import.
13+
* -addon blueprints for all the things to generate .ts files in `app/` in an addon.
1314

1415
### Changed
1516

blueprints/-addon-import.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
var stringUtil = require('ember-cli-string-utils');
4+
var path = require('path');
5+
var inflector = require('inflection');
6+
7+
module.exports = {
8+
description: 'Generates an import wrapper.',
9+
10+
fileMapTokens: function() {
11+
return {
12+
__name__: function(options) {
13+
return options.dasherizedModuleName;
14+
},
15+
__path__: function(options) {
16+
return inflector.pluralize(options.locals.blueprintName);
17+
},
18+
__root__: function(options) {
19+
if (options.inRepoAddon) {
20+
return path.join('lib', options.inRepoAddon, 'app');
21+
}
22+
return 'app';
23+
}
24+
};
25+
},
26+
27+
locals: function(options) {
28+
var addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
29+
var addonName = stringUtil.dasherize(addonRawName);
30+
var fileName = stringUtil.dasherize(options.entity.name);
31+
var blueprintName = options.originBlueprintName;
32+
var modulePathSegments = [addonName, inflector.pluralize(options.originBlueprintName), fileName];
33+
34+
if (blueprintName.match(/-addon/)) {
35+
blueprintName = blueprintName.substr(0, blueprintName.indexOf('-addon'));
36+
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
37+
}
38+
39+
return {
40+
modulePath: modulePathSegments.join('/'),
41+
blueprintName: blueprintName
42+
};
43+
}
44+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '<%= modulePath %>';
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default, <%= camelizedModuleName %> } from '<%= modulePath %>';

blueprints/helper-addon/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('../-addon-import');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default, initialize } from '<%= modulePath %>';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('../-addon-import');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default, initialize } from '<%= modulePath %>';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('../-addon-import');

0 commit comments

Comments
 (0)