Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 06f6fe9

Browse files
committed
feat(generators): Add page generator
1 parent efdb85f commit 06f6fe9

15 files changed

Lines changed: 283 additions & 69 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ rucken commands clear prepare link ~~lib lib1
6363
rucken grid --entity-name apple
6464
rucken grid --help
6565
```
66+
### Scaffold
67+
68+
69+
```bash
70+
# generate model, service, grid, lookup input, modal for edit row in grid, modal for select items from grid with items
71+
rucken grid --entity-name apple
72+
rucken grid --help
73+
74+
# generate page
75+
rucken page --page-name apple
76+
rucken page --help
77+
```
6678

6779
## Quick links
6880

src/bin/app.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class App {
6363
.option('-lcp, --list-components-postfix [name]',
6464
'components postfix for collect to name-value object, example {\'users\': UsersGridComponent} it for list-components-postfix="grid" with component class file name="users-grid.component.ts"')
6565
.action(async (dummy, command) => {
66-
await (new PrepareCommand(_.merge(this.program, command))).process();
66+
await (new PrepareCommand(_.merge(this.program, command, dummy))).process();
6767
});
6868
this.program
6969
.command('commands [listOfCommands...]')
@@ -107,7 +107,7 @@ export class App {
107107
'components postfix for collect to name-value object, example {\'users\': UsersGridComponent} it for list-components-postfix="grid" with component class file name="users-grid.component.ts"')
108108
.description('make index.ts with import all ts files in application/library')
109109
.action(async (dummy, command) => {
110-
await (new MakeTsListCommand(_.merge(this.program, command))).process();
110+
await (new MakeTsListCommand(_.merge(this.program, command, dummy))).process();
111111
});
112112
this.program
113113
.command('grid')
@@ -121,7 +121,16 @@ export class App {
121121
.option('-pf, --platform-folder [path]', 'platform library path')
122122
.description('scaffold model, service, grid, lookup input, modal for edit row in grid, modal for select items from grid with items')
123123
.action(async (dummy, command) => {
124-
await (new GeneratorCommand(_.merge(this.program, command))).processGrid();
124+
await (new GeneratorCommand(_.merge(this.program, command, dummy))).processGrid();
125+
});
126+
this.program
127+
.command('page')
128+
.option('-pn, --page-name [name]', 'page name')
129+
.option('-al, --app-name [name]', 'app name, by default it is first app from ".angular-cli.json"')
130+
.option('-af, --app-folder [path]', 'app path, by default it is first app from ".angular-cli.json"')
131+
.description('scaffold empty page')
132+
.action(async (dummy, command) => {
133+
await (new GeneratorCommand(_.merge(this.program, command, dummy))).processPage();
125134
});
126135
this.program.parse(process.argv);
127136
}

src/commands/generator.command.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { GridGenerator } from '../generators/grid';
22
import { BaseCommand } from './base.command';
3+
import { PageGenerator } from '../generators/page';
34

45
export class GeneratorCommand extends BaseCommand {
56
constructor(public options: any) {
67
super(options);
7-
this.log('generator=>').info(options);
88
}
99
async processGrid() {
1010
this.log('generator').info('Run generator for ' + this.rootFolder);
@@ -34,4 +34,25 @@ export class GeneratorCommand extends BaseCommand {
3434
})
3535
);
3636
}
37+
async processPage() {
38+
this.log('generator').info('Run generator for ' + this.rootFolder);
39+
const gen = new PageGenerator(this.rootFolder);
40+
gen.debug = this.debug;
41+
const result = false;
42+
return await new Promise<boolean>((resolve: any) =>
43+
gen.proccess({
44+
pageName: this.options.pageName,
45+
project: this.project,
46+
appName: this.options.appName,
47+
appFolder: this.options.appFolder
48+
}).then((result: boolean) => {
49+
this.log('generator').info('Done!');
50+
resolve(true);
51+
}).catch((e: any) => {
52+
this.log('generator').error(e);
53+
this.log('generator').info('Done with errors!');
54+
resolve(false);
55+
})
56+
);
57+
}
3758
}

src/generators/page.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as _ from 'lodash';
2+
import * as path from 'path';
3+
4+
import { Base } from '../lib/base';
5+
import { Project } from '../lib/project';
6+
7+
8+
export class PageGenerator extends Base {
9+
10+
name = 'page';
11+
12+
constructor(public rootFolder?: string) {
13+
super(null, rootFolder);
14+
}
15+
async proccess(customOptions?: {
16+
project: Project,
17+
pageName: string,
18+
appName: string,
19+
appFolder: string
20+
}) {
21+
let rootFolder = path.resolve(this.rootFolder);
22+
let pageName = '';
23+
let appName =
24+
(customOptions && customOptions.project.appsConfigs[0] && customOptions &&
25+
customOptions.project.appsConfigs[0].name) ?
26+
customOptions && customOptions.project.appsConfigs[0].name : 'app';
27+
let appFolder =
28+
(customOptions && customOptions.project.appsConfigs[0] && customOptions &&
29+
customOptions.project.appsConfigs[0].localPath) ?
30+
customOptions && customOptions.project.appsConfigs[0].localPath : 'app';
31+
if (customOptions && customOptions.pageName) {
32+
pageName = customOptions.pageName;
33+
}
34+
if (customOptions && customOptions.appName) {
35+
appName = customOptions.appName;
36+
}
37+
if (customOptions && customOptions.appFolder) {
38+
appFolder = customOptions.appFolder;
39+
}
40+
const options = _.merge(
41+
{
42+
'app': {
43+
'name': appName,
44+
'folder': appFolder
45+
},
46+
'page': {
47+
'name': _.kebabCase(pageName),
48+
'classPrefix': _.upperFirst(_.camelCase(pageName)),
49+
'title': _.upperFirst(_.words(pageName).join(' '))
50+
}
51+
}
52+
);
53+
return await this.srcgen(
54+
rootFolder,
55+
'generatorPage',
56+
'empty.page',
57+
options,
58+
rootFolder
59+
);
60+
}
61+
}

srcgen/convert.po.to.ts/README!.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# USED
2-
```
3-
npm install po2json -g
4-
npm install recursive-readdir -g
5-
```
61
# VARIABLES
72
```
83
<prompt name="po.input.dir">./frontend/src/app/appname/i18n</prompt>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="container-fluid">
2+
<page-header [title]="title"></page-header>
3+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.<%=page.name%>{
2+
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component, Injector } from '@angular/core';
2+
import { BasePageComponent } from '@rucken/web';
3+
4+
@Component({
5+
selector: '<%=page.name%>-page',
6+
templateUrl: './<%=page.name%>-page.component.html',
7+
styleUrls: ['./<%=page.name%>-page.component.scss']
8+
})
9+
export class <%=page.classPrefix%>PageComponent extends BasePageComponent {
10+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ModuleWithProviders, NgModule } from '@angular/core';
2+
import { RouterModule } from '@angular/router';
3+
import { RuckenWebPipes, SharedModule, PipesModule } from '@rucken/web';
4+
import { PageHeaderModule } from '@rucken/web';
5+
6+
import { <%=page.classPrefix%>PageComponent } from './<%=page.name%>-page.component';
7+
import { <%=page.classPrefix%>PageRoutes } from './<%=page.name%>-page.routes';
8+
9+
@NgModule({
10+
imports: [
11+
SharedModule.forRoot(),
12+
PageHeaderModule.forRoot(),
13+
PipesModule.forRoot(),
14+
RouterModule.forChild(<%=page.classPrefix%>PageRoutes)
15+
],
16+
declarations: [<%=page.classPrefix%>PageComponent],
17+
exports: [<%=page.classPrefix%>PageComponent],
18+
entryComponents: [<%=page.classPrefix%>PageComponent]
19+
})
20+
export class <%=page.classPrefix%>PageModule {
21+
static forRoot(): ModuleWithProviders {
22+
return {
23+
ngModule: <%=page.classPrefix%>PageModule,
24+
providers: []
25+
};
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { translate } from '@rucken/core';
2+
import { HomeGuardService } from '@rucken/web';
3+
4+
import { <%=page.classPrefix%>PageComponent } from './<%=page.name%>-page.component';
5+
6+
export const <%=page.classPrefix%>PageRoutes = [{
7+
path: '',
8+
pathMatch: 'full',
9+
component: <%=page.classPrefix%>PageComponent,
10+
data: {
11+
name: '<%=page.name%>',
12+
title: translate('<%=page.title%>'),
13+
visible: true
14+
}
15+
}];

0 commit comments

Comments
 (0)