Add a switch that allows to get all console.log or none in production package

This commit is contained in:
Luc
2020-10-07 13:59:28 +02:00
parent b915f3f592
commit ca3b298753
23 changed files with 58 additions and 42 deletions

View File

@@ -34,6 +34,22 @@ in ESP3D-WEBUI directory (repository root)
```
npm run build
```
Will generate production and debug versions for grbl and printer
```
npm run build-debug
```
Will generate debug versions for grbl and printer, which contain all console.log message.
```
npm run build-prod
```
Will generate production versions for grbl and printer, cleaned from all `console.log` messages.
you can even go to more atomic level with : `npm run build-printer`, `npm run build-grbl`, `npm run build-printer-debug`, `npm run build-grbl-debug`, `npm run build-lang`
### Code beautify with prettier
use pluggin or cli

BIN
dist/grbl/debug/index.html.gz vendored Normal file
View File

Binary file not shown.

View File

Binary file not shown.

BIN
dist/grbl/production/index.html.gz vendored Normal file
View File

Binary file not shown.

BIN
dist/printer/debug/index.html.gz vendored Normal file
View File

Binary file not shown.

View File

Binary file not shown.

BIN
dist/printer/production/index.html.gz vendored Normal file
View File

Binary file not shown.

View File

@@ -4,9 +4,13 @@
"description": "Preact version of WebUI for ESP3D per @aganov suggestion",
"main": "index.js",
"scripts": {
"build-grbl": "cross-env NODE_ENV=production TARGET_ENV=grbl webpack --mode=production",
"build-printer": "cross-env NODE_ENV=production TARGET_ENV=printer webpack --mode=production",
"build": "npm run build-printer & npm run build-grbl & npm run build-lang",
"build-grbl-debug": "cross-env NODE_ENV=production TARGET_ENV=grbl BUILD_ENV=debug webpack --mode=production",
"build-printer-debug": "cross-env NODE_ENV=production TARGET_ENV=printer BUILD_ENV=debug webpack --mode=production",
"build-debug": "npm run build-printer-debug & npm run build-grbl-debug & npm run build-lang",
"build-grbl": "cross-env NODE_ENV=production TARGET_ENV=grbl BUILD_ENV=production webpack --mode=production",
"build-printer": "cross-env NODE_ENV=production TARGET_ENV=printer BUILD_ENV=production webpack --mode=production",
"build-prod": "npm run build-printer & npm run build-grbl & npm run build-lang",
"build": "npm run build-printer & npm run build-grbl & npm run build-printer-debug & npm run build-grbl-debug & npm run build-lang",
"clean": "rm -rf dist",
"grbl": "cross-env NODE_ENV=development TARGET_ENV=grbl webpack-dev-server --open --mode=development",
"printer": "cross-env NODE_ENV=development TARGET_ENV=printer webpack-dev-server --open --mode=development",

View File

@@ -133,7 +133,7 @@ const MainPage = () => {
* Apply necessary settings
*/
function applyConfig(data) {
//console.log("Apply settings")
console.log("Apply settings")
esp3dSettings = data
document.title = esp3dSettings.Hostname
if (esp3dSettings.FWTarget == "unknown") {

View File

@@ -224,7 +224,7 @@ const DialogPage = () => {
const { showDialog } = useStoreon("showDialog")
const { dialogData } = useStoreon("dialogData")
if (!dialogData) return null
//console.log(dialogData)
console.log(dialogData)
if (!showDialog) {
disableNode(document.getElementById("mainwindow"), false)
return null
@@ -232,7 +232,7 @@ const DialogPage = () => {
useEffect(() => {
disableNode(document.getElementById("mainwindow"), true)
})
//console.log(dialogData)
console.log(dialogData)
let classname = "modal d-block"
let iconTitle, iconMsg
let progressbar
@@ -247,7 +247,6 @@ const DialogPage = () => {
}
if (dialogData.type == "login") {
title = T("S145")
//TODO ADD PROPER FORM
dialogData.message = (
<div>
<LoginEntry />

View File

@@ -201,7 +201,7 @@ function loadImportFile() {
let reader = new FileReader()
reader.onload = function(e) {
var contents = e.target.result
//console.log(contents)
console.log(contents)
try {
printerImportSettings = JSON.parse(contents)
currentIndex = -1
@@ -231,7 +231,7 @@ function loadImportFile() {
function cancelImport() {
stopImport = true
showDialog({ displayDialog: false })
//console.log("stopping import")
console.log("stopping import")
}
/*
@@ -268,7 +268,7 @@ function exportSettings() {
}
}
data += "]}"
//console.log(data)
console.log(data)
file = new Blob([data], { type: "application/json" })
if (window.navigator.msSaveOrOpenBlob)
// IE10+
@@ -325,8 +325,8 @@ function processEventsData(type, data) {
function processWSData(buffer) {
processFeedRate(buffer)
if (isConfigRequested) {
//console.log("config requested, processing " + buffer)
//console.log("setting size " + listrawSettings.length)
console.log("config requested, processing " + buffer)
console.log("setting size " + listrawSettings.length)
if (
buffer.startsWith(configurationCmd()[2]) ||
buffer.startsWith(configurationCmd()[3])
@@ -575,7 +575,7 @@ function setState(entry, state) {
let input = document.getElementById("printer_input_" + id)
let button = document.getElementById("printer_button_" + id)
if (!label || !input || !button) {
//console.log("not found" + entry.id)
console.log("not found" + entry.id)
return
}
input.classList.remove("is-valid")

View File

@@ -77,7 +77,7 @@ function defaultHttpResultFn(response_text) {
) {
httpCommandList[0].resultfn(response_text)
}
//console.log("Success : " + response_text)
console.log("Success : " + response_text)
nextCommand()
}
@@ -107,12 +107,10 @@ function defaultHttpErrorFn(errorcode, response_text) {
* Request Login/Password
*/
function requestAuthentication() {
console.log("Need login password")
//remove previous failed command
if (httpCommandList.length > 0) {
if (httpCommandList[0].id == "login") httpCommandList.shift()
}
console.log(httpCommandList)
showDialog({ type: "login" })
}
@@ -120,7 +118,7 @@ function requestAuthentication() {
* Go to next command in queries list
*/
function nextCommand() {
//console.log("pop " + httpCommandList[0].uri)
console.log("pop " + httpCommandList[0].uri)
httpCommandList.shift()
isProcessingHttpCommand = false
pausePing(false)
@@ -258,8 +256,6 @@ function SubmitCredentials(login, password, newpassword, timeout) {
}
//put command at the top of list
httpCommandList.unshift(cmd)
console.log("New login")
console.log(httpCommandList)
isProcessingHttpCommand = false
processCommands()
}
@@ -269,12 +265,12 @@ function SubmitCredentials(login, password, newpassword, timeout) {
*/
function processCommands() {
if (httpCommandList.length > 0 && !isProcessingHttpCommand) {
/*console.log(
console.log(
"Processing " +
httpCommandList[0].type +
" command:" +
httpCommandList[0].uri
)*/
)
if (
httpCommandList[0].type == "GET" ||
httpCommandList[0].type == "POST"
@@ -331,7 +327,7 @@ function processCommands() {
)
}
if (httpCommandList[0].type == "POST") {
//console.log("Post query")
console.log("Post query")
console.log(httpCommandList[0].data)
}
currentHttpCommand.send(

View File

@@ -337,7 +337,7 @@ function processFiles(rawdata) {
let data = rawdata
data.trim()
if (data.length == 0) return
//console.log(rawdata)
console.log(rawdata)
if (isSDCheckRequested) {
let response = checkSerialSDCmd()
if (data.indexOf(response[1]) != -1) {

View File

@@ -315,7 +315,7 @@ function isVerboseData(data) {
//TODO split by FW possibilities
if (typeof data == "object") {
//TODO What about error message ?
//console.log(data)
console.log(data)
return true
}
if (
@@ -488,7 +488,7 @@ function loadImportFile() {
let reader = new FileReader()
reader.onload = function(e) {
var contents = e.target.result
//console.log(contents)
console.log(contents)
try {
printerImportSettings = JSON.parse(contents)
currentIndex = -1
@@ -518,7 +518,7 @@ function loadImportFile() {
function cancelImport() {
stopImport = true
showDialog({ displayDialog: false })
//console.log("stopping import")
console.log("stopping import")
}
/*
@@ -555,7 +555,7 @@ function exportSettings() {
}
}
data += "]}"
//console.log(data)
console.log(data)
file = new Blob([data], { type: "application/json" })
if (window.navigator.msSaveOrOpenBlob)
// IE10+
@@ -796,7 +796,7 @@ function processConfigData() {
}
}
//console.log(listSettings)
console.log(listSettings)
showDialog({ displayDialog: false, refreshPage: true })
stopTimeout()
}
@@ -1148,7 +1148,7 @@ function setState(entry, state) {
let input = document.getElementById("printer_input_" + id)
let button = document.getElementById("printer_button_" + id)
if (!label || !input || !button) {
//console.log("not found" + entry.id)
console.log("not found" + entry.id)
return
}
input.classList.remove("is-valid")

View File

@@ -451,7 +451,7 @@ function checkValue(entry, type) {
*/
function updateState(entry, id) {
if (typeof entry == "undefined") {
//console.log("undefined state")
console.log("undefined state")
return
}
let type = id.split("_")[0]

View File

@@ -548,7 +548,7 @@ function loadSettingsSuccess(responseText) {
try {
refreshOngoing = false
esp3dFWSettings = JSON.parse(responseText)
//console.log(esp3dFWSettings)
console.log(esp3dFWSettings)
showDialog({ displayDialog: false, refreshPage: true })
} catch (e) {
console.log(responseText)
@@ -586,7 +586,7 @@ function loadWiFiNetworksSuccess(responseText) {
</tr>
</thead>
)
//console.log(listnetworks)
console.log(listnetworks)
for (let key in listnetworks.AP_LIST) {
let sub_key = Object.keys(listnetworks.AP_LIST[key])
let sub_val = Object.values(listnetworks.AP_LIST[key])

View File

@@ -65,7 +65,7 @@ function T(id) {
if (typeof translatedText === "undefined") {
translatedText = enLangRessource[id]
if (typeof translatedText === "undefined") {
//console.log("[Translation]" + id + " is not defined!")
console.log("[Translation]" + id + " is not defined!")
translatedText = id
}
}

View File

@@ -88,7 +88,7 @@ function ping(start = false) {
setTimeout(ping, pingDelay)
if (pingPaused) return
if (webSocketClient.readyState == 1) {
//console.log("ping")
console.log("ping")
webSocketClient.send("ping")
}
}
@@ -97,7 +97,7 @@ function ping(start = false) {
* Process WS terminal line
*/
function processWebSocketBuffer(wsBuffer) {
//console.log(wsBuffer)
console.log(wsBuffer)
updateTerminal(wsBuffer)
processWSData(wsBuffer)
}
@@ -171,7 +171,7 @@ function connectWsServer() {
//On open WS
webSocketClient.onopen = function(e) {
reconnectCounter = 0
//console.log("ws connection ok")
console.log("ws connection ok")
ping(true)
}
//On close ws

View File

@@ -1467,6 +1467,6 @@ wss.on("connection", function(ws) {
})
currentID++
ws.on("message", function(message) {
//console.log("received: %s", message)
console.log("received: %s", message)
})
})

View File

@@ -575,6 +575,6 @@ wss.on("connection", function(ws) {
})
currentID++
ws.on("message", function(message) {
//console.log("received: %s", message)
console.log("received: %s", message)
})
})

View File

@@ -4,14 +4,14 @@
*/
const RemoveFilesWebpackPlugin = require("remove-files-webpack-plugin")
var dist = "dist/" + process.env.TARGET_ENV
var dist = "dist/" + process.env.TARGET_ENV + "/" + process.env.BUILD_ENV
const config = {
before: {
include: [process.env.TARGET_ENV],
},
after: {
exclude: [dist + "/index.html.gz"],
exclude: [dist + "/index.html.gz"],
test: [
{
folder: "./" + dist,

View File

@@ -4,7 +4,7 @@
*/
import TerserPlugin from "terser-webpack-plugin"
import environment from "../environment"
const config = {
parallel: true,
cache: false,
@@ -19,6 +19,7 @@ const config = {
ecma: 5,
warnings: false,
comparisons: false,
drop_console: process.env.BUILD_ENV == "debug" ? false:true,
},
mangle: {
safari10: true,

View File

@@ -2,7 +2,7 @@ import merge from "webpack-merge"
import environment from "./environment"
import { productionPlugins, optimizationPlugins } from "./plugins"
var path = require("path")
var dist = "../dist/" + process.env.TARGET_ENV
var dist = "../dist/" + process.env.TARGET_ENV + "/" + process.env.BUILD_ENV
module.exports = merge(environment, {
optimization: optimizationPlugins,
plugins: productionPlugins,