minimaz-cli 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +12 -8
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env node
2
- var ht=Object.defineProperty;var u=(t,e)=>()=>(t&&(e=t(t=0)),e);var vt=(t,e)=>{for(var i in e)ht(t,i,{get:e[i],enumerable:!0})};import g from"fs-extra";import h from"path";import O from"clean-css";import{minify as bt}from"html-minifier-terser";import{minify as z}from"terser";async function F(){let t=await I(),e=d(),i=h.resolve(e,t.dist);if(await R(i),await g.ensureDir(i),!t.folders||Object.keys(t.folders).length===0){r("warn","No folders defined in config. Nothing to build.");return}for(let[n,s]of Object.entries(t.folders))r("debug",`Building folder: ${n} -> /${s}`),await xt(n,s,t,i);r("success",`Build completed. Output saved in /${t.dist}`)}async function xt(t,e,i,n){let s=d([t]),o=h.join(n,e);if(!await g.pathExists(s)){r("warn",`Folder not found: ${t}`);return}let a={css:[],js:[]};await Y(s,o,i,a),t===i.src&&await Et(a,i,n),r("success",`Processed folder: ${t} -> /${e}`)}async function Y(t,e,i,n){await g.ensureDir(e);for(let s of await g.readdir(t)){let o=h.join(t,s),a=h.join(e,s),l=await g.stat(o);if(r("debug",`Found ${l.isDirectory()?"DIRECTORY":"FILE"}: ${s}`),l.isDirectory()){await Y(o,a,i,n);continue}await $t(o,a,i,n)}}async function $t(t,e,i,n){switch(r("debug",`Processing file: ${t}`),h.extname(t).toLowerCase()){case".html":await Ct(t,e,i);break;case".css":{await jt(t,e,i,n.css);break}case".js":{await Pt(t,e,i,n.js);break}default:await g.copy(t,e)}}async function Ct(t,e,i){let n=await S(t,i.replace),s=/<script([^>]*)>([\s\S]*?)<\/script>/gi,o=0,a="",l;for(;(l=s.exec(n))!==null;){let[c,v,b]=l;if(a+=n.slice(o,l.index),o=l.index+c.length,/src=/i.test(v)){a+=c;continue}let j=(v.match(/type=["']([^"']+)["']/i)?.[1]||"").toLowerCase(),H=/module/i.test(j),yt=/nomodule/i.test(v);if(j==="application/json")try{let $=JSON.stringify(JSON.parse(b));a+=`<script${v}>${$}</script>`}catch($){r("warn",`Invalid JSON in ${t}: ${$}`),a+=c}else if(j===""||j==="text/javascript"||H||yt)try{let $=await z(b,{format:{semicolons:!0},module:H});a+=`<script${v}>${$.code||""}</script>`}catch($){r("warn",`JS minify error in ${t}: ${$}`),a+=c}else a+=c}a+=n.slice(o),i.minify?.html&&(a=await bt(a,{collapseWhitespace:!0,removeComments:!0,minifyCSS:i.minify.css,minifyJS:!1})),await g.outputFile(e,a)}async function jt(t,e,i,n){let s=await S(t,i.replace);if(i.bundling?.css)n.push(s);else{let o=s;if(i.minify?.css){let a=new O().minify(s);a.warnings.length&&a.warnings.forEach(l=>r("warn",l)),o=a.styles}await g.outputFile(e,o)}}async function Pt(t,e,i,n){let s=await S(t,i.replace);if(i.bundling?.js)n.push(s);else{let o=s;i.minify?.js&&(o=(await z(s)).code??""),await g.outputFile(e,o)}}async function Et(t,e,i){await N(e.styles,t.css,e,"css",!!e.bundling?.css,i),await N(e.scripts,t.js,e,"js",!!e.bundling?.js,i),e.bundling?.css&&await zt(t.css,e,i),e.bundling?.js&&await St(t.js,e,i)}async function N(t,e,i,n,s,o){if(t?.length)for(let a of t){let l=d([a]);if(!await g.pathExists(l)){r("warn",`File not found: ${a} `);continue}let c=await g.readFile(l,"utf-8");if(c=M(c,i.replace),s)e.push(c);else{if(n==="css"&&i.minify?.css){let b=new O().minify(c);b.warnings.length&&b.warnings.forEach(j=>r("warn",j)),c=b.styles}else if(n==="js"&&i.minify?.js)try{c=(await z(c)).code??""}catch(b){r("warn",`JS minify failed for external file ${a}: ${b} `)}let v=h.basename(a);await g.outputFile(h.join(o,v),c),r("info",`Copied external ${n} file: ${v} `)}}}async function zt(t,e,i){if(!t.length)return;let n=t.join("");if(e.minify?.css){let s=new O().minify(n);s.warnings.length&&s.warnings.forEach(o=>r("warn",o)),n=s.styles}await g.outputFile(h.join(i,"style.css"),n)}async function St(t,e,i){if(!t.length)return;let n=t.join("");if(e.minify?.js)try{n=(await z(n)).code??""}catch(s){r("warn",`JS minify failed: ${s} `)}n&&await g.outputFile(h.join(i,"script.js"),n)}var V=u(()=>{"use strict";f()});import k from"fs-extra";import K from"path";async function G(t,e){let i=K.join(await D(),e.template),n=d([t]);if(!await k.pathExists(i))throw new Error(`Template '${e.template}' not found.`);if(await k.pathExists(n))throw new Error(`Target directory '${n}' already exists.`);e.npm=e.npm??(await y("Init NPM? [Y/n]:","y")).startsWith("y"),e.git=e.git??(await y("Init Git repository? [Y/n]:","y")).startsWith("y"),e.git&&!e.gitprovider&&(e.gitprovider=e.gitprovider??await y("Select a provider or paste a url to connect your existing repo (cli tools needed) [LOCAL/github/gitlab]:","local")),r("debug",`Copying template from '${i}' to '${n}'`),await k.copy(i,n),r("debug","Initializing gitignore..."),await A(Z,K.join(n,".gitignore")),e.npm&&await q(n,t),e.git&&await X(t,n,e.gitprovider),r("success",`Project '${t}' created using template '${e.template}'.`)}var Q=u(()=>{"use strict";f()});function T(t){if(t){let e=B[t];if(!e){console.log(`No help found for command: ${t}
2
+ var ht=Object.defineProperty;var d=(t,e)=>()=>(t&&(e=t(t=0)),e);var bt=(t,e)=>{for(var i in e)ht(t,i,{get:e[i],enumerable:!0})};import g from"fs-extra";import h from"path";import M from"clean-css";import{minify as xt}from"html-minifier-terser";import{minify as z}from"terser";import F from"typescript";async function I(){let t=await G(),e=u(),i=h.resolve(e,t.dist);if(await T(i),await g.ensureDir(i),!t.folders||Object.keys(t.folders).length===0){r("warn","No folders defined in config. Nothing to build.");return}for(let[n,s]of Object.entries(t.folders))r("debug",`Building folder: ${n} -> /${s}`),await vt(n,s,t,i);r("success",`Build completed. Output saved in /${t.dist}`)}async function vt(t,e,i,n){let s=u([t]),a=h.join(n,e);if(!await g.pathExists(s)){r("warn",`Folder not found: ${t}`);return}let o={css:[],js:[]};await V(s,a,i,o),t===i.src&&await zt(o,i,n),r("success",`Processed folder: ${t} -> /${e}`)}async function V(t,e,i,n){await g.ensureDir(e);for(let s of await g.readdir(t)){let a=h.join(t,s),o=h.join(e,s),l=await g.stat(a);if(r("debug",`Found ${l.isDirectory()?"DIRECTORY":"FILE"}: ${s}`),l.isDirectory()){await V(a,o,i,n);continue}await $t(a,o,i,n)}}async function $t(t,e,i,n){switch(r("debug",`Processing file: ${t}`),h.extname(t).toLowerCase()){case".html":await Ct(t,e,i);break;case".css":{await jt(t,e,i,n.css);break}case".js":{await Pt(t,e,i,n.js);break}case".ts":{await Et(t,e,i,n.js);break}default:await g.copy(t,e)}}async function Ct(t,e,i){let n=await S(t,i.replace),s=/<script([^>]*)>([\s\S]*?)<\/script>/gi,a=0,o="",l;for(;(l=s.exec(n))!==null;){let[c,x,v]=l;if(o+=n.slice(a,l.index),a=l.index+c.length,/src=/i.test(x)){o+=c;continue}let E=(x.match(/type=["']([^"']+)["']/i)?.[1]||"").toLowerCase(),Y=/module/i.test(E),yt=/nomodule/i.test(x);if(E==="application/json")try{let C=JSON.stringify(JSON.parse(v));o+=`<script${x}>${C}</script>`}catch(C){r("warn",`Invalid JSON in ${t}: ${C}`),o+=c}else if(E===""||E==="text/javascript"||Y||yt)try{let C=await z(v,{format:{semicolons:!0},module:Y});o+=`<script${x}>${C.code||""}</script>`}catch(C){r("warn",`JS minify error in ${t}: ${C}`),o+=c}else o+=c}o+=n.slice(a),i.minify?.html&&(o=await xt(o,{collapseWhitespace:!0,removeComments:!0,minifyCSS:i.minify.css,minifyJS:!1})),await g.outputFile(e,o)}async function jt(t,e,i,n){let s=await S(t,i.replace);if(i.bundling?.css)n.push(s);else{let a=s;if(i.minify?.css){let o=new M().minify(s);o.warnings.length&&o.warnings.forEach(l=>r("warn",l)),a=o.styles}await g.outputFile(e,a)}}async function Pt(t,e,i,n){let s=await S(t,i.replace);if(i.bundling?.js)n.push(s);else{let a=s;i.minify?.js&&(a=(await z(s)).code??""),await g.outputFile(e,a)}}async function Et(t,e,i,n){let s=await S(t,i.replace),o=F.transpileModule(s,{compilerOptions:{module:F.ModuleKind.ESNext,target:F.ScriptTarget.ES2020,sourceMap:!1,strict:!0}}).outputText;if(i.bundling?.js)n.push(o);else{let l=o;i.minify?.js&&(l=(await z(l)).code??""),await g.outputFile(e.replace(/\.ts$/,".js"),l)}}async function zt(t,e,i){await K(e.styles,t.css,e,"css",!!e.bundling?.css,i),await K(e.scripts,t.js,e,"js",!!e.bundling?.js,i),e.bundling?.css&&await St(t.css,e,i),e.bundling?.js&&await Tt(t.js,e,i)}async function K(t,e,i,n,s,a){if(t?.length)for(let o of t){let l=u([o]);if(!await g.pathExists(l)){r("warn",`File not found: ${o} `);continue}let c=await g.readFile(l,"utf-8");if(c=k(c,i.replace),s)e.push(c);else{if(n==="css"&&i.minify?.css){let v=new M().minify(c);v.warnings.length&&v.warnings.forEach(E=>r("warn",E)),c=v.styles}else if(n==="js"&&i.minify?.js)try{c=(await z(c)).code??""}catch(v){r("warn",`JS minify failed for external file ${o}: ${v} `)}let x=h.basename(o);await g.outputFile(h.join(a,x),c),r("info",`Copied external ${n} file: ${x} `)}}}async function St(t,e,i){if(!t.length)return;let n=t.join("");if(e.minify?.css){let s=new M().minify(n);s.warnings.length&&s.warnings.forEach(a=>r("warn",a)),n=s.styles}await g.outputFile(h.join(i,"style.css"),n)}async function Tt(t,e,i){if(!t.length)return;let n=t.join("");if(e.minify?.js)try{n=(await z(n)).code??""}catch(s){r("warn",`JS minify failed: ${s} `)}n&&await g.outputFile(h.join(i,"script.js"),n)}var Q=d(()=>{"use strict";f()});import L from"fs-extra";async function B(t,e){let i=await X(e.template),n=u([t]);if(!await L.pathExists(i))throw new Error(`Template '${e.template}' not found.`);if(await L.pathExists(n))throw new Error(`Target directory '${n}' already exists.`);r("debug",`Copying template from '${i}' to '${n}'`),await L.copy(i,n),r("debug","Initializing minimaz.config.json..."),await R(D,[n,"minimaz.config.json"]),(e.npm!==void 0?!!e.npm:(await y("Init NPM? [Y/n]:","y")).toLowerCase().startsWith("y"))&&await Ot(n,t),(e.git!==void 0?!!e.git:(await y("Init Git repository? [Y/n]:","y")).toLowerCase().startsWith("y"))&&await Rt(t,n,e.gitprovider),r("success",`Project '${t}' created using template '${e.template}'.`)}async function Rt(t,e,i,n="origin"){i||(i=(await y("Select a provider or paste a url to connect your existing repo (cli tools needed) [LOCAL/github/gitlab]:","local")).toLowerCase().trim()),r("info","Initializing Git repository..."),r("debug","Initializing gitignore..."),await R(tt,[e,".gitignore"]),r("debug","Running git init..."),await j("git",["init"],e),i?(await Dt(t,e,i,n),r("success","Git repository initialized.")):r("info","Git repository initialized locally (no remote).")}async function Dt(t,e,i,n="origin"){if(/^https?:\/\//.test(i)||i.startsWith("git@")){r("info",`Connecting existing remote '${i}'`),await j("git",["remote","add",n,i],e);return}if(i==="github"){r("info",`Creating GitHub repository '${t}'`),await j("gh",["repo","create",t,"--private","--source=.","--remote",n],e);return}if(i==="gitlab"){r("info",`Creating GitLab repository '${t}'`);let s=process.env.GITLAB_USER;if(!s)throw new Error("GITLAB_USER environment variable not set");await j("glab",["repo","create",t,"--source=."],e),await j("git",["remote","add",n,`git@gitlab.com:${s}/${t}.git`],e);return}throw new Error(`Unsupported git provider or remote: '${i}'`)}async function Ot(t,e){r("info","Initializing NPM..."),await R({name:e,...Z},[t,"package.json"]),r("debug","Running npm install..."),await j("npm",["i"],t)}var q=d(()=>{"use strict";f()});function O(t){if(t){let e=A[t];if(!e){console.log(`No help found for command: ${t}
3
3
  `);return}if(console.log(e.usage,`
4
4
  ${e.description}`),e.options){console.log(" Options:");for(let[i,n]of Object.entries(e.options))console.log(` ${i} ${n}`)}console.log("");return}console.log(`Usage:
5
- `);for(let e of Object.values(B)){if(console.log(e.usage,`
6
- ${e.description}`),e.options){console.log(" Options:");for(let[i,n]of Object.entries(e.options))console.log(` ${i} ${n}`)}console.log("")}}var tt=u(()=>{"use strict";f()});import w from"fs-extra";import C from"path";async function J(t,e){let i=await D();if(t.list)return await Ft(i);if(t.delete)return await Tt(i,t.delete);if(await Ot(i,e),t.update)return typeof t.update=="string"&&t.update.trim()?await Rt(i,t.update.trim()):await Dt(i)}async function Rt(t,e){let i=d([]),n=C.join(t,e);if(!await w.pathExists(n))throw new Error(`Template '${e}' not found in ~/.minimaz/templates`);if(!(await y(`Update '${e}' with current directory? [Y/n]:`,"y")).startsWith("y")){r("info","Update cancelled.");return}try{await w.copy(i,n,{overwrite:!0}),r("success",`Template '${e}' updated from current directory.`)}catch{throw new Error(`Failed to update '${e}'`)}}async function Dt(t){let e=await L(),i=await w.readdir(e);if(!(await y("Update local templates overwriting them with defaults? [Y/n]:","y")).startsWith("y")){r("info","Update cancelled.");return}try{for(let n of i){let s=C.join(e,n),o=C.join(t,n);await w.copy(s,o,{overwrite:!0}),r("success",`Updated '${n}'`)}r("info","\u2728 All templates and files updated successfully.")}catch(n){throw new Error(`Update failed: ${n.message}`)}}async function Tt(t,e){let i=C.join(t,e);if(!await w.pathExists(i))throw new Error(`Template not found: ${e}`);if(!(await y(`Confirm delete '${e}'? [Y/n]:`,"y")).startsWith("y")){r("info","Delete cancelled.");return}try{await w.remove(i),r("success",`Template '${e}' deleted.`)}catch(n){throw new Error(`Delete error: ${n.message}`)}}async function Ot(t,e){let i=d(e?[e]:[]);if(!await w.pathExists(i))if(r("warn",`Path not found: ${i}`),(await y("Use current directory instead? [Y/n]:","y")).startsWith("y"))i=process.cwd();else throw new Error("Operation cancelled.");try{await w.ensureDir(t);let n=C.join(t,C.basename(i));if(await w.pathExists(n)&&!(await y(`Template '${C.basename(n)}' already exists. Overwrite? [y/N]:`,"n")).startsWith("y")){r("info","Save cancelled.");return}await w.copy(i,n,{overwrite:!0}),r("success",`Template saved to ${n}`)}catch(n){throw new Error(`Failed to save template: ${n.message}`)}}async function Ft(t){let e=await w.readdir(t);if(e.length===0){r("info","No global templates available.");return}r("info","Available global templates:");for(let i=0;i<e.length;i++)console.log(`${i} - ${e[i]}`)}var et=u(()=>{"use strict";f()});async function U(){R()}var it=u(()=>{"use strict";f()});async function _(){let t=d(["package.json"]),{version:e}=await rt(t);if(typeof e!="string")throw new Error("Invalid or missing version in package.json");console.log("==========================================",`
5
+ `);for(let e of Object.values(A)){if(console.log(e.usage,`
6
+ ${e.description}`),e.options){console.log(" Options:");for(let[i,n]of Object.entries(e.options))console.log(` ${i} ${n}`)}console.log("")}}var et=d(()=>{"use strict";f()});import w from"fs-extra";import P from"path";async function J(t,e){let i=await U();if(t.list)return await Gt(i);if(t.delete)return await It(i,t.delete);if(await kt(i,e),t.update)return typeof t.update=="string"&&t.update.trim()?await Ft(i,t.update.trim()):await Mt(i)}async function Ft(t,e){let i=u([]),n=P.join(t,e);if(!await w.pathExists(n))throw new Error(`Template '${e}' not found in ~/.minimaz/templates`);if(!(await y(`Update '${e}' with current directory? [Y/n]:`,"y")).startsWith("y")){r("info","Update cancelled.");return}try{await w.copy(i,n,{overwrite:!0}),r("success",`Template '${e}' updated from current directory.`)}catch{throw new Error(`Failed to update '${e}'`)}}async function Mt(t){let e=await _(),i=await w.readdir(e);if(!(await y("Update local templates overwriting them with defaults? [Y/n]:","y")).startsWith("y")){r("info","Update cancelled.");return}try{for(let n of i){let s=P.join(e,n),a=P.join(t,n);await w.copy(s,a,{overwrite:!0}),r("success",`Updated '${n}'`)}r("info","\u2728 All templates and files updated successfully.")}catch(n){throw new Error(`Update failed: ${n.message}`)}}async function It(t,e){let i=P.join(t,e);if(!await w.pathExists(i))throw new Error(`Template not found: ${e}`);if(!(await y(`Confirm delete '${e}'? [Y/n]:`,"y")).startsWith("y")){r("info","Delete cancelled.");return}try{await w.remove(i),r("success",`Template '${e}' deleted.`)}catch(n){throw new Error(`Delete error: ${n.message}`)}}async function kt(t,e){let i=u(e?[e]:[]);if(!await w.pathExists(i))if(r("warn",`Path not found: ${i}`),(await y("Use current directory instead? [Y/n]:","y")).startsWith("y"))i=process.cwd();else throw new Error("Operation cancelled.");try{await w.ensureDir(t);let n=P.join(t,P.basename(i));if(await w.pathExists(n)&&!(await y(`Template '${P.basename(n)}' already exists. Overwrite? [y/N]:`,"n")).startsWith("y")){r("info","Save cancelled.");return}await w.copy(i,n,{overwrite:!0}),r("success",`Template saved to ${n}`)}catch(n){throw new Error(`Failed to save template: ${n.message}`)}}async function Gt(t){let e=await w.readdir(t);if(e.length===0){r("info","No global templates available.");return}r("info","Available global templates:");for(let i=0;i<e.length;i++)console.log(`${i} - ${e[i]}`)}var it=d(()=>{"use strict";f()});async function W(){T()}var nt=d(()=>{"use strict";f()});async function N(){let t=u(["package.json"]),{version:e}=await rt(t);if(typeof e!="string")throw new Error("Invalid or missing version in package.json");console.log("==========================================",`
7
7
  `,`minimaz-cli version: ${e}`,`
8
- `,"==========================================")}var nt=u(()=>{"use strict";f()});var st=u(()=>{"use strict"});import Mt from"readline";import p from"fs-extra";import m from"path";import It from"cross-spawn";import{homedir as ot}from"os";import{execSync as kt}from"child_process";function at(t){let e={_:[]};for(let i=0;i<t.length;i++){let n=t[i].toLowerCase();if(!n.startsWith("-")){e._.push(n);continue}if(n.startsWith("--")&&n.includes("=")){let[a,l]=n.slice(2).split("=");e[a]=l;continue}let s=n.replace(/^-+/,""),o=t[i+1];o&&!o.startsWith("-")?(e[s]=o,i++):e[s]=!0}return e}function y(t,e=""){return new Promise(i=>{let n=Mt.createInterface({input:process.stdin,output:process.stdout}),s=setTimeout(()=>{n.close(),i(e)},6e4);n.question(`\u2753 ${t} `,o=>{clearTimeout(s),n.close(),i(o.trim()||e)}),n.on("SIGINT",()=>{clearTimeout(s),n.close(),process.exit(130)})})}function M(t,e={}){return Object.entries(e).reduce((i,[n,s])=>{let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(o,"gi");return i.replace(a,s)},t)}async function S(t,e){try{let i=await p.readFile(t,"utf8");return e&&(i=M(i,e)),i}catch(i){return r("error",`Failed to read file ${t}: ${i.message}`),""}}async function lt(){try{let t=kt("npm config get prefix",{encoding:"utf8"}).trim();if(!t)throw new Error("Empty npm prefix");return process.platform==="win32"?m.join(t,"node_modules","minimaz-cli"):m.join(t,"lib","node_modules","minimaz-cli")}catch{return process.platform==="win32"?m.join(process.env.APPDATA||"","npm","node_modules","minimaz-cli"):"/usr/local/lib/node_modules/minimaz-cli"}}async function Gt(){return await W(),m.join(ot(),".minimaz")}async function D(){return m.join(await Gt(),"templates")}async function L(){let t=m.join(await lt(),"templates");if(t)throw new Error("Failed to resolve node_modules templates path");return t}async function W(){let t=m.join(ot(),".minimaz"),e=m.join(t,"templates"),i=await L(),n=m.join(t,"settings.json");try{await p.ensureDir(t),await p.pathExists(n)||(await p.outputJson(n,{createdAt:new Date().toISOString(),templatesPath:e,npmGlobalPath:lt()},{spaces:2}),r("success",`Created settings.json at ${n}`));let s=await p.pathExists(e),o=s?(await p.readdir(e)).length===0:!0;if(s||(await p.ensureDir(e),r("success","Created global templates directory.")),!o){r("debug","Global templates directory not empty. Skipping copy.");return}if(await p.pathExists(i))for(let a of await p.readdir(i))await p.copy(m.join(i,a),m.join(e,a)),r("success",`Copied template '${a}'.`);else r("warn","Default templates directory not found.");r("success","Default templates setup completed.")}catch(s){throw r("error",`Failed to create global templates directory: ${s.message}`),s}}function P(t,e,i){return new Promise((n,s)=>{r("debug",`Running: ${t} ${e.join(" ")}`);let o=It(t,e,{cwd:i,stdio:"inherit"});o.on("error",s),o.on("close",a=>a===0?n():s(new Error(`${t} exited with code ${a}`)))})}async function A(t,e){let i=typeof t=="string"?t.endsWith(`
9
- `)?t:t+`
10
- `:JSON.stringify(t,null,2)+`
11
- `;try{await p.outputFile(e,i)}catch(n){throw new Error(`Failed to create file at '${e}': ${n.message}`)}}async function q(t,e){r("info","Initializing NPM..."),await A({name:e,...mt},m.join(t,"package.json")),await P("npm",["install"],t)}async function X(t,e,i,n="origin"){r("info","Initializing Git repository..."),await P("git",["init"],e),i?(await At(t,e,i,n),r("success","Git repository initialized.")):r("info","Git repository initialized locally (no remote).")}async function At(t,e,i,n="origin"){if(console.log(i,n,t,e),/^https?:\/\//.test(i)||i.startsWith("git@")){r("info",`Connecting existing remote '${i}'`),await P("git",["remote","add",n,i],e);return}if(i==="github"){r("info",`Creating GitHub repository '${t}'`),await P("gh",["repo","create",t,"--private","--source=.","--remote",n],e);return}if(i==="gitlab"){r("info",`Creating GitLab repository '${t}'`);let s=process.env.GITLAB_USER;if(!s)throw new Error("GITLAB_USER environment variable not set");await P("glab",["repo","create",t,"--source=."],e),await P("git",["remote","add",n,`git@gitlab.com:${s}/${t}.git`],e);return}throw new Error(`Unsupported git provider or remote: '${i}'`)}async function R(t){let e=t?m.isAbsolute(t)?t:d([t]):m.resolve(process.cwd(),(await I()).dist??"dist"),i=process.cwd();if(e===i||e.length<=i.length)throw new Error(`Refusing to delete unsafe directory: ${e}`);if(!await p.pathExists(e)){r("debug",`No dist folder found: ${e}`);return}await p.remove(e),r("success",`Cleared ${e}`)}async function I(){let t=d(["minimaz.config.json"]),e;return await p.pathExists(t)?(e=await p.readJson(t),r("success","Loaded config from minimaz.config.json")):(e=JSON.parse(JSON.stringify(gt)),r("warn","No minimaz.config.json found. Using default config")),e}function ct(t){process.env.VERBOSE=t?"true":"false",r("debug",`VERBOSE = ${process.env.VERBOSE}`),process.env.CLI_WORKDIR=process.cwd(),r("debug",`CLI_WORKDIR = ${process.env.CLI_WORKDIR}`)}function d(t=[]){return m.resolve(process.env.CLI_WORKDIR??process.cwd(),...t)}async function rt(t){return await p.readJson(t)}var pt=u(()=>{"use strict";f()});var mt,Z,gt,B,x,dt=u(()=>{"use strict";mt={version:"0.0.1",license:"ISC",type:"commonjs",scripts:{build:"npx mz b",start:"npx mz b && npx serve dist/"},devDependencies:{"minimaz-cli":"latest",serve:"latest"}},Z=`dist
8
+ `,"==========================================")}var st=d(()=>{"use strict";f()});var ot=d(()=>{"use strict"});import Lt from"readline";import p from"fs-extra";import m from"path";import Bt from"cross-spawn";import{homedir as at}from"os";import{execSync as At}from"child_process";function lt(t){let e={_:[]};for(let i=0;i<t.length;i++){let n=t[i].toLowerCase();if(!n.startsWith("-")){e._.push(n);continue}if(n.startsWith("--")&&n.includes("=")){let[o,l]=n.slice(2).split("=");e[o]=l;continue}let s=n.replace(/^-+/,""),a=t[i+1];a&&!a.startsWith("-")?(e[s]=a,i++):e[s]=!0}return e}function y(t,e=""){return new Promise(i=>{let n=Lt.createInterface({input:process.stdin,output:process.stdout}),s=setTimeout(()=>{n.close(),i(e)},6e4);n.question(`\u2753 ${t} `,a=>{clearTimeout(s),n.close(),i(a.trim()||e)}),n.on("SIGINT",()=>{clearTimeout(s),n.close(),process.exit(130)})})}function k(t,e={}){return Object.entries(e).reduce((i,[n,s])=>{let a=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(a,"gi");return i.replace(o,s)},t)}async function S(t,e){try{let i=await p.readFile(t,"utf8");return e&&(i=k(i,e)),i}catch(i){return r("error",`Failed to read file ${t}: ${i.message}`),""}}async function ct(){try{let t=At("npm config get prefix",{encoding:"utf8"}).trim();if(!t)throw new Error("Empty npm prefix");return process.platform==="win32"?m.join(t,"node_modules","minimaz-cli"):m.join(t,"lib","node_modules","minimaz-cli")}catch{return process.platform==="win32"?m.join(process.env.APPDATA||"","npm","node_modules","minimaz-cli"):"/usr/local/lib/node_modules/minimaz-cli"}}async function Jt(){return await H(),m.join(at(),".minimaz")}async function U(){return m.join(await Jt(),"templates")}async function X(t){return m.join(await U(),t)}async function _(){return m.join(await ct(),"templates")}async function H(){let t=m.join(at(),".minimaz"),e=m.join(t,"templates"),i=await _(),n=m.join(t,"settings.json");try{await p.ensureDir(t),await p.pathExists(n)||(await p.outputJson(n,{createdAt:new Date().toISOString(),templatesPath:e,npmGlobalPath:await ct()},{spaces:2}),r("success",`Created settings.json at ${n}`));let s=await p.pathExists(e),a=s?(await p.readdir(e)).length===0:!0;if(s||(await p.ensureDir(e),r("success","Created global templates directory.")),!a){r("debug","Global templates directory not empty. Skipping copy.");return}if(await p.pathExists(i))for(let o of await p.readdir(i))await p.copy(m.join(i,o),m.join(e,o)),r("success",`Copied template '${o}'.`);else r("warn","Default templates directory not found.");r("success","Default templates setup completed.")}catch(s){throw r("error",`Failed to create global templates directory: ${s.message}`),s}}function j(t,e,i){return new Promise((n,s)=>{r("debug",`Running: ${t} ${e.join(" ")}`);let a=Bt(t,e,{cwd:i,stdio:"inherit"});a.on("error",s),a.on("close",o=>o===0?n():s(new Error(`${t} exited with code ${o}`)))})}async function R(t,e){let i=m.resolve(...e),n="";if(t!==void 0)if(typeof t=="string")n=t.endsWith(`
9
+ `)?t:`${t}
10
+ `;else if(typeof t=="object"&&t!==null)n=`${JSON.stringify(t,null,2)}
11
+ `;else throw new Error("Unsupported template type. Must be string or object.");try{await p.outputFile(i,n)}catch(s){let a=s instanceof Error?s.message:String(s);throw new Error(`Failed to create file at '${i}': ${a}`)}}async function T(t){let e=t?m.isAbsolute(t)?t:u([t]):m.resolve(process.cwd(),(await G()).dist??"dist"),i=process.cwd();if(e===i||e.length<=i.length)throw new Error(`Refusing to delete unsafe directory: ${e}`);if(!await p.pathExists(e)){r("debug",`No dist folder found: ${e}`);return}await p.remove(e),r("success",`Cleared ${e}`)}async function G(){let t=u(["minimaz.config.json"]),e;return await p.pathExists(t)?(e=await p.readJson(t),r("success","Loaded config from minimaz.config.json")):(e=JSON.parse(JSON.stringify(D)),r("warn","No minimaz.config.json found. Using default config")),e}function pt(t){process.env.VERBOSE=t?"true":"false",r("debug",`VERBOSE = ${process.env.VERBOSE}`),process.env.CLI_WORKDIR=process.cwd(),r("debug",`CLI_WORKDIR = ${process.env.CLI_WORKDIR}`)}function u(t=[]){return m.resolve(process.env.CLI_WORKDIR??process.cwd(),...t)}async function rt(t){return await p.readJson(t)}function $(t,e){return`${e}${t}${b.reset}`}var mt=d(()=>{"use strict";f()});var Z,tt,D,A,b,gt,ut=d(()=>{"use strict";f();Z={version:"0.0.1",license:"ISC",type:"commonjs",scripts:{build:"npx mz b",start:"npx mz b && npx serve dist/"},devDependencies:{"minimaz-cli":"latest",serve:"latest"}},tt=`
12
+ node_modules
13
+ dist
14
+ .env
12
15
  .vscode
13
- node_modules`,gt={src:"src",dist:"dist",public:"public",bundling:{css:!0,js:!0},minify:{html:!0,css:!0,js:!0},replace:{"../public/":"public/"},styles:["style.css","style-2.css"],scripts:["script.js","script-2.js"],folders:{src:"",public:"public"}},B={init:{usage:"minimaz init | i <project-name>",description:'Create a new project (default: "minimaz-site")',options:{"--template | -t <template-name>":'Use a global template (default: "default")'}},build:{usage:"minimaz build | b",description:"Build and minify files into the dist folder"},template:{usage:"minimaz template | t [path]",description:"Save current folder as a template (no path = current folder)",options:{"--list | -l":"List available global templates","--delete | -d <template-name>":"Delete a global template"}},help:{usage:"minimaz help | h",description:"Show this help message"},clear:{usage:"minimaz clear | c",description:"Clear the dist folder"},version:{usage:"minimaz version | v",description:"Show Minimaz version"}},x={reset:"\x1B[0m",red:"\x1B[31m",yellow:"\x1B[33m",green:"\x1B[32m",blue:"\x1B[34m",gray:"\x1B[90m"}});function r(t="info",e){let i={error:E("[ --- ERROR ----- ] ",x.red),warn:E("[ --- WARN ------ ] ",x.yellow),success:E("[ --- SUCCESS --- ] ",x.green),info:E("[ --- INFO ------ ] ",x.blue),debug:E("[ --- DEBUG ----- ] ",x.gray)},n=process.env.VERBOSE==="true";if(t==="debug"&&!n)return;let o=`${n?E(`[${Bt()}] `,x.gray):""}${i[t]} ${e}`;switch(t){case"error":console.error(o);break;case"warn":console.warn(o);break;default:console.log(o);break}}function E(t,e){return`${e}${t}${x.reset}`}function Bt(t=new Date){let e=c=>c.toString().padStart(2,"0"),i=t.getFullYear(),n=e(t.getMonth()+1),s=e(t.getDate()),o=e(t.getHours()),a=e(t.getMinutes()),l=e(t.getSeconds());return`${i}-${n}-${s} ${o}:${a}:${l}`}var ut=u(()=>{"use strict";f()});var f=u(()=>{"use strict";V();Q();tt();et();it();nt();st();pt();dt();ut()});var ft={};vt(ft,{postInstall:()=>Jt});async function Jt(){try{r("info","Running Post Install..."),await W(),r("success","Postinstall: Global templates setup completed")}catch(t){r("error",`Postinstall setup failed: ${t.message}`)}}var wt=u(()=>{"use strict";f()});f();process.env.npm_lifecycle_event==="postinstall"&&(Promise.resolve().then(()=>(wt(),ft)).then(({postInstall:t})=>t()),process.exit(0));async function Lt(){let t=at(process.argv.slice(2)),e=t._[0]||"",i=t._[1];ct(!!t.v),(e==="help"||t.h||t.help)&&(T(i||(t.h||t.help?e:void 0)),process.exit(0));let n={build:async()=>F(),clear:()=>U(),init:async()=>{await G(i||"minimaz-project",{template:t.template||t.t||"default",npm:t.npm,git:t.git,gitremote:t.gitremote,gitprovider:t.gitprovider})},template:async()=>{await J({list:t.l||t.list,delete:t.d||t.delete,update:t.u||t.update})},version:()=>_(),b:()=>n.build(),c:()=>n.clear(),i:()=>n.init(),t:()=>n.template(),v:()=>n.version()};try{n[e]?(r("info",`Executing command '${e}'...`),await n[e]()):(r("error",`Unknown command '${e}'. Use 'minimaz help' to see available commands.`),T())}catch(s){r("error",s instanceof Error?process.env.DEBUG?s.stack??s.message:s.message:String(s)),process.exit(1)}}Lt();
16
+ .DS_Store
17
+ `.trim(),D={src:"src",dist:"dist",public:"public",bundling:{css:!0,js:!0},minify:{html:!0,css:!0,js:!0},replace:{"../public/":"public/"},styles:["style.css","style-2.css"],scripts:["script.js","script-2.js"],folders:{src:"",public:"public"}},A={init:{usage:"minimaz init | i <project-name>",description:'Create a new project (default: "minimaz-site")',options:{"--template | -t <template-name>":'Use a global template (default: "default")'}},build:{usage:"minimaz build | b",description:"Build and minify files into the dist folder"},template:{usage:"minimaz template | t [path]",description:"Save current folder as a template (no path = current folder)",options:{"--list | -l":"List available global templates","--delete | -d <template-name>":"Delete a global template"}},help:{usage:"minimaz help | h",description:"Show this help message"},clear:{usage:"minimaz clear | c",description:"Clear the dist folder"},version:{usage:"minimaz version | v",description:"Show Minimaz version"}},b={reset:"\x1B[0m",red:"\x1B[31m",yellow:"\x1B[33m",green:"\x1B[32m",blue:"\x1B[34m",gray:"\x1B[90m"},gt={error:$("[ --- ERROR ----- ] ",b.red),warn:$("[ --- WARN ------ ] ",b.yellow),success:$("[ --- SUCCESS --- ] ",b.green),info:$("[ --- INFO ------ ] ",b.blue),debug:$("[ --- DEBUG ----- ] ",b.gray)}});function r(t="info",e){let i=process.env.VERBOSE==="true";if(t==="debug"&&!i)return;let s=`${i?$(`[${Ut()}] `,b.gray):""}${gt[t]} ${e}`;switch(t){case"error":console.error(s);break;case"warn":console.warn(s);break;default:console.log(s);break}}function Ut(t=new Date){let e=c=>c.toString().padStart(2,"0"),i=t.getFullYear(),n=e(t.getMonth()+1),s=e(t.getDate()),a=e(t.getHours()),o=e(t.getMinutes()),l=e(t.getSeconds());return`${i}-${n}-${s} ${a}:${o}:${l}`}var dt=d(()=>{"use strict";f()});var f=d(()=>{"use strict";Q();q();et();it();nt();st();ot();mt();ut();dt()});var ft={};bt(ft,{postInstall:()=>_t});async function _t(){try{r("info","Running Post Install..."),await H(),r("success","Postinstall: Global templates setup completed")}catch(t){r("error",`Postinstall setup failed: ${t.message}`)}}var wt=d(()=>{"use strict";f()});f();process.env.npm_lifecycle_event==="postinstall"&&(Promise.resolve().then(()=>(wt(),ft)).then(({postInstall:t})=>t()),process.exit(0));async function Wt(){let t=lt(process.argv.slice(2)),e=t._[0]||"",i=t._[1];pt(!!t.v),(e==="help"||t.h||t.help)&&(O(i||(t.h||t.help?e:void 0)),process.exit(0));let n={build:async()=>I(),clear:()=>W(),init:async()=>{await B(i||"minimaz-project",{template:t.template||t.t||"default",npm:t.npm,git:t.git,gitremote:t.gitremote,gitprovider:t.gitprovider})},template:async()=>{await J({list:t.l||t.list,delete:t.d||t.delete,update:t.u||t.update})},version:()=>N(),b:()=>n.build(),c:()=>n.clear(),i:()=>n.init(),t:()=>n.template(),v:()=>n.version()};try{n[e]?(r("info",`Executing command '${e}'...`),await n[e]()):(r("error",`Unknown command '${e}'. Use 'minimaz help' to see available commands.`),O())}catch(s){r("error",s instanceof Error?process.env.DEBUG?s.stack??s.message:s.message:String(s)),process.exit(1)}}Wt();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimaz-cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Minimal project initializer and builder CLI",
5
5
  "author": "MrZeller",
6
6
  "license": "MIT",