| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import {inject} from 'aurelia-dependency-injection';
- import {Project, ProjectItem, CLIOptions, UI} from 'aurelia-cli';
- @inject(Project, CLIOptions, UI)
- export default class GeneratorGenerator {
- constructor(project, options, ui) {
- this.project = project;
- this.options = options;
- this.ui = ui;
- }
- execute() {
- return this.ui
- .ensureAnswer(this.options.args[0], 'What would you like to call the generator?')
- .then(name => {
- let fileName = this.project.makeFileName(name);
- let className = this.project.makeClassName(name);
- this.project.generators.add(
- ProjectItem.text(`${fileName}.js`, this.generateSource(className))
- );
- return this.project.commitChanges()
- .then(() => this.ui.log(`Created ${fileName}.`));
- });
- }
- generateSource(className) {
- return `import {inject} from 'aurelia-dependency-injection';
- import {Project, ProjectItem, CLIOptions, UI} from 'aurelia-cli';
- @inject(Project, CLIOptions, UI)
- export default class ${className}Generator {
- constructor(project, options, ui) {
- this.project = project;
- this.options = options;
- this.ui = ui;
- }
- execute() {
- return this.ui
- .ensureAnswer(this.options.args[0], 'What would you like to call the new item?')
- .then(name => {
- let fileName = this.project.makeFileName(name);
- let className = this.project.makeClassName(name);
- this.project.elements.add(
- ProjectItem.text(\`\${fileName}.js\`, this.generateSource(className))
- );
- return this.project.commitChanges()
- .then(() => this.ui.log(\`Created \${fileName}.\`));
- });
- }
- generateSource(className) {
- return \`import {bindable} from 'aurelia-framework';
- export class \${className} {
- @bindable value;
- valueChanged(newValue, oldValue) {
- }
- }
- \`
- }
- }
- `;
- }
- }
|