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;
}

View File

@@ -45,7 +45,7 @@ const {
Shell
} = Electron;
ArduShell.DEFAULT_CONFIG = goog.getJSON(path.join(Env.templatePath, 'json/arduino-cli-config.json'));
ArduShell.DEFAULT_CONFIG = goog.readJsonSync(path.join(Env.templatePath, 'json/arduino-cli-config.json'));
ArduShell.binFilePath = '';

View File

@@ -49,7 +49,7 @@ BU.burning = false;
BU.shell = null;
BU.FILMWARE_LAYER = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/filmware-layer.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/filmware-layer.html'))
).render({
cancel: Msg.Lang['nav.btn.cancel'],
burn: Msg.Lang['nav.btn.burn']

View File

@@ -18,8 +18,8 @@ const fs = Mixly.require('fs');
class WikiGenerator {
static {
this.WIKI_PAGE_FILE = goog.get(path.join(Env.templatePath, 'markdown/wiki-page-file.md'));
this.WIKI_PAGE_DIR = goog.get(path.join(Env.templatePath, 'markdown/wiki-page-dir.md'));
this.WIKI_PAGE_FILE = goog.readFileSync(path.join(Env.templatePath, 'markdown/wiki-page-file.md'));
this.WIKI_PAGE_DIR = goog.readFileSync(path.join(Env.templatePath, 'markdown/wiki-page-dir.md'));
}
#$xml_ = null;

View File

@@ -18,16 +18,16 @@ const {
class AmpyExt extends Ampy {
static {
this.LS = goog.get(path.join(Env.templatePath, 'python/ls.py'));
this.LS_RECURSIVE = goog.get(path.join(Env.templatePath, 'python/ls-recursive.py'));
this.LS_LONG_FORMAT = goog.get(path.join(Env.templatePath, 'python/ls-long-format.py'));
this.MKDIR = goog.get(path.join(Env.templatePath, 'python/mkdir.py'));
this.MKFILE = goog.get(path.join(Env.templatePath, 'python/mkfile.py'));
this.RENAME = goog.get(path.join(Env.templatePath, 'python/rename.py'));
this.RM = goog.get(path.join(Env.templatePath, 'python/rm.py'));
this.RMDIR = goog.get(path.join(Env.templatePath, 'python/rmdir.py'));
this.GET = goog.get(path.join(Env.templatePath, 'python/get.py'));
this.CWD = goog.get(path.join(Env.templatePath, 'python/cwd.py'));
this.LS = goog.readFileSync(path.join(Env.templatePath, 'python/ls.py'));
this.LS_RECURSIVE = goog.readFileSync(path.join(Env.templatePath, 'python/ls-recursive.py'));
this.LS_LONG_FORMAT = goog.readFileSync(path.join(Env.templatePath, 'python/ls-long-format.py'));
this.MKDIR = goog.readFileSync(path.join(Env.templatePath, 'python/mkdir.py'));
this.MKFILE = goog.readFileSync(path.join(Env.templatePath, 'python/mkfile.py'));
this.RENAME = goog.readFileSync(path.join(Env.templatePath, 'python/rename.py'));
this.RM = goog.readFileSync(path.join(Env.templatePath, 'python/rm.py'));
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
}
#device_ = null;
@@ -223,12 +223,17 @@ class AmpyExt extends Ampy {
return this.#device_.decode(this.unhexlify(data));
}
async put(filename, code, timeout = 5000) {
async put(filename, data, timeout = 5000) {
if (!this.isActive()) {
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
}
await this.exec(`file = open('${filename}', 'wb')`, timeout);
const buffer = this.#device_.encode(code);
let buffer = null;
if (typeof data === 'string') {
buffer = this.#device_.encode(data);
} else {
buffer = data;
}
const len = Math.ceil(buffer.length / 64);
for (let i = 0; i < len; i++) {
const writeBuffer = buffer.slice(i * 64, Math.min((i + 1) * 64, buffer.length));

View File

@@ -54,7 +54,7 @@ BU.uploading = false;
BU.burning = false;
BU.FILMWARE_LAYER = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/filmware-layer.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/filmware-layer.html'))
).render({
cancel: Msg.Lang['nav.btn.cancel'],
burn: Msg.Lang['nav.btn.burn']
@@ -166,7 +166,7 @@ BU.burnByUSB = async () => {
const { web } = SELECTED_BOARD;
const { burn } = web;
const hexStr = goog.get(path.join(Env.boardDirPath, burn.filePath));
const hexStr = goog.readFileSync(path.join(Env.boardDirPath, burn.filePath));
const hex2Blob = new Blob([ hexStr ], { type: 'text/plain' });
const buffer = await hex2Blob.arrayBuffer();
if (!buffer) {
@@ -499,7 +499,7 @@ BU.getImportModules = (code) => {
const libPath = SELECTED_BOARD.upload.libPath;
for (let i = libPath.length - 1; i >= 0; i--) {
const dirname = MString.tpl(libPath[i], { indexPath: Env.boardDirPath });
const map = goog.getJSON(path.join(dirname, 'map.json'));
const map = goog.readJsonSync(path.join(dirname, 'map.json'));
if (!(map && map instanceof Object)) {
continue;
}
@@ -603,7 +603,7 @@ BU.uploadByUSB = async (portName) => {
const importsMap = BU.getImportModules(code);
for (let key in importsMap) {
const filename = importsMap[key]['__name__'];
const data = goog.get(importsMap[key]['__path__']);
const data = goog.readFileSync(importsMap[key]['__path__']);
FSWrapper.writeFile(filename, data);
}
const layerNum = layer.open({
@@ -690,7 +690,7 @@ BU.uploadWithAmpy = (portName) => {
let libraries = {};
for (let key in importsMap) {
const filename = importsMap[key]['__name__'];
const data = goog.get(importsMap[key]['__path__']);
const data = goog.readFileSync(importsMap[key]['__path__']);
libraries[filename] = {
data,
size: importsMap[key]['__size__']

View File

@@ -77,7 +77,7 @@ class FooterLayerExampleExt extends FooterLayerExample {
}
dataToWorkspace(inPath) {
const data = goog.get(path.join(Env.boardDirPath, 'examples', inPath));
const data = goog.readFileSync(path.join(Env.boardDirPath, 'examples', inPath));
this.updateCode(path.extname(inPath), data);
}
}

View File

@@ -43,7 +43,7 @@ class WebSerial extends Serial {
this.devicesRegistry = new Registry();
this.type = Serial.type;
this.DEVICES_SELECT_LAYER = new HTMLTemplate(
goog.get(path.join(Env.templatePath, 'html/devices-select-layer.html'))
goog.readFileSync(path.join(Env.templatePath, 'html/devices-select-layer.html'))
);
this.getConfig = function () {

View File

@@ -49,8 +49,8 @@ class microbitFsWrapper {
* initial main.py
*/
setupFilesystem(folderPath) {
const uPyV1 = goog.get(path.join(folderPath, 'microbit-micropython-v1.hex'));
const uPyV2 = goog.get(path.join(folderPath, 'microbit-micropython-v2.hex'));
const uPyV1 = goog.readFileSync(path.join(folderPath, 'microbit-micropython-v1.hex'));
const uPyV2 = goog.readFileSync(path.join(folderPath, 'microbit-micropython-v2.hex'));
if (!uPyV1 || !uPyV2) {
console.error('There was an issue loading the MicroPython Hex files.');
}

View File

@@ -8,7 +8,7 @@ const { Msg, Env } = Mixly;
if (['zh-hans', 'zh-hant'].includes(Msg.nowLang)) {
const i18nFilePath = path.join(Env.templatePath, `json/monaco.i18n.${Msg.nowLang}.json`);
window.monacoI18N = goog.getJSON(i18nFilePath);
window.monacoI18N = goog.readJsonSync(i18nFilePath);
} else {
window.monacoI18N = {};
}

View File

@@ -24,9 +24,9 @@ Config.USER = {
* @return {void}
**/
Config.init = () => {
Config.SOFTWARE = goog.getJSON('./sw-config.json', {});
Config.SOFTWARE = goog.readJsonSync('./sw-config.json', {});
console.log('Config.SOFTWARE:', Config.SOFTWARE);
Config.BOARDS_INFO = goog.getJSON('./boards.json', {});
Config.BOARDS_INFO = goog.readJsonSync('./boards.json', {});
console.log('Config.BOARDS_INFO:', Config.BOARDS_INFO);
const boardPageConfig = Url.getConfig();
Config.BOARD_PAGE = boardPageConfig ?? {};

View File

@@ -211,7 +211,7 @@ for (let i of XML.TEMPLATE_CONFIG) {
generateDom
} = i;
if (XML.TEMPLATE_ENV[type]) {
const xmlStr = goog.get(XML.TEMPLATE_DIR_PATH + path);
const xmlStr = goog.readFileSync(XML.TEMPLATE_DIR_PATH + path);
if (xmlStr) {
XML.TEMPLATE_STR[type] = xmlStr;
if (generateDom) {