- remove toplevel option from terser as it will cause certain error

- rename some functions name to fix above issue, but finally no relation with it.
- correct source map command line options
- optimize commands
This commit is contained in:
Xen 2020-05-21 22:54:41 +08:00
parent 5bb7a2e0f3
commit f1bb8de22a
5 changed files with 36 additions and 34 deletions

View File

@ -7,11 +7,10 @@
"repository": "https://github.com/xenkuo/comNG", "repository": "https://github.com/xenkuo/comNG",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {
"prestart": "terser src/base.js src/editor.js src/serialport.js --source-map -o src/index.js -c -m toplevel",
"start": "electron-forge start", "start": "electron-forge start",
"rebuild": "electron-rebuild -f -w serialport", "rebuild": "electron-rebuild -f -w serialport",
"package": "electron-forge package", "package": "electron-forge package",
"premake": "terser src/base.js src/editor.js src/serialport.js --source-map -o src/index.js -c -m toplevel", "premake": "rm src/index.js.map && terser src/base.js src/editor.js src/serialport.js -o src/index.js -c -m",
"make": "electron-forge make", "make": "electron-forge make",
"publish": "electron-forge publish", "publish": "electron-forge publish",
"lint": "echo \"No linting configured\"" "lint": "echo \"No linting configured\""

View File

@ -6,8 +6,8 @@ const appVersion = remote.app.getVersion();
const appUpdaterUrl = const appUpdaterUrl =
"https://gitee.com/api/v5/repos/xenkuo/comNG/releases/latest"; "https://gitee.com/api/v5/repos/xenkuo/comNG/releases/latest";
var M = require("materialize-css"); var mcss = require("materialize-css");
M.AutoInit(); mcss.AutoInit();
var config; var config;
var barHeight; var barHeight;
@ -139,14 +139,14 @@ window.onload = () => {
menu.offsetHeight + menu.offsetHeight +
"px"; "px";
M.Tabs.getInstance(document.getElementById("menu-tabs")).select( mcss.Tabs.getInstance(document.getElementById("menu-tabs")).select(
config.menu.tab config.menu.tab
); );
let baudSelect = document.getElementById("baud-select"); let baudSelect = document.getElementById("baud-select");
baudSelect.options[0].text = config.general.customized; baudSelect.options[0].text = config.general.customized;
baudSelect.selectedIndex = config.baudIndex; baudSelect.selectedIndex = config.baudIndex;
M.FormSelect.init(baudSelect); mcss.FormSelect.init(baudSelect);
portUpdate(); portUpdate();
@ -164,16 +164,16 @@ window.onload = () => {
let databits = document.getElementById("databits-select"); let databits = document.getElementById("databits-select");
databits.selectedIndex = config.general.databitsIndex; databits.selectedIndex = config.general.databitsIndex;
M.FormSelect.init(databits); mcss.FormSelect.init(databits);
let parity = document.getElementById("parity-select"); let parity = document.getElementById("parity-select");
parity.selectedIndex = config.general.parityIndex; parity.selectedIndex = config.general.parityIndex;
M.FormSelect.init(parity); mcss.FormSelect.init(parity);
let stopbits = document.getElementById("stopbits-select"); let stopbits = document.getElementById("stopbits-select");
stopbits.selectedIndex = config.general.stopbitsIndex; stopbits.selectedIndex = config.general.stopbitsIndex;
M.FormSelect.init(stopbits); mcss.FormSelect.init(stopbits);
let flowcontrol = document.getElementById("flowcontrol-select"); let flowcontrol = document.getElementById("flowcontrol-select");
flowcontrol.selectedIndex = config.general.flowcontrolIndex; flowcontrol.selectedIndex = config.general.flowcontrolIndex;
M.FormSelect.init(flowcontrol); mcss.FormSelect.init(flowcontrol);
document.getElementById("editor-font-family").value = document.getElementById("editor-font-family").value =
config.general.fontFamily; config.general.fontFamily;
@ -371,7 +371,7 @@ document.body.onclick = (e) => {
}; };
document.getElementById("menu-tabs").onclick = () => { document.getElementById("menu-tabs").onclick = () => {
let tabs = M.Tabs.getInstance(document.getElementById("menu-tabs")); let tabs = mcss.Tabs.getInstance(document.getElementById("menu-tabs"));
configUpdate("menu.tab", tabs.$content[0].id); configUpdate("menu.tab", tabs.$content[0].id);
}; };
@ -404,7 +404,7 @@ document.getElementById("customized").onblur = (e) => {
let baudSelect = document.getElementById("baud-select"); let baudSelect = document.getElementById("baud-select");
baudSelect.options[0].text = customized; baudSelect.options[0].text = customized;
M.FormSelect.init(baudSelect); mcss.FormSelect.init(baudSelect);
}; };
document.getElementById("databits-select").onchange = (e) => { document.getElementById("databits-select").onchange = (e) => {
@ -463,8 +463,8 @@ document.getElementById("trans-send-btn").onclick = () => {
if (serialWrite(data) === false) return; if (serialWrite(data) === false) return;
p.value += "\n" + document.getElementById("trans-data").value; p.value += "\n" + document.getElementById("trans-data").value;
M.updateTextFields(p); mcss.updateTextFields(p);
M.textareaAutoResize(p); mcss.textareaAutoResize(p);
p.scrollTop = p.scrollHeight; p.scrollTop = p.scrollHeight;
if (document.getElementById("trans-repeat-switch").checked === true) { if (document.getElementById("trans-repeat-switch").checked === true) {
@ -491,8 +491,8 @@ document.getElementById("trans-log-btn").onclick = () => {
let p = document.getElementById("trans-log-area"); let p = document.getElementById("trans-log-area");
p.value = ""; p.value = "";
M.updateTextFields(p); mcss.updateTextFields(p);
M.textareaAutoResize(p); mcss.textareaAutoResize(p);
}; };
document.getElementById("bar-color-head").oninput = (e) => { document.getElementById("bar-color-head").oninput = (e) => {

View File

@ -40,8 +40,8 @@ function decoGet() {
return decoTable[decoIndex++ % decoMod]; return decoTable[decoIndex++ % decoMod];
} }
function decoApply(m, text) { function decoApply(model, text) {
let matches = m.findMatches( let matches = model.findMatches(
text, text,
false, false,
false, false,
@ -56,7 +56,7 @@ function decoApply(m, text) {
for (let i of matches) { for (let i of matches) {
let range = i.range; let range = i.range;
m.deltaDecorations( model.deltaDecorations(
[], [],
[ [
{ {
@ -74,8 +74,8 @@ function decoApply(m, text) {
} }
} }
function decoRemove(m, text) { function decoRemove(model, text) {
let matches = m.findMatches( let matches = model.findMatches(
text, text,
false, false,
false, false,
@ -85,11 +85,11 @@ function decoRemove(m, text) {
); );
for (let match of matches) { for (let match of matches) {
let decos = m.getDecorationsInRange(match.range); let decos = model.getDecorationsInRange(match.range);
// super word remove decoration will cause sub word decoration to 1 // super word remove decoration will cause sub word decoration to 1
for (let deco of decos) { for (let deco of decos) {
m.deltaDecorations([deco.id], []); model.deltaDecorations([deco.id], []);
} }
} }
} }
@ -97,11 +97,11 @@ function decoRemove(m, text) {
function highlightToggle() { function highlightToggle() {
console.log("highligh toggle"); console.log("highligh toggle");
let decoExpectedLength = 1; let decoExpectedLength = 1;
let m = editor.getModel(); let model = editor.getModel();
let range = editor.getSelection(); let range = editor.getSelection();
let text = m.getValueInRange(range); let text = model.getValueInRange(range);
if (text === "") { if (text === "") {
let word = m.getWordAtPosition(editor.getPosition()); let word = model.getWordAtPosition(editor.getPosition());
text = word.word; text = word.word;
range.startColumn = word.startColumn; range.startColumn = word.startColumn;
range.endColumn = word.endColumn; range.endColumn = word.endColumn;
@ -110,11 +110,11 @@ function highlightToggle() {
if (text === "") return; if (text === "") return;
let decos = m.getDecorationsInRange(range); let decos = model.getDecorationsInRange(range);
if (decos.length === decoExpectedLength) { if (decos.length === decoExpectedLength) {
decoApply(m, text); decoApply(model, text);
} else { } else {
decoRemove(m, text); decoRemove(model, text);
} }
return null; return null;

View File

@ -1,5 +1,6 @@
// All of the Node.js APIs are available in the preload process. // All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension. // It has the same sandbox as a Chrome extension.
let pjson = require("../package.json"); let pjson = require("../package.json");
if ("dev" == pjson.mode) { if ("dev" == pjson.mode) {
console.log("dev mode"); console.log("dev mode");
@ -7,8 +8,10 @@ if ("dev" == pjson.mode) {
const fs = require("fs"); const fs = require("fs");
let terser = require("terser"); let terser = require("terser");
let options = { let options = {
toplevel: true, sourceMap: {
sourceMap: true, filename: "index.js",
url: "index.js.map",
},
}; };
let result = terser.minify( let result = terser.minify(
{ {

View File

@ -23,7 +23,7 @@ function portUpdate() {
pSelect.options.add(new Option(item.path, index)); pSelect.options.add(new Option(item.path, index));
if (index === config.pathIndex) pSelect.selectedIndex = index; if (index === config.pathIndex) pSelect.selectedIndex = index;
}); });
M.FormSelect.init(pSelect); mcss.FormSelect.init(pSelect);
}) })
.catch((e) => { .catch((e) => {
console.error(e); console.error(e);
@ -127,7 +127,7 @@ function serialGetOptions() {
} }
function toast(text) { function toast(text) {
M.toast({ html: text, displayLength: 1000 }); mcss.toast({ html: text, displayLength: 1000 });
// alert(text) // alert(text)
} }
@ -159,7 +159,7 @@ document.getElementById("port-switch").onclick = (e) => {
if (config.general.modemSignal === true) { if (config.general.modemSignal === true) {
modemSignalTimer = setInterval(modemSignalTimerHandle, 100); modemSignalTimer = setInterval(modemSignalTimerHandle, 100);
} }
port.set({rts: true, dtr: true}, (e) => { port.set({ rts: true, dtr: true }, (e) => {
if (e !== null) console.error(e); if (e !== null) console.error(e);
}); });
}); });