@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
119 lines (117 loc) • 3.54 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.VsCodeRecommendations = void 0;
const Log_1 = require("../core/Log");
const ste_events_1 = require("ste-events");
exports.VsCodeRecommendations = [
"esbenp.prettier-vscode",
"blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension",
"mojang-studios.minecraft-debugger",
];
class VsCodeExtensionsDefinition {
constructor() {
this._isLoaded = false;
this._onLoaded = new ste_events_1.EventDispatcher();
}
get isLoaded() {
return this._isLoaded;
}
get file() {
return this._file;
}
set file(newFile) {
this._file = newFile;
}
get onLoaded() {
return this._onLoaded.asEvent();
}
get id() {
return this._id;
}
set id(newId) {
this._id = newId;
}
static async ensureOnFile(file, loadHandler) {
let dt;
if (file.manager === undefined) {
dt = new VsCodeExtensionsDefinition();
dt.file = file;
file.manager = dt;
}
if (file.manager !== undefined && file.manager instanceof VsCodeExtensionsDefinition) {
dt = file.manager;
if (!dt.isLoaded && loadHandler) {
dt.onLoaded.subscribe(loadHandler);
}
await dt.load();
return dt;
}
return dt;
}
async persist() {
if (this._file === undefined) {
return;
}
const extensionsJsonString = JSON.stringify(this.definition, null, 2);
this._file.setContent(extensionsJsonString);
}
async save() {
if (this._file === undefined) {
return;
}
this.persist();
await this._file.saveContent(false);
}
async hasMinContent() {
await this.load();
if (!this.definition || !this.definition.recommendations) {
return false;
}
for (const reco of exports.VsCodeRecommendations) {
if (!this.definition.recommendations.includes(reco)) {
return false;
}
}
return true;
}
async ensureMinContent() {
const hasRecos = await this.hasMinContent();
if (hasRecos) {
return true;
}
if (!this.definition) {
this.definition = { recommendations: [] };
}
if (!this.definition.recommendations) {
this.definition.recommendations = [];
}
for (const reco of exports.VsCodeRecommendations) {
if (!this.definition.recommendations.includes(reco)) {
this.definition.recommendations.push(reco);
}
}
return this.definition;
}
async load() {
if (this._file === undefined || this._isLoaded) {
return;
}
await this._file.loadContent();
if (this._file.content === null || this._file.content instanceof Uint8Array) {
return;
}
this.id = this._file.name;
try {
const data = JSON.parse(this._file.content);
this.definition = data;
}
catch (e) {
Log_1.default.fail("Could not parse vscode launch JSON " + e);
}
this._isLoaded = true;
}
}
exports.default = VsCodeExtensionsDefinition;
//# sourceMappingURL=../maps/devproject/VsCodeExtensionsDefinition.js.map