Comparing version 1.1.5 to 1.1.6
@@ -6,5 +6,5 @@ #!/usr/bin/env node | ||
* author: Nolann Morencé | ||
* version: 1.1.5 | ||
* version: 1.1.6 | ||
*/ | ||
const fs=require("fs"),path=require("path"),liveServer=require("live-server"),prompts=require("prompts"),TEMPLATE_APP={Name:"My First App",ShortName:"MyFirstApp",Description:"Simple app for progressive web app with WebAppKit framework",Lang:"en",ThemeColor:"white",LaunchScreen:"home_screen",NewScreen:"new_screen",NewComponent:"NewComponent"},TEMPLATE_PATH=path.join(path.dirname(__filename),"templates"),HELP_MESSAGE="\n[94mWelcome on WebAppKit !\nThanks for using this framework[0m\n\n[92mUsage: [93mnode wak.js <command>[0m\n---\n[93minit[0m[92m: Initiate a new project\n[93mhelp[0m[92m: Show this help\n\n[92mUsage: [93mnode wak.js <app-name> <command>[0m\n---\n[93mscreen[0m[92m: Create new screen\n[93mcomponent[0m[92m: Create new component\n[93mbuild[0m[92m: Build app with manifest update\n[93mstart[0m[92m: Run your app (-p|--port XXXX, -l|--launch)\n\n[96mLink to github project: https://github.com/exagyde/webappkit[0m\n",INIT_PROMPT=[{type:"text",name:"app_name",message:`[1;39mWhat is your app name ? (${TEMPLATE_APP.Name}) [0m`,initial:TEMPLATE_APP.Name},{type:"text",name:"app_short_name",message:`[1;39mWhat is your short app name ? (${TEMPLATE_APP.ShortName}) [0m`,initial:TEMPLATE_APP.ShortName},{type:"text",name:"app_description",message:"[1;39mWhat is your app description ? [0m",initial:TEMPLATE_APP.Description},{type:"select",name:"app_lang",message:"Set you app language : ",choices:[{title:"English",value:"en"},{title:"French",value:"fr"},{title:"Spanish",value:"es"},{title:"German",value:"de"}]},{type:"select",name:"app_theme_color",message:"Set you app theme color : ",choices:[{title:"Light",value:"white"},{title:"Dark",value:"black"}]},{type:"text",name:"app_launch_screen",message:`[1;39mSet your launch screen : (${TEMPLATE_APP.LaunchScreen}) [0m`,initial:TEMPLATE_APP.LaunchScreen}],WEBAPPKIT={Init:async()=>{let e=await prompts(INIT_PROMPT);if(fs.existsSync("./"+e.app_short_name))return void console.log(`[91mProject ${e.app_short_name} already exists[0m`);fs.mkdirSync("./"+e.app_short_name),fs.mkdirSync("./"+e.app_short_name+"/app"),fs.mkdirSync("./"+e.app_short_name+"/components"),fs.mkdirSync("./"+e.app_short_name+"/resources"),fs.mkdirSync("./"+e.app_short_name+"/screens"),fs.copyFileSync(TEMPLATE_PATH+"/favicon.ico","./"+e.app_short_name+"/favicon.ico"),fs.mkdirSync("./"+e.app_short_name+"/resources/icons"),fs.copyFileSync(TEMPLATE_PATH+"/resources/icons/icon-128.png","./"+e.app_short_name+"/resources/icons/icon-128.png"),fs.copyFileSync(TEMPLATE_PATH+"/resources/icons/icon-144.png","./"+e.app_short_name+"/resources/icons/icon-144.png"),fs.copyFileSync(TEMPLATE_PATH+"/resources/icons/icon-152.png","./"+e.app_short_name+"/resources/icons/icon-152.png"),fs.copyFileSync(TEMPLATE_PATH+"/resources/icons/icon-192.png","./"+e.app_short_name+"/resources/icons/icon-192.png"),fs.copyFileSync(TEMPLATE_PATH+"/resources/icons/icon-256.png","./"+e.app_short_name+"/resources/icons/icon-256.png"),fs.copyFileSync(TEMPLATE_PATH+"/resources/icons/icon-512.png","./"+e.app_short_name+"/resources/icons/icon-512.png"),fs.copyFileSync(TEMPLATE_PATH+"/sw.js","./"+e.app_short_name+"/sw.js"),fs.copyFileSync(TEMPLATE_PATH+"/app/App.js","./"+e.app_short_name+"/app/App.js"),fs.copyFileSync(TEMPLATE_PATH+"/app/register.js","./"+e.app_short_name+"/app/register.js"),fs.copyFileSync(TEMPLATE_PATH+"/app/style.css","./"+e.app_short_name+"/app/style.css");let n=fs.readFileSync(TEMPLATE_PATH+"/index.html","utf-8").replace(/{{ APP_LANG }}/g,e.app_lang).replace(/{{ APP_THEME_COLOR }}/g,e.app_theme_color).replace(/{{ APP_NAME }}/g,e.app_name).replace(/{{ APP_SHORT_NAME }}/g,e.app_short_name).replace(/{{ APP_DESCRIPTION }}/g,e.app_description);fs.writeFileSync("./"+e.app_short_name+"/index.html",n);let a=fs.readFileSync(TEMPLATE_PATH+"/manifest.json","utf-8").replace(/{{ APP_NAME }}/g,e.app_name).replace(/{{ APP_SHORT_NAME }}/g,e.app_short_name).replace(/{{ APP_LANG }}/g,e.app_lang).replace(/{{ APP_THEME_COLOR }}/g,e.app_theme_color).replace(/{{ APP_BACKGROUND_COLOR }}/g,e.app_theme_color).replace(/{{ APP_LAUNCH_SCREEN }}/g,e.app_launch_screen).replace(/{{ APP_DESCRIPTION }}/g,e.app_description);fs.writeFileSync("./"+e.app_short_name+"/manifest.json",a),WEBAPPKIT.CreateScreen({screen_name:e.app_launch_screen,app_name:e.app_short_name,app_lang:e.app_lang}),console.log(`[92mProject ${e.app_name} created[0m`)},ReadManifest:({app_name:e})=>{if(!fs.existsSync("./"+e+"/manifest.json"))return console.log("[91mManifest not found[0m"),null;let n=fs.readFileSync("./"+e+"/manifest.json","utf-8");return JSON.parse(n)},CreateScreen:({app_name:e,screen_name:n,app_lang:a})=>{if(fs.existsSync("./"+e+"/screens/"+n))return void console.log(`[91mScreen ${n} already exists[0m`);fs.mkdirSync("./"+e+"/screens/"+n);let s=fs.readFileSync(TEMPLATE_PATH+"/screens/home_screen/screen.html","utf-8").replace(/{{ APP_LANG }}/g,a);fs.writeFileSync("./"+e+"/screens/"+n+"/screen.html",s),fs.copyFileSync(TEMPLATE_PATH+"/screens/home_screen/script.js","./"+e+"/screens/"+n+"/script.js"),fs.copyFileSync(TEMPLATE_PATH+"/screens/home_screen/style.css","./"+e+"/screens/"+n+"/style.css"),console.log(`[92mScreen ${n} created[0m`)},CreateComponent:({app_name:e,component_name:n})=>{if(fs.existsSync("./"+e+"/components/"+n))return void console.log(`[91mComponent ${n} already exists[0m`);let a=fs.readFileSync(TEMPLATE_PATH+"/components/NewComponent.js","utf-8").replace(/NewComponent/g,n);fs.writeFileSync("./"+e+"/components/"+n+".js",a),console.log(`[92mComponent ${n} created[0m`)},Build:({app_name:e})=>{let n=WEBAPPKIT.ReadManifest({app_name:e});if(n){let a=fs.readFileSync(TEMPLATE_PATH+"/index.html","utf-8").replace(/{{ APP_LANG }}/g,n.lang??TEMPLATE_APP.Lang).replace(/{{ APP_THEME_COLOR }}/g,n.theme_color??TEMPLATE_APP.ThemeColor).replace(/{{ APP_NAME }}/g,n.name??TEMPLATE_APP.Name).replace(/{{ APP_SHORT_NAME }}/g,n.short_name??TEMPLATE_APP.ShortName).replace(/{{ APP_DESCRIPTION }}/g,n.description??TEMPLATE_APP.Description);fs.writeFileSync("./"+e+"/index.html",a),console.log("[92mBuild successful[0m")}},Start:({port:e,app:n,open:a})=>{liveServer.start({port:e??3e3,host:"localhost",root:n,open:a??!1,logLevel:2})},Help:()=>{console.log(HELP_MESSAGE)}},args=process.argv.slice(2);function getParamValue(e){let n=args.findIndex((n=>n==`-${e}`||n==`--${e}`));return-1!==n&&n+1<args.length?args[n+1]:null}function hasParam(e){return args.some((n=>n==`-${e}`||n==`--${e}`))}switch(process.argv[2]){case"init":WEBAPPKIT.Init();break;case"help":WEBAPPKIT.Help();break;default:if(fs.existsSync(process.argv[2])&&fs.statSync(process.argv[2]).isDirectory())switch(process.argv[3]){case"screen":!async function(){let e=await prompts({type:"text",name:"screen_name",message:`[1;39mSet your screen name : (${TEMPLATE_APP.NewScreen}) [0m`,initial:TEMPLATE_APP.NewScreen}),n=WEBAPPKIT.ReadManifest({app_name:process.argv[2]});n&&n.lang&&WEBAPPKIT.CreateScreen({screen_name:e.screen_name,app_name:process.argv[2],app_lang:n.lang})}();break;case"component":!async function(){let e=await prompts({type:"text",name:"component_name",message:`[1;39mSet your component name : (${TEMPLATE_APP.NewComponent}) [0m`,initial:TEMPLATE_APP.NewComponent});WEBAPPKIT.CreateComponent({component_name:e.component_name,app_name:process.argv[2]})}();break;case"build":WEBAPPKIT.Build({app_name:process.argv[2]});break;case"start":let e=getParamValue("p")||getParamValue("port"),n=hasParam("l")||hasParam("launch");WEBAPPKIT.Start({port:e?parseInt(e,10):3e3,app:process.argv[2],open:n||!1});break;default:WEBAPPKIT.Help()}else null!=process.argv[2]?console.log("[91mApp not found, check help command[0m"):WEBAPPKIT.Help()} |
{ | ||
"name": "wakx", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Manage WebAppKit framework", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -45,3 +45,3 @@ # Web App Kit framework | ||
super(); | ||
// Add events listener like this.onclick | ||
// Add events listener or other | ||
} | ||
@@ -54,2 +54,7 @@ | ||
} | ||
update() { | ||
// Optional | ||
// Define processing after displaying the component and its updates | ||
} | ||
} | ||
@@ -56,0 +61,0 @@ |
@@ -1,1 +0,1 @@ | ||
class CustomComponent extends HTMLElement{constructor(){super(),this.innerHTML=this.render();let e=this;new MutationObserver((t=>{t.forEach((()=>{e.innerHTML=e.render()}))})).observe(this,{attributes:!0})}get properties(){return Object.values(this.attributes).reduce(((e,t)=>(e[t.name]=t.value,e)),{})}}const App={navigate:e=>{parent.document.getElementById("app-screen").src="./../screens/"+e+"/screen.html"},getResourceURL:e=>"./../../resources/"+e,addComponent:(e,t)=>{let n=document.createElement("script");n.type="module",n.src="./../../components/"+t+".js",document.head.appendChild(n),customElements.define(e,t)}};export{CustomComponent,App}; | ||
class CustomComponent extends HTMLElement{constructor(){super(),this.innerHTML=this.render(),this.update();let e=this;new MutationObserver((t=>{t.forEach((()=>{e.innerHTML=e.render(),this.update()}))})).observe(this,{attributes:!0})}update(){}get properties(){return Object.values(this.attributes).reduce(((e,t)=>(e[t.name]=t.value,e)),{})}}const App={navigate:e=>{parent.document.getElementById("app-screen").src="./../screens/"+e+"/screen.html"},getResourceURL:e=>"./../../resources/"+e,addComponent:(e,t)=>{let n=document.createElement("script");n.type="module",n.src="./../../components/"+t+".js",document.head.appendChild(n),customElements.define(e,t)}};export{CustomComponent,App}; |
@@ -15,4 +15,6 @@ import { CustomComponent } from "../app/App.js"; | ||
} | ||
update() {} | ||
} | ||
export { NewComponent }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139954
70
129