From 1e6645d90a53a463a0f7eac5186ab454dc2b9ca3 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Sat, 19 Nov 2022 00:06:15 +0100 Subject: [PATCH] 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) })