Skip to content

Commit 3aa3002

Browse files
authored
Fix content while creating a "js only" component (#718)
* Fix component-js content * Test case fix
1 parent 833cc4c commit 3aa3002

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

app/mixins/files.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,19 @@ export default Mixin.create({
6565
run.scheduleOnce('afterRender', this, this.updateOpenFiles);
6666
},
6767

68-
addFile(type) {
69-
let fileProperties = type ? this.emberCli.buildProperties(type) : {filePath:'file.js'};
68+
async addFile(type) {
69+
let replacements = {};
70+
let isGlimmer = await this.emberCli.twiddleJson.hasAddon(this.model, '@glimmer/component');
71+
72+
if (type === 'component-js') {
73+
replacements.importComponent = isGlimmer ?
74+
`import Component from '@glimmer/component';` :
75+
`import Component from '@ember/component';`;
76+
replacements.importTemplate = '';
77+
replacements.defaultExport = "class extends Component {\n}";
78+
}
79+
80+
let fileProperties = type ? this.emberCli.buildProperties(type, replacements) : {filePath:'file.js'};
7081
let filePath = fileProperties.filePath;
7182

7283
if (['twiddle.json','router', 'css'].indexOf(type)===-1) {

app/services/twiddle-json.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export default Service.extend({
131131
},
132132

133133
async hasAddon(gist, addonName) {
134-
let json = await this._getTwiddleJson(gist);
135-
return addonName in json.addons;
134+
let { addons = {} } = await this._getTwiddleJson(gist);
135+
return addonName in addons;
136136
},
137137

138138
_dedupEmberData(json) {

0 commit comments

Comments
 (0)