value-converter.js 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {inject} from 'aurelia-dependency-injection';
  2. import {Project, ProjectItem, CLIOptions, UI} from 'aurelia-cli';
  3. @inject(Project, CLIOptions, UI)
  4. export default class ValueConverterGenerator {
  5. constructor(project, options, ui) {
  6. this.project = project;
  7. this.options = options;
  8. this.ui = ui;
  9. }
  10. execute() {
  11. return this.ui
  12. .ensureAnswer(this.options.args[0], 'What would you like to call the value converter?')
  13. .then(name => {
  14. let fileName = this.project.makeFileName(name);
  15. let className = this.project.makeClassName(name);
  16. this.project.valueConverters.add(
  17. ProjectItem.text(`${fileName}.js`, this.generateSource(className))
  18. );
  19. return this.project.commitChanges()
  20. .then(() => this.ui.log(`Created ${fileName}.`));
  21. });
  22. }
  23. generateSource(className) {
  24. return `export class ${className}ValueConverter {
  25. toView(value) {
  26. }
  27. fromView(value) {
  28. }
  29. }
  30. `;
  31. }
  32. }