UNPKG

1.89 kBJavaScriptView Raw
1const smapiCommandDescription = 'Provides a number of subcommands that '
2+ 'map 1:1 to the underlying API operations in Alexa Skill Management API (SMAPI).'
3+ 'The commands allow detailed control of API inputs and expose raw outputs. '
4+ 'There are subcommands for creating and updating the skill, interaction model, '
5+ 'and account linking information as well as starting the skill certification process.';
6
7class SmapiDocs {
8 constructor(commander) {
9 this.commander = commander;
10 this.commands = commander.commands;
11 }
12
13 _makeOptionsString(options) {
14 return options.map(option => {
15 const { mandatory, flags } = option;
16 const prefix = mandatory ? '<' : '[';
17 const suffix = mandatory ? '>' : ']';
18 return `${prefix}${flags.split(',').join('|')}${suffix}`;
19 }).join(' ');
20 }
21
22 _cleanDescription(description = '') {
23 let cleanedDescription = description.trim();
24 if (cleanedDescription.length > 1 && !cleanedDescription.endsWith('.')) {
25 cleanedDescription = `${cleanedDescription}.`;
26 }
27 // adding new line before * to correctly render list in markdown
28 return cleanedDescription.replace('*', '\n*');
29 }
30
31 generateViewData() {
32 const commands = this.commands.map(command => {
33 const parsedCommand = {
34 name: command._name,
35 description: this._cleanDescription(command._description),
36 optionsString: this._makeOptionsString(command.options),
37 options: command.options.map(option => ({ name: option.flags, description: this._cleanDescription(option.description) }))
38 };
39 return parsedCommand;
40 });
41 return { smapiCommandDescription,
42 baseCommand: 'ask smapi',
43 commands };
44 }
45}
46
47module.exports = { SmapiDocs };