1
1
import * as path from 'path' ;
2
2
import { getGlobalVariable } from '../../utils/env' ;
3
3
import { exec , execAndWaitForOutputToMatch , silentNpm } from '../../utils/process' ;
4
+ import { rimraf } from '../../utils/fs' ;
4
5
5
6
export default async function ( ) {
6
7
// setup
@@ -9,7 +10,6 @@ export default async function () {
9
10
return ;
10
11
}
11
12
12
- const startCwd = process . cwd ( ) ;
13
13
await silentNpm (
14
14
'install' ,
15
15
'-g' ,
@@ -18,17 +18,23 @@ export default async function () {
18
18
) ;
19
19
await exec ( process . platform . startsWith ( 'win' ) ? 'where' : 'which' , 'schematics' ) ;
20
20
21
- // create blank schematic
22
- await exec ( 'schematics' , 'schematic' , '--name' , 'test-schematic' ) ;
21
+ const startCwd = process . cwd ( ) ;
22
+ const schematicPath = path . join ( startCwd , 'test-schematic' ) ;
23
23
24
- process . chdir ( path . join ( startCwd , 'test-schematic' ) ) ;
25
- await execAndWaitForOutputToMatch (
26
- 'schematics' ,
27
- [ '.:' , '--list-schematics' ] ,
28
- / m y - f u l l - s c h e m a t i c / ,
29
- ) ;
24
+ try {
25
+ // create blank schematic
26
+ await exec ( 'schematics' , 'schematic' , '--name' , 'test-schematic' ) ;
30
27
31
- // restore path
32
- process . chdir ( startCwd ) ;
28
+ process . chdir ( path . join ( startCwd , 'test-schematic' ) ) ;
29
+ await execAndWaitForOutputToMatch (
30
+ 'schematics' ,
31
+ [ '.:' , '--list-schematics' ] ,
32
+ / m y - f u l l - s c h e m a t i c / ,
33
+ ) ;
33
34
35
+ } finally {
36
+ // restore path
37
+ process . chdir ( startCwd ) ;
38
+ await rimraf ( schematicPath ) ;
39
+ }
34
40
}
0 commit comments