1
- import { Logger } from './logger/logger' ;
2
1
import { generateContext } from './util/config' ;
3
2
import * as Constants from './util/constants' ;
4
3
import { BuildContext } from './util/interfaces' ;
5
- import { readFileAsync , writeFileAsync } from './util/helpers' ;
6
- import { getTypescriptSourceFile , appendNgModuleDeclaration , insertNamedImportIfNeeded } from './util/typescript-utils' ;
7
- import { applyTemplates , filterOutTemplates , getNgModules , GeneratorOption , GeneratorRequest , hydrateRequest , readTemplates , writeGeneratedFiles } from './generators/util' ;
8
- import * as path from 'path' ;
4
+ import { getNgModules , GeneratorOption , GeneratorRequest , nonPageFileManipulation , processNonTabRequest } from './generators/util' ;
9
5
10
6
export { getNgModules , GeneratorOption , GeneratorRequest } ;
11
7
@@ -19,31 +15,19 @@ export function processPageRequest(context: BuildContext, name: string) {
19
15
}
20
16
21
17
export function processPipeRequest ( context : BuildContext , name : string , ngModulePath : string ) {
22
- const hydratedRequest = hydrateRequest ( context , { type : 'pipe' , name } ) ;
23
- return readFileAsync ( ngModulePath ) . then ( ( fileContent : string ) => {
24
- fileContent = insertNamedImportIfNeeded ( ngModulePath , fileContent , hydratedRequest . className , path . relative ( path . dirname ( ngModulePath ) , hydratedRequest . dirToWrite ) ) ;
25
- fileContent = appendNgModuleDeclaration ( ngModulePath , fileContent , hydratedRequest . className ) ;
26
- return writeFileAsync ( ngModulePath , fileContent ) ;
27
- } ) . then ( ( ) => {
28
- return processNonTabRequest ( context , hydratedRequest ) ;
29
- } ) . then ( ( ) => {
30
- // TODO
31
- } ) ;
18
+ return nonPageFileManipulation ( context , name , ngModulePath , 'pipe' ) ;
32
19
}
33
20
34
- function processNonTabRequest ( context : BuildContext , request : GeneratorRequest ) : Promise < string [ ] > {
35
- Logger . debug ( '[Generators] processNonTabRequest: Hydrating the request with project data ...' ) ;
36
- const hydratedRequest = hydrateRequest ( context , request ) ;
37
- Logger . debug ( '[Generators] processNonTabRequest: Reading templates ...' ) ;
38
- return readTemplates ( hydratedRequest . dirToRead ) . then ( ( map : Map < string , string > ) => {
39
- Logger . debug ( '[Generators] processNonTabRequest: Filtering out NgModule and Specs if needed ...' ) ;
40
- return filterOutTemplates ( hydratedRequest , map ) ;
41
- } ) . then ( ( filteredMap : Map < string , string > ) => {
42
- Logger . debug ( '[Generators] processNonTabRequest: Applying tempaltes ...' ) ;
43
- const appliedTemplateMap = applyTemplates ( hydratedRequest , filteredMap ) ;
44
- Logger . debug ( '[Generators] processNonTabRequest: Writing generated files to disk ...' ) ;
45
- return writeGeneratedFiles ( hydratedRequest , appliedTemplateMap ) ;
46
- } ) ;
21
+ export function processDirectiveRequest ( context : BuildContext , name : string , ngModulePath : string ) {
22
+ return nonPageFileManipulation ( context , name , ngModulePath , 'directive' ) ;
23
+ }
24
+
25
+ export function processComponentRequest ( context : BuildContext , name : string , ngModulePath : string ) {
26
+ return nonPageFileManipulation ( context , name , ngModulePath , 'component' ) ;
27
+ }
28
+
29
+ export function processProviderRequest ( context : BuildContext , name : string , ngModulePath : string ) {
30
+ return nonPageFileManipulation ( context , name , ngModulePath , 'provider' ) ;
47
31
}
48
32
49
33
export function listOptions ( ) {
0 commit comments