UI/Update blueprints to glimmer components (#13149)

* updates generator to glimmer

* adds changelog

* accounts for addon vs reg components

* moves imports to the top of components
This commit is contained in:
claire bontempo 2021-11-16 13:14:16 -08:00 committed by GitHub
parent eda9607c8a
commit c8bfbbdf7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 10 deletions

3
changelog/13149.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
ui: Updates ember blueprints to glimmer components
```

View File

@ -1,3 +1,6 @@
import Component from '@glimmer/component';
<%= importTemplate %>
<%= setComponentTemplate %>
/** /**
* @module <%= classifiedModuleName %> * @module <%= classifiedModuleName %>
* <%= classifiedModuleName %> components are used to... * <%= classifiedModuleName %> components are used to...
@ -11,7 +14,7 @@
* @param {string} [param1=defaultValue] - param1 is... * @param {string} [param1=defaultValue] - param1 is...
*/ */
import Component from '@ember/component'; <%= exportDefault %>class <%= classifiedModuleName %> extends Component {
<%= importTemplate %> }
export default Component.extend({<%= contents %>
}); <%= exportAddOn %>

View File

@ -54,11 +54,13 @@ module.exports = {
}, },
locals: function(options) { locals: function(options) {
let templatePath = ''; let exportDefault = 'export default ';
let exportAddOn = '';
let importTemplate = ''; let importTemplate = '';
let contents = ''; let setComponentTemplate = '';
let templatePath = '';
// if we're in an addon, build import statement // if we're in an addon, build import statement and set layout
if (options.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy) || !!options.in) { if (options.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy) || !!options.in) {
if (options.pod) { if (options.pod) {
templatePath = './template'; templatePath = './template';
@ -68,13 +70,19 @@ module.exports = {
'templates/components/' + 'templates/components/' +
stringUtil.dasherize(options.entity.name); stringUtil.dasherize(options.entity.name);
} }
importTemplate = "import layout from '" + templatePath + "';\n"; exportDefault = '';
contents = '\n layout'; exportAddOn = `export default setComponentTemplate(layout, ${stringUtil.classify(
options.entity.name
)})`;
importTemplate = "import layout from '" + templatePath + "';";
setComponentTemplate = "import { setComponentTemplate } from '@ember/component'; \n";
} }
return { return {
exportDefault: exportDefault,
exportAddOn: exportAddOn,
importTemplate: importTemplate, importTemplate: importTemplate,
contents: contents, setComponentTemplate: setComponentTemplate,
path: getPathOption(options), path: getPathOption(options),
}; };
}, },