Merge pull request #21 from lucaspalomodevelop/cmd

Cmd
This commit is contained in:
Lucas Manuel Palomo Lauterbach 2022-11-20 19:34:42 +01:00 committed by GitHub
commit 63f84f72d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 108 deletions

View File

@ -6,6 +6,9 @@
"directories": {
"test": "test"
},
"bin": {
"jsste": "./src/cli.js"
},
"files": [
"src",
"package.json",
@ -15,7 +18,7 @@
"scripts": {
"test": "mocha ./test/test.test.js",
"publish": "npm publish --access publish",
"cmd": "node ./src/cmd.js"
"cmd": "node ./src/cli.js"
},
"repository": {
"type": "git",

View File

@ -1,97 +0,0 @@
let jsste = require("./index");
let myargs = process.argv.slice(2);
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) =>{
if(elem.startsWith(prefix))
{
elem = elem.replace(prefix,"")
callback(elem);
}
})
}
/**
* -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")
{
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

@ -27,7 +27,7 @@ function replaceAll(str, find, replace) {
}
/**
* function to handle consts
* function to handle consts
* @param {*} pagecode
* @param {*} constant
* @param {*} callback
@ -56,20 +56,23 @@ app.render = function (pagecode, templatecode) {
pagecode = JSON.parse(pagecode);
app.setState({ status: 0, statusMSG: "Parse Pagecode" });
} else {
if(typeof pagecode === "object")
{
if (typeof pagecode === "object") {
app.setState({ status: 0, statusMSG: "Pagecode is an object" });
}
else{
} else {
app.setState({ status: 1, statusMSG: "Pagecode is undefined" });
}
}
}
if (!templatecode) {
try {
app.setState({ status: 0, statusMSG: "Load Templatecode" });
console.log(app.config.templatePath)
app.setState({
status: 4,
statusMSG: path.join(
app.config.templatePath,
pagecode["_TEMPLATE_"] + ".tjsste"
),
});
templatecode = fs.readFileSync(
path.join(app.config.templatePath, pagecode["_TEMPLATE_"] + ".tjsste"),
"utf-8"
@ -124,10 +127,10 @@ app.render = function (pagecode, templatecode) {
pagecode = currentPagecode;
};
// Handle _IMPORTS_ const
// Handle _IMPORTS_ const
app.CONST(pagecode, "_IMPORTS_", DissolveImports);
// Handle _STYLES_ const
// Handle _STYLES_ const
app.CONST(pagecode, "_STYLES_", (pagecode, value) => {
app.setState({ status: 0, statusMSG: "Import Styles" });
let rex = /<head>(.|\n|\t|\r)*?<\/head>/;