UNPKG

cdejs

Version:

CanvasDotEffect is a lightweight JS library that helps create customizable and interactive dot-based effects using the Canvas API

2 lines 1.73 kB
#!/usr/bin/env node import{spawn}from"child_process";import{dirname,join}from"path";import{createInterface}from"readline";const commands={template:"createProjectTemplate.min.js",t:"createProjectTemplate.min.js","browser-template":"createBrowserProjectTemplate.min.js",bt:"createBrowserProjectTemplate.min.js",react:"createDefaultReactComponent.min.js",doc:"openDocumentation.min.js",documentation:"openDocumentation.min.js",signature:"getSignature.min.js",sig:"getSignature.min.js",s:"getSignature.min.js"},customCommands=["list"];function getCommand(e,o){const n=Boolean(commands[e]),t=Object.entries(commands).find((o=>o[0].toLowerCase().includes(e)));return customCommands.includes(e)?{cmd:e}:t&&e&&"cdejs"!=e?{isAutoComplete:!n&&!o.includes("-y")&&!o.includes("-f"),cmdName:t[0],cmd:[join(dirname(process.argv[1]),t[1]),...o.filter((e=>!e.includes("-y")&&!e.includes("-f")))].filter(Boolean)}:void 0}function executeCmd(e){"list"==e?console.log(`NPX:\n ${Object.keys(commands).join("\n ")}\nCUSTOM:\n ${customCommands.join("\n ")}\n`):spawn("node",e,{stdio:"inherit"})}const command=getCommand(process.argv[2]?.toLowerCase().trim(),process.argv.slice(3));if(command)if(command.isAutoComplete){const e=createInterface({input:process.stdin,output:process.stdout});function close(e){e.close(),console.log("")}e.question("The command was autocompleted to 'cdejs-"+command.cmdName+"', continue [Y/N]? ",(o=>{const n=o?.toLowerCase()?.trim();n&&!["y","yes","ye","ok","for sure"].includes(n)||(close(e),executeCmd(command.cmd))})),process.stdin.on("keypress",((o,n)=>{"escape"==n.name&&close(e)}))}else executeCmd(command.cmd);else console.log("\n'"+process.argv[2]?.toLowerCase()+"' is not part of any cdejs command...\n");