jsht v1.0.4
jsht
Program to generate templates files using NodeJS code, using tags <# #> and <#= #> to print values. With all capabilities NodeJS has to offer.
Prerequisites
NodeJS installed.
Installing
npm i -g jshtGetting Started
1 - Create new template: Template file will be created at current dir/.jshtTemplates/create/class.js
jsht -n create class2 - Edit new template current dir/.jshtTemplates/create/class.js
<#
//any NodeJS here
var className = "HelloWorld";
#>
class <#=className#>{
}3 - Execute template
jsht create classWill generate
class HelloWorld{
}Examples
Create new template file
jsht -n create classNew template file will be created at current dir/.jshtTemplates/create/class.js.
Execute template file
jsht create classExecute template file: current dir/.jshtTemplates/create/class.js.
Hello World
<#
//any NodeJS here
var className = "HelloWorld";
#>
class <#=className#>{
}Will generate
class HelloWorld{
}Print text
print text: <#
printText("printed text");
#>
short form: <#="printed text"#>Will generate
print text: printed text
short form: printed textIF
<#if(5 > 6){#>
var biggerVar;
<#}else{#>
var smallerVar;
<#}#>Will generate
var smallerVar;FOR
<#for(var i = 0; i < 10; i++){#>
let var<#=i#>;
<#}#>Will generate
let var0;
let var1;
let var2;
let var3;
let var4;
let var5;
let var6;
let var7;
let var8;
let var9;Location variables
Outputfile: <#=outputFile#>
Outputfile directory: <#=currentDir#>
Template name: <#=templateName#>
Template path: <#=templatePath#>
Template path directory: <#=templateDir#>Will generate
Outputfile: <YOUR_LOCATION>/class.js
Outputfile directory: <YOUR_LOCATION>
Template name: class
Template path: <YOUR_LOCATION>/.jshtTemplates/create/class.js
Template path directory: <YOUR_LOCATION>/.jshtTemplates/createChange output Name
<#
outputFile = "myNewFile.js";
#>Change output location
<#
outputFile = "../class.js";
#>not generating output location
<#
outputFile = "";
#>or
<#
outputFile = null;
#>Overwite file without asking -rf option overwrite existing files without asking. Example
jsht create class -rfOutput generated template in console\ -outputTemplate \ Example
jsht create class -outputTemplateOutput generated JS Code in console for debug\ -outputJSCode \ Example
jsht create class -outputJSCodeCreate global template A global template can executed in any folder/path. To creat global template instead local template add "-g" after "-n":
jsht -n -g create classFirst jsht will look for the template at "./.jshtTemplates" folder, if not found it will look search in the global template path.
Global template path Get
jsht config template locationSet
jsht config template location C:/Desenv/TemplatesRequire Modules Install your modules at ".jshtTemplates" folder, to see where ".jshtTemplates" is, execute command "jsht config template location". Any module installed at your ".jshtTemplates" folder will be accessible by require method in your template.
Require Files A js file can be called using require, by the relative path of the template file. Example:
require("./folder/fileToBeCalled");Call Template from template
callTemplate("./otherTemplate.js", [], []);or through command:
execShell("jsht otherTemplate");The second parameter is an array of input arguments. The third parameter is an arrays of named arguments.
Build in functions
- execShell - execute command in the system \ params: \ command - command to be executed \ path - optional, folder to execute the command, if not provided it will be executed on the current folder. \ Example:
execShell("ls");
execShell("cd ..");Input Args Aditional parameters will became arguments inside the template:
jsht create class MyClassName calculateAgeclass <#=inputArgs[0]#>{
<#=inputArgs[1]#>(){
}
}Named Args Passing named parameters.
jsht create class -methodName calculateAge -className MyClassNameclass <#=namedArgs["className"]#>{
<#=namedArgs["methodName"]#>(){
}
}