From 60e26ffb37cd80c95972fe05402fe31c0589fb84 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Fri, 18 Nov 2022 16:58:42 +0100 Subject: [PATCH 1/7] add log mode in cmd --- src/cmd.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cmd.js b/src/cmd.js index 1fdf046..dc14477 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -1,11 +1,11 @@ let jsste = require("./index"); let myargs = process.argv.slice(2); -let path = require("path"); -const { fstat } = require("fs"); let output = ""; let pagefile, tempfile; let fs = require("fs"); + + let addCommand = ({prefix,args = myargs}, callback) => { myargs.forEach((elem) =>{ @@ -17,23 +17,26 @@ let addCommand = ({prefix,args = myargs}, callback) => }) } +addCommand({prefix:"-log"},(arg) =>{ + jsste.setStateFunction((state) =>{ + console.log(state); + }) +}) + addCommand({prefix:"-Jsconfig="},(arg) =>{ jsste.__config.setConfig(arg); }) addCommand({prefix:"-page="},(arg) =>{ - pagefile = JSON.parse(fs.readFileSync(arg,"utf-8").toString()) - console.log(pagefile) }) addCommand({prefix:"-temp="},(arg) =>{ tempfile = fs.readFileSync(arg, "utf-8").toString() - console.log(tempfile) }) output = jsste.render(pagefile || undefined, tempfile || undefined) addCommand({prefix:"-out"},(arg) =>{ - console.log("output\n", output ) + console.log(output) }) From 1bddfdd4fdb436348ed7da9764ddf0a3ed82ac45 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Fri, 18 Nov 2022 19:05:05 +0100 Subject: [PATCH 2/7] modify cmd | add templatefile to renderFile --- src/cmd.js | 9 ++++----- src/index.js | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cmd.js b/src/cmd.js index dc14477..324518d 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -4,8 +4,6 @@ let output = ""; let pagefile, tempfile; let fs = require("fs"); - - let addCommand = ({prefix,args = myargs}, callback) => { myargs.forEach((elem) =>{ @@ -28,14 +26,15 @@ addCommand({prefix:"-Jsconfig="},(arg) =>{ }) addCommand({prefix:"-page="},(arg) =>{ - pagefile = JSON.parse(fs.readFileSync(arg,"utf-8").toString()) + + pagefile = arg }) addCommand({prefix:"-temp="},(arg) =>{ - tempfile = fs.readFileSync(arg, "utf-8").toString() + tempfile = arg }) -output = jsste.render(pagefile || undefined, tempfile || undefined) +output = jsste.renderFile(pagefile || undefined, tempfile || undefined) addCommand({prefix:"-out"},(arg) =>{ console.log(output) diff --git a/src/index.js b/src/index.js index b882f48..86c648a 100644 --- a/src/index.js +++ b/src/index.js @@ -11,14 +11,16 @@ app.CONST = engine.CONST; * @param {*} filePath * @returns */ -app.renderFile = (filePath) => { +app.renderFile = (filePath, templatePath) => { app.setState({ status: 0, statusMSG: "read file" }); let file = fs.readFileSync(filePath, "utf8"); app.setState({ status: 0, statusMSG: "parse file" }); file = JSON.parse(file); + app.setState({ status: 0, statusMSG: "read template" }); + let temp = fs.readFileSync(templatePath, "utf8"); app.setState({ status: 0, statusMSG: "set Selfpath" }); file["_SELFPATH_"] = path.dirname(filePath); - return engine.render(file); + return engine.render(file,temp); }; /** From ac539956082f1769c3c6e2e33f5a94421038f3b2 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Fri, 18 Nov 2022 20:53:08 +0100 Subject: [PATCH 3/7] add jsste_info to cmd --- src/engine.js | 9 ++++++++- src/index.js | 6 ++++++ src/scriptExecuter.js | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/engine.js b/src/engine.js index 37c5885..c4593f5 100644 --- a/src/engine.js +++ b/src/engine.js @@ -56,7 +56,14 @@ app.render = function (pagecode, templatecode) { pagecode = JSON.parse(pagecode); app.setState({ status: 0, statusMSG: "Parse Pagecode" }); } else { - app.setState({ status: 1, statusMSG: "Pagecode is undefined" }); + if(typeof pagecode === "object") + { + app.setState({ status: 0, statusMSG: "Pagecode is an object" }); + } + else{ + app.setState({ status: 1, statusMSG: "Pagecode is undefined" }); + } + } if (!templatecode) { diff --git a/src/index.js b/src/index.js index 86c648a..ca40acf 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,12 @@ var app = {}; app.render = engine.render; app.CONST = engine.CONST; + +let pj = require("../package.json") + +app.info = {}; +app.info["version"] = pj.version +app.info["license"] = pj.license /** * Render File * @param {*} filePath diff --git a/src/scriptExecuter.js b/src/scriptExecuter.js index 82c466d..1caa9fe 100644 --- a/src/scriptExecuter.js +++ b/src/scriptExecuter.js @@ -3,6 +3,16 @@ */ function Added() { let outString = ""; + + //[jsste_info] + + function jsste_info() + { + let jssteinfo = jsste_input_file + result = `\tINFOS\n\t${Object.keys(jssteinfo).map((key) => key + " : " + jssteinfo[key] ).join("\n\t") }` + + return result; + } function out(arg) { outString += arg; @@ -26,8 +36,14 @@ function exec(script) { script ); + script = script.replace("//[jsste_info]",`let jsste_input_file = ${JSON.stringify(require("./index").info)}`), + + // console.log(`a: }`) + script += "\n return outString;"; + // console.log(script) + try { let F = new Function(script); From 4daba83eebeddc4fa96c3a7580970f29073c491d Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Fri, 18 Nov 2022 21:43:31 +0100 Subject: [PATCH 4/7] added direct code input in cmd --- src/cmd.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd.js b/src/cmd.js index 324518d..d1f780a 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -2,6 +2,7 @@ let jsste = require("./index"); let myargs = process.argv.slice(2); let output = ""; let pagefile, tempfile; +let path = require("path"); let fs = require("fs"); let addCommand = ({prefix,args = myargs}, callback) => @@ -25,16 +26,25 @@ addCommand({prefix:"-Jsconfig="},(arg) =>{ jsste.__config.setConfig(arg); }) +addCommand({prefix:"-pageFile="},(arg) =>{ + pagefile = JSON.parse(fs.readFileSync(arg, "utf8")); + pagefile["_SELFPATH_"] = path.dirname(arg); +}) addCommand({prefix:"-page="},(arg) =>{ - pagefile = arg + pagefile = JSON.parse(arg); + pagefile["_SELFPATH_"] = path.dirname(arg); +}) + +addCommand({prefix:"-tempFile="},(arg) =>{ + tempfile = fs.readFileSync(arg, "utf8"); }) addCommand({prefix:"-temp="},(arg) =>{ tempfile = arg }) -output = jsste.renderFile(pagefile || undefined, tempfile || undefined) +output = jsste.render(pagefile || undefined, tempfile || undefined) addCommand({prefix:"-out"},(arg) =>{ console.log(output) From 1c221ef0482d88c6bfd21a3681528c5e7d619a14 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Fri, 18 Nov 2022 22:09:29 +0100 Subject: [PATCH 5/7] add -info to cmd --- src/cmd.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cmd.js b/src/cmd.js index d1f780a..0aabe6e 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -46,6 +46,22 @@ addCommand({prefix:"-temp="},(arg) =>{ output = jsste.render(pagefile || undefined, tempfile || undefined) +addCommand({prefix:"-info"},(arg) =>{ + + if(arg == "?json") + { + console.log(JSON.stringify(jsste.info)) + } + else{ + Object.keys(jsste.info).forEach((key)=>{ + console.log(key + " : " + jsste.info[key] ) + }) + } +}) + + + + addCommand({prefix:"-out"},(arg) =>{ console.log(output) }) From 0a815718276563a7fea616505177db748ed78009 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Fri, 18 Nov 2022 22:18:36 +0100 Subject: [PATCH 6/7] prettify --- src/cmd.js | 3 --- src/scriptExecuter.js | 4 ---- 2 files changed, 7 deletions(-) diff --git a/src/cmd.js b/src/cmd.js index 0aabe6e..abb0fde 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -59,9 +59,6 @@ addCommand({prefix:"-info"},(arg) =>{ } }) - - - addCommand({prefix:"-out"},(arg) =>{ console.log(output) }) diff --git a/src/scriptExecuter.js b/src/scriptExecuter.js index 1caa9fe..1b1f261 100644 --- a/src/scriptExecuter.js +++ b/src/scriptExecuter.js @@ -38,12 +38,8 @@ function exec(script) { script = script.replace("//[jsste_info]",`let jsste_input_file = ${JSON.stringify(require("./index").info)}`), - // console.log(`a: }`) - script += "\n return outString;"; - // console.log(script) - try { let F = new Function(script); From 1e6645d90a53a463a0f7eac5186ab454dc2b9ca3 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Sat, 19 Nov 2022 00:06:15 +0100 Subject: [PATCH 7/7] comment cmd --- src/cmd.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/cmd.js b/src/cmd.js index abb0fde..c30bbdc 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -5,6 +5,11 @@ let pagefile, tempfile; let path = require("path"); let fs = require("fs"); +/** + * this function filters the prefix and call the callback with the param + * @param {prefix, args } settings + * @param {*} callback + */ let addCommand = ({prefix,args = myargs}, callback) => { myargs.forEach((elem) =>{ @@ -16,36 +21,61 @@ let addCommand = ({prefix,args = myargs}, callback) => }) } +/** + * -log | show jsste log + */ addCommand({prefix:"-log"},(arg) =>{ jsste.setStateFunction((state) =>{ console.log(state); }) }) +/** + * -Jsconfig | set jsste config as json + */ addCommand({prefix:"-Jsconfig="},(arg) =>{ jsste.__config.setConfig(arg); }) +/** + * -pageFile | set pageFile path + */ addCommand({prefix:"-pageFile="},(arg) =>{ pagefile = JSON.parse(fs.readFileSync(arg, "utf8")); pagefile["_SELFPATH_"] = path.dirname(arg); }) + +/** + * -pageFile | set pageFile as json + */ addCommand({prefix:"-page="},(arg) =>{ pagefile = JSON.parse(arg); pagefile["_SELFPATH_"] = path.dirname(arg); }) +/** + * -tempFile | set tempFile path + */ addCommand({prefix:"-tempFile="},(arg) =>{ tempfile = fs.readFileSync(arg, "utf8"); }) +/** + * -pageFile | set pageFile as code + */ addCommand({prefix:"-temp="},(arg) =>{ tempfile = arg }) +/** + * rendering + */ output = jsste.render(pagefile || undefined, tempfile || undefined) +/** + * -info | show jsste.info + */ addCommand({prefix:"-info"},(arg) =>{ if(arg == "?json") @@ -59,6 +89,9 @@ addCommand({prefix:"-info"},(arg) =>{ } }) +/** + * -out | write rendered code into the commandling + */ addCommand({prefix:"-out"},(arg) =>{ console.log(output) })