| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-28 17:38:00 -08:00
										 |  |  | // @ts-check
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2021-01-07 15:00:04 -08:00
										 |  |  | const Documentation = require('./documentation'); | 
					
						
							|  |  |  | const { parseApi } = require('./api_parser'); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | const PROJECT_DIR = path.join(__dirname, '..', '..'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 14:31:41 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-01-07 15:00:04 -08:00
										 |  |  |   const documentation = parseApi(path.join(PROJECT_DIR, 'docs', 'src', 'api')); | 
					
						
							|  |  |  |   documentation.setLinkRenderer(item => { | 
					
						
							|  |  |  |     const { clazz, param, option } = item; | 
					
						
							| 
									
										
										
										
											2020-12-29 12:12:46 -08:00
										 |  |  |     if (param) | 
					
						
							|  |  |  |       return `\`${param}\``; | 
					
						
							|  |  |  |     if (option) | 
					
						
							|  |  |  |       return `\`${option}\``; | 
					
						
							|  |  |  |     if (clazz) | 
					
						
							|  |  |  |       return `\`${clazz.name}\``; | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-01-07 15:00:04 -08:00
										 |  |  |   documentation.generateSourceCodeComments(); | 
					
						
							|  |  |  |   const result = serialize(documentation); | 
					
						
							| 
									
										
										
										
											2021-06-02 14:01:05 -07:00
										 |  |  |   console.log(JSON.stringify(result)); | 
					
						
							| 
									
										
										
										
											2020-12-26 14:31:41 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 12:12:46 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Documentation} documentation | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | function serialize(documentation) { | 
					
						
							| 
									
										
										
										
											2021-01-05 09:42:49 -08:00
										 |  |  |   return documentation.classesArray.map(serializeClass); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 12:12:46 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Documentation.Class} clazz | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | function serializeClass(clazz) { | 
					
						
							| 
									
										
										
										
											2021-03-01 13:00:01 -08:00
										 |  |  |   const result = { name: clazz.name, spec: clazz.spec }; | 
					
						
							| 
									
										
										
										
											2020-10-02 19:19:19 -07:00
										 |  |  |   if (clazz.extends) | 
					
						
							|  |  |  |     result.extends = clazz.extends; | 
					
						
							| 
									
										
										
										
											2021-01-08 15:00:14 -08:00
										 |  |  |   result.langs = clazz.langs; | 
					
						
							| 
									
										
										
										
											2021-01-15 16:01:41 -08:00
										 |  |  |   if (result.langs && result.langs.types) { | 
					
						
							|  |  |  |     for (const key in result.langs.types) | 
					
						
							|  |  |  |       result.langs.types[key] = serializeType(result.langs.types[key]); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-02 18:31:32 -08:00
										 |  |  |   if (clazz.comment) | 
					
						
							|  |  |  |     result.comment = clazz.comment; | 
					
						
							| 
									
										
										
										
											2022-12-21 16:30:01 -08:00
										 |  |  |   if (clazz.since) | 
					
						
							|  |  |  |     result.since = clazz.since; | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   result.members = clazz.membersArray.map(serializeMember); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 12:12:46 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Documentation.Member} member | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  | function serializeMember(member) { | 
					
						
							| 
									
										
										
										
											2020-12-29 12:12:46 -08:00
										 |  |  |   const result = /** @type {any} */ ({ ...member }); | 
					
						
							| 
									
										
										
										
											2020-09-29 13:48:24 -07:00
										 |  |  |   sanitize(result); | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   result.args = member.argsArray.map(serializeProperty); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   if (member.type) | 
					
						
							| 
									
										
										
										
											2024-07-03 10:46:33 +02:00
										 |  |  |     result.type = serializeType(member.type); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function serializeProperty(arg) { | 
					
						
							| 
									
										
										
										
											2024-08-22 10:15:47 +02:00
										 |  |  |   const result = { ...arg, parent: undefined }; | 
					
						
							| 
									
										
										
										
											2020-09-29 13:48:24 -07:00
										 |  |  |   sanitize(result); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   if (arg.type) | 
					
						
							| 
									
										
										
										
											2024-07-03 10:46:33 +02:00
										 |  |  |     result.type = serializeType(arg.type, arg.name === 'options'); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 13:48:24 -07:00
										 |  |  | function sanitize(result) { | 
					
						
							|  |  |  |   delete result.args; | 
					
						
							|  |  |  |   delete result.argsArray; | 
					
						
							| 
									
										
										
										
											2020-12-29 12:12:46 -08:00
										 |  |  |   delete result.clazz; | 
					
						
							| 
									
										
										
										
											2021-01-29 16:02:17 -08:00
										 |  |  |   delete result.enclosingMethod; | 
					
						
							| 
									
										
										
										
											2020-09-29 13:48:24 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Documentation.Type} type | 
					
						
							| 
									
										
										
										
											2021-04-08 09:21:10 -03:00
										 |  |  |  * @param {boolean} sortProperties | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-04-08 09:21:10 -03:00
										 |  |  | function serializeType(type, sortProperties = false) { | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   /** @type {any} */ | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   const result = { ...type }; | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   if (type.properties) | 
					
						
							| 
									
										
										
										
											2021-04-08 09:21:10 -03:00
										 |  |  |     result.properties = (sortProperties ? type.sortedProperties() : type.properties).map(serializeProperty); | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   if (type.union) | 
					
						
							| 
									
										
										
										
											2021-04-08 09:21:10 -03:00
										 |  |  |     result.union = type.union.map(type => serializeType(type)); | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   if (type.templates) | 
					
						
							| 
									
										
										
										
											2021-04-08 09:21:10 -03:00
										 |  |  |     result.templates = type.templates.map(type => serializeType(type)); | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   if (type.args) | 
					
						
							| 
									
										
										
										
											2021-04-08 09:21:10 -03:00
										 |  |  |     result.args = type.args.map(type => serializeType(type)); | 
					
						
							| 
									
										
										
										
											2021-01-04 17:59:23 -08:00
										 |  |  |   if (type.returnType) | 
					
						
							|  |  |  |     result.returnType = serializeType(type.returnType); | 
					
						
							| 
									
										
										
										
											2020-07-30 17:51:41 -07:00
										 |  |  |   return result; | 
					
						
							|  |  |  | } |