Skip to content

Commit

Permalink
Fix content while creating a "js only" component (#718)
Browse files Browse the repository at this point in the history
* Fix component-js content

* Test case fix
  • Loading branch information
RajaSK05 authored Apr 21, 2020
1 parent 833cc4c commit 3aa3002
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions app/mixins/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ export default Mixin.create({
run.scheduleOnce('afterRender', this, this.updateOpenFiles);
},

addFile(type) {
let fileProperties = type ? this.emberCli.buildProperties(type) : {filePath:'file.js'};
async addFile(type) {
let replacements = {};
let isGlimmer = await this.emberCli.twiddleJson.hasAddon(this.model, '@glimmer/component');

if (type === 'component-js') {
replacements.importComponent = isGlimmer ?
`import Component from '@glimmer/component';` :
`import Component from '@ember/component';`;
replacements.importTemplate = '';
replacements.defaultExport = "class extends Component {\n}";
}

let fileProperties = type ? this.emberCli.buildProperties(type, replacements) : {filePath:'file.js'};
let filePath = fileProperties.filePath;

if (['twiddle.json','router', 'css'].indexOf(type)===-1) {
Expand Down
4 changes: 2 additions & 2 deletions app/services/twiddle-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export default Service.extend({
},

async hasAddon(gist, addonName) {
let json = await this._getTwiddleJson(gist);
return addonName in json.addons;
let { addons = {} } = await this._getTwiddleJson(gist);
return addonName in addons;
},

_dedupEmberData(json) {
Expand Down

0 comments on commit 3aa3002

Please sign in to comment.