minimaz-cli 0.2.0 â 0.3.0
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 +84 -33
- package/bin/cli.js +1 -1
- package/package.json +2 -2
- package/src/commands/build.js +1 -1
- package/src/commands/clear.js +1 -1
- package/src/commands/help.js +3 -2
- package/src/commands/init.js +1 -1
- package/src/commands/template.js +1 -1
- package/src/commands/version.js +1 -1
- package/src/index.js +1 -0
- package/src/templates/default/public/favicon.ico +0 -0
- package/src/templates/simple/public/favicon.ico +0 -0
- package/src/utils/constants.js +3 -0
- package/src/utils/functions.js +4 -1
- package/src/utils/logService.js +1 -1
- package/src/utils/postInstall.js +1 -1
- package/src/utils/types.js +0 -0
- package/src/templates/default/minimaz.config.json +0 -26
- package/src/templates/gitignore +0 -2
- package/src/templates/simple/minimaz.config.json +0 -26
- package/src/utils/loadConfig.js +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Minimaz
|
|
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
|
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* ðŠ Optional path replacements for asset links
|
|
14
14
|
* ðŠķ Lightweight and fast â ideal for small static or utility projects
|
|
15
15
|
* ðĨ Usable with `minimaz` or its alias `mz`
|
|
16
|
+
* ðŧ NPM integration and optional Git repository initialization
|
|
17
|
+
* âą Interactive prompts with 60s timeout
|
|
16
18
|
|
|
17
19
|
## ðĶ Installation
|
|
18
20
|
|
|
@@ -28,9 +30,9 @@ npx minimaz version
|
|
|
28
30
|
Or using the alias:
|
|
29
31
|
|
|
30
32
|
```bash
|
|
31
|
-
npx mz
|
|
32
|
-
npx mz
|
|
33
|
-
npx mz
|
|
33
|
+
npx mz i my-site
|
|
34
|
+
npx mz b
|
|
35
|
+
npx mz v
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
## ð Project Structure
|
|
@@ -41,6 +43,8 @@ my-site/
|
|
|
41
43
|
âââ public/ # Static assets (images, fonts, etc.)
|
|
42
44
|
âââ src/ # HTML, CSS, JS, TS files
|
|
43
45
|
âââ minimaz.config.json
|
|
46
|
+
âââ package.json # Optional, created if npm init is used
|
|
47
|
+
âââ .gitignore # Default gitignore copied from template
|
|
44
48
|
âââ ...
|
|
45
49
|
```
|
|
46
50
|
|
|
@@ -53,6 +57,10 @@ Customize your build using a `minimaz.config.json` file:
|
|
|
53
57
|
"src": "src",
|
|
54
58
|
"dist": "dist",
|
|
55
59
|
"public": "public",
|
|
60
|
+
"bundling": {
|
|
61
|
+
"css": true,
|
|
62
|
+
"js": true
|
|
63
|
+
},
|
|
56
64
|
"minify": {
|
|
57
65
|
"html": true,
|
|
58
66
|
"css": true,
|
|
@@ -65,45 +73,88 @@ Customize your build using a `minimaz.config.json` file:
|
|
|
65
73
|
"folders": {
|
|
66
74
|
"src": "",
|
|
67
75
|
"public": "public"
|
|
68
|
-
}
|
|
76
|
+
},
|
|
69
77
|
"styles": [
|
|
70
|
-
"
|
|
71
|
-
"
|
|
78
|
+
"../node_modules/some-package/dist/library.css",
|
|
79
|
+
"C:/Users/YourUser/Desktop/custom.css"
|
|
72
80
|
],
|
|
73
81
|
"scripts": [
|
|
74
|
-
"
|
|
75
|
-
"
|
|
82
|
+
"../node_modules/some-package/dist/library.js",
|
|
83
|
+
"D:/Scripts/custom.js"
|
|
76
84
|
]
|
|
77
85
|
}
|
|
78
86
|
```
|
|
79
87
|
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* If omitted, fallback defaults are
|
|
88
|
+
* 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.
|
|
89
|
+
* scripts (optional): array of .js files to include in the build, can also point outside src.
|
|
90
|
+
* If omitted, fallback defaults are style.css and script.js.
|
|
91
|
+
* `bundling.css` / `bundling.js`: controls whether listed CSS/JS files are concatenated into a single `style.css` / `script.js`.
|
|
92
|
+
* `minify.html`, `minify.css`, `minify.js`, `minify.ts`: enable minification for the corresponding file types. TypeScript files are compiled to JS before minification.
|
|
83
93
|
|
|
84
|
-
|
|
94
|
+
**Tip**: Using external paths is useful for including library CSS/JS without copying them into your project.
|
|
85
95
|
|
|
86
|
-
|
|
87
|
-
minimaz build # Build and minify the site (uses config or defaults)
|
|
88
|
-
minimaz clear # Clears dist folder
|
|
89
|
-
minimaz init <project-name> # Create a new project using global templates
|
|
90
|
-
minimaz help # Show help message
|
|
91
|
-
minimaz template <path> # Save a new template from specified path (or current dir)
|
|
92
|
-
minimaz template -list # List available templates
|
|
93
|
-
minimaz template -delete <name> # Delete a saved template
|
|
94
|
-
minimaz version # Display Minimaz version
|
|
95
|
-
```
|
|
96
|
+
## ð Commands
|
|
96
97
|
|
|
97
|
-
### Commands Aliases
|
|
98
98
|
```bash
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
mz
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
# -----------------------------
|
|
100
|
+
# Build
|
|
101
|
+
# -----------------------------
|
|
102
|
+
minimaz build # Build and minify the project
|
|
103
|
+
mz b # alias
|
|
104
|
+
|
|
105
|
+
# -----------------------------
|
|
106
|
+
# Clear
|
|
107
|
+
# -----------------------------
|
|
108
|
+
minimaz clear # Delete the dist folder
|
|
109
|
+
mz c # alias
|
|
110
|
+
|
|
111
|
+
# -----------------------------
|
|
112
|
+
# Init
|
|
113
|
+
# -----------------------------
|
|
114
|
+
minimaz init <project-name> # Initialize a new project with default template
|
|
115
|
+
mz i <project-name> # alias
|
|
116
|
+
|
|
117
|
+
minimaz init <project-name> --template <name> # Use a specific template
|
|
118
|
+
mz i <project-name> -t <name> # alias
|
|
119
|
+
|
|
120
|
+
minimaz init <project-name> --npm # Initialize npm project
|
|
121
|
+
minimaz init <project-name> --git # Initialize git repository
|
|
122
|
+
|
|
123
|
+
# Specify git provider or remote URL
|
|
124
|
+
minimaz init <project-name> --git --gitprovider <provider-or-url>
|
|
125
|
+
mz i <project-name> --git --gitprovider github # alias example
|
|
126
|
+
|
|
127
|
+
# -----------------------------
|
|
128
|
+
# Help
|
|
129
|
+
# -----------------------------
|
|
130
|
+
minimaz help # Show general help
|
|
131
|
+
mz h # alias
|
|
132
|
+
minimaz help <command> # Show help for a specific command
|
|
133
|
+
mz h build # alias example
|
|
134
|
+
|
|
135
|
+
# -----------------------------
|
|
136
|
+
# Template management
|
|
137
|
+
# -----------------------------
|
|
138
|
+
minimaz template <template-path> # Save current folder as a template
|
|
139
|
+
minimaz t <template-path> # alias
|
|
140
|
+
|
|
141
|
+
minimaz template --list # List available global templates
|
|
142
|
+
minimaz t -l # alias
|
|
143
|
+
|
|
144
|
+
minimaz template --delete <template-name> # Delete a saved template
|
|
145
|
+
minimaz t -d <template-name> # alias
|
|
146
|
+
|
|
147
|
+
minimaz template --update <template-name> # Update a specific template from current folder
|
|
148
|
+
minimaz t -u <template-name> # alias
|
|
149
|
+
|
|
150
|
+
minimaz template --update # Update all templates from node_modules
|
|
151
|
+
minimaz t -u # alias
|
|
152
|
+
|
|
153
|
+
# -----------------------------
|
|
154
|
+
# Version
|
|
155
|
+
# -----------------------------
|
|
156
|
+
minimaz version # Show Minimaz CLI version
|
|
157
|
+
mz v # alias
|
|
107
158
|
```
|
|
108
159
|
|
|
109
160
|
## ð Templates
|
|
@@ -118,4 +169,4 @@ Use them to quickly initialize consistent projects across environments.
|
|
|
118
169
|
|
|
119
170
|
## ð License
|
|
120
171
|
|
|
121
|
-
MIT
|
|
172
|
+
MIT
|
package/bin/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{fileURLToPath as
|
|
2
|
+
import{fileURLToPath as s}from"url";import{dirname as m}from"path";import{build as l,init as p,help as o,template as c,clear as d,version as g,log as r,parseArgs as u}from"../src/index.js";const f=s(import.meta.url),O=m(f);async function v(){const e=u(process.argv.slice(2)),i=e._[0]||"",a=e._[1];(i==="help"||e.h||e.help)&&(o(a||(e.h||e.help?i:void 0)),process.exit(0));const t={build:async()=>l(),clear:()=>d(),init:async()=>{await p(a||"minimaz-project",{template:e.template||e.t||"default",npm:e.npm,git:e.git,gitremote:e.gitremote,gitprovider:e.gitprovider})},template:async()=>{await c(a,{list:e.l||e.list,delete:e.d||e.delete,update:e.u||e.update})},version:()=>g(),b:()=>t.build(),c:()=>t.clear(),i:()=>t.init(),t:()=>t.template(),v:()=>t.version()};try{t[i]?await t[i]():(r("error",`Unknown command '${i}'. Use 'minimaz help' to see available commands.`),o())}catch(n){r("error",n instanceof Error?process.env.DEBUG?n.stack??n.message:n.message:String(n)),process.exit(1)}}v();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minimaz-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Minimal project initializer and builder CLI",
|
|
5
5
|
"author": "MrZeller",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"html-minifier-terser": "^7.2.0",
|
|
35
35
|
"terser": "^5.44.0"
|
|
36
36
|
},
|
|
37
|
-
"postinstall": "node
|
|
37
|
+
"postinstall": "node dist/src/utils/postInstall.js",
|
|
38
38
|
"bin": {
|
|
39
39
|
"minimaz": "./bin/cli.js",
|
|
40
40
|
"mz": "./bin/cli.js"
|
package/src/commands/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import f from"fs-extra";import m from"path";import j from"clean-css";import{minify as v}from"html-minifier-terser";import{minify as g}from"terser";import{loadConfig as S,log as l,applyReplacements as F,getFile as y,removeDistDir as M}from"../index.js";async function W(){const i=await S(),s=m.resolve(process.cwd(),i.dist||"dist");if(await M(s),await f.ensureDir(s),!i.folders||Object.keys(i.folders).length===0){l("warn","No folders defined in config. Nothing to build.");return}for(const[t,n]of Object.entries(i.folders))l("info",`Building folder: ${t} -> /${n}`),await J(t,n,i,s);l("success",`Build completed. Output saved in /${i.dist}`)}async function J(i,s,t,n){const r=m.resolve(process.cwd(),i),a=m.join(n,s);if(!await f.pathExists(r)){l("warn",`Folder not found: ${i}`);return}const e={css:[],js:[]};await C(r,a,t,e),i===t.src&&await B(e,t,n),l("success",`Processed folder: ${i} -> /${s}`)}async function C(i,s,t,n){await f.ensureDir(s);for(const r of await f.readdir(i)){const a=m.join(i,r),e=m.join(s,r);if((await f.stat(a)).isDirectory()){await C(a,e,t,n);continue}await b(a,e,t,n)}}async function b(i,s,t,n){switch(l("info",`Processing file: ${i}`),m.extname(i).toLowerCase()){case".html":await z(i,s,t);break;case".css":{const a=await y(i,t.replace);if(t.bundling?.css)n.css.push(a);else{let e=a;if(t.minify?.css){const c=new j().minify(a);c.warnings.length&&c.warnings.forEach(o=>l("warn",o)),e=c.styles}await f.outputFile(s,e)}break}case".js":{const a=await y(i,t.replace);if(t.bundling?.js)n.js.push(a);else{let e=a;if(t.minify?.js)try{e=(await g(a)).code??""}catch(c){l("warn",`JS minify failed in ${i}: ${c}`)}await f.outputFile(s,e)}break}default:await f.copy(i,s)}}async function z(i,s,t){let n=await y(i,t.replace);const r=/<script([^>]*)>([\s\S]*?)<\/script>/gi;let a=0,e="",c;for(;(c=r.exec(n))!==null;){const[o,u,d]=c;if(e+=n.slice(a,c.index),a=c.index+o.length,/src=/i.test(u)){e+=o;continue}const p=(u.match(/type=["']([^"']+)["']/i)?.[1]||"").toLowerCase(),$=/module/i.test(p),x=/nomodule/i.test(u);if(p==="application/json")try{const w=JSON.stringify(JSON.parse(d));e+=`<script${u}>${w}</script>`}catch(w){l("warn",`Invalid JSON in ${i}: ${w}`),e+=o}else if(p===""||p==="text/javascript"||$||x)try{const w=await g(d,{format:{semicolons:!0},module:$});e+=`<script${u}>${w.code||""}</script>`}catch(w){l("warn",`JS minify error in ${i}: ${w}`),e+=o}else e+=o}e+=n.slice(a),t.minify?.html&&(e=await v(e,{collapseWhitespace:!0,removeComments:!0,minifyCSS:t.minify.css,minifyJS:!1})),await f.outputFile(s,e)}async function B(i,s,t){await h(s.styles,i.css,s,"css",!!s.bundling?.css,t),await h(s.scripts,i.js,s,"js",!!s.bundling?.js,t),s.bundling?.css&&await E(i.css,s,t),s.bundling?.js&&await N(i.js,s,t)}async function h(i,s,t,n,r,a){if(i?.length)for(const e of i){const c=m.resolve(process.cwd(),e);if(!await f.pathExists(c)){l("warn",`File not found: ${e}`);continue}let o=await f.readFile(c,"utf-8");if(o=F(o,t.replace),r)s.push(o);else{if(n==="css"&&t.minify?.css){const d=new j().minify(o);d.warnings.length&&d.warnings.forEach(p=>l("warn",p)),o=d.styles}else if(n==="js"&&t.minify?.js)try{o=(await g(o)).code??""}catch(d){l("warn",`JS minify failed for external file ${e}: ${d}`)}const u=m.basename(e);await f.outputFile(m.join(a,u),o),l("info",`Copied external ${n} file: ${u}`)}}}async function E(i,s,t){if(!i.length)return;let n=i.join("");if(s.minify?.css){const r=new j().minify(n);r.warnings.length&&r.warnings.forEach(a=>l("warn",a)),n=r.styles}await f.outputFile(m.join(t,"style.css"),n)}async function N(i,s,t){if(!i.length)return;let n=i.join("");if(s.minify?.js)try{n=(await g(n)).code??""}catch(r){l("warn",`JS minify failed: ${r}`)}n&&await f.outputFile(m.join(t,"script.js"),n)}export{W as build,z as processHtml};
|
package/src/commands/clear.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{removeDistDir as o}from"../index.js";async function i(){o()}export{i as clear};
|
package/src/commands/help.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
`))}
|
|
1
|
+
import{commands as e}from"../index.js";function i(n){if(n){const o=e[n];if(!o){console.log(`No help found for command: ${n}
|
|
2
|
+
`);return}if(console.log(o.usage),console.log(` ${o.description}`),o.options){console.log(" Options:");for(const[t,s]of Object.entries(o.options))console.log(` ${t} ${s}`)}console.log("");return}console.log(`Usage:
|
|
3
|
+
`);for(const o of Object.values(e)){if(console.log(o.usage),console.log(` ${o.description}`),o.options){console.log(" Options:");for(const[t,s]of Object.entries(o.options))console.log(` ${t} ${s}`)}console.log("")}}export{i as help};
|
package/src/commands/init.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import o from"fs-extra";import n from"path";import{log as a,createGlobalDir as f,askQuestion as g,executeCommand as w,createFileFromTemplate as m,pkgTemplate as d,gitIgnoreTemplate as y,initGit as u,getGlobalDirPath as h}from"../index.js";async function I(e,i={}){const r=h(),l=i.template??"default",s=n.join(r,"templates",l),t=n.resolve(process.cwd(),e);if(await o.pathExists(r)||(a("info",`Global folder '${r}' not found. Creating...`),await f()),!await o.pathExists(s))throw new Error(`Template '${l}' not found.`);if(await o.pathExists(t))throw new Error(`Target directory '${t}' already exists.`);const c=i.npm??(await g("Init NPM? [y/n]:","y")).startsWith("y"),p=i.git??(await g("Init Git repository? [y/n]:","y")).startsWith("y");p&&(i.gitprovider=i.gitprovider??await g("Select a provider or paste a url to connect your existing repo (cli tools needed) [local/github/gitlab]:","local")),a("info",`Copying template from '${s}' to '${t}'`),await o.copy(s,t),a("info","Initializing gitignore..."),await m(y,n.join(t,".gitignore")),c&&(a("info","Initializing NPM..."),await m({...d,name:e},n.join(t,"package.json")),await w("npm",["install"],t)),p&&(a("info","Initializing GIT..."),await u(e,t,i.gitprovider)),a("success",`Project '${e}' created using template '${l}'.`)}export{I as init};
|
package/src/commands/template.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import i from"fs-extra";import a from"path";import{askQuestion as c,listTemplates as l,getGlobalNodeModulesPath as w,log as n,getGlobalDirPath as u}from"../index.js";async function E(s,e={}){const r=a.join(u(),"templates"),t=e.delete||e.d,o=e.update||e.u;if(t)return await m(r,t);if(e.list||e.l)return await l();if(o!==void 0)return typeof o=="string"&&o.trim()?await p(r,o.trim()):await f(r);await y(r,s)}async function p(s,e){const r=a.resolve(process.cwd()),t=a.join(s,e);if(!await i.pathExists(t))throw new Error(`Template '${e}' not found in ~/.minimaz/templates`);if(!(await c(`Update template '${e}' with current directory? [y/n]:`,"y")).startsWith("y")){n("info","Update cancelled.");return}try{await i.copy(r,t,{overwrite:!0}),n("success",`Template '${e}' updated from current directory.`)}catch{throw new Error(`Failed to update '${e}'`)}}async function f(s){const e=a.join(w(),"src","templates");if(!await i.pathExists(e))throw new Error("'node_modules/minimaz/src/templates' not found.");const r=await i.readdir(e);if(!(await c("Update local templates overwriting them with defaults? [y/n]:","y")).startsWith("y")){n("info","Update cancelled.");return}try{for(const t of r){const o=a.join(e,t),d=a.join(s,t);await i.copy(o,d,{overwrite:!0}),n("success",`Updated '${t}'`)}n("info","\u2728 All templates and files updated successfully.")}catch(t){throw new Error(`Update failed: ${t.message}`)}}async function m(s,e){if(!e)throw new Error("No template name specified to delete.");const r=a.join(s,e);if(!await i.pathExists(r))throw new Error(`Template not found: ${e}`);if(!(await c(`Confirm delete '${e}'? [y/n]:`,"y")).startsWith("y")){n("info","Delete cancelled.");return}try{await i.remove(r),n("success",`Template '${e}' deleted.`)}catch(t){throw new Error(`Delete error: ${t.message}`)}}async function y(s,e){let r=e?a.resolve(process.cwd(),e):process.cwd();if(!await i.pathExists(r))if(n("warn",`Path not found: ${r}`),(await c("Use current directory instead? [y/n]:","y")).startsWith("y"))r=process.cwd();else throw new Error("Operation cancelled.");try{await i.ensureDir(s);const t=a.join(s,a.basename(r));if(await i.pathExists(t)&&!(await c(`Template '${a.basename(t)}' already exists. Overwrite? [y/n]:`,"n")).startsWith("y")){n("info","Save cancelled.");return}await i.copy(r,t,{overwrite:!0}),n("success",`Template saved to ${t}`)}catch(t){throw new Error(`Failed to save template: ${t.message}`)}}export{E as template};
|
package/src/commands/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import i from"path";import n from"fs-extra";import{log as s}from"../index.js";async function p(){const r=i.resolve(process.cwd(),"package.json"),{version:o}=await n.readJson(r);if(typeof o!="string")throw new Error("Invalid or missing version in package.json");s("info",o)}export{p as version};
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{build as e}from"./commands/build.js";import{init as p}from"./commands/init.js";import{help as f}from"./commands/help.js";import{template as l}from"./commands/template.js";import{clear as a}from"./commands/clear.js";import{version as b}from"./commands/version.js";export*from"./utils/types.js";export*from"./utils/functions.js";export*from"./utils/constants.js";import{log as s}from"./utils/logService.js";export{e as build,a as clear,f as help,p as init,s as log,l as template,b as version};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e={version:"0.0.1",license:"ISC",type:"commonjs",scripts:{build:"mz b",start:"npx mz b && npx serve dist/"},devDependencies:{"minimaz-cli":"latest",serve:"latest"}},t=`dist
|
|
2
|
+
.vscode
|
|
3
|
+
node_modules`,i={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"}},s={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"}};export{s as commands,t as gitIgnoreTemplate,i as minimazConfigTemplate,e as pkgTemplate};
|
package/src/utils/functions.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import m from"readline";import s from"fs-extra";import a from"path";import d from"os";import{execSync as w,spawn as h}from"child_process";import{log as r,minimazConfigTemplate as y}from"../index.js";function T(i){const t={_:[]};for(let e=0;e<i.length;e++){const n=i[e].toLowerCase();if(!n.startsWith("-")){t._.push(n);continue}if(n.startsWith("--")&&n.includes("=")){const[c,u]=n.slice(2).split("=");t[c]=u;continue}const o=n.replace(/^-+/,""),l=i[e+1];l&&!l.startsWith("-")?(t[o]=l,e++):t[o]=!0}return t}function S(i,t=""){return new Promise(e=>{const n=m.createInterface({input:process.stdin,output:process.stdout}),o=setTimeout(()=>{n.close(),e(t)},6e4);n.question(`\u2753 ${i} `,l=>{clearTimeout(o),n.close(),e(l.trim()||t)}),n.on("SIGINT",()=>{clearTimeout(o),n.close(),process.exit(130)})})}async function A(){const i=a.join(f(),"templates");if(!await s.pathExists(i)){r("info","No templates directory found.");return}const t=await s.readdir(i);if(t.length===0){r("info","No global templates available.");return}r("info","Available global templates:"),t.forEach(e=>r("info",`- ${e}`))}function x(i,t={}){return Object.entries(t).reduce((e,[n,o])=>{const l=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(l,"gi");return e.replace(c,o)},i)}async function D(i,t){try{let e=await s.readFile(i,"utf8");return t&&(e=x(e,t)),e}catch(e){return r("error",`Failed to read file ${i}: ${e.message}`),""}}function p(){try{const i=w("npm config get prefix",{encoding:"utf8"}).trim();if(!i)throw new Error("Empty npm prefix");return process.platform==="win32"?a.join(i,"node_modules","minimaz-cli"):a.join(i,"lib","node_modules","minimaz-cli")}catch{return process.platform==="win32"?a.join(process.env.APPDATA||"","npm","node_modules","minimaz-cli"):"/usr/local/lib/node_modules/minimaz-cli"}}function f(){return a.join(d.homedir(),".minimaz")}async function F(){const i=f(),t=a.join(i,"templates"),e=a.join(p(),"src","templates"),n=a.join(i,"settings.json");try{await s.ensureDir(i),await s.pathExists(n)||(await s.outputJson(n,{createdAt:new Date().toISOString(),templatesPath:t,npmGlobalPath:p()},{spaces:2}),r("success",`Created settings.json at ${n}`));const o=await s.pathExists(t),l=o?(await s.readdir(t)).length===0:!0;if(o||(await s.ensureDir(t),r("success","Created global templates directory.")),!l){r("info","Global templates directory not empty. Skipping copy.");return}for(const c of await s.readdir(e))await s.copy(a.join(e,c),a.join(t,c)),r("success",`Copied template '${c}'.`);r("success","Default templates setup completed.")}catch(o){throw r("error",`Failed to create global templates directory: ${o.message}`),o}}function g(i,t,e){return new Promise((n,o)=>{r("info",`Running: ${i} ${t.join(" ")}`);const l=h(i,t,{cwd:e,stdio:"inherit",shell:!0});l.on("error",c=>{r("error",`Failed to run command: ${c}`),o(c)}),l.on("close",c=>{c===0?n():o(new Error(`${i} exited with code ${c}`))})})}async function _(i,t){const e=typeof i=="string"?i.endsWith(`
|
|
2
|
+
`)?i:i+`
|
|
3
|
+
`:JSON.stringify(i,null,2)+`
|
|
4
|
+
`;try{await s.outputFile(t,e)}catch(n){throw new Error(`Failed to create file at '${t}': ${n.message}`)}}async function I(i,t,e,n="origin"){if(r("info","Initializing Git repository..."),await g("git",["init"],t),e){await b(i,t,e,n),r("success","Git repository initialized.");return}throw new Error("Git remote configuration is invalid.")}async function b(i,t,e,n="origin"){if(console.log(e,n,i,t),/^https?:\/\//.test(e)||e.startsWith("git@")){r("info",`Connecting existing remote '${e}'`),await g("git",["remote","add",n,e],t);return}if(e==="github"){r("info",`Creating GitHub repository '${i}'`),await g("gh",["repo","create",i,"--private","--source=.","--remote",n],t);return}if(e==="gitlab"){r("info",`Creating GitLab repository '${i}'`);const o=process.env.GITLAB_USER;if(!o)throw new Error("GITLAB_USER environment variable not set");await g("glab",["repo","create",i,"--source=."],t),await g("git",["remote","add",n,`git@gitlab.com:${o}/${i}.git`],t);return}throw new Error(`Unsupported git provider or remote: '${e}'`)}async function k(i){const t=i?a.isAbsolute(i)?i:a.resolve(process.cwd(),i):a.resolve(process.cwd(),(await $()).dist??"dist"),e=process.cwd();if(t===e||t.length<=e.length)throw new Error(`Refusing to delete unsafe directory: ${t}`);if(!await s.pathExists(t)){r("info",`No dist folder found: ${t}`);return}await s.remove(t),r("success",`Cleared ${t}`)}async function $(){const i=a.resolve(process.cwd(),"minimaz.config.json");let t;return await s.pathExists(i)?(t=await s.readJson(i),r("info","Loaded config from minimaz.config.json")):(t=JSON.parse(JSON.stringify(y)),r("warn","No minimaz.config.json found. Using default config")),t}export{x as applyReplacements,S as askQuestion,_ as createFileFromTemplate,F as createGlobalDir,g as executeCommand,D as getFile,f as getGlobalDirPath,p as getGlobalNodeModulesPath,I as initGit,A as listTemplates,$ as loadConfig,T as parseArgs,k as removeDistDir};
|
package/src/utils/logService.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function c(o="log",n){const r={error:"\u274C",warn:"\u26A0\uFE0F",success:"\u2705",info:"\u2139\uFE0F",log:"\u{1F4C1}"};o
|
|
1
|
+
function c(o="log",n){const r={error:"\u274C",warn:"\u26A0\uFE0F",success:"\u2705",info:"\u2139\uFE0F",log:"\u{1F4C1}"};switch(o){case"error":console.error(r[o]," ",n);break;case"warn":console.warn(r[o]," ",n);break;default:console.log(r[o]||r.log," ",n);break}}export{c as log};
|
package/src/utils/postInstall.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createGlobalDir as s
|
|
1
|
+
import{createGlobalDir as s,log as e}from"../index.js";async function a(){try{await s(),e("success","Postinstall: Global templates setup completed.")}catch(t){e("error",`Postinstall setup failed: ${t.message}`)}}a();
|
|
File without changes
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"src": "src",
|
|
3
|
-
"dist": "dist",
|
|
4
|
-
"public": "public",
|
|
5
|
-
"minify": {
|
|
6
|
-
"html": true,
|
|
7
|
-
"css": true,
|
|
8
|
-
"js": true,
|
|
9
|
-
"ts": true
|
|
10
|
-
},
|
|
11
|
-
"replace": {
|
|
12
|
-
"../public/": "public/"
|
|
13
|
-
},
|
|
14
|
-
"styles": [
|
|
15
|
-
"style.css",
|
|
16
|
-
"style-2.css"
|
|
17
|
-
],
|
|
18
|
-
"scripts": [
|
|
19
|
-
"script.js",
|
|
20
|
-
"script-2.js"
|
|
21
|
-
],
|
|
22
|
-
"folders": {
|
|
23
|
-
"src": "",
|
|
24
|
-
"public": "public"
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/templates/gitignore
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"src": "src",
|
|
3
|
-
"dist": "dist",
|
|
4
|
-
"public": "public",
|
|
5
|
-
"minify": {
|
|
6
|
-
"html": true,
|
|
7
|
-
"css": true,
|
|
8
|
-
"js": true,
|
|
9
|
-
"ts": true
|
|
10
|
-
},
|
|
11
|
-
"replace": {
|
|
12
|
-
"../public/": "public/"
|
|
13
|
-
},
|
|
14
|
-
"styles": [
|
|
15
|
-
"style.css",
|
|
16
|
-
"style-2.css"
|
|
17
|
-
],
|
|
18
|
-
"scripts": [
|
|
19
|
-
"script.js",
|
|
20
|
-
"script-2.js"
|
|
21
|
-
],
|
|
22
|
-
"folders": {
|
|
23
|
-
"src": "",
|
|
24
|
-
"public": "public"
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/utils/loadConfig.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"fs-extra";import s from"path";import{log as a}from"./logService.js";const f={src:"src",dist:"dist",public:"public",minify:{html:!0,css:!0,js:!0,ts:!0},replace:{"../public/":"public/"},folders:{src:"",public:"public"}};function e(r,n){const o={...r};for(const i in n)n[i]&&typeof n[i]=="object"&&!Array.isArray(n[i])?o[i]=e(r[i]||{},n[i]):n[i]!==void 0&&(o[i]=n[i]);return o}async function m(){const r=s.resolve(process.cwd(),"minimaz.config.json");let n={};if(await t.pathExists(r))try{n=await t.readJson(r),a("info","Loaded config from minimaz.config.json")}catch(i){throw new Error(`Failed to parse minimaz.config.json: ${i.message}`)}else a("info","No minimaz.config.json found. Using default config");const o=e(f,n);if(!o.src||!o.dist)throw new Error("Invalid configuration: src and dist are required");return o}export{m as loadConfig};
|