npx ember-getset-util-codemod getset-util path/of/files/ or/some**/*glob.js
# or
yarn global add ember-getset-util-codemod
ember-getset-util-codemod getset-util path/of/files/ or/some**/*glob.js
Input (basic.input.js):
import Service from '@ember/service';
export default Service.extend({
init() {
this.set('hello', 'world');
console.log(this.get('hello'));
},
doStuff() {
this.getProperties(['hello']);
this.setProperties({
hello: 'world',
});
},
});
Output (basic.output.js):
import { get, getProperties, set, setProperties } from "@ember/object";
import Service from '@ember/service';
export default Service.extend({
init() {
set(this, 'hello', 'world');
console.log(get(this, 'hello'));
},
doStuff() {
getProperties(this, ['hello']);
setProperties(this, {
hello: 'world',
});
},
});
Input (existing-imports.input.js):
import { getWithDefault, get } from '@ember/object';
import Service from '@ember/service';
export default Service.extend({
init() {
get(this, 'hello');
getWithDefault(this, 'hello', 'world');
this.set('hello', 'world');
console.log(this.get('hello'));
},
doStuff() {
this.getProperties(['hello']);
this.setProperties({
hello: 'world',
});
},
});
Output (existing-imports.output.js):
import { getWithDefault, get, getProperties, set, setProperties } from '@ember/object';
import Service from '@ember/service';
export default Service.extend({
init() {
get(this, 'hello');
getWithDefault(this, 'hello', 'world');
set(this, 'hello', 'world');
console.log(get(this, 'hello'));
},
doStuff() {
getProperties(this, ['hello']);
setProperties(this, {
hello: 'world',
});
},
});