@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
141 lines (139 loc) • 4.08 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.VsCodeDefaultSettings = void 0;
const Log_1 = require("../core/Log");
const ste_events_1 = require("ste-events");
exports.VsCodeDefaultSettings = {
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"git.ignoreLimitWarning": true,
"editor.formatOnSave": true,
"search.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/dist": true,
"**/lib": true,
},
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/node_modules": true,
},
"cSpell.words": ["gametest", "gametests", "mcaddon"],
"editor.tabSize": 2,
"eslint.experimental.useFlatConfig": true,
};
class VsCodeSettingsDefinition {
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 VsCodeSettingsDefinition();
dt.file = file;
file.manager = dt;
}
if (file.manager !== undefined && file.manager instanceof VsCodeSettingsDefinition) {
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) {
return false;
}
for (const settingName in exports.VsCodeDefaultSettings) {
if (!this.definition[settingName]) {
return false;
}
}
return true;
}
async ensureMinContent() {
const hasSettings = await this.hasMinContent();
if (hasSettings) {
return true;
}
if (!this.definition) {
this.definition = exports.VsCodeDefaultSettings;
}
for (const settingName in exports.VsCodeDefaultSettings) {
if (!this.definition[settingName]) {
this.definition[settingName] = exports.VsCodeDefaultSettings[settingName];
}
}
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 = VsCodeSettingsDefinition;
//# sourceMappingURL=../maps/devproject/VsCodeSettingsDefinition.js.map