@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
133 lines (131 loc) • 4.38 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
class DocumentedScriptEnum {
get isLoaded() {
return this._isLoaded;
}
get undocumentedCount() {
return this._undocumentedCount;
}
get id() {
return this._id;
}
set id(newId) {
this._id = newId;
}
get docEnum() {
return this.enumDefinition;
}
constructor(module, docEnum) {
this._isLoaded = false;
this._undocumentedCount = 0;
this.isInterface = false;
this.enumDefinition = docEnum;
this.module = module;
this._id = docEnum.name;
}
async load() {
if (!this._isLoaded) {
await this.ensureInfoJson(this.module.docFolder);
}
this._isLoaded = true;
}
getEffectiveConstants() {
if (this._effectiveConstants) {
return this._effectiveConstants;
}
const constants = [];
if (this.docEnum.constants) {
constants.push(...this.docEnum.constants);
}
this._effectiveConstants = constants;
return constants;
}
getConstant(name) {
const constants = this.getEffectiveConstants();
if (constants) {
for (const constant of constants) {
if (constant.name === name) {
return constant;
}
}
}
return undefined;
}
async persist() {
if (this.infoJsonFiles) {
for (const fileName in this.infoJsonFiles) {
const infoJsonFile = this.infoJsonFiles[fileName];
await infoJsonFile.saveContent();
}
}
}
generateUndocumentedCount() {
let unDocCount = 0;
for (const functionName in this.infoJsonFiles) {
const file = this.infoJsonFiles[functionName];
let isDefaultDoced = false;
if (functionName === "_enum") {
if (this.docEnum.raw_tsdoc_text !== undefined && this.docEnum.raw_tsdoc_text.length > 2) {
isDefaultDoced = true;
}
}
if (!isDefaultDoced) {
const constant = this.getConstant(functionName);
if (constant && constant.raw_tsdoc_text && constant.raw_tsdoc_text.length > 2) {
isDefaultDoced = true;
}
}
if (!isDefaultDoced) {
if (file.content === undefined || file.content === "" || typeof file.content !== "string") {
unDocCount++;
}
else {
try {
const obj = JSON.parse(file.content);
if (!obj) {
unDocCount++;
}
else {
if (!obj.description || obj.description === "") {
unDocCount++;
}
}
}
catch (e) {
unDocCount++;
}
}
}
}
this._undocumentedCount = unDocCount;
}
async ensureInfoJson(docsFolder) {
if (!this._id) {
return;
}
const rootFolder = this.module.ensureDocFolder(docsFolder);
if (!rootFolder) {
return;
}
this.infoJsonFiles = {};
const enumFolder = rootFolder.ensureFolder(this._id);
const rootFile = enumFolder.ensureFile("info.json");
await rootFile.loadContent();
this.infoJsonFiles["_enum"] = rootFile;
const constants = this.getEffectiveConstants();
if (constants) {
for (const docConstant of constants) {
const memberFolder = enumFolder.ensureFolder(docConstant.name);
const memberFile = memberFolder.ensureFile("info.json");
await memberFile.loadContent();
this.infoJsonFiles[docConstant.name] = memberFile;
}
}
this.generateUndocumentedCount();
}
}
exports.default = DocumentedScriptEnum;
//# sourceMappingURL=../../maps/minecraft/docs/DocumentedScriptEnum.js.map