forked from nestjs/nest-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
develop controller copy asset generator
- Loading branch information
thomrick
committed
May 30, 2017
1 parent
580bd80
commit 70f01fb
Showing
2 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
import {Generator} from '../../common/interfaces/generator.interface'; | ||
import {Readable, Writable} from 'stream'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
export class ControllerGenerator implements Generator { | ||
private templatePath: string = '../../assets/ts/controller/controller.ts.template'; | ||
private testTemplatePath: string = '../../assets/ts/controller/controller.spec.ts.template'; | ||
private filename: string = '[name].controller.ts'; | ||
private testFilename: string = '[name].controller.spec.ts'; | ||
|
||
public generate(name: string): Promise<void> { | ||
throw new Error("Method not implemented."); | ||
this.generateAsset(name); | ||
this.generateTestAsset(name); | ||
return Promise.resolve(); | ||
} | ||
|
||
private generateAsset(name: string): void { | ||
const reader: Readable = fs.createReadStream(path.resolve(__dirname, this.templatePath)); | ||
const writer: Writable = fs.createWriteStream(path.resolve(process.cwd(), name, this.filename)); | ||
reader.pipe(writer); | ||
} | ||
|
||
private generateTestAsset(name: string): void { | ||
const reader: Readable = fs.createReadStream(path.resolve(__dirname, this.testTemplatePath)); | ||
const writer: Writable = fs.createWriteStream(path.resolve(process.cwd(), name, this.testFilename)); | ||
reader.pipe(writer); | ||
} | ||
} |
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