Skip to content

Commit aae7976

Browse files
committed
Generate documentation for only one module
1 parent 4f8d68e commit aae7976

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

tools/office-cmdlet-updater/controllers/cli.controller.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
class CliController {
2-
constructor(cliService) {
2+
constructor(cliService, cmdletService, markdownController) {
33
this.cliServoce = cliService;
4+
this.cmdletService = cmdletService;
5+
this.markdownController = markdownController;
46
}
57

68
startCli(argv) {
79
this.cliServoce.addOption({
810
option: '-m --module <module>',
911
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+
}
1122
});
1223

1324
this.cliServoce.addOption({
1425
option: '-c --cmdlet <cmdet>',
1526
description: 'update documentation for cmdlet in module'
1627
});
1728

18-
this.cliServoce.start(argv, (cli) => {
29+
this.cliServoce.start(argv, async (cli) => {
1930
const { module, cmdlet } = cli;
2031

32+
this.markdownController.updateMarkdown({ moduleName: module });
2133
console.log(module);
2234
console.log(cmdlet);
2335
});

tools/office-cmdlet-updater/controllers/markdown.controller.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,32 @@ class MarkdownController {
99
this.config = config;
1010
}
1111

12-
async updateMarkdown() {
12+
async updateMarkdown({ moduleName, cmdlet }) {
1313
let err;
1414
const { docs } = this.config.get('platyPS');
1515

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+
}
2021

21-
[, err] = await of(this.markdownService.updateMd(doc));
22+
[, err] = await of(this.markdownService.updateMd(doc));
2223

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+
}
2628
}
27-
});
29+
);
30+
}
31+
32+
_filterModules(doc, moduleName) {
33+
if (moduleName === 'all') {
34+
return true;
35+
}
36+
37+
return doc.name === moduleName;
2838
}
2939
}
3040

tools/office-cmdlet-updater/helpers/di.container.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const CmdletDependenciesService = require('../services/cmdlet.dependencies.servi
1111
const FsService = require('../services/fs.service');
1212
const CliService = require('../services/cli.service');
1313
const CliController = require('../controllers/cli.controller');
14+
const CmdletService = require('../services/cmdlet.service');
1415

1516
module.exports = () => {
1617
const container = awilix.createContainer({
@@ -35,7 +36,8 @@ module.exports = () => {
3536
.asClass(CmdletDependenciesService)
3637
.singleton(),
3738
fsService: awilix.asClass(FsService).singleton(),
38-
markdownService: awilix.asClass(MarkdownService).singleton()
39+
markdownService: awilix.asClass(MarkdownService).singleton(),
40+
cmdletService: awilix.asClass(CmdletService).singleton()
3941
});
4042

4143
container.register({

tools/office-cmdlet-updater/services/cli.service.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class CliService {
1616
defaultValue = '',
1717
action = () => {}
1818
}) {
19-
this.cli.option(option, description, defaultValue).action(action);
19+
this.cli
20+
.option(option, description, defaultValue)
21+
.action(() => action(this.cli));
2022
}
2123

2224
start(argv, cb = () => {}) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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;

0 commit comments

Comments
 (0)