Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from momentumframework/cli-generate-fix
Cli generate fix
- Loading branch information
Showing
14 changed files
with
70 additions
and
266 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
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
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,43 +1,17 @@ | ||
import { Injectable } from "../../deps.ts"; | ||
import { FileIOService } from "../../global/mod.ts"; | ||
import { SchematicType } from "./generate-file.command-parameters.ts"; | ||
import { Schematic } from "./schematics/schematic.interface.ts"; | ||
|
||
export interface SchematicDetails { | ||
schematicFileContents: string; | ||
schematicFileName: string; | ||
} | ||
|
||
@Injectable({ global: false }) | ||
export class SchematicsService { | ||
constructor( | ||
private readonly fileIOService: FileIOService, | ||
private readonly schematics: Schematic[], | ||
) { | ||
} | ||
|
||
getSchematicDetails(type: SchematicType): SchematicDetails { | ||
const schematicsDirectoryPath = this.fileIOService | ||
.getCliWorkingDirectoryPath("schematics"); | ||
|
||
const files = this.fileIOService.getDirectoryContents( | ||
schematicsDirectoryPath, | ||
); | ||
|
||
const file = files.find((f: Deno.DirEntry) => | ||
f.isFile && f.name.endsWith(`.${type}.ts.tpl`) | ||
); | ||
|
||
if (!file) { | ||
throw new Error(`Could not find schematic for type "${type}".`); | ||
getSchematicDetails(type: SchematicType): Schematic { | ||
const schematic = this.schematics.find((s) => s.type === type); | ||
if (!schematic) { | ||
throw new Error(`Schematic could not be found for type "${type}".`); | ||
} | ||
|
||
const schematicFilePath = this.fileIOService.getCliWorkingDirectoryPath([ | ||
"schematics", | ||
file.name, | ||
]); | ||
|
||
return { | ||
schematicFileContents: this.fileIOService.readFile(schematicFilePath), | ||
schematicFileName: file.name, | ||
}; | ||
return schematic; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
cli/commands/generate-file/schematics/controller.schematic.ts
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Schematic } from "./schematic.interface.ts"; | ||
|
||
export const CONTROLLER_SCHEMATIC: Schematic = { | ||
type: "controller", | ||
fileNameTemplate: "__name__.controller.ts", | ||
template: `import { Controller } from "__depsPath__"; | ||
@Controller("__name__") | ||
export class __className__ {} | ||
`, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./controller.schematic.ts"; | ||
export * from "./module.schematic.ts"; | ||
export * from "./service.schematic.ts"; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Schematic } from "./schematic.interface.ts"; | ||
|
||
export const MODULE_SCHEMATIC: Schematic = { | ||
type: "module", | ||
fileNameTemplate: "__name__.module.ts", | ||
template: `import { MvModule } from "__depsPath__"; | ||
@MvModule({}) | ||
export class __className__ {} | ||
`, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { SchematicType } from "../generate-file.command-parameters.ts"; | ||
|
||
export interface Schematic { | ||
type: SchematicType; | ||
fileNameTemplate: string; | ||
template: string; | ||
} |
11 changes: 11 additions & 0 deletions
11
cli/commands/generate-file/schematics/service.schematic.ts
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Schematic } from "./schematic.interface.ts"; | ||
|
||
export const SERVICE_SCHEMATIC: Schematic = { | ||
type: "service", | ||
fileNameTemplate: "__name__.service.ts", | ||
template: `import { Injectable } from "__depsPath__"; | ||
@Injectable(__injectableOptions__) | ||
export class __className__ {} | ||
`, | ||
}; |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.