1 | "use strict";
|
2 |
|
3 |
|
4 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
5 | if (k2 === undefined) k2 = k;
|
6 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
7 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
8 | desc = { enumerable: true, get: function() { return m[k]; } };
|
9 | }
|
10 | Object.defineProperty(o, k2, desc);
|
11 | }) : (function(o, m, k, k2) {
|
12 | if (k2 === undefined) k2 = k;
|
13 | o[k2] = m[k];
|
14 | }));
|
15 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
16 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
17 | }) : function(o, v) {
|
18 | o["default"] = v;
|
19 | });
|
20 | var __importStar = (this && this.__importStar) || function (mod) {
|
21 | if (mod && mod.__esModule) return mod;
|
22 | var result = {};
|
23 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
24 | __setModuleDefault(result, mod);
|
25 | return result;
|
26 | };
|
27 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
28 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
29 | };
|
30 | Object.defineProperty(exports, "__esModule", { value: true });
|
31 | exports.OfficeYamlDocumenter = void 0;
|
32 | const colors_1 = __importDefault(require("colors"));
|
33 | const path = __importStar(require("path"));
|
34 | const yaml = require("js-yaml");
|
35 | const node_core_library_1 = require("@rushstack/node-core-library");
|
36 | const YamlDocumenter_1 = require("./YamlDocumenter");
|
37 |
|
38 |
|
39 |
|
40 | class OfficeYamlDocumenter extends YamlDocumenter_1.YamlDocumenter {
|
41 | constructor(apiModel, inputFolder, newDocfxNamespaces) {
|
42 | super(apiModel, newDocfxNamespaces);
|
43 |
|
44 | this._apiSetUrlDefault = '/office/dev/add-ins/reference/javascript-api-for-office';
|
45 |
|
46 | this._apiSetUrls = {
|
47 | Excel: '/javascript/api/requirement-sets/excel/excel-api-requirement-sets',
|
48 | OneNote: '/javascript/api/requirement-sets/onenote/onenote-api-requirement-sets',
|
49 | Outlook: '/javascript/api/requirement-sets/outlook/outlook-api-requirement-sets',
|
50 | PowerPoint: '/javascript/api/requirement-sets/powerpoint/powerpoint-api-requirement-sets',
|
51 | Visio: '/office/dev/add-ins/reference/overview/visio-javascript-reference-overview',
|
52 | Word: '/javascript/api/requirement-sets/word/word-api-requirement-sets'
|
53 | };
|
54 | const snippetsFilePath = path.join(inputFolder, 'snippets.yaml');
|
55 | console.log('Loading snippets from ' + snippetsFilePath);
|
56 | const snippetsContent = node_core_library_1.FileSystem.readFile(snippetsFilePath);
|
57 | this._snippets = yaml.load(snippetsContent, { filename: snippetsFilePath });
|
58 | this._snippetsAll = yaml.load(snippetsContent, { filename: snippetsFilePath });
|
59 | }
|
60 |
|
61 | generateFiles(outputFolder) {
|
62 | super.generateFiles(outputFolder);
|
63 |
|
64 | console.log();
|
65 | for (const apiName of Object.keys(this._snippets)) {
|
66 | console.error(colors_1.default.yellow('Warning: Unused snippet ' + apiName));
|
67 | }
|
68 | }
|
69 |
|
70 | onGetTocRoot() {
|
71 |
|
72 | return {
|
73 | name: 'API reference',
|
74 | href: 'overview.md',
|
75 | items: []
|
76 | };
|
77 | }
|
78 |
|
79 | onCustomizeYamlItem(yamlItem) {
|
80 | const nameWithoutPackage = yamlItem.uid.replace(/^[^.]+\!/, '');
|
81 | if (yamlItem.summary) {
|
82 | yamlItem.summary = this._fixupApiSet(yamlItem.summary, yamlItem.uid);
|
83 | }
|
84 | if (yamlItem.remarks) {
|
85 | yamlItem.remarks = this._fixupApiSet(yamlItem.remarks, yamlItem.uid);
|
86 | }
|
87 | const snippets = this._snippetsAll[nameWithoutPackage];
|
88 | if (snippets) {
|
89 | delete this._snippets[nameWithoutPackage];
|
90 | const snippetText = this._generateExampleSnippetText(snippets);
|
91 | if (yamlItem.remarks) {
|
92 | yamlItem.remarks += snippetText;
|
93 | }
|
94 | else if (yamlItem.syntax && yamlItem.syntax.return) {
|
95 | if (!yamlItem.syntax.return.description) {
|
96 | yamlItem.syntax.return.description = '';
|
97 | }
|
98 | yamlItem.syntax.return.description += snippetText;
|
99 | }
|
100 | else {
|
101 | yamlItem.remarks = snippetText;
|
102 | }
|
103 | }
|
104 | }
|
105 | _fixupApiSet(markup, uid) {
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | markup = markup.replace(/Api/, 'API');
|
112 | return markup.replace(/\\\[(API set:[^\]]+)\\\]/, '\\[ [$1](' + this._getApiSetUrl(uid) + ') \\]');
|
113 | }
|
114 |
|
115 | _getApiSetUrl(uid) {
|
116 | for (const key of Object.keys(this._apiSetUrls)) {
|
117 | const regexp = new RegExp(key, 'i');
|
118 | if (regexp.test(uid)) {
|
119 | return this._apiSetUrls[key];
|
120 | }
|
121 | }
|
122 | return this._apiSetUrlDefault;
|
123 | }
|
124 | _generateExampleSnippetText(snippets) {
|
125 | const text = ['\n\n#### Examples\n'];
|
126 | for (const snippet of snippets) {
|
127 | text.push(`\`\`\`TypeScript\n${snippet}\n\`\`\``);
|
128 | }
|
129 | return text.join('\n');
|
130 | }
|
131 | }
|
132 | exports.OfficeYamlDocumenter = OfficeYamlDocumenter;
|
133 |
|
\ | No newline at end of file |