Merge pull request #17 from lucaspalomodevelop/cmd

Cmd
This commit is contained in:
Lucas Manuel Palomo Lauterbach 2022-11-19 17:42:31 +01:00 committed by GitHub
commit 69d86e44f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 12 deletions

View File

@ -1,11 +1,15 @@
let jsste = require("./index");
let myargs = process.argv.slice(2);
let path = require("path");
const { fstat } = require("fs");
let output = "";
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) =>{
@ -17,23 +21,77 @@ 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(fs.readFileSync(arg,"utf-8").toString())
console.log(pagefile)
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 = fs.readFileSync(arg, "utf-8").toString()
console.log(tempfile)
tempfile = arg
})
/**
* rendering
*/
output = jsste.render(pagefile || undefined, tempfile || undefined)
addCommand({prefix:"-out"},(arg) =>{
console.log("output\n", output )
/**
* -info | show jsste.info
*/
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] )
})
}
})
/**
* -out | write rendered code into the commandling
*/
addCommand({prefix:"-out"},(arg) =>{
console.log(output)
})

View File

@ -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) {

View File

@ -6,19 +6,27 @@ 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
* @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);
};
/**

View File

@ -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,6 +36,8 @@ function exec(script) {
script
);
script = script.replace("//[jsste_info]",`let jsste_input_file = ${JSON.stringify(require("./index").info)}`),
script += "\n return outString;";
try {