File tree Expand file tree Collapse file tree 5 files changed +58
-15
lines changed
tools/office-cmdlet-updater Expand file tree Collapse file tree 5 files changed +58
-15
lines changed Original file line number Diff line number Diff line change 1
1
class CliController {
2
- constructor ( cliService ) {
2
+ constructor ( cliService , cmdletService , markdownController ) {
3
3
this . cliServoce = cliService ;
4
+ this . cmdletService = cmdletService ;
5
+ this . markdownController = markdownController ;
4
6
}
5
7
6
8
startCli ( argv ) {
7
9
this . cliServoce . addOption ( {
8
10
option : '-m --module <module>' ,
9
11
description : 'update documentation for module' ,
10
- defaultValue : 'all'
12
+ defaultValue : 'all' ,
13
+ action : ( cli ) => {
14
+ const { module } = cli ;
15
+
16
+ if ( module === 'all' ) {
17
+ return ;
18
+ }
19
+
20
+ this . cmdletService . ensureModuleExist ( module ) ;
21
+ }
11
22
} ) ;
12
23
13
24
this . cliServoce . addOption ( {
14
25
option : '-c --cmdlet <cmdet>' ,
15
26
description : 'update documentation for cmdlet in module'
16
27
} ) ;
17
28
18
- this . cliServoce . start ( argv , ( cli ) => {
29
+ this . cliServoce . start ( argv , async ( cli ) => {
19
30
const { module, cmdlet } = cli ;
20
31
32
+ this . markdownController . updateMarkdown ( { moduleName : module } ) ;
21
33
console . log ( module ) ;
22
34
console . log ( cmdlet ) ;
23
35
} ) ;
Original file line number Diff line number Diff line change @@ -9,22 +9,32 @@ class MarkdownController {
9
9
this . config = config ;
10
10
}
11
11
12
- async updateMarkdown ( ) {
12
+ async updateMarkdown ( { moduleName , cmdlet } ) {
13
13
let err ;
14
14
const { docs } = this . config . get ( 'platyPS' ) ;
15
15
16
- docs . forEach ( async ( doc ) => {
17
- if ( ! ( await fs . pathExists ( doc . path ) ) ) {
18
- throw new Error ( powerShellErrors . DOC_PATH_DOESNT_EXIST ) ;
19
- }
16
+ docs . filter ( ( doc ) => this . _filterModules ( doc , moduleName ) ) . forEach (
17
+ async ( doc ) => {
18
+ if ( ! ( await fs . pathExists ( doc . path ) ) ) {
19
+ throw new Error ( powerShellErrors . DOC_PATH_DOESNT_EXIST ) ;
20
+ }
20
21
21
- [ , err ] = await of ( this . markdownService . updateMd ( doc ) ) ;
22
+ [ , err ] = await of ( this . markdownService . updateMd ( doc ) ) ;
22
23
23
- if ( err ) {
24
- this . powerShellService . dispose ( ) ;
25
- throw new Error ( err ) ;
24
+ if ( err ) {
25
+ this . powerShellService . dispose ( ) ;
26
+ throw new Error ( err ) ;
27
+ }
26
28
}
27
- } ) ;
29
+ ) ;
30
+ }
31
+
32
+ _filterModules ( doc , moduleName ) {
33
+ if ( moduleName === 'all' ) {
34
+ return true ;
35
+ }
36
+
37
+ return doc . name === moduleName ;
28
38
}
29
39
}
30
40
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const CmdletDependenciesService = require('../services/cmdlet.dependencies.servi
11
11
const FsService = require ( '../services/fs.service' ) ;
12
12
const CliService = require ( '../services/cli.service' ) ;
13
13
const CliController = require ( '../controllers/cli.controller' ) ;
14
+ const CmdletService = require ( '../services/cmdlet.service' ) ;
14
15
15
16
module . exports = ( ) => {
16
17
const container = awilix . createContainer ( {
@@ -35,7 +36,8 @@ module.exports = () => {
35
36
. asClass ( CmdletDependenciesService )
36
37
. singleton ( ) ,
37
38
fsService : awilix . asClass ( FsService ) . singleton ( ) ,
38
- markdownService : awilix . asClass ( MarkdownService ) . singleton ( )
39
+ markdownService : awilix . asClass ( MarkdownService ) . singleton ( ) ,
40
+ cmdletService : awilix . asClass ( CmdletService ) . singleton ( )
39
41
} ) ;
40
42
41
43
container . register ( {
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ class CliService {
16
16
defaultValue = '' ,
17
17
action = ( ) => { }
18
18
} ) {
19
- this . cli . option ( option , description , defaultValue ) . action ( action ) ;
19
+ this . cli
20
+ . option ( option , description , defaultValue )
21
+ . action ( ( ) => action ( this . cli ) ) ;
20
22
}
21
23
22
24
start ( argv , cb = ( ) => { } ) {
Original file line number Diff line number Diff line change
1
+ class CmdletService {
2
+ constructor ( config ) {
3
+ this . config = config ;
4
+ }
5
+
6
+ ensureModuleExist ( moduleName ) {
7
+ const modules = this . config . get ( 'platyPS.docs' ) ;
8
+
9
+ const isExist = modules . find ( ( { name } ) => name === moduleName ) ;
10
+
11
+ if ( ! isExist ) {
12
+ throw new Error ( `Module with name "${ moduleName } " didn't exist` ) ;
13
+ }
14
+ }
15
+ }
16
+
17
+ module . exports = CmdletService ;
You can’t perform that action at this time.
0 commit comments