Last active
November 28, 2018 19:30
-
-
Save davidlav/70e5ffe3572be7cd577f168346860991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {autoinject} from 'aurelia-dependency-injection'; | |
import {Project, ProjectItem, CLIOptions, UI} from 'aurelia-cli'; | |
import * as path from 'path'; | |
@autoinject() | |
export default class StyledComponentGenerator { | |
constructor(private project: Project, private options: CLIOptions, private ui: UI) { } | |
execute() { | |
return this.ui | |
.ensureAnswer(this.options.args[0], 'What would you like to call the new component?') | |
.then(name => { | |
let fileName = this.project.makeFileName(name); | |
let className = this.project.makeClassName(name); | |
this.project.root.add( | |
ProjectItem.text(path.join('components', fileName,`${fileName}.html`), this.generateHTMLSource(fileName)), | |
ProjectItem.text(path.join('components', fileName,`${fileName}.styl`), this.generateStylusSource(fileName)), | |
ProjectItem.text(path.join('components', fileName,`${fileName}.ts`), this.generateTSSource(className)), | |
); | |
return this.project.commitChanges() | |
.then(() => this.ui.log(`Created ${fileName} in ${path.join('components', fileName)}`)); | |
}); | |
} | |
generateHTMLSource(fileName) { | |
return `<template> | |
<require from="./${fileName}.styl"></require> | |
<h1>\${message}</h1> | |
</template>` | |
} | |
generateStylusSource(fileName) { | |
return `${fileName} | |
//`; | |
} | |
generateTSSource(className) { | |
return `export class ${className} { | |
message: string; | |
constructor() { | |
this.message = 'Hello world'; | |
} | |
}` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment