5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { Path , strings } from '@angular-devkit/core' ;
8
+ import { strings } from '@angular-devkit/core' ;
9
9
import {
10
10
Rule ,
11
11
SchematicContext ,
12
- SchematicsException ,
13
12
Tree ,
14
13
apply ,
15
14
filter ,
@@ -19,41 +18,12 @@ import {
19
18
template ,
20
19
url ,
21
20
} from '@angular-devkit/schematics' ;
22
- import * as ts from 'typescript' ;
23
- import { getFirstNgModuleName } from '../utility/ast-utils' ;
24
21
import { getWorkspace } from '../utility/config' ;
25
- import { buildRelativePath , findModuleFromOptions } from '../utility/find-module' ;
26
22
import { parseName } from '../utility/parse-name' ;
27
23
import { Schema as ServiceOptions } from './schema' ;
28
24
29
- function getModuleNameFromPath ( host : Tree , modulePath : Path ) {
30
- if ( ! host . exists ( modulePath ) ) {
31
- throw new SchematicsException ( `File ${ modulePath } does not exist.` ) ;
32
- }
33
-
34
- const text = host . read ( modulePath ) ;
35
- if ( text === null ) {
36
- throw new SchematicsException ( `File ${ modulePath } cannot be read.` ) ;
37
- }
38
- const sourceText = text . toString ( 'utf-8' ) ;
39
- const source = ts . createSourceFile ( modulePath , sourceText , ts . ScriptTarget . Latest , true ) ;
40
-
41
- return getFirstNgModuleName ( source ) ;
42
- }
43
-
44
- function stripTsExtension ( path : string ) : string {
45
- if ( ! path . endsWith ( '.ts' ) ) {
46
- throw new SchematicsException ( `File ${ path } is not a Typescript file.` ) ;
47
- }
48
-
49
- return path . substr ( 0 , path . length - 3 ) ;
50
- }
51
-
52
25
export default function ( options : ServiceOptions ) : Rule {
53
26
return ( host : Tree , context : SchematicContext ) => {
54
- let providedByModule = '' ;
55
- let providedInPath = '' ;
56
-
57
27
const workspace = getWorkspace ( host ) ;
58
28
if ( ! options . project ) {
59
29
options . project = Object . keys ( workspace . projects ) [ 0 ] ;
@@ -64,25 +34,6 @@ export default function (options: ServiceOptions): Rule {
64
34
options . path = `/${ project . root } /src/app` ;
65
35
}
66
36
67
- if ( options . module ) {
68
- const modulePath = findModuleFromOptions ( host , options ) ;
69
- if ( ! modulePath || ! host . exists ( modulePath ) ) {
70
- throw new Error ( 'Specified module does not exist' ) ;
71
- }
72
- providedByModule = getModuleNameFromPath ( host , modulePath ) || '' ;
73
-
74
- if ( ! providedByModule ) {
75
- throw new SchematicsException ( `module option did not point to an @NgModule.` ) ;
76
- }
77
-
78
- const servicePath = `/${ options . path } /`
79
- + ( options . flat ? '' : strings . dasherize ( options . name ) + '/' )
80
- + strings . dasherize ( options . name )
81
- + '.service' ;
82
-
83
- providedInPath = stripTsExtension ( buildRelativePath ( servicePath , modulePath ) ) ;
84
- }
85
-
86
37
const parsedPath = parseName ( options . path , options . name ) ;
87
38
options . name = parsedPath . name ;
88
39
options . path = parsedPath . path ;
@@ -93,8 +44,6 @@ export default function (options: ServiceOptions): Rule {
93
44
...strings ,
94
45
'if-flat' : ( s : string ) => options . flat ? '' : s ,
95
46
...options ,
96
- providedIn : providedByModule ,
97
- providedInPath : providedInPath ,
98
47
} ) ,
99
48
move ( parsedPath . path ) ,
100
49
] ) ;
0 commit comments