feat(core): 将goog.get接口调整为goog.readJsonSync以指示其同步操作特性

This commit is contained in:
王立帮
2025-04-27 15:40:33 +08:00
parent 46b3da8cc8
commit af2910adb0
44 changed files with 92 additions and 87 deletions

View File

@@ -87,7 +87,7 @@ class App extends Component {
static {
HTMLTemplate.add(
'html/app.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/app.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/app.html')))
);
}

View File

@@ -51,18 +51,18 @@ const SOFTWARE_DEFAULT_CONFIG = {
Config.init = () => {
const urlConfig = Url.getConfig();
Config.BOARD = {
...goog.getJSON(path.join(Env.boardDirPath, 'config.json'), BOARD_DEFAULT_CONFIG),
...goog.readJsonSync(path.join(Env.boardDirPath, 'config.json'), BOARD_DEFAULT_CONFIG),
...urlConfig
};
if (typeof Config.BOARD.board === 'string'
&& path.extname(Config.BOARD.board) === '.json') {
Config.BOARD.board = goog.getJSON(path.join(Env.boardDirPath, Config.BOARD.board));
Config.BOARD.board = goog.readJsonSync(path.join(Env.boardDirPath, Config.BOARD.board));
}
let pathPrefix = '../';
Config.SOFTWARE = goog.getJSON(path.join(Env.srcDirPath, 'sw-config.json'), SOFTWARE_DEFAULT_CONFIG);
Config.SOFTWARE = goog.readJsonSync(path.join(Env.srcDirPath, 'sw-config.json'), SOFTWARE_DEFAULT_CONFIG);
Config.pathPrefix = pathPrefix;
Env.hasSocketServer = Config.SOFTWARE?.webSocket?.enabled ? true : false;

View File

@@ -20,7 +20,7 @@ class ContextMenu {
static {
HTMLTemplate.add(
'html/context-menu-item.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/context-menu-item.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/context-menu-item.html')))
);
this.getItem = (name, hotKey) => HTMLTemplate.get('html/context-menu-item.html').render({ name, hotKey });

View File

@@ -24,16 +24,16 @@ class EditorAce extends EditorBase {
static {
this.CTRL_BTNS = ['resetFontSize', 'increaseFontSize', 'decreaseFontSize'];
this.CTRL_BTN_TEMPLATE = '<div m-id="{{d.mId}}" class="code-editor-btn setFontSize"></div>';
this.MODE_MAP = goog.getJSON(path.join(Env.templatePath, 'json/ace-mode-map.json'));
this.MODE_MAP = goog.readJsonSync(path.join(Env.templatePath, 'json/ace-mode-map.json'));
HTMLTemplate.add(
'html/editor/editor-code.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-code.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-code.html')))
);
if (['zh-hans', 'zh-hant'].includes(Msg.nowLang)) {
ace.config.setMessages(
goog.getJSON(path.join(Env.templatePath, `json/ace.i18n.${Msg.nowLang}.json`))
goog.readJsonSync(path.join(Env.templatePath, `json/ace.i18n.${Msg.nowLang}.json`))
);
}
}

View File

@@ -46,12 +46,12 @@ class EditorBlockly extends EditorBase {
static {
HTMLTemplate.add(
'html/editor/editor-blockly.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-blockly.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-blockly.html')))
);
HTMLTemplate.add(
'xml/default-categories.xml',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'xml/default-categories.xml')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'xml/default-categories.xml')))
);
this.$blockly = $('<div class="page-item"></div>');

View File

@@ -28,12 +28,12 @@ class EditorMd extends EditorBase {
static {
HTMLTemplate.add(
'html/editor/editor-md.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-md.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-md.html')))
);
HTMLTemplate.add(
'html/editor/editor-md-btns.html',
goog.get(path.join(Env.templatePath, 'html/editor/editor-md-btns.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-md-btns.html'))
);
marked.use(markedKatex({ throwOnError: false }));

View File

@@ -49,12 +49,12 @@ class EditorMix extends EditorBase {
static {
HTMLTemplate.add(
'html/editor/editor-mix.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-mix.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-mix.html')))
);
HTMLTemplate.add(
'html/editor/editor-mix-btns.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-mix-btns.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-mix-btns.html')))
);
}

View File

@@ -25,7 +25,7 @@ class EditorMonaco extends EditorBase {
static {
HTMLTemplate.add(
'html/editor/editor-code.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-code.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-code.html')))
);
this.$monaco = $('<div class="page-item"></div>');

View File

@@ -18,7 +18,7 @@ class EditorUnknown extends EditorBase {
static {
HTMLTemplate.add(
'html/editor/editor-unknown.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-unknown.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-unknown.html')))
);
}

View File

@@ -17,7 +17,7 @@ class EditorWelcome extends EditorBase {
static {
HTMLTemplate.add(
'html/editor/editor-welcome.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-welcome.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-welcome.html')))
);
}

View File

@@ -42,12 +42,12 @@ class EditorsManager extends PagesManager {
static {
HTMLTemplate.add(
'html/editor/editor-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-manager.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-manager.html')))
);
HTMLTemplate.add(
'html/editor/editor-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-tab.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/editor/editor-tab.html')))
);
this.typesRegistry = new Registry();

View File

@@ -34,12 +34,12 @@ const { USER } = Config;
class FileTree extends Component {
static {
this.FILE_ICON_MAP = goog.getJSON(path.join(Env.templatePath, 'json/file-icons.json'));
this.FOLDER_ICON_MAP = goog.getJSON(path.join(Env.templatePath, 'json/folder-icons.json'));
this.FILE_ICON_MAP = goog.readJsonSync(path.join(Env.templatePath, 'json/file-icons.json'));
this.FOLDER_ICON_MAP = goog.readJsonSync(path.join(Env.templatePath, 'json/folder-icons.json'));
HTMLTemplate.add(
'html/file-tree.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/file-tree.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/file-tree.html')))
);
}

View File

@@ -39,7 +39,7 @@ class FooterBar extends Component {
static {
HTMLTemplate.add(
'html/footerbar.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/footerbar.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/footerbar.html')))
);
}

View File

@@ -25,7 +25,7 @@ class FooterLayerBoardConfig extends FooterLayer {
static {
// 弹层模板
this.menuHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-board-config.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-board-config.html'))
);
}

View File

@@ -25,7 +25,7 @@ class FooterLayerExample extends FooterLayer {
static {
// 弹层模板
this.menuHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-example.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-example.html'))
);
}

View File

@@ -21,15 +21,15 @@ class FooterLayerMessage extends FooterLayer {
// 弹层模板
static {
this.menuHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message.html'))
);
this.menuItemHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item.html'))
);
this.menuItemWithIconHTMLTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item-with-icon.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer-message-item-with-icon.html'))
);
this.STYLES = ['primary', 'secondary', 'success', 'danger', 'warning'];

View File

@@ -12,7 +12,7 @@ const { Env, XML, Msg } = Mixly;
class FooterLayer {
static {
// 弹层模板和一些默认配置项
this.TEMPLATE = goog.get(path.join(Env.templatePath, 'html/footerlayer/footerlayer.html'));
this.TEMPLATE = goog.readFileSync(path.join(Env.templatePath, 'html/footerlayer/footerlayer.html'));
this.DEFAULT_CONFIG_TIPPY = {
allowHTML: true,
trigger: 'manual',

View File

@@ -48,7 +48,7 @@ window.addEventListener('load', () => {
}
const app = new App($('body')[0]);
Mixly.app = app;
const $xml = $(goog.get(Env.boardIndexPath));
const $xml = $(goog.readFileSync(Env.boardIndexPath));
let scrpitPaths = [];
let cssPaths = [];
let $categories = null;

View File

@@ -28,7 +28,7 @@ class Nav extends Component {
*/
HTMLTemplate.add(
'html/nav/nav.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav.html')))
);
/**
@@ -37,7 +37,7 @@ class Nav extends Component {
*/
HTMLTemplate.add(
'html/nav/nav-btn.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav-btn.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav-btn.html')))
);
/**
@@ -46,7 +46,7 @@ class Nav extends Component {
*/
HTMLTemplate.add(
'html/nav/nav-item-container.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav-item-container.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav-item-container.html')))
);
/**
@@ -55,7 +55,7 @@ class Nav extends Component {
*/
HTMLTemplate.add(
'html/nav/nav-item.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/nav-item.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/nav-item.html')))
);
/**
@@ -64,7 +64,7 @@ class Nav extends Component {
*/
HTMLTemplate.add(
'html/nav/board-selector-div.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/board-selector-div.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/board-selector-div.html')))
);
/**
@@ -73,7 +73,7 @@ class Nav extends Component {
*/
HTMLTemplate.add(
'html/nav/port-selector-div.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/nav/port-selector-div.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/nav/port-selector-div.html')))
);
Nav.Scope = {

View File

@@ -23,7 +23,7 @@ class SideBarLibs extends PageBase {
static {
HTMLTemplate.add(
'html/sidebar/sidebar-libs.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/sidebar-libs.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/sidebar-libs.html')))
);
}

View File

@@ -38,7 +38,7 @@ class SideBarLocalStorage extends PageBase {
static {
HTMLTemplate.add(
'html/sidebar/sidebar-local-storage-open-folder.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/sidebar-local-storage-open-folder.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/sidebar-local-storage-open-folder.html')))
);
}

View File

@@ -31,22 +31,22 @@ class SideBarsManager extends PagesManager {
static {
HTMLTemplate.add(
'html/sidebar/left-sidebars-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/left-sidebars-manager.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/left-sidebars-manager.html')))
);
HTMLTemplate.add(
'html/sidebar/left-sidebars-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/left-sidebars-tab.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/left-sidebars-tab.html')))
);
HTMLTemplate.add(
'html/sidebar/right-sidebars-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/right-sidebars-manager.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/right-sidebars-manager.html')))
);
HTMLTemplate.add(
'html/sidebar/right-sidebars-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/sidebar/right-sidebars-tab.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/sidebar/right-sidebars-tab.html')))
);
this.typesRegistry = new Registry();

View File

@@ -32,17 +32,17 @@ class StatusBarAmpy extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-ampy.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy.html')))
);
HTMLTemplate.add(
'html/statusbar/statusbar-ampy-open-fs.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-open-fs.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-open-fs.html')))
);
HTMLTemplate.add(
'html/statusbar/statusbar-ampy-editor-empty.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-editor-empty.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-ampy-editor-empty.html')))
);
}

View File

@@ -41,7 +41,7 @@ class Panel extends Component {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-fs-panel.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-fs-panel.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-fs-panel.html')))
);
}
@@ -195,7 +195,7 @@ class StatusBarFS extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-fs.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-fs.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-fs.html')))
);
}

View File

@@ -17,7 +17,7 @@ class StatusBarLibsCode extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-libs-mix.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html')))
);
}

View File

@@ -18,7 +18,7 @@ class StatusBarLibsMix extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-libs-mix.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-libs-mix.html')))
);
}

View File

@@ -28,7 +28,7 @@ class StatusBarSerialChart extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-serial-chart.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-chart.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-chart.html')))
);
}

View File

@@ -21,7 +21,7 @@ class StatusBarSerialOutput extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-serial-output.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-output.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-serial-output.html')))
);
}

View File

@@ -58,7 +58,7 @@ class StatusBarSerial extends PageBase {
static {
HTMLTemplate.add(
'html/statusbar/statusbar-serial.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbar-serial.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbar-serial.html')))
);
SideBarsManager.typesRegistry.register(['serial_output'], StatusBarSerialOutput);
SideBarsManager.typesRegistry.register(['serial_chart'], StatusBarSerialChart);

View File

@@ -53,11 +53,11 @@ class StatusBarsManager extends PagesManager {
static {
HTMLTemplate.add(
'html/statusbar/statusbars-manager.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbars-manager.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbars-manager.html')))
);
HTMLTemplate.add(
'html/statusbar/statusbars-tab.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/statusbar/statusbars-tab.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/statusbar/statusbars-tab.html')))
);
this.typesRegistry = new Registry();
this.managersRegistry = new Registry();

View File

@@ -20,7 +20,7 @@ const {
class ToolboxSearcher {
static {
this.searchHtmlTemplate = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/search-div.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/search-div.html'))
);
}

View File

@@ -35,7 +35,7 @@ class Workspace extends Component {
static {
HTMLTemplate.add(
'html/workspace.html',
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/workspace.html')))
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/workspace.html')))
);
this.workspaces = [];

View File

@@ -123,7 +123,7 @@ XML.convert = function (str, trimEscaped) {
for (let i of XML.TEMPLATE_CONFIG) {
const { type, config, appendToBody } = i;
if (XML.TEMPLATE_ENV[type]) {
const xmlStr = goog.get(path.join(Env.templatePath, i.path));
const xmlStr = goog.readFileSync(path.join(Env.templatePath, i.path));
if (xmlStr) {
XML.TEMPLATE_STR[type] = xmlStr;
XML.TEMPLATE_STR_RENDER[type] = XML.render(xmlStr, config);
@@ -139,7 +139,7 @@ if (layui._typeof(BOARD.board) === 'object') {
const boardConfig = BOARD.board[i];
if (layui._typeof(boardConfig) === 'object'
&& layui._typeof(boardConfig.xmlPath) === 'string') {
const categoriesStr = goog.get(path.join(Env.boardDirPath, boardConfig.xmlPath));
const categoriesStr = goog.readFileSync(path.join(Env.boardDirPath, boardConfig.xmlPath));
if (categoriesStr)
XML.CATEGORIES_STR[i] = categoriesStr;
}