minimaz-cli 0.4.1 → 0.5.1

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.
package/README.md CHANGED
@@ -1,24 +1,10 @@
1
- # Minimaz CLI 🎄
1
+ # Minimaz CLI
2
2
 
3
3
  **Minimaz** is a minimal, low-dependency static site builder and project initializer focused on speed, simplicity, and clean output.
4
4
 
5
- ## 🚀 Features
6
-
7
- * 📁 Initialize projects from templates
8
- * 🧩 Save, list, and delete custom templates
9
- * 📝 Supports HTML, CSS, JS, and TypeScript (.ts → .js)
10
- * 🧹 Minifies HTML, CSS, JS, and TS (compiled & minified)
11
- * ⚙️ Configurable with a `minimaz.config.json` file
12
- * ➕ Supports concatenation of additional scripts and styles
13
- * 🪄 Optional path replacements for asset links
14
- * 🪶 Lightweight and fast — ideal for small static or utility projects
15
- * 🔥 Usable with `minimaz` or its alias `mz`
16
- * 💻 NPM integration and optional Git repository initialization
17
- * ⏱ Interactive prompts with 60s timeout
18
-
19
5
  ## 📦 Installation
20
6
 
21
- Run directly with `npx` without global install:
7
+ Run directly with `npx` or as global module:
22
8
 
23
9
  ```bash
24
10
  npx minimaz init my-site
@@ -27,27 +13,25 @@ npx minimaz build
27
13
  npx minimaz version
28
14
  ```
29
15
 
30
- Or using the alias:
16
+ Or as global module:
31
17
 
32
18
  ```bash
33
- npx mz i my-site
34
- npx mz b
35
- npx mz v
19
+ minimaz init my-site
20
+ cd my-site
21
+ minimaz version
22
+ minimaz build
36
23
  ```
37
24
 
38
25
  > During `npm install`, a post-install script runs to finalize setup automatically.
39
26
 
40
- ## 📁 Project Structure
27
+ ## 📁 Default Project Structure
41
28
 
42
29
  ```txt
43
30
  my-site/
44
- ├── dist/ # Output folder (generated)
45
- ├── public/ # Static assets (images, fonts, etc.)
46
- ├── src/ # HTML, CSS, JS, TS files
31
+ ├── dist/ # Output folder (generated)
32
+ ├── src/ # HTML, CSS, JS, TS files
47
33
  ├── minimaz.config.json
48
- ├── package.json # Optional, created if npm init is used
49
- ├── .gitignore # Default gitignore copied from template
50
- └── ...
34
+ └── ... # Other optional files (es. package.json or .gitignore)
51
35
  ```
52
36
 
53
37
  ## ⚙️ Configuration
@@ -56,52 +40,38 @@ Customize your build using a `minimaz.config.json` file:
56
40
 
57
41
  ```json
58
42
  {
59
- outDir: "dist",
60
- bundling: {
61
- css: {
62
- enabled: true,
63
- outFile: "styles.css"
43
+ "input": {
44
+ "dir": "./src",
45
+ "mapping": {
46
+ "pages": "",
47
+ "public": "",
64
48
  },
65
- js: {
66
- enabled: true,
67
- outFile: "scripts.js"
49
+ "externals": {
50
+ "node_modules/bootstrap-icons/font/fonts": "public/fonts"
68
51
  },
69
- outDir: ""
70
- },
71
- minify: {
72
- "html": true,
73
- "css": true,
74
- "js": true,
75
- "ts": true
76
-
52
+ "exclude": []
77
53
  },
78
-
79
- replace: {
80
- "../public/": "public/"
81
- },
82
-
83
- styles: [
84
- "style.css",
85
- "style-2.css"
86
- ],
87
-
88
- scripts: [
89
- "script.js",
90
- "script-2.js"
91
- ],
92
-
93
- folders: {
94
- src: "",
95
- public: "public"
54
+ "output": {
55
+ "dir": "./dist",
56
+ "replace": {
57
+ "../public/": "/public/",
58
+ },
59
+ "css": {
60
+ "bundling": true,
61
+ "minify": true
62
+ },
63
+ "js": {
64
+ "bundling": true,
65
+ "minify": true
66
+ },
67
+ "html": {
68
+ "minify": true
69
+ }
96
70
  }
97
71
  }
98
72
  ```
99
73
 
100
- * styles (optional): array of .css files to include in the build, can be inside src, node_modules, or any absolute/relative path on your system.
101
- * scripts (optional): array of .js files to include in the build, can also point outside src.
102
- * If omitted, fallback defaults are style.css and script.js.
103
- * `bundling.css` / `bundling.js`: controls whether listed CSS/JS files are concatenated into a single `style.css` / `script.js`.
104
- * `minify.html`, `minify.css`, `minify.js`, `minify.ts`: enable minification for the corresponding file types. TypeScript files are compiled to JS before minification.
74
+ + Bundling: Scans your files for import or require statements to create a dependency graph, then merges that code into a single file (or a few files) to reduce network requests.
105
75
 
106
76
  **Tip**: Using external paths is useful for including library CSS/JS without copying them into your project.
107
77
 
@@ -170,6 +140,13 @@ Notes:
170
140
  * If specified folder does not exist, you can choose to use the current folder instead.
171
141
  * Errors are thrown if operations fail or are cancelled.
172
142
 
143
+ # -----------------------------
144
+ # Validate
145
+ # -----------------------------
146
+ minimaz validate --path=/path/to/file
147
+
148
+ Validates HTML, CSS, JS, TS, JSON files
149
+
173
150
  # -----------------------------
174
151
  # Version
175
152
  # -----------------------------
package/bin/cli.js CHANGED
@@ -1,19 +1,18 @@
1
1
  #!/usr/bin/env node
2
- var $t=Object.defineProperty;var u=(t,e)=>()=>(t&&(e=t(t=0)),e);var Pt=(t,e)=>{for(var i in e)$t(t,i,{get:e[i],enumerable:!0})};import d from"fs-extra";import h from"path";import K from"clean-css";import{minify as jt}from"html-minifier-terser";import{minify as q}from"terser";import{transform as Ct,build as Et}from"esbuild";async function M(){let t=await L(),e=h.resolve(f(),t.outDir);await O(e),await d.ensureDir(e);let i={outDir:Rt(t,e),css:[],js:[]};if(await d.ensureDir(i.outDir),!t.folders||Object.keys(t.folders).length===0){s("warn","No folders defined in config. Nothing to build.");return}for(let[n,o]of Object.entries(t.folders))s("debug",`Building folder: ${n} -> /${o}`),await Dt(f([n]),h.join(e,o),t,i);t.styles?.length&&await V(e,t.styles,i,t),t.scripts?.length&&await V(e,t.scripts,i,t),t.bundling?.css&&await Ft(i.css,!!t.minify?.css,i.outDir),t.bundling?.js&&await Ot(i.js,!!t.minify?.js,i.outDir),s("success",`Build completed. Output saved in /${t.outDir}`)}async function Dt(t,e,i,n){if(!await d.pathExists(t)){s("warn",`Folder not found: ${t}`);return}await G(t,e,i,n),s("success",`Processed folder: ${t} -> /${e}`)}async function G(t,e,i,n){await d.ensureDir(e);for(let o of await z(t)){let r=h.join(t,o),a=h.join(e,o),l=await d.stat(r);if(s("debug",`Found ${l.isDirectory()?"DIRECTORY":"FILE"}: ${o}`),l.isDirectory()){await G(r,a,i,n);continue}let y=await B(r,i.replace);if(y.length>0){let m=h.extname(r).toLowerCase();await Q({src:r,dest:a,content:y,ext:m},i,n)}}}async function Q(t,e,i){switch(s("debug",`Processing file: ${t.src}`),t.ext){case".html":await St(t,e);break;case".css":{await zt(t,i.css,!!e.bundling?.css,!!e.minify?.css);break}case".js":{await X(t,i.js,!!e.bundling?.js,!!e.minify?.js);break}case".tsx":case".ts":{await Tt(t,i.js,!!e.bundling?.js,!!e.minify?.js);break}default:await d.copy(t.src,t.dest)}}async function St(t,e){let i=/<script([^>]*)>([\s\S]*?)<\/script>/gi,n=0,o="",r;for(;(r=i.exec(t.content))!==null;){let[a,l,y]=r;if(o+=t.content.slice(n,r.index),n=r.index+a.length,/src=/i.test(l)){o+=a;continue}let m=(l.match(/type=["']([^"']+)["']/i)?.[1]||"").toLowerCase(),p=/module/i.test(m),S=/nomodule/i.test(l);if(m==="application/json")try{let c=JSON.stringify(JSON.parse(y));o+=`<script${l}>${c}</script>`}catch(c){s("warn",`Invalid JSON in ${t.src}: ${c}`),o+=a}else if(m===""||m==="text/javascript"||p||S)try{let c=await q(y,{format:{semicolons:!0},module:p});o+=`<script${l}>${c.code||""}</script>`}catch(c){s("warn",`JS minify error in ${t.src}: ${c}`),o+=a}else o+=a}o+=t.content.slice(n),e.minify?.html&&(o=await jt(o,{collapseWhitespace:!0,removeComments:!0,minifyCSS:e.minify.css,minifyJS:!1})),await d.outputFile(t.dest,o)}async function zt(t,e,i,n){if(i)e.push(t.content);else{let o=t.content;if(n){let r=new K().minify(t.content);r.warnings.length&&r.warnings.forEach(a=>s("warn",a)),o=r.styles}await d.outputFile(t.dest,o)}}async function X(t,e,i,n){if(/require\s*\(|module\.exports|exports\./.test(t.content)&&s("warn","CommonJS detected consider converting to ESM"),i)e.push(t.content);else{let o=t.content;n&&(o=(await q(o)).code??""),await d.outputFile(t.dest,o)}}async function Tt(t,e,i,n){/require\s*\(|module\.exports|exports\./.test(t.content)&&s("warn",`CommonJS detected in ${t.src}, consider converting to ESM`);let o=t.ext===".ts"?"ts":"tsx",a=(await Ct(t.content,{loader:o,target:"es2020",format:"esm",sourcemap:!1})).code,l=t.dest.replace(/\.(ts|tsx)$/i,".js");await X({src:t.src,dest:l,content:a,ext:"js"},e,i,n)}async function V(t,e,i,n){s("info","Processing externals...");for(let o of e){let r=f([o]);if(!await d.pathExists(r)){s("warn",`External not found: ${o}`);continue}if((await d.stat(r)).isDirectory()){s("debug",`Processing external folder: ${o}`),await G(r,t,n,i);continue}s("debug",`Processing external file: ${o}`);let l=h.extname(r).toLowerCase(),y=await B(r,n.replace);await Q({src:r,dest:h.join(i.outDir,h.basename(r)),content:y,ext:l},n,i)}}async function Ft(t,e,i){if(!t.length)return;let n=t.join("");if(e){let o=new K().minify(n);o.warnings.length&&o.warnings.forEach(r=>s("warn",r)),n=o.styles}await d.outputFile(h.join(i,"style.css"),n)}async function Ot(t,e,i){if(t.length)try{let n=await Et({stdin:{contents:t.join(`
3
- `),resolveDir:i,loader:"js",sourcefile:"bundle.js"},bundle:!0,format:"esm",minify:e,sourcemap:!1,write:!1});await d.outputFile(h.join(i,"script.js"),n.outputFiles[0].text),s("success",`JS bundle written to /${i}/script.js`)}catch(n){s("warn",`ESBuild JS bundle failed: ${n}`)}}function Rt(t,e){return t.bundling?.outDir?h.join(e,t.bundling.outDir):e}var Z=u(()=>{"use strict";w()});import tt from"fs-extra";async function J(t,e){let i=f([t]);if(await tt.pathExists(i))throw new Error(`Target directory '${i}' already exists.`);let n=await it(e.template);s("debug",`Copying template from '${n}' to '${i}'`),await tt.copy(n,i),s("debug","Initializing minimaz.config.json..."),await j(R,[i,"minimaz.config.json"],!1),U(e.npm)&&await Mt(i,t),U(e.git)&&await kt(t,i,e.gitprovider),s("success",`Project '${t}' created using template '${e.template}'.`)}async function kt(t,e,i,n="origin"){i||(i=await P("Select a provider or paste a url to connect your existing repo (cli tools needed) [LOCAL/github/gitlab]:","local")),i=i.toLowerCase().trim(),s("info","Initializing Git repository..."),s("debug","Running git init..."),await E("git",["init"],e),i&&i!=="false"&&i!=="local"?await It(t,e,i,n):s("info","Git repository initialized locally. No remote linked."),s("debug","Initializing gitignore..."),await j(st,[e,".gitignore"]),s("success","Git repository initialized.")}async function It(t,e,i,n="origin"){if(i==="local"){s("info","Using local Git repository only. No remote linked.");return}if(/^https?:\/\//.test(i)||i.startsWith("git@")){s("info",`Connecting existing remote '${i}'`),await E("git",["remote","add",n,i],e);return}if(i==="github"){s("info",`Creating GitHub repository '${t}'`),await E("gh",["repo","create",t,"--private","--source=.","--remote",n],e);return}if(i==="gitlab"){s("info",`Creating GitLab repository '${t}'`);let o=process.env.GITLAB_USER;if(!o)throw new Error("GITLAB_USER environment variable not set");await E("glab",["repo","create",t,"--source=."],e),await E("git",["remote","add",n,`git@gitlab.com:${o}/${t}.git`],e);return}throw new Error(`Unsupported git provider or remote: '${i}'`)}async function Mt(t,e){s("info","Initializing NPM..."),await j({name:e,...nt},[t,"package.json"]),s("debug","Running npm install..."),await E("npm",["i"],t)}var et=u(()=>{"use strict";w()});function k(t){if(t){let e=A[t];if(!e){console.log(`No help found for command: ${t}
4
- `);return}if(console.log(e.usage,`
5
- ${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:
6
- `);for(let e of Object.values(A)){if(console.log(e.usage,`
7
- ${e.description}`),e.options){console.log(" Options:");for(let[i,n]of Object.entries(e.options))console.log(` ${i} ${n}`)}console.log("")}}var ot=u(()=>{"use strict";w()});import v from"fs-extra";import D from"path";async function N(t,e){let i=await _();if(t.list)return await Jt(i);if(t.delete)return await Lt(i,t.delete);if(await Ut(i,e),t.update)return typeof t.update=="string"&&t.update.trim()?await Gt(i,t.update.trim()):await Bt(i)}async function Gt(t,e){let i=f([]),n=D.join(t,e);if(!await v.pathExists(n))throw new Error(`Template '${e}' not found in ~/.minimaz/templates`);if(!(await P(`Update '${e}' with current directory? [Y/n]:`,"y")).startsWith("y")){s("info","Update cancelled.");return}try{await v.copy(i,n,{overwrite:!0}),s("success",`Template '${e}' updated from current directory.`)}catch{throw new Error(`Failed to update '${e}'`)}}async function Bt(t){let e=await I(),i=await z(e);if(!(await P("Update local templates overwriting them with defaults? [Y/n]:","y")).startsWith("y")){s("info","Update cancelled.");return}try{for(let n of i){let o=D.join(e,n),r=D.join(t,n);await v.copy(o,r,{overwrite:!0}),s("success",`Updated '${n}'`)}s("info","\u2728 All templates and files updated successfully.")}catch(n){throw new Error(`Update failed: ${n.message}`)}}async function Lt(t,e){let i=D.join(t,e);if(!await v.pathExists(i))throw new Error(`Template not found: ${e}`);if(!(await P(`Confirm delete '${e}'? [Y/n]:`,"y")).startsWith("y")){s("info","Delete cancelled.");return}try{await v.remove(i),s("success",`Template '${e}' deleted.`)}catch(n){throw new Error(`Delete error: ${n.message}`)}}async function Ut(t,e){let i=f(e?[e]:[]);if(!await v.pathExists(i))if(s("warn",`Path not found: ${i}`),(await P("Use current directory instead? [Y/n]:","y")).startsWith("y"))i=process.cwd();else throw new Error("Operation cancelled.");try{await v.ensureDir(t);let n=D.join(t,D.basename(i));if(await v.pathExists(n)&&!(await P(`Template '${D.basename(n)}' already exists. Overwrite? [y/N]:`,"n")).startsWith("y")){s("info","Save cancelled.");return}await v.copy(i,n,{overwrite:!0}),s("success",`Template saved to ${n}`)}catch(n){throw new Error(`Failed to save template: ${n.message}`)}}async function Jt(t){let e=await z(t);if(e.length===0){s("info","No global templates available.");return}s("info","Available global templates:");for(let i=0;i<e.length;i++)console.log(`${i} - ${e[i]}`)}var rt=u(()=>{"use strict";w()});async function W(){O()}var at=u(()=>{"use strict";w()});async function H(){let t=f(["package.json"]),{version:e}=await lt(t);if(typeof e!="string")throw new Error("Invalid or missing version in package.json");console.log("==========================================",`
8
- `,`minimaz-cli version: ${e}`,`
9
- `,"==========================================")}var ct=u(()=>{"use strict";w()});import T from"path";import b from"fs-extra";import{homedir as At}from"os";async function F(t){s("debug",""+t);let e=T.join(At(),".minimaz");await b.pathExists(e)?s("info","~/.minimaz already exists. Skipping..."):await r();let i=await I();if(!await b.pathExists(i)){s("error","Default templates directory not found. Try reinstalling minimaz or open an issue on github");return}let n=T.join(e,"templates");await b.pathExists(n)?s("info","~/.minimaz/templates already exists. Skipping..."):await a(),await l();let o=T.join(e,"settings.json");await y();async function r(){s("info","~/.minimaz doesn't exist. Generating..."),await b.ensureDir(e)}async function a(){await b.ensureDir(n),s("success",`Created templates directory at ${n}`)}async function l(){s("info","Checking default templates...");let m=await b.readdir(i);if(m.length===0){s("warn","Default templates directory is empty");return}for(let p of m){let S=T.join(i,p),c=T.join(n,p),Y=await b.pathExists(c);if(Y&&!t){s("info",`Template '${p}' already exists. Skipping...`);continue}await b.copy(S,c,{overwrite:t}),Y&&t?s("success",`Overwritten template '${p}'.`):s("success",`Copied template '${p}'.`)}}async function y(){let m=await gt(n);if(!await b.pathExists(o)||t){await j(m,[o]),t&&await b.pathExists(o)?s("success",`Overwritten settings.json at ${o}`):s("success",`Created settings.json at ${o}`);return}let p;try{p=await b.readJson(o)}catch{s("warn","Failed to read settings.json. Recreating from template..."),await j(m,[o]);return}let S=!1;for(let c of Object.keys(m))c in p||(p[c]=m[c],s("warn",`Added missing key '${c}' to settings.json`),S=!0);for(let c of Object.keys(p))c in m||s("warn",`Unknown key '${c}' found in settings.json`);S?(await j(p,[o]),s("success","Updated settings.json to match template")):s("info","settings.json is valid and up-to-date")}}var mt=u(()=>{"use strict";w()});var pt=u(()=>{"use strict"});import Nt from"readline";import g from"fs-extra";import x from"path";import _t from"cross-spawn";import{homedir as Wt}from"os";import{execSync as Ht}from"child_process";function ut(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 o=n.replace(/^-+/,""),r=t[i+1];r&&!r.startsWith("-")?(e[o]=r,i++):e[o]=!0}return e}function P(t,e=""){return new Promise(i=>{let n=Nt.createInterface({input:process.stdin,output:process.stdout}),o=setTimeout(()=>{n.close(),i(e)},6e4);n.question(`\u2753 ${t} `,r=>{clearTimeout(o),n.close(),i(r.trim()||e)}),n.on("SIGINT",()=>{clearTimeout(o),n.close(),process.exit(130)})})}function Yt(t,e={}){return Object.entries(e).reduce((i,[n,o])=>{let r=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(r,"gi");return i.replace(a,o)},t)}async function B(t,e){try{let i=await g.readFile(t,"utf8");return e&&(i=Yt(i,e)),i}catch(i){return s("error",`Failed to read file ${t}: ${i.message}`),""}}async function dt(){s("debug","Getting global node modules path...");try{let t=Ht("npm config get prefix",{encoding:"utf8"}).trim();if(!t)throw new Error("Empty npm prefix");return process.platform==="win32"?x.join(t,"node_modules","minimaz-cli"):x.join(t,"lib","node_modules","minimaz-cli")}catch{return process.platform==="win32"?x.join(process.env.APPDATA||"","npm","node_modules","minimaz-cli"):"/usr/local/lib/node_modules/minimaz-cli"}}async function Vt(){s("debug","Checking existence of global Minimaz directory...");let t=x.join(Wt(),".minimaz");if(!await g.pathExists(t))throw new Error(`Global Minimaz folder does not exist.
10
- Run 'minimaz config' to generate it.`);return t}async function _(){s("debug","Getting global templates directory path...");let t=x.join(await Vt(),"templates");if(!await g.pathExists(t))throw new Error("Template directory not found in global directory");return t}async function it(t){s("debug",`Getting template '${t}'directory path...`);let e=x.join(await _(),t);if(!await g.pathExists(e))throw new Error(`Template '${t}' not found.`);return e}async function I(){s("debug","Getting default templates directory path...");let t=x.join(await dt(),"templates");if(!await g.pathExists(t))throw new Error("Default template folder not found");return t}function E(t,e,i){return s("debug",`Running: ${t} ${e.join(" ")}`),new Promise((n,o)=>{let r=_t(t,e,{cwd:i,stdio:"inherit"});r.on("error",o),r.on("close",a=>a===0?n():o(new Error(`${t} exited with code ${a}`)))})}async function j(t,e,i=!0){s("debug","Creating file from template...");let n=x.resolve(...e),o="";if(t!==void 0)if(typeof t=="string")o=t.endsWith(`
2
+ import{transform as fe}from"esbuild";import{cp as Vt,lstat as Yt,mkdir as ot,readdir as Kt,readFile as it,rm as Qt,stat as qt,writeFile as Xt}from"node:fs/promises";import{dirname as Zt}from"node:path";var Bt={error:"\x1B[31m[ --- ERROR ----- ] \x1B[0m",warn:"\x1B[33m[ --- WARN ------ ] \x1B[0m",success:"\x1B[32m[ --- SUCCESS --- ] \x1B[0m",info:"\x1B[34m[ --- INFO ------ ] \x1B[0m",debug:"\x1B[90m[ --- DEBUG ----- ] \x1B[0m"};function Nt(t=new Date){let e=p=>p<10?"0"+p:""+p,r=t.getFullYear(),o=e(t.getMonth()+1),n=e(t.getDate()),a=e(t.getHours()),s=e(t.getMinutes()),c=e(t.getSeconds());return`${r}-${o}-${n} ${a}:${s}:${c}`}var rt=()=>process.env.VERBOSE==="true";function _t(t){return Array.isArray(t)?t:[t]}function Ht(t,e){let r=Bt[t]+e;if(t==="error"){console.error(r);return}if(t==="warn"){console.warn(r);return}console.log(r)}function Jt(){return rt()?`[${Nt()}] `:""}function E(t,e,r=!1,o=!1){let n=rt();if(o&&!n)return;let a=_t(e);for(let s=0;s<a.length;s++){let c=a[s];if(r){console.log(n?`${Jt()}${c}`:c);continue}Ht(t,c)}}var i={debug(t){E("debug",t,!1,!0)},default(t){E("info",t,!0)},error(t){E("error",t)},info(t){E("info",t)},success(t){E("success",t,!1)},verbose(t){E("info",t,!0,!0)},warn(t){E("warn",t)}};async function m(t){try{return await qt(t),!0}catch{return!1}}async function L(t){if(!await m(t))throw new Error(`NOT FOUND: "${t}" does not exist`);try{let r=await it(t,"utf8");return JSON.parse(r)}catch(r){let o=r instanceof Error?r.message:String(r);throw new Error(`PARSE ERROR: Failed to parse JSON in "${t}" - ${o}`,{cause:r})}}async function y(t){return i.debug(`Reading directory: ${t}`),await m(t)?await Kt(t):(i.warn(`Directory does not exist: ${t}`),[])}async function I(t){await Qt(t,{recursive:!0,force:!0})}async function P(t){await ot(t,{recursive:!0})}async function $(t,e,r=!1){await Vt(t,e,{recursive:!0,force:r,errorOnExist:!r})}async function x(t,e,r){let o=Zt(t);await ot(o,{recursive:!0}),await Xt(t,e,r||"utf8")}async function T(t){return Yt(t).then(e=>e.isDirectory()).catch(()=>!1)}async function F(t){try{return await it(t,"utf8")}catch(e){let r=e instanceof Error?e.message:String(e);return i.error(`Failed to read file at "${t}": ${r}`),""}}import{basename as R,dirname as V,extname as S,isAbsolute as A,join as l,normalize as b,resolve as d}from"node:path";var g={globalDir:".minimaz",inputDir:"./src",outputDir:"./dist"},G={input:{dir:g.inputDir,mapping:{pages:"",scripts:"",styles:"",public:""},externals:{"./node_modules/example/fonts":"assets/fonts","https://example.com/library.js":"js/vendor/vue.js"},exclude:["**/test/**","**dev**"]},output:{dir:g.outputDir,replace:{"../public/":"/"},css:{bundling:!0,minify:!0},html:{minify:!0},js:{bundling:!0,minify:!0}}};var U=new Map;import{spawn as re}from"cross-spawn";import{execSync as oe}from"node:child_process";import{homedir as ie}from"node:os";import{createInterface as ne}from"node:readline";import{transform as te}from"esbuild";import{minify as ee}from"html-minifier-terser";async function nt(t,e,r){try{let o=r===".css"?"css":r.includes("ts")?"ts":"js";await te(e,{loader:o,format:"esm",logLevel:"silent"}),i.success(`${o.toUpperCase()} Valid: ${t}`)}catch(o){i.error(`Syntax Error in ${t}:`);let n=o;n.errors&&Array.isArray(n.errors)&&n.errors.forEach(a=>{let s=a.location?.line??"??";i.error(` -> Line ${s}: ${a.text}`)})}}async function st(t,e){try{await ee(e,{continueOnParseError:!1,caseSensitive:!0}),i.success(`HTML Valid: ${t}`)}catch(r){let o=r instanceof Error?r.message:String(r);i.error(`HTML Error [${t}]: ${o}`)}}var W=class extends Error{errors;constructor(e){super("Config validation error"),this.name="ConfigValidationError",this.errors=e}};function Y(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.values(t).every(e=>typeof e=="string")}function B(t,e){try{let r=JSON.parse(e);if(typeof r!="object"||r===null)throw new Error("Invalid config root object");let o=r,n=[];if(!o.input)n.push("Missing 'input' section");else{let{input:s}=o;typeof s.dir!="string"&&n.push("input.dir must be a string"),Y(s.mapping)||n.push("input.mapping must be a valid key-value record of strings"),s.externals!==void 0&&!Y(s.externals)&&n.push("input.externals must be a valid key-value record of strings"),s.exclude!==void 0&&!Array.isArray(s.exclude)&&n.push("input.exclude must be an array of strings")}if(!o.output)n.push("Missing 'output' section");else{let{output:s}=o;typeof s.dir!="string"&&n.push("output.dir must be a string"),s.replace!==void 0&&!Y(s.replace)&&n.push("output.replace must be a valid key-value record of strings"),["css","js"].forEach(p=>{let u=s[p];(!u||typeof u.bundling!="boolean"||typeof u.minify!="boolean")&&n.push(`output.${p} must contain 'bundling' (boolean) and 'minify' (boolean)`)}),(!s.html||typeof s.html.minify!="boolean")&&n.push("output.html must contain 'minify' (boolean)")}let a=Object.keys(G);if(Object.keys(o).forEach(s=>{a.includes(s)||i.warn(`Unknown configuration key: '${s}' in ${t}`)}),n.length>0)throw new W(n);i.success("Config: valid")}catch(r){i.error(`Config Error in ${t}:`),r instanceof W?r.errors.forEach(o=>{i.error(` -> ${o}`)}):r instanceof SyntaxError?i.error(` -> Invalid JSON syntax: ${r.message}`):r instanceof Error?i.error(` -> ${r.message}`):i.error(" -> Unknown error")}}function h(t,e=""){return new Promise(r=>{let o=ne({input:process.stdin,output:process.stdout}),n=setTimeout(()=>{o.close(),r(e)},6e4);o.question(`[QUESTION] ${t}`,a=>{clearTimeout(n),o.close(),r(a.trim()||e)}),o.on("SIGINT",()=>{clearTimeout(n),o.close(),process.exit(130)})})}function O(t,e={}){return Object.entries(e).reduce((r,[o,n])=>{let a=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(a,"g");return r.replace(s,n)},t)}async function D(t,e){try{let r=b(t),o;return U.has(r)?(o=U.get(r),i.debug(`Cache hit: ${r}`)):(o=await F(r),U.set(r,o),i.debug(`Cache miss (Disk read): ${r}`)),e&&(o=O(o,e)),o}catch(r){let o=r instanceof Error?r.message:String(r);return i.error(`Failed to read file ${t}: ${o}`),""}}function at(){i.debug("Getting global node modules");try{let t=oe("npm config get prefix",{encoding:"utf8"}).trim();if(!t)throw new Error("Empty npm prefix");return process.platform==="win32"?l(t,"node_modules","minimaz-cli"):l(t,"lib","node_modules","minimaz-cli")}catch{return process.platform==="win32"?l(process.env.APPDATA||"","npm","node_modules","minimaz-cli"):"/usr/local/lib/node_modules/minimaz-cli"}}async function se(){i.debug("Checking existence of global Minimaz directory");let t=l(ie(),g.globalDir);if(!await m(t))throw new Error('Global Minimaz folder does not exist.Run "minimaz config" to generate it');return t}async function K(){i.debug("Getting global templates directory");let t=l(await se(),"templates");if(!await m(t))throw new Error("Template directory not found in global directory");return t}async function ct(t){i.debug(`Getting template "${t}"directory`);let e=l(await K(),t);if(!await m(e))throw new Error(`Template "${t}" not found`);return e}async function N(){i.debug("Getting default templates directory");let t=l(at(),"templates");if(!await m(t))throw new Error("Default template folder not found");return t}function j(t,e,r){return i.debug(`Running: ${t} ${e.join(" ")}`),new Promise((o,n)=>{let a=re(t,e,{cwd:r,stdio:"inherit"});a.on("error",n),a.on("close",s=>s===0?o():n(new Error(`${t} exited with code ${s}`)))})}async function C(t,e,r=!0){i.debug("Creating file from template");let o=d(...e),n="";if(t!==void 0)if(typeof t=="string")n=t.endsWith(`
11
3
  `)?t:`${t}
12
- `;else if(typeof t=="object"&&t!==null)o=`${JSON.stringify(t,null,2)}
13
- `;else throw new Error("Unsupported template type. Must be string or object.");try{if(!i&&await g.pathExists(n)){s("info",`File already exists at '${n}', skipping creation.`);return}await g.outputFile(n,o)}catch(r){let a=r instanceof Error?r.message:String(r);throw new Error(`Failed to create file at '${n}': ${a}`)}}async function O(t){s("debug","Removing outDir...");let e=t?x.isAbsolute(t)?t:f([t]):x.resolve(process.cwd(),(await L()).outDir??"dist"),i=process.cwd();if(e===i||e.length<=i.length)throw new Error(`Refusing to delete unsafe directory: ${e}`);if(!await g.pathExists(e)){s("debug",`No dist folder found: ${e}`);return}await g.remove(e),s("success",`Cleared ${e}`)}async function L(){let t=f(["minimaz.config.json"]),e;if(await g.pathExists(t)?(e=await g.readJson(t),s("success","Loaded config from minimaz.config.json")):(s("warn","No minimaz.config.json found. Using default config"),e=JSON.parse(JSON.stringify(R))),!e.outDir||typeof e.outDir!="string")throw new Error("Invalid config: outDir must be a string");if(!e.folders||typeof e.folders!="object")throw new Error("Invalid config: folders must be an object");return e.bundling??={outDir:""},e.minify??={},e.replace??={},e}function ft(t){s("debug","Initializing environments variables..."),process.env.VERBOSE=t?"true":"false",s("debug",`VERBOSE = ${process.env.VERBOSE}`),process.env.CLI_WORKDIR=process.cwd(),s("debug",`CLI_WORKDIR = ${process.env.CLI_WORKDIR}`)}function f(t=[]){return s("debug","Resolving current path..."),x.resolve(process.env.CLI_WORKDIR??process.cwd(),...t)}async function lt(t){if(!await g.pathExists(t))throw new Error(`NOT FOUND: '${t}' does not exist`);return await g.readJson(t)}async function z(t){return s("debug",`Reading elements of ${t}...`),await g.pathExists(t)?await g.readdir(t):(s("warn",`Directory does not exist: ${t}`),[])}function C(t,e){return`${e}${t}${$.reset}`}async function gt(t){return{createdAt:new Date().toISOString(),templatesPath:t,npmGlobalPath:await dt()}}function U(t){if(t===void 0)return!1;if(typeof t=="boolean")return t;let e=t.toLowerCase();return e==="true"||e===""}var wt=u(()=>{"use strict";w()});var nt,st,R,A,$,yt,ht=u(()=>{"use strict";w();nt={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"}},st=`
14
- node_modules
15
- dist
4
+ `;else if(typeof t=="object"&&t!==null)n=`${JSON.stringify(t,null,2)}
5
+ `;else throw new Error("Unsupported template type. Must be string or object");try{if(!r&&await m(o)){i.info(`File already exists at "${o}", skipping`);return}await x(o,n)}catch(a){let s=a instanceof Error?a.message:String(a);throw new Error(`Failed to create file at "${o}": ${s}`,{cause:a})}}async function _(t){i.debug("Output Directory: removing");let e=t?A(t)?t:f([t]):d(process.cwd(),(await Q()).output.dir??g.outputDir),r=process.cwd();if(e===r||e.length<=r.length)throw new Error(`Refusing to delete unsafe directory: ${e}`);if(!await m(e)){i.debug(`No output.dir folder found: ${e}`);return}await I(e),i.success("Output Directory: removed")}async function Q(){i.info("Loading minimaz.config.json");let t=f(["minimaz.config.json"]);if(!await m(t))throw new Error("minimaz.config.json not found");try{let e=await F(t);B(t,e);let r=JSON.parse(e);return i.success("Loaded config from minimaz.config.json"),r}catch(e){let r=e instanceof Error?e.message:String(e);throw new Error(`Failed to load configuration: ${r}`,{cause:e})}}function f(t=[]){i.debug("Current path: resolving");let e=d(process.env.CLI_WORKDIR??process.cwd(),...t);return i.debug(`Current path: ${e}`),e}function pt(t){return{createdAt:new Date().toISOString(),templatesPath:t,npmGlobalPath:at()}}function q(t){if(t===void 0)return;if(typeof t=="boolean")return t;let e=t.toLowerCase();return!(e==="false"||e==="0"||e==="n")}import{build as ae}from"esbuild";async function mt(t,e,r,o,n,a,s){if(i.debug(`Processing CSS: ${t.src}`),o){let c=await ae({stdin:{contents:t.content,resolveDir:d(t.src,".."),loader:"css",sourcefile:t.src},bundle:!0,write:!1,metafile:!0,minify:n,charset:"utf8",legalComments:"none",external:["*.woff","*.woff2","*.ttf","*.otf","*.eot","*.svg","*.png","*.jpg","*.jpeg","*.gif","*.webp"],target:["chrome80","safari13","firefox70","edge79"]}),p=c.outputFiles[0]?.text??"";if(s&&(p=O(p,s)),a){for(let u of Object.values(a))if(u.startsWith("/")){let w=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),v=new RegExp(`(\\.\\.\\/|\\.\\/)+${w}`,"g");p=p.replace(v,u)}}if(c.metafile){let u=b(d(t.src));for(let w of Object.keys(c.metafile.inputs)){let v=b(d(w));v!==u&&r.add(v)}}e.chunks.push(p),await x(t.dest,p)}else{let c=t.content;n&&(c=await ce(c)),await x(t.dest,c)}}async function ce(t){return M(t,{loader:"css",minify:!0,charset:"utf8",sourcemap:!1,legalComments:"none",target:["chrome80","safari13","firefox70","edge79"]},"MinifyCSS")}import{minify as pe}from"html-minifier-terser";async function lt(t,e){i.debug(`Processing HTML: ${t.src}`);let r=t.content;e.output?.html?.minify&&(r=await me(r,t.src)),await x(t.dest,r)}async function me(t,e="unknown"){if(typeof t!="string")throw new Error(`[MinifyHTML] Input for ${e} must be a string`);let r=t.trim();if(!r)return"";try{return await pe(r,{collapseWhitespace:!0,removeComments:!0,removeRedundantAttributes:!0,removeScriptTypeAttributes:!0,removeStyleLinkTypeAttributes:!0,useShortDoctype:!0,minifyJS:!0,minifyCSS:!0,processConditionalComments:!0,ignoreCustomComments:[/^!/],caseSensitive:!0})}catch(o){let n=o instanceof Error?o.message:String(o);return i.error(`[MinifyHTML Failed in ${e}]
6
+ ${n}`),t}}import{build as le}from"esbuild";async function ut(t,e,r,o,n,a,s){if(/require\s*\(|module\.exports|exports\./.test(t.content)&&i.warn(`CommonJS detected in ${t.src}. Esbuild will attempt to convert, but ESM is recommended.`),o){let c=await gt(t,n,r,a,s);e.chunks.push(c),await x(t.dest,c)}else{let c=t.content;n&&(c=await ue(c,!0)),await x(t.dest,c)}}async function ft(t,e,r,o,n,a,s){let c=t.dest.replace(/\.(ts|tsx)$/i,".js");if(o){let p=await gt(t,n,r,a,s);e.chunks.push(p),await x(c,p)}else{let p=t.ext===".tsx"?"tsx":"ts",u=await M(t.content,{loader:p,target:"es2022",format:"esm",minify:n},"ProcessTS");await x(c,u)}}async function gt(t,e,r,o,n){let a=t.ext===".tsx"?"tsx":t.ext===".ts"?"ts":"js",s=await le({stdin:{contents:t.content,resolveDir:d(t.src,".."),loader:a,sourcefile:t.src},bundle:!0,write:!1,metafile:!0,format:"esm",platform:"browser",target:"es2022",minify:e,splitting:!1,treeShaking:!0,mainFields:["module","main"],conditions:["import","browser"],footer:{js:""},legalComments:"none"}),c=s.outputFiles[0]?.text??"";if(n&&(c=O(c,n)),o){for(let p of Object.values(o))if(p.startsWith("/")){let u=p.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),w=new RegExp(`(\\.\\.\\/|\\.\\/)+${u}`,"g");c=c.replace(w,p)}}if(s.metafile){let p=b(d(t.src));for(let u of Object.keys(s.metafile.inputs)){let w=b(d(u));w!==p&&r.add(w)}}return c}async function ue(t,e=!0){return M(t,{loader:"js",format:"esm",minify:e,treeShaking:!0,sourcemap:!1,legalComments:"none",target:"es2022",pure:["console.log","console.debug"]},"MinifyJS")}async function M(t,e,r){if(typeof t!="string")throw new Error(`[${r}] Input must be a string`);let o=t.trim();if(!o)return i.debug(`[${r}] empty input skipped`),"";i.debug(`[${r}] transform start`);try{let{code:n}=await fe(o,{...e,charset:"utf8",logLevel:"silent"});return i.debug(`[${r}] transform success`),n??""}catch(n){let a=n,s=(a.errors||[]).map(c=>`[Line ${c.location?.line??"?"}] ${c.text}`).join(`
7
+ `);return i.error(`[${r} Failed]
8
+ ${s||a.message}`),""}}async function H(t,e,r,o){let n=await y(t),a=f([r.input.dir]),s=f([r.output.dir]),c=d(t);for(let p of n){if(r.input.exclude?.includes(p))continue;let u=l(t,p),w=b(u),k=(r.input.mapping||{})[p],z;if(c===a&&typeof k=="string"?z=l(s,k):z=l(e,p),o.has(w)){i.debug(`Skipping bundled dependency: ${w}`);continue}if(await T(u)){await H(u,z,r,o);continue}await P(V(z));let Ut=await D(u,r.output.replace),Wt=S(u).toLowerCase();await dt({src:u,dest:z,content:Ut,ext:Wt},r,o)}}async function dt(t,e,r){let o={chunks:[],outFile:t.dest};switch(t.ext){case".html":await lt(t,e);break;case".css":await mt(t,o,r,!!e.output?.css?.bundling,!!e.output?.css?.minify,e.input.externals,e.output.replace);break;case".js":await ut(t,o,r,!!e.output?.js?.bundling,!!e.output?.js?.minify,e.input?.externals,e.output?.replace);break;case".ts":case".tsx":await ft(t,o,r,!!e.output?.js?.bundling,!!e.output?.js?.minify,e.input?.externals,e.output?.replace);break;default:await $(t.src,t.dest)}}async function wt(t,e,r,o){i.debug("External: Processing");for(let[n,a]of Object.entries(e)){if(n.startsWith("http")){i.info(`Remote external: ${n} \u2192 ${a}`);continue}let s=f([n]);if(o.has(b(s)))continue;if(!await m(s)){i.warn(`External not found: ${n}`);continue}let c=l(t,a);if(await T(s)){await H(s,c,r,o);continue}let p=await D(s,r.output.replace);await dt({src:s,dest:c,content:p,ext:S(s).toLowerCase()},r,o)}}async function yt(t){await _(t),await P(t)}function ge(t,e){let r=[],o=/import\s+(?:(?:[\w\s{},*]+\s+from\s+)?["'](.+?)["']|["'](.+?)["'])\s*;?/g,a={".css":/@import\s+(?:url\s*\()?\s*["']([^"']+)["']\s*\)?\s*;?/g,".js":o,".ts":o,".tsx":o}[e];if(!a)return[];let s=Array.from(t.matchAll(a));for(let c of s){let p=c[1]||c[2];p&&r.push(p)}return r}async function X(t,e,r,o){let n=await y(t);for(let a of n){if(e.input.exclude?.includes(a))continue;let s=l(t,a);if(await T(s)){await X(s,e,r,o);continue}let c=S(s).toLowerCase();if([".css",".js",".ts",".tsx"].includes(c)){let p=await D(s,o),u=ge(p,c);for(let w of u){let v=d(V(s),w);if(!S(v)){for(let k of[".ts",".js",".css",".tsx"])if(await m(v+k)){v+=k;break}}r.add(b(v))}}}}async function xt(){let t=await Q(),e=f([t.input.dir]),r=f([t.output.dir]);await yt(r);let o=new Set;if((await y(t.input.dir)).length===0){i.error(`Directory ${t.input.dir} is empty`);return}i.info("Discovery: starting"),await X(e,t,o,t.output.replace??{}),i.info("Processing: starting"),await H(e,r,t,o);let a=t.input.externals||{},s=Object.keys(a);s.length>0&&(i.debug(`Processing ${s.length} external resources`),await wt(r,a,t,o)),i.success(`Build completed. Output saved in ${t.output.dir}`)}async function bt(){await _()}import{homedir as de}from"node:os";async function ht(t){if(await m(t)){i.info(`~/${g.globalDir} already exists. Skipping`);return}i.info(`~/${g.globalDir} does not exist. Generating`),await P(t)}async function vt(t){if(await m(t)){i.info(`~/${g.globalDir}/templates already exists, skipping`);return}await P(t),i.success(`Templates directory created at ${t}`)}async function $t(t,e,r){i.info("Checking default templates");let o=await y(t);if(o.length===0){i.warn("No default templates available");return}for(let n of o){let a=l(t,n),s=l(e,n),c=await m(s);if(c&&!r){i.info(`Template "${n}" already exists. Skipping`);continue}await $(a,s,r),c&&r?i.success(`Template "${n}" overwritten`):i.success(`Template "${n}" copied`)}}async function Ct(t,e,r){let o=pt(e);if(!await m(t)||r){await C(o,[t]),await m(t)&&r?i.success(`Overwritten settings.json at ${t}`):i.success(`Created settings.json at ${t}`);return}let n;try{n=await L(t)}catch{i.warn("Failed to read settings.json. Recreating from template"),await C(o,[t]);return}let a=!1;for(let s of Object.keys(o))s in n||(n[s]=o[s],i.warn(`Added missing key "${s}" to settings.json`),a=!0);for(let s of Object.keys(n))s in o||i.warn(`Unknown key "${s}" found in settings.json`);a?(await C(n,[t]),i.success("Updated settings.json")):i.info("settings.json is valid and up-to-date")}async function J(t){i.debug(`Config initialization (overwrite=${t})`);let e=l(de(),g.globalDir);await ht(e);let r=await N();if(!await m(r)){i.error("Default templates directory not found");return}let o=l(e,"templates");await vt(o),await $t(r,o,t);let n=l(e,"settings.json");await Ct(n,o,t)}var Z={build:{usage:"minimaz build | b",description:`Build project into output.dir folder (default: ${g.outputDir})`},clear:{usage:"minimaz clear | c",description:`Clear the output.dir folder (default: ${g.outputDir})`},help:{usage:"minimaz help | h",description:"Show this help message"},init:{usage:"minimaz init | i <project-name>",description:"Create a new project (default: 'minimaz-project')",options:{"--template | -t <template-name>":"Use a global template (default: 'default')"}},template:{usage:"minimaz template | t [path]",description:"Save folder as a template (no path = current folder)",options:{"--list | -l":"List available global templates","--delete | -d <template-name>":"Delete a global template"}},validate:{usage:"minimaz validate",description:"Validate file"},version:{usage:"minimaz version | v",description:"Show Minimaz version"}};function tt(t){if(t){let e=Z[t];if(!e){i.default(`No help found for: ${t}
9
+ `);return}if(i.default([e.usage,`
10
+ ${e.description}`]),e.options){i.default(" Options:");for(let[r,o]of Object.entries(e.options))i.default(` ${r} ${o}`)}i.default("");return}i.default(`Usage:
11
+ `);for(let e of Object.values(Z)){if(i.default([e.usage,`
12
+ ${e.description}`]),e.options){i.default(" Options:");for(let[r,o]of Object.entries(e.options))i.default(` ${r} ${o}`)}i.default("")}}var Et={version:"0.0.1",license:"ISC",type:"commonjs",scripts:{build:"npx mz b",start:`npx mz b && npx serve ${g.outputDir}`},devDependencies:{"minimaz-cli":"latest",serve:"latest"}},Pt=`node_modules
13
+ ${g.outputDir.replace("./","")}
16
14
  .env
17
15
  .vscode
18
- .DS_Store
19
- `.trim(),R={outDir:"dist",bundling:{css:{enabled:!0,outFile:"styles.css"},js:{enabled:!0,outFile:"scripts.js"},outDir:""},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"}},$={reset:"\x1B[0m",red:"\x1B[31m",yellow:"\x1B[33m",green:"\x1B[32m",blue:"\x1B[34m",gray:"\x1B[90m"},yt={error:C("[ --- ERROR ----- ] ",$.red),warn:C("[ --- WARN ------ ] ",$.yellow),success:C("[ --- SUCCESS --- ] ",$.green),info:C("[ --- INFO ------ ] ",$.blue),debug:C("[ --- DEBUG ----- ] ",$.gray)}});function s(t="info",e){let i=process.env.VERBOSE==="true";if(t==="debug"&&!i)return;let o=`${i?C(`[${Kt()}] `,$.gray):""}${yt[t]} ${e}`;switch(t){case"error":console.error(o);break;case"warn":console.warn(o);break;default:console.log(o);break}}function Kt(t=new Date){let e=y=>y.toString().padStart(2,"0"),i=t.getFullYear(),n=e(t.getMonth()+1),o=e(t.getDate()),r=e(t.getHours()),a=e(t.getMinutes()),l=e(t.getSeconds());return`${i}-${n}-${o} ${r}:${a}:${l}`}var bt=u(()=>{"use strict";w()});var w=u(()=>{"use strict";Z();et();ot();rt();at();ct();mt();pt();wt();ht();bt()});var xt={};Pt(xt,{postInstall:()=>qt});async function qt(){try{s("info","Running Post Install..."),await F(!1),s("success","Postinstall: Global templates setup completed")}catch(t){s("error",`Postinstall setup failed: ${t.message}`)}}var vt=u(()=>{"use strict";w()});w();process.env.npm_lifecycle_event==="postinstall"&&(Promise.resolve().then(()=>(vt(),xt)).then(({postInstall:t})=>t()),process.exit(0));async function Qt(){let t=ut(process.argv.slice(2)),e=t._[0]||"",i=t._[1];ft(!!t.v),(e==="help"||t.h||t.help)&&(k(i||(t.h||t.help?e:void 0)),process.exit(0));let n={build:async()=>M(),clear:()=>W(),config:async()=>F(t.overwrite===!0||t.overwrite==="true"),init:async()=>{await J(i||"minimaz-project",{template:t.template||t.t||"default",npm:t.npm,git:t.git,gitremote:t.gitremote,gitprovider:t.gitprovider})},template:async()=>{await N({list:t.l||t.list,delete:t.d||t.delete,update:t.u||t.update})},version:()=>H(),b:()=>n.build(),c:()=>n.clear(),i:()=>n.init(),t:()=>n.template(),v:()=>n.version()};try{n[e]?(s("info",`Executing command '${e}'...`),await n[e]()):(s("error",`Unknown command '${e}'. Use 'minimaz help' to see available commands.`),k())}catch(o){s("error",o instanceof Error?process.env.DEBUG?o.stack??o.message:o.message:String(o)),process.exit(1)}}Qt();
16
+ .DS_Store`;async function St(t,e){i.info("npm: initializing"),await C({name:e,...Et},[t,"package.json"]),await j("npm",["i"],t)}async function we(t,e,r,o="origin"){if(r==="local"){i.info("Using local Git repository");return}if(/^https?:\/\//.test(r)||r.startsWith("git@")){i.info(`Connecting existing remote "${r}"`),await j("git",["remote","add",o,r],e);return}if(r==="github"){i.info(`Creating GitHub repository "${t}"`),await j("gh",["repo","create",t,"--private","--source=.","--remote",o],e);return}if(r==="gitlab"){i.info(`Creating GitLab repository "${t}"`);let n=process.env.GITLAB_USER;if(!n)throw new Error("GITLAB_USER not set");await j("glab",["repo","create",t,"--source=."],e),await j("git",["remote","add",o,`git@gitlab.com:${n}/${t}.git`],e);return}throw new Error(`Unsupported git provider or remote: "${r}"`)}async function jt(t,e,r,o="origin"){r||(r=(await h("Select a provider or paste a url to connect your existing repo (cli tools needed) [LOCAL/github/gitlab]:","local")).toLowerCase().trim()),i.info("Initializing Git repository"),await j("git",["init"],e),r&&r!=="false"&&r!=="local"?await we(t,e,r,o):i.info("Git repository initialized locally"),i.debug("Initializing gitignore"),await C(Pt,[e,".gitignore"]),i.success("Git repository initialized")}async function Tt(t,e){let r=f([t]);if(await m(r))throw new Error(`Target directory "${r}" already exists`);let o=await ct(e.template);i.debug(`Copying template from "${o}" to "${r}"`),await $(o,r),i.debug("Initializing minimaz.config.json"),await C(G,[r,"minimaz.config.json"],!1),(q(e.npm)??(await h("Init NPM? [Y/n]:","y")).toLowerCase().startsWith("y"))&&await St(r,t),(q(e.git)??(await h("Init Git repository? [Y/n]:","y")).toLowerCase().startsWith("y"))&&await jt(t,r,e.gitprovider),i.success(`Project "${t}" created using template "${e.template}"`)}async function Dt(t,e){let r=f([]),o=l(t,e);if(!await m(o))throw new Error(`Template "${e}" not found`);if(!(await h(`Update "${e}" with current directory? [Y/n]:`,"y")).startsWith("y")){i.info("Update cancelled");return}try{await $(r,o,!0),i.success(`Template "${e}" updated`)}catch(n){let a=n instanceof Error?n.message:String(n);throw new Error(`Update template error: ${a}`,{cause:n})}}async function kt(t){let e=await N(),r=await y(e);if(!(await h("Update local templates overwriting them with defaults? [Y/n]:","y")).startsWith("y")){i.info("Update cancelled");return}try{for(let o of r){let n=l(e,o),a=l(t,o);await $(n,a,!0),i.success(`Updated "${o}"`)}i.info("Templates updated successfully")}catch(o){let n=o instanceof Error?o.message:String(o);throw new Error(`Update template error: ${n}`,{cause:o})}}async function zt(t,e){let r=l(t,e);if(!await m(r))throw new Error(`Template not found: ${e}`);if(!(await h(`Confirm delete "${e}"? [Y/n]:`,"y")).startsWith("y")){i.info("Delete cancelled");return}try{await I(r),i.success(`Template "${e}" deleted`)}catch(o){let n=o instanceof Error?o.message:String(o);throw new Error(`Delete template error: ${n}`,{cause:o})}}async function Ft(t,e){let r=f(e?[e]:[]);if(!await m(r))if(i.warn(`Not found: ${r}`),(await h("Use current directory? [Y/n]:","y")).startsWith("y"))r=process.cwd();else throw new Error("Operation cancelled");try{await P(t);let o=l(t,R(r));if(await m(o)&&!(await h(`Template "${R(o)}" exists. Overwrite? [y/N]:`,"n")).startsWith("y")){i.info("Save cancelled");return}await $(r,o,!0),i.success(`Template saved to ${o}`)}catch(o){let n=o instanceof Error?o.message:String(o);throw new Error(`Save template error: ${n}`,{cause:o})}}async function Rt(t){let e=await y(t);if(e.length===0){i.info("No global templates available");return}i.info("Available global templates:");for(let r=0;r<e.length;r++)i.default(`${r} - ${e[r]}`)}async function Ot(t,e){let r=await K();if(t.list)return await Rt(r);if(t.delete)return await zt(r,t.delete);if(await Ft(r,e),t.update)return typeof t.update=="string"&&t.update.trim()?await Dt(r,t.update.trim()):await kt(r)}var Mt=[".js",".cjs",".mjs",".ts",".cts",".mts",".jsx",".tsx",".json",".css"];async function et(t){if(t==="undefined")throw new Error("No target path");let e=A(t)?t:f([t]);if(!await m(e))throw new Error(`Path does not exist: ${e}`);if(await T(e)){let a=await y(e);await Promise.all(a.map(s=>et(l(e,s))))}let r=R(e),o=S(e).toLowerCase(),n=await D(e);if(!n&&(await F(e)).length>0)throw new Error(`Failed to read content from non-empty file: ${e}`);if(r==="minimaz.config.json"){B(e,n);return}if(o===".html"){await st(e,n);return}if(Mt.includes(o)){await nt(e,n,o);return}i.debug(`Skipping: ${e}`)}async function Lt(){let t=f(["package.json"]),e=await L(t);if(typeof e.version!="string")throw new Error("Invalid or missing version in package.json");i.default(e.version)}function It(t){let e={_:[]};for(let r=0;r<t.length;r++){let o=t[r].toLowerCase();if(!o.startsWith("-")){e._.push(o);continue}if(o.startsWith("--")&&o.includes("=")){let[s,c]=o.slice(2).split("=");e[s]=c;continue}let n=o.replace(/^-+/,""),a=t[r+1];a&&!a.startsWith("-")?(e[n]=a,r++):e[n]=!0}return e}function At(t,e){process.env.VERBOSE=t?"true":"false",process.env.CLI_WORKDIR=e??process.cwd(),i.debug(["Initializing environment variables",`CLI_WORKDIR = ${process.env.CLI_WORKDIR}`,`VERBOSE = ${process.env.VERBOSE}`])}async function Gt(){try{i.info("Post install: running"),await J(!1),i.success("Post install: completed")}catch(t){let e=t instanceof Error?t.message:String(t);throw new Error(`Post install: Failed
17
+ ${e}`,{cause:t})}}process.env.npm_lifecycle_event==="postinstall"&&(await Gt(),process.exit(0));async function ye(){let t=It(process.argv.slice(2)),e=t._[0]||"",r=t._[1];At(t.v),(e==="help"||t.help||t.h)&&(tt(r||(t.help||t.h?e:void 0)),process.exit(0));let o={build:async()=>xt(),clear:()=>bt(),config:async()=>J(t.overwrite===!0||t.overwrite==="true"),init:async()=>{await Tt(r||"minimaz-project",{template:t.template||t.t||"default",npm:t.npm,git:t.git,gitremote:t.gitremote,gitprovider:t.gitprovider})},template:async()=>{await Ot({list:t.list||t.l,delete:t.delete||t.d,update:t.update||t.u},r)},validate:async()=>{await et(String(t.path))},version:()=>Lt(),b:()=>o.build(),c:()=>o.clear(),i:()=>o.init(),t:()=>o.template(),v:()=>o.version()};try{o[e]?(i.info(`Executing "${e}"`),await o[e]()):(i.error(`Unknown command "${e}"
18
+ Use "minimaz help" to see available commands`),tt())}catch(n){let a=process.env.DEBUG==="true",s=n instanceof Error?a?n.stack??n.message:n.message:String(n);i.error(s),process.exit(1)}}await ye();export{At as initEnv,It as parseArgs,Gt as postInstall};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimaz-cli",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Minimal project initializer and builder CLI",
5
5
  "author": "MrZeller",
6
6
  "license": "MIT",
@@ -29,16 +29,13 @@
29
29
  "url": "https://github.com/zeller-dev/minimaz-cli/issues"
30
30
  },
31
31
  "dependencies": {
32
- "clean-css": "^5.3.3",
33
32
  "cross-spawn": "^7.0.6",
34
- "fs-extra": "^11.3.0",
35
- "html-minifier-terser": "^7.2.0",
36
- "terser": "^5.44.0",
37
- "esbuild": "^0.25.12"
33
+ "esbuild": "^0.25.12",
34
+ "html-minifier-terser": "^7.2.0"
38
35
  },
39
- "postinstall": "node dist/bin/cli.js",
36
+ "postinstall": "node bin/cli.js",
40
37
  "bin": {
41
38
  "minimaz": "bin/cli.js",
42
39
  "mz": "bin/cli.js"
43
40
  }
44
- }
41
+ }
@@ -1,25 +1,34 @@
1
1
  {
2
- "src": "src",
3
- "dist": "dist",
4
- "public": "public",
5
- "bundling": {
6
- "css": true,
7
- "js": true
2
+ "input": {
3
+ "dir": "./src",
4
+ "mapping": {
5
+ "pages": "",
6
+ "public": "",
7
+ "styles": ""
8
+ },
9
+ "externals": {
10
+ "node_modules/bootstrap-icons/font/fonts": "public/fonts"
11
+ },
12
+ "exclude": []
8
13
  },
9
- "minify": {
10
- "html": true,
11
- "css": true,
12
- "js": true
13
- },
14
- "replace": {
15
- "../public/": "/public/",
16
- "<link rel=\"stylesheet\" href=\"styles/bootstrap-icons.css\">": "",
17
- "../../node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff2": "/public/fonts/bootstrap-icons.woff2",
18
- "../../node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff": "/public/fonts/bootstrap-icons.woff"
19
- },
20
- "folders": {
21
- "public": "public",
22
- "src": "",
23
- "node_modules/bootstrap-icons/font/fonts": "public/fonts"
14
+ "output": {
15
+ "dir": "./dist",
16
+ "replace": {
17
+ "../public/": "/public/",
18
+ "<link rel=\"stylesheet\" href=\"styles/bootstrap-icons.css\">": "",
19
+ "../public/fonts/bootstrap-icons.woff2": "/public/fonts/bootstrap-icons.woff2",
20
+ "../public/bootstrap-icons/font/fonts/bootstrap-icons.woff": "/public/fonts/bootstrap-icons.woff"
21
+ },
22
+ "css": {
23
+ "bundling": true,
24
+ "minify": true
25
+ },
26
+ "js": {
27
+ "bundling": true,
28
+ "minify": true
29
+ },
30
+ "html": {
31
+ "minify": true
32
+ }
24
33
  }
25
34
  }