Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change stackblitz services so that it will work with new generat…
…ors (#336) * fix: change stackblitz services so that it will work with new generators * fix: small change to package and util * fix: change stackblitz services so that it will work with new generators * fix: duplicate angular router * fix: missing data * chore: remove makefile * fix: reorder angular generation code * fix(codegen): resolve incorrect routing path
- Loading branch information
Showing
15 changed files
with
195 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
100 changes: 100 additions & 0 deletions
100
projects/angular-codegen/src/lib/angular-bootstrap.service.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,100 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { FormatService } from '@xlayers/sketch-lib'; | ||
|
||
type WebCodeGenOptions = any; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AngularBootstrapService { | ||
constructor(private readonly formatService: FormatService) {} | ||
|
||
generate(files) { | ||
return [ | ||
{ | ||
uri: 'xlayers-routing.module.ts', | ||
value: this.renderRoutingModule(), | ||
language: 'typescript', | ||
kind: 'angular' | ||
}, | ||
{ | ||
uri: 'xlayers.module.ts', | ||
value: this.renderModule(files), | ||
language: 'typescript', | ||
kind: 'angular' | ||
} | ||
]; | ||
} | ||
|
||
private renderRoutingModule() { | ||
return `\ | ||
import { NgModule } from '@angular/core' | ||
import { RouterModule, Routes } from '@angular/router'; | ||
const xlayersRoutes: Routes = [{ | ||
path: 'xlayers',\ | ||
loadChildren: 'app/xlayers/xlayers.module#XlayersModule' | ||
}]; | ||
@NgModule({ | ||
imports: [ RouterModule.forChild(xlayersRoutes) ], | ||
exports: [ RouterModule ] | ||
}) | ||
export class XlayersRoutingModule {}`; | ||
} | ||
|
||
private renderModule(files) { | ||
const importStatements = this.renderImports(files); | ||
const ngStatements = this.renderNgClasses(files); | ||
return `\ | ||
${importStatements} | ||
@NgModule({ | ||
declarations: [ | ||
${ngStatements} | ||
], | ||
exports: [ | ||
${ngStatements} | ||
], | ||
imports: [ | ||
CommonModule | ||
] | ||
}) | ||
export class XlayersModule {}`; | ||
} | ||
|
||
private renderImports(files) { | ||
return [ | ||
'import { NgModule } from \'@angular/core\';', | ||
'import { CommonModule } from \'@angular/common\';' | ||
] | ||
.concat( | ||
files | ||
.filter(file => file.uri.endsWith('.component.ts')) | ||
.map( | ||
file => | ||
`import { ${this.extractClassName( | ||
file | ||
)} } from './${this.extractCompenentFileName(file)}';` | ||
) | ||
) | ||
.join('\n'); | ||
} | ||
|
||
private renderNgClasses(files) { | ||
return files | ||
.filter(file => file.uri.endsWith('.component.ts')) | ||
.map(file => this.formatService.indent(2, this.extractClassName(file))) | ||
.join(',\n'); | ||
} | ||
|
||
private extractClassName(file) { | ||
const uri = file.uri.split('/'); | ||
const fileName = uri[uri.length - 1].replace('.component.ts', ''); | ||
return this.formatService.className(`${fileName}Component`); | ||
} | ||
|
||
private extractCompenentFileName(file) { | ||
return file.uri.split('.ts')[0]; | ||
} | ||
} |
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
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
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
Oops, something went wrong.