add cmd.js

This commit is contained in:
lucaspalomodevelop 2022-11-18 16:37:10 +01:00
parent 908058bce6
commit 794d6b5550
4 changed files with 40 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
testfiles
planning
.vscode
built

View File

@ -14,7 +14,8 @@
],
"scripts": {
"test": "mocha ./test/test.test.js",
"publish": "npm publish --access publish"
"publish": "npm publish --access publish",
"cmd": "node ./src/cmd.js"
},
"repository": {
"type": "git",

36
src/cmd.js Normal file
View File

@ -0,0 +1,36 @@
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) =>{
if(elem.startsWith(prefix))
{
elem = elem.replace(prefix,"")
callback(elem);
}
})
}
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 )
})

View File

@ -62,6 +62,7 @@ app.render = function (pagecode, templatecode) {
if (!templatecode) {
try {
app.setState({ status: 0, statusMSG: "Load Templatecode" });
console.log(app.config.templatePath)
templatecode = fs.readFileSync(
path.join(app.config.templatePath, pagecode["_TEMPLATE_"] + ".tjsste"),
"utf-8"