mirror of
https://github.com/lucaspalomodevelop/JSSTE.git
synced 2026-03-12 23:17:22 +00:00
commit
69d86e44f3
76
src/cmd.js
76
src/cmd.js
@ -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)
|
||||
})
|
||||
|
||||
@ -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) {
|
||||
|
||||
12
src/index.js
12
src/index.js
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user