@solution-lib/space 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Maysara Elshewehy (https://github.com/maysara-elshewehy)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ <!-- ╔══════════════════════════════ BEG ══════════════════════════════╗ -->
2
+
3
+ <br>
4
+ <div align="center">
5
+ <p>
6
+ <img src="./assets/img/logo.png" alt="logo" style="" height="70" />
7
+ </p>
8
+ </div>
9
+
10
+ <div align="center">
11
+ <img src="https://img.shields.io/badge/v-0.0.1-black"/>
12
+ <a href="https://github.com/maysara-elshewehy">
13
+ </a>
14
+ <a href="https://github.com/solution-lib"><img src="https://img.shields.io/badge/🔥-@solution--lib-black"/></a>
15
+ </div>
16
+
17
+ <div align="center">
18
+ <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/>
19
+ <br>
20
+ </div>
21
+
22
+ <!-- ╚═════════════════════════════════════════════════════════════════╝ -->
23
+
24
+
25
+
26
+ <!-- ╔══════════════════════════════ DOC ══════════════════════════════╗ -->
27
+
28
+ - ## Quick Start 🔥
29
+
30
+ ```bash
31
+ # install via bun or npm
32
+ bun install @solution-lib/space
33
+ bun link @sulotion-lib/space
34
+
35
+ # Now use 'space' anywhere
36
+ space --help
37
+ ```
38
+
39
+ ```bash
40
+ # Create a new space (interactive)
41
+ space init
42
+
43
+ # Or with options
44
+ space init my-lib --type lib --pm bun --desc "My library"
45
+
46
+ # Navigate and setup
47
+ cd my-lib
48
+ space i # or `space install`
49
+ space build
50
+ ```
51
+
52
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
53
+
54
+ - ## Commands
55
+
56
+ ```bash
57
+ # Space Management
58
+ space init [name] # Create new space (interactive)
59
+ space info # Show space information
60
+
61
+ # Package Manager (Bun/npm wrapper)
62
+ space install [packages...] # Install dependencies
63
+ space i [packages...] # Alias for install
64
+ space remove <packages...> # Remove packages (with confirmation)
65
+ space r <packages...> # Alias for remove
66
+ space update [packages...] # Update packages (interactive)
67
+ space up [packages...] # Alias for update
68
+ space link # Link package globally
69
+ space unlink # Unlink package
70
+ space list # List installed packages
71
+ space ls # Alias for list
72
+ space run <script> # Run scripts from `package.json` file
73
+
74
+ # Build & Development
75
+ space build # Build the project
76
+ space start # Build and start
77
+ space test # Run tests
78
+ space clean # Clean build artifacts
79
+
80
+ # Publishing
81
+ space publish # Publish to npm (interactive)
82
+ ```
83
+
84
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
85
+
86
+ - ## Space Types
87
+
88
+ **Library (lib)**
89
+ ```
90
+ my-lib/
91
+ ┣ src/
92
+ ┃ ┣ ...
93
+ ┃ ┗ main.ts
94
+ ┣ test/
95
+ ┣ dist/
96
+ ┣ .space
97
+ ┗ package.json
98
+ ```
99
+
100
+ **CLI Tool (cli)**
101
+ ```
102
+ my-cli/
103
+ ┣ src/
104
+ ┃ ┣ ...
105
+ ┃ ┗ main.ts
106
+ ┣ test/
107
+ ┣ dist/
108
+ ┣ .space
109
+ ┗ package.json
110
+ ```
111
+
112
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
113
+
114
+ - ## Examples
115
+
116
+ **Create and publish a library:**
117
+ ```bash
118
+ space init math-utils --type lib --pm bun
119
+ cd math-utils
120
+ space install
121
+ space start # Build and Start
122
+ space test # Run tests
123
+ space build # Build for production
124
+ space link # Test locally
125
+ space publish # Publish to npm
126
+ ```
127
+
128
+ **Create a CLI tool:**
129
+ ```bash
130
+ space init my-tool --type cli
131
+ cd my-tool
132
+ space i chalk inquirer # Add dependencies
133
+ space start # Test your CLI
134
+ space link # Make it global
135
+ my-tool --help # Use it!
136
+ ```
137
+
138
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
139
+
140
+ - ## Configuration
141
+
142
+ > Each space contains a `.space` configuration file:
143
+
144
+ ```json
145
+ {
146
+ "type" : "cli",
147
+ "template" : "clean",
148
+ "pm" : "bun",
149
+ "repo" : {
150
+ "org" : "solution-lib",
151
+ "name" : "space",
152
+ "version" : "0.0.1",
153
+ "desc" : "Creates and manages the spaces",
154
+ "kw" : ["solution", "space", "framework"],
155
+ "license" : "MIT",
156
+ "issues" : "https://github.com/solution-lib/space/issues",
157
+ "homepage" : "https://github.com/solution-lib/space#readme",
158
+ "git_url" : "git+https://github.com/solution-lib/space.git"
159
+ },
160
+ "author" : {
161
+ "id" : "maysara-elshewehy",
162
+ "name" : "Maysara",
163
+ "email" : "maysara.elshewehy@gmail.com",
164
+ "url" : "https://github.com/maysara-elshewehy"
165
+ },
166
+ "createdAt" : "2025-11-29T01:22:48.497Z"
167
+ }
168
+ ```
169
+
170
+ > Space automatically uses the correct package manager based on this config.
171
+
172
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> <br> </div>
173
+
174
+ - ## Documentation
175
+
176
+ > Full documentation coming soon at [Github Pages](#)
177
+
178
+ > For now, run `space --help` or check the [detailed guide](#).
179
+
180
+
181
+ <!-- ╚═════════════════════════════════════════════════════════════════╝ -->
182
+
183
+
184
+
185
+ <!-- ╔══════════════════════════════ END ══════════════════════════════╗ -->
186
+
187
+ <br>
188
+ <div align="center">
189
+ <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/>
190
+ <br>
191
+ </div>
192
+ <br>
193
+ <div align="center">
194
+ <a href="https://github.com/maysara-elshewehy"><img src="https://img.shields.io/badge/by-Maysara-black"/></a>
195
+ </div>
196
+
197
+ <!-- ╚═════════════════════════════════════════════════════════════════╝ -->
package/dist/main.cjs ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bun
2
+ 'use strict';var cli=require('@je-es/cli'),u=require('fs'),T=require('path'),prompts=require('@inquirer/prompts'),child_process=require('child_process');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var u__namespace=/*#__PURE__*/_interopNamespace(u);var T__namespace=/*#__PURE__*/_interopNamespace(T);var U=Object.defineProperty;var q=(h=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(h,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):h)(function(h){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+h+'" is not supported')});var B=(h,t)=>()=>(h&&(t=h(h=0)),t);var J=(h,t)=>{for(var e in t)U(h,e,{get:t[e],enumerable:true});};var _={};J(_,{TemplateRegistry:()=>S});var S,D=B(()=>{S=class{static{this.TEMPLATES={lib:{type:"lib",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Library",description:"Zero dependencies - just TypeScript and build tools",repo:"lib-clean",requiresSetup:false,ready:true}]},cli:{type:"cli",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean CLI",description:"Comes with @je-es/cli library for quick CLI development",repo:"cli-clean",deps:["@je-es/cli"],requiresSetup:true,ready:true}]},server:{type:"server",defaultTemplate:"clean",templates:[{name:"clean",label:"Clean Server",description:"Comes with @je-es/server library for quick server development",repo:"server-clean",deps:["@je-es/server"],requiresSetup:true,ready:true}]}};}static getTemplatesForType(t,e=false){let r=this.TEMPLATES[t]?.templates||[];return e?r:r.filter(s=>s.ready)}static getReadyTemplatesForType(t){return this.getTemplatesForType(t,false)}static getDefaultTemplate(t){let e=this.TEMPLATES[t];if(!e)return "clean";let r=e.templates.find(a=>a.name===e.defaultTemplate&&a.ready);return r?r.name:e.templates.find(a=>a.ready)?.name||e.defaultTemplate}static getTemplate(t,e){let r=this.TEMPLATES[t];return r?r.templates.find(s=>s.name===e):null}static isTemplateReady(t,e){return this.getTemplate(t,e)?.ready||false}static isValidTemplate(t,e){return this.getTemplatesForType(t).some(s=>s.name===e)}static getRepoName(t,e){return this.getTemplate(t,e)?.repo||"ready-lib"}static getSpaceTypes(){return Object.keys(this.TEMPLATES)}};});D();var I=["name","version","description","keywords","license","homepage","bugs","author","repository","type","main","types","bin","files","exports","scripts","engines","peerDependencies","dependencies","devDependencies"],L=["type","template","pm","repo","author","createdAt"];var P=class{static format(t,e={}){let r=e.indent||" ",s=e.alignColons!==false,a=e.sortKeys||false,i=e.tabWidth||4,n=e.keyOrder||[],p=s?this.calculateGlobalMaxKeyLength(t):0,m=this.calculateMaxDepth(t)*(r===" "?i:r.length);return this.formatValue(t,0,r,s,a,p,m,i,n)}static formatFile(t,e={}){let r=q("fs"),s=r.readFileSync(t,"utf-8"),a=JSON.parse(s),i=this.format(a,e);r.writeFileSync(t,i+`
3
+ `,"utf-8");}static calculateMaxDepth(t,e=0){if(!t||typeof t!="object")return e;let r=e;return Array.isArray(t)?t.forEach(s=>{let a=this.calculateMaxDepth(s,e+1);a>r&&(r=a);}):Object.values(t).forEach(s=>{let a=this.calculateMaxDepth(s,e+1);a>r&&(r=a);}),r}static sortKeys(t,e,r){if(e.length===0)return r?t.sort():t;let s=[],a=[];return t.forEach(i=>{e.includes(i)?s.push(i):a.push(i);}),s.sort((i,n)=>e.indexOf(i)-e.indexOf(n)),r&&a.sort(),[...s,...a]}static calculateGlobalMaxKeyLength(t){let e=0,r=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){s.forEach(i=>r(i));return}Object.keys(s).forEach(i=>{let n=JSON.stringify(i).length;n>e&&(e=n),r(s[i]);});};return r(t),e}static formatValue(t,e,r,s,a,i,n,p,d){if(t===null)return "null";if(t===void 0)return "undefined";let m=typeof t;return m==="string"?JSON.stringify(t):m==="number"||m==="boolean"?String(t):Array.isArray(t)?this.formatArray(t,e,r,s,a,i,n,p,d):m==="object"?this.formatObject(t,e,r,s,a,i,n,p,d):JSON.stringify(t)}static formatArray(t,e,r,s,a,i,n,p,d){if(t.length===0)return "[]";if(t.every(c=>typeof c=="string"||typeof c=="number"||typeof c=="boolean"||c===null)&&t.length<=3)return "["+t.map(c=>this.formatValue(c,e,r,s,a,i,n,p,d)).join(", ")+"]";let f=r.repeat(e+1);return `[
4
+ `+t.map(c=>f+this.formatValue(c,e+1,r,s,a,i,n,p,d)).join(`,
5
+ `)+`
6
+ `+r.repeat(e)+"]"}static formatObject(t,e,r,s,a,i,n,p,d){if(Object.keys(t).length===0)return "{}";let m=Object.keys(t);m=this.sortKeys(m,d,a);let f=r.repeat(e+1),v=(e+1)*(r===" "?p:r.length);return `{
7
+ `+m.map(y=>{let g=JSON.stringify(y),b=this.formatValue(t[y],e+1,r,s,a,i,n,p,d);if(s){let l=n-v,E=i-g.length,N=" ".repeat(l+E);return `${f}${g}${N} : ${b}`}else return `${f}${g} : ${b}`}).join(`,
8
+ `)+`
9
+ `+r.repeat(e)+"}"}};var R=class{constructor(t=process.cwd()){this.basePath=t;}async createSpace(t,e){let r=e||T__namespace.join(this.basePath,t.repo.name);if(u__namespace.existsSync(r))throw new Error(`Space path "${r}" already exists!`);let s=false;try{u__namespace.existsSync(r)||(u__namespace.mkdirSync(r,{recursive:!0}),s=!0),await this.cloneTemplate(t.type,r,t,t.template),this.createSpaceConfig(r,t);}catch(a){if(s&&u__namespace.existsSync(r))try{await this.safeDeleteDirectory(r);}catch{console.warn(`Warning: Could not clean up directory at "${r}"`);}throw a}}loadSpaceConfig(t){let e=t||this.basePath,r=T__namespace.join(e,".space");if(!u__namespace.existsSync(r))return null;let s=u__namespace.readFileSync(r,"utf-8");return JSON.parse(s)}isSpace(t){let e=t||this.basePath;return u__namespace.existsSync(T__namespace.join(e,".space"))}async cloneTemplate(t,e,r,s){let i=`https://github.com/solution-dist/${S.getRepoName(t,s)}.git`;try{let{execSync:n}=await import('child_process');n(`git clone --quiet --depth 1 ${i} "${e}"`,{stdio:"pipe"});let p=T__namespace.join(e,".git");u__namespace.existsSync(p)&&await this.safeDeleteDirectory(p),await this.updateTemplateFiles(e,r);}catch(n){throw n.message&&n.message.includes("Repository not found")?new Error(`Template repository not found: ${i}
10
+ This template is not yet available. Please mark it as ready: false in templateRegistry.ts`):new Error(`Failed to clone template from ${i}: ${n.message||n}`)}}async updateTemplateFiles(t,e){let r=e.repo.org&&e.repo.org.trim()!=="",s=e.author.id&&e.author.id.trim()!=="",a=r?e.repo.org:s?e.author.id:"",i=a?`git+https://github.com/${a}/${e.repo.name}.git`:"",n=a?`https://github.com/${a}/${e.repo.name}#readme`:"",p=a?`https://github.com/${a}/${e.repo.name}/issues`:"",d=r?`@${e.repo.org}/${e.repo.name}`:e.repo.name,m="\u{1F525}-";r?m+=`@${(e.repo.org.replace(/-/g,"--")+"/"+e.repo.name.replace(/-/g,"--")).replace(/ /g,"_")}`:e.author.name?m+=(e.author.name.replace(/-/g,"--")+"/"+e.repo.name.replace(/-/g,"--")).replace(/ /g,"_"):m+=e.repo.name.replace(/-/g,"--").replace(/ /g,"_");let f=s?`https://github.com/${e.author.id}`:e.author.url||"",v=e.repo.kw&&e.repo.kw.length>0?JSON.stringify(e.repo.kw):"[]",c=this.getAllFiles(t);for(let y of c)if(!(y.includes("node_modules")||y.includes(".git")))try{let g=u__namespace.readFileSync(y,"utf-8"),b=!1;if(g.includes("{{")&&(b=!0,g=g.replace(/\{\{tag\}\}/g,d).replace(/\{\{tag-badge\}\}/g,m).replace(/\{\{name\}\}/g,e.repo.name).replace(/\{\{repo\}\}/g,e.repo.name).replace(/\{\{org\}\}/g,e.repo.org||"").replace(/\{\{desc\}\}/g,e.repo.desc||`A ${e.type} space`).replace(/\{\{description\}\}/g,e.repo.desc||`A ${e.type} space`).replace(/\{\{version\}\}/g,e.repo.version).replace(/\{\{license\}\}/g,e.repo.license||"MIT").replace(/\{\{kw\}\}/g,v).replace(/\{\{keywords\}\}/g,v).replace(/\{\{url\}\}/g,i).replace(/\{\{repo_url\}\}/g,i).replace(/\{\{git_url\}\}/g,i).replace(/\{\{homepage\}\}/g,n).replace(/\{\{issues\}\}/g,p).replace(/\{\{type\}\}/g,e.type).replace(/\{\{template\}\}/g,e.template||"clean").replace(/\{\{pm\}\}/g,e.pm).replace(/\{\{author\}\}/g,e.author.name||"").replace(/\{\{author_name\}\}/g,e.author.name||"").replace(/\{\{author_id\}\}/g,e.author.id||"").replace(/\{\{author_email\}\}/g,e.author.email||"").replace(/\{\{author_url\}\}/g,f),u__namespace.writeFileSync(y,g,"utf-8")),y.endsWith("package.json")){let l=JSON.parse(g);if(l.name=d,l.version=e.repo.version,l.description=e.repo.desc||`A ${e.type} space`,l.license=e.repo.license||"MIT",e.repo.kw&&e.repo.kw.length>0?l.keywords=e.repo.kw:l.keywords=[],n&&(l.homepage=n),p&&(l.bugs||(l.bugs={}),l.bugs.url=p),e.author.name&&(e.author.email?l.author={name:e.author.name,email:e.author.email,url:f||void 0}:l.author={name:e.author.name,url:f||void 0}),i&&(l.repository={type:"git",url:i}),e.type==="cli"&&l.bin){let E=Object.keys(l.bin)[0],N=l.bin[E];delete l.bin[E],l.bin[e.repo.name]=N;}l.engines||(l.engines={}),l.engines.bun||(l.engines.bun=">=1.0.0"),g=P.format(l,{keyOrder:I}),u__namespace.writeFileSync(y,g+`
11
+ `,"utf-8");continue}}catch{continue}}getAllFiles(t,e=[]){return u__namespace.readdirSync(t).forEach(s=>{let a=T__namespace.join(t,s);u__namespace.statSync(a).isDirectory()?e=this.getAllFiles(a,e):e.push(a);}),e}createSpaceConfig(t,e){let r=T__namespace.join(t,".space"),s=e.repo.org&&e.repo.org.trim()!=="",a=e.author.id&&e.author.id.trim()!=="",i=s?e.repo.org:a?e.author.id:"",n=i?`git+https://github.com/${i}/${e.repo.name}.git`:"",p=i?`https://github.com/${i}/${e.repo.name}#readme`:"",d=i?`https://github.com/${i}/${e.repo.name}/issues`:"",m=a?`https://github.com/${e.author.id}`:e.author.url||"",f={type:e.type,template:e.template||"clean",pm:e.pm,repo:{org:e.repo.org||"",name:e.repo.name,version:e.repo.version,desc:e.repo.desc||`A ${e.type} space`,kw:e.repo.kw||[],license:e.repo.license||"MIT",issues:d,homepage:p,git_url:n},author:{id:e.author.id||"",name:e.author.name||"",email:e.author.email||"",url:m},createdAt:new Date().toISOString()},v=P.format(f,{keyOrder:L});u__namespace.writeFileSync(r,v+`
12
+ `,"utf-8");}async safeDeleteDirectory(t,e=3){for(let r=0;r<e;r++)try{if(u__namespace.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u__namespace.existsSync(t))return}catch(s){if(r===e-1)throw s;await new Promise(a=>setTimeout(a,300*(r+1)));}}};var O=class{constructor(){this.pm="bun";this.DEFAULT_SCRIPTS={build:"tsup",test:"test"};}install(t,e){let r=["install"];t&&t.length>0&&r.push(...t),e?.dev&&r.push("--dev"),e?.global&&r.push("--global"),console.log(`\u{1F4E6} Installing${t?` ${t.join(", ")}`:" dependencies"}...`),this.execute(r),this.format();}remove(t,e){let r=["remove"];r.push(...t),e?.global&&r.push("--global"),console.log(`\u{1F5D1}\uFE0F Removing ${t.join(", ")}...`),this.execute(r),this.format();}link(){console.log("\u{1F517} Linking package globally..."),this.execute(["link"]);}unlink(){console.log("\u{1F513} Unlinking package..."),this.execute(["unlink"]);}run(t,e){let r=this.getScriptCommand(t);if(r||(console.error(`\u2718 Script "${t}" not found in package.json and no default available`),process.exit(1)),this.isUsingDefaultScript(t)){let a=[...r.split(" ")];e&&e.length>0&&a.push(...e),this.execute(a);}else {let s=["run",t];e&&e.length>0&&s.push("--",...e),this.execute(s);}}runSilent(t,e){let r=this.getScriptCommand(t);if(!r)throw new Error(`Script "${t}" not found in package.json and no default available`);if(this.isUsingDefaultScript(t)){let a=[...r.split(" ")];e&&e.length>0&&a.push(...e),this.executeSilent(a);}else {let s=["run",t];e&&e.length>0&&s.push("--",...e),this.executeSilent(s);}}update(t){console.log(`\u{1F504} Updating${t?` ${t.join(", ")}`:" all packages"}...`);let e=["update"];t&&t.length>0&&e.push(...t),this.execute(e),this.format();}list(t){let e=["pm","ls"];t?.global&&e.push("--global"),this.execute(e);}init(){console.log("\u{1F4DD} Initializing package.json..."),this.execute(["init","-y"]),this.format();}publish(t,e){let r=["publish"];t?.tag&&r.push("--tag",t.tag);let s=t?.access||"public";r.push("--access",s);let a=Bun.spawnSync(["bun",...r],{stdout:"pipe",stderr:"pipe"});if(a.exitCode===0){let n=new TextDecoder().decode(a.stdout).match(/\+ (.+@[\d.]+)/);e?n?e.stop(`\u2714 Published ${n[1]} successfully!`):e.stop("\u2714 Published successfully!"):console.log(n?`\u2714 Published ${n[1]} successfully!`:"\u2714 Published successfully!");}else {let i=new TextDecoder().decode(a.stderr);e?e.stopWithError("Publish failed!"):console.error("Publish failed!"),i&&console.error(i),process.exit(1);}}execute(t){Bun.spawnSync(["bun",...t],{stdout:"inherit",stderr:"inherit"}).exitCode!==0&&(console.error(`\u2718 Command failed: bun ${t.join(" ")}`),process.exit(1));}executeSilent(t){let e=Bun.spawnSync(["bun",...t],{stdout:"pipe",stderr:"pipe"});if(e.exitCode!==0){let r=new TextDecoder().decode(e.stderr);console.error(`\u2718 Command failed: bun ${t.join(" ")}`),r&&console.error(r),process.exit(1);}}getName(){return "bun"}getEmoji(){return "\u{1F95F}"}format(){try{let t=T__namespace.join(process.cwd(),"package.json");u__namespace.existsSync(t)&&P.formatFile(t,{keyOrder:I});}catch{}}getScriptCommand(t){let e=T__namespace.join(process.cwd(),"package.json");if(u__namespace.existsSync(e))try{let r=JSON.parse(u__namespace.readFileSync(e,"utf-8"));if(r.scripts&&r.scripts[t])return r.scripts[t]}catch{}return t in this.DEFAULT_SCRIPTS?this.DEFAULT_SCRIPTS[t]:null}isUsingDefaultScript(t){let e=T__namespace.join(process.cwd(),"package.json");if(u__namespace.existsSync(e))try{let r=JSON.parse(u__namespace.readFileSync(e,"utf-8"));if(r.scripts&&r.scripts[t])return !1}catch{}return t in this.DEFAULT_SCRIPTS}};D();var o=class{static async promptInit(t){let e=t.name,r=t.type,s=t.template,a=t.desc,i="";if((!e||e==="my-space")&&(e=await prompts.input({message:"name:",default:"my-space",validate:c=>{if(!c||c.trim()==="")return "Space name is required";let y=/^@([a-z0-9-_]+)\/([a-z0-9-_]+)$/,g=/^[a-z0-9-_]+$/;return !y.test(c)&&!g.test(c)?'Name must be either "package-name" or "@org/package-name" (lowercase, numbers, hyphens, underscores only)':true}})),!r){let c=S.getTemplatesForType("lib",false).length>0,y=S.getTemplatesForType("cli",false).length>0,g=S.getTemplatesForType("server",false).length>0;r=await prompts.select({message:"type:",choices:[{name:`\u{1F4DA} Library - TypeScript library for npm${c?"":" (Coming Soon)"}`,value:"lib",disabled:c?false:"No templates ready yet"},{name:`\u26A1 CLI - Command-line tool${y?"":" (Coming Soon)"}`,value:"cli",disabled:y?false:"No templates ready yet"},{name:`\u{1F5A5}\uFE0F Server - Backend server application${g?"":" (Coming Soon)"}`,value:"server",disabled:g?false:"No templates ready yet"}]});}if(!s){let c=S.getTemplatesForType(r,true);if(c.filter(b=>b.ready).length===0)throw new Error(`No templates are ready yet for "${r}" spaces. This space type is coming soon!`);let g=c.map(b=>{let l=b.ready?"\u2714":"\u{1F6A7}",E=b.ready?"":" (Coming Soon)";return {name:`${l} ${b.label}${E} - ${b.description}`,value:b.name,short:b.label,disabled:b.ready?false:"Not ready yet"}});s=await prompts.select({message:"template:",choices:g,default:S.getDefaultTemplate(r)});}a||(a=await prompts.input({message:"desc:",default:r==="lib"?"A TypeScript library":r==="cli"?"A command-line tool":"A backend server"}));let n="bun";i=await prompts.input({message:"author name:",default:""});let p=await prompts.input({message:"author email:",default:"",validate:c=>c&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c)?"Please enter a valid email address or leave empty":true}),d=await prompts.input({message:"github username:",default:"",validate:c=>c&&!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(c)?"Please enter a valid GitHub username or leave empty":true}),m=await prompts.input({message:"keywords (comma-separated):",default:""}),f=m?m.split(",").map(c=>c.trim()).filter(c=>c):[],v=await prompts.input({message:"license:",default:"MIT"});return {name:e,type:r,template:s,description:a,packageManager:n,author:i,authorEmail:p,githubId:d,keywords:f,license:v}}static async promptPublish(t){if(!await prompts.confirm({message:`Are you sure you want to publish "${t}" to npm?`,default:false}))return {confirm:false};let r=await prompts.input({message:"Publish with a tag (e.g., beta, next) or leave empty for latest:",default:""}),s=await prompts.select({message:"\u{1F510} Access level:",choices:[{name:"Public - Anyone can install",value:"public"},{name:"Restricted - Requires authentication",value:"restricted"}],default:"public"});return {confirm:true,tag:r||void 0,access:s}}static async promptRemove(t){let e=await prompts.confirm({message:`Remove ${t.join(", ")}?`,default:true});return {packages:t,confirm:e}}static async promptConfirm(t,e=false){let s=(await import('readline')).createInterface({input:process.stdin,output:process.stdout}),a=e?" (Y/n)":" (y/N)";return new Promise(i=>{s.question(`${t}${a} `,n=>{s.close(),n.trim()===""?i(e):i(n.trim().toLowerCase()==="y"||n.trim().toLowerCase()==="yes");});})}static async promptInstall(t){let e=await prompts.input({message:"Enter package names (space-separated):",default:t||"",validate:s=>!s||s.trim()===""?"Please enter at least one package name":true}),r=await prompts.confirm({message:"\u{1F6E0}\uFE0F Install as dev dependency?",default:false});return {packages:e.split(" ").filter(s=>s.trim()),isDev:r}}static async promptUpdate(){return await prompts.select({message:"What do you want to update?",choices:[{name:"All packages",value:"all"},{name:"Specific packages",value:"specific"}]})==="all"?{updateAll:true}:{updateAll:false,packages:(await prompts.input({message:"\u{1F4E6} Enter package names (space-separated):",validate:r=>!r||r.trim()===""?"Please enter at least one package name":true})).split(" ").filter(r=>r.trim())}}static async promptUseCurrentDir(t){return await prompts.confirm({message:`Use current directory "${t}" as the space root?`,default:true})}static async promptDeleteExistingDir(t){return await prompts.confirm({message:`\u26A0\uFE0F Directory already exists at "${t}". Delete and recreate?`,default:false})}static showSuccess(t,e){console.log(""),e.forEach((r,s)=>{console.log(`\u2192 ${r}`);}),console.log("");}static showError(t,e){console.log(`
13
+ \u2718 Error:`,t),e&&e.message&&console.log(` ${e.message}`),console.log("");}static showWarning(t){console.log(`
14
+ \u26A0\uFE0F Warning:`,t),console.log("");}static showInfo(t){console.log(`
15
+ \u2139\uFE0F `,t),console.log("");}};var $=class{constructor(){this.frames=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];this.currentFrame=0;this.interval=null;}start(t){process.stdout.write(`
16
+ ${t}`),this.interval=setInterval(()=>{process.stdout.write(`\r${this.frames[this.currentFrame]} ${t}`),this.currentFrame=(this.currentFrame+1)%this.frames.length;},80);}stop(t){this.interval&&(clearInterval(this.interval),this.interval=null),t===""?process.stdout.write("\r\x1B[K\x1B[1A\x1B[K"):process.stdout.write(`\r${t}
17
+
18
+ `);}stopWithError(t){this.interval&&(clearInterval(this.interval),this.interval=null),process.stdout.write(`\r\u2718 ${t}
19
+
20
+ `);}},M=class h{constructor(t){this.config=t;this.pm=null;this.spaceManager=new R,this.initPackageManager();}static create(t){return new h(t)}run(){cli.cli(this.config.name,this.config.version).description(this.config.desc).command({name:"init",description:"Create a new space (lib or cli)",args:[{name:"name",required:false,default:"my-space",description:"Name of the space (supports @org/name format)"}],options:[{name:"type",flag:"--type",type:"string",required:false,description:"Type of space (lib or cli)"},{name:"description",flag:"--desc",type:"string",required:false,description:"Description of the space"}],action:t=>this.createNewSpaceOnGroundViaCLI(t)}).command({name:"info",description:"Show current space information",action:()=>this.showSpaceInfo()}).command({name:"install",aliases:["i"],description:"Install packages",args:[{name:"packages",required:false,description:"Packages to install (space-separated)"}],options:[{name:"dev",flag:"--dev",type:"boolean",required:false,description:"Install as dev dependency"},{name:"global",flag:"--global",type:"boolean",required:false,description:"Install globally"}],action:t=>this.installPackages(t)}).command({name:"remove",aliases:["r"],description:"Remove packages",args:[{name:"packages",required:true,description:"Packages to remove (space-separated)"}],options:[{name:"global",flag:"--global",type:"boolean",required:false,description:"Remove globally"}],action:t=>this.removePackages(t)}).command({name:"update",aliases:["up"],description:"Update packages",args:[{name:"packages",required:false,description:"Packages to update (space-separated, or all if empty)"}],action:t=>this.updatePackages(t)}).command({name:"link",description:"Link package globally for development",action:()=>this.linkPackage()}).command({name:"unlink",description:"Unlink package globally",action:()=>this.unlinkPackage()}).command({name:"list",aliases:["ls"],description:"List installed packages",options:[{name:"global",flag:"--global",type:"boolean",required:false,description:"List global packages"}],action:t=>this.listPackages(t)}).command({name:"build",description:"Build the current space",action:()=>this.buildSpace()}).command({name:"test",description:"Run tests for the current space",args:[{name:"path",required:false,description:"Specific test file or folder (optional)"}],action:t=>this.runTests(t)}).command({name:"run",description:"Run any script from package.json",args:[{name:"script",required:true,description:"Script name from package.json"}],allowDynamicArgs:true,allowDynamicOptions:true,action:t=>this.runScript(t)}).command({name:"clean",description:"Clean build artifacts",action:()=>this.clean()}).command({name:"start",description:"Start the main file",allowDynamicArgs:true,allowDynamicOptions:true,action:t=>this.startMain(t)}).command({name:"publish",description:"Publish space to npm registry",options:[{name:"tag",flag:"--tag",type:"string",required:false,description:"Publish with tag (e.g., beta, next)"},{name:"access",flag:"--access",type:"string",required:false,description:"Access level (public or restricted)"}],action:t=>this.publish(t)}).build().run();}static defaultConfig(){return {name:"Space",version:"0.0.1",desc:"Build flexible spaces for any platform"}}initPackageManager(){this.spaceManager.isSpace()&&(this.pm=new O);}ensureSpace(){return this.spaceManager.isSpace()?true:(console.error('\u2718 Not a space directory. Run "space init <name> --type lib|cli" first.'),false)}parsePackageName(t){let e=/^@([a-z0-9-_]+)\/([a-z0-9-_]+)$/i,r=t.match(e);return r?{org:r[1],name:r[2]}:{org:"",name:t}}async deleteDirectoryWithRetry(t,e=3){for(let r=0;r<e;r++)try{if(u__namespace.rmSync(t,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),!u__namespace.existsSync(t))return}catch(s){if(r===e-1)throw s;await new Promise(a=>setTimeout(a,500*(r+1)));}throw new Error("Failed to delete directory after multiple attempts")}async createNewSpaceOnGroundViaCLI(t){try{let e=await o.promptInit({type:t.options.type,template:t.options.template,org:"",name:t.args.name,desc:t.options.desc}),{org:r,name:s}=this.parsePackageName(e.name);["lib","cli","server"].includes(e.type)||(o.showError("Invalid space type. Must be lib, cli or server."),process.exit(1));let{TemplateRegistry:a}=await Promise.resolve().then(()=>(D(),_));a.isValidTemplate(e.type,e.template)||(o.showError("Invalid template for this space type."),process.exit(1)),a.isTemplateReady(e.type,e.template)||(o.showError("This template is not ready yet. Please choose another template."),process.exit(1));let i,n=T__namespace.basename(process.cwd());if(!s||s.trim()===""?await o.promptUseCurrentDir(n)?i=process.cwd():(o.showError("Space name is required when not using current directory"),process.exit(1)):n===s&&await o.promptUseCurrentDir(s)&&(i=process.cwd()),i||(i=T__namespace.join(process.cwd(),s)),u__namespace.existsSync(i)){u__namespace.statSync(i).isDirectory()||(o.showError(`Path "${i}" exists but is not a directory`),process.exit(1)),await o.promptDeleteExistingDir(i)||(o.showInfo("Space creation cancelled"),process.exit(0));try{await this.deleteDirectoryWithRetry(i);}catch(f){f.message&&(f.message.includes("EBUSY")||f.message.includes("EPERM")||f.message.includes("resource busy"))?o.showError(`Cannot delete directory - it's being used by another program.
21
+
22
+ Please try:
23
+ 1. Close any terminals/editors with "${i}" open
24
+ 2. Navigate out of the directory in all terminals
25
+ 3. Run PowerShell/Terminal as Administrator
26
+ 4. Wait a few seconds and try again`):o.showError("Failed to delete existing directory.",f),process.exit(1);}}r&&(console.log(`\u{1F4E6} Detected organization: @${r}`),console.log(`\u{1F4DD} Package name: ${s}`));let p=a.getTemplate(e.type,e.template);p?.deps&&console.log(`\u{1F4E6} Includes: ${p.deps.join(", ")}`),await this.spaceManager.createSpace({type:e.type,template:e.template,pm:"bun",repo:{org:r,name:s,version:"0.0.1",desc:e.description,kw:e.keywords.length>0?e.keywords:[],license:e.license||"MIT"},author:{id:e.githubId,name:e.author,email:e.authorEmail,url:""},createdAt:new Date().toISOString()},i),o.showSuccess(s,[i===process.cwd()?"space install":`cd ${s}`,"space install","space build"]);}catch(e){o.showError("Failed to create space",e),process.exit(1);}}showSpaceInfo(){if(!this.ensureSpace())return;let t=this.spaceManager.loadSpaceConfig();if(!t){console.error("\u2718 Could not load space configuration.");return}console.log("");let r=t.repo?.org&&t.repo.org.trim()!==""?`${t.repo.org}/${t.repo.name}`:t.repo.name;if(console.log(`Name: ${r}`),console.log(`Type: ${t.type}`),console.log(`Version: ${t.repo.version}`),t.repo.desc&&t.repo.desc!=="{{desc}}"&&t.repo.desc!=="{{description}}"&&console.log(`Description: ${t.repo.desc}`),t.repo.kw){let s=[];if(Array.isArray(t.repo.kw))s=t.repo.kw.filter(a=>a&&typeof a=="string"&&a.trim()!==""&&a!=="{{kw}}"&&a!=="{{keywords}}");else if(typeof t.repo.kw=="string"){let a=t.repo.kw;a!=="{{kw}}"&&a!=="{{keywords}}"&&a.trim()!==""&&(s=a.split(",").map(i=>i.trim()).filter(i=>i!==""));}s.length>0&&console.log(`Keywords: ${s.join(", ")}`);}t.repo.license&&t.repo.license!=="{{license}}"&&console.log(`License: ${t.repo.license}`),console.log("PackageManager: bun"),t.author?.name&&t.author.name!=="{{author}}"&&t.author.name!=="{{author_name}}"&&console.log(`Author: ${t.author.name}`),console.log(`Created: ${new Date(t.createdAt).toLocaleDateString()}`),console.log("");}async installPackages(t){if(this.ensureSpace()){this.pm||this.initPackageManager();try{let e=t.args.packages?t.args.packages.split(" ").filter(s=>s.trim()):void 0,r=t.options.dev||!1;if((!e||e.length===0)&&!await o.promptConfirm("No packages specified. Install all dependencies from package.json?",!0)){let a=await o.promptInstall();e=a.packages,r=a.isDev;}this.pm.install(e,{dev:r,global:t.options.global});}catch(e){o.showError("\u2718 Installation failed",e),process.exit(1);}}}async removePackages(t){if(this.ensureSpace()){this.pm||this.initPackageManager();try{let e=t.args.packages.split(" ").filter(s=>s.trim());if(e.length===0){o.showError("Please specify packages to remove");return}if(!(await o.promptRemove(e)).confirm){o.showInfo("Removal cancelled");return}this.pm.remove(e,{global:t.options.global});}catch(e){o.showError("\u2718 Removal failed",e),process.exit(1);}}}async updatePackages(t){if(this.ensureSpace()){this.pm||this.initPackageManager();try{let e=t.args.packages?t.args.packages.split(" ").filter(r=>r.trim()):void 0;if(!e||e.length===0){let r=await o.promptUpdate();e=r.updateAll?void 0:r.packages;}this.pm.update(e);}catch(e){o.showError("\u2718 Update failed",e),process.exit(1);}}}linkPackage(){this.ensureSpace()&&(this.pm||this.initPackageManager(),this.pm.link());}unlinkPackage(){this.ensureSpace()&&(this.pm||this.initPackageManager(),this.pm.unlink());}listPackages(t){this.ensureSpace()&&(this.pm||this.initPackageManager(),this.pm.list({global:t.options.global}));}runScript(t){if(!this.ensureSpace())return;this.pm||this.initPackageManager();let e=t?.args?.script;if(!e){o.showError("Please specify a script name");return}try{let r=[];if(t?.dynamicArgs&&Array.isArray(t.dynamicArgs)&&r.push(...t.dynamicArgs),t?.dynamicOptions&&typeof t.dynamicOptions=="object")for(let[s,a]of Object.entries(t.dynamicOptions))r.push(`--${s}`),a!==!0&&a!==!1&&r.push(String(a));this.pm.run(e,r.length>0?r:void 0);}catch(r){o.showError(`Failed to run script "${e}"`,r),process.exit(1);}}buildSpace(t){if(!this.ensureSpace())return;this.pm||this.initPackageManager();let e=new $;e.start("Building space...");try{this.pm.runSilent("build"),e.stop(t?"":"\u2714 Build succeeded");}catch{e.stopWithError("\u2718 Build failed"),process.exit(1);}}buildSpaceBool(t){if(!this.ensureSpace())return false;this.pm||this.initPackageManager();let e=new $;e.start("Building space...");try{return this.pm.runSilent("build"),e.stop(t?"":"\u2714 Build succeeded"),!0}catch{return e.stopWithError("\u2718 Build failed!"),false}}runTests(t){if(!this.ensureSpace())return;this.pm||this.initPackageManager();let e=t?.args?.path||null;e?this.pm.run("test",[e]):this.pm.run("test");}clean(){if(!this.ensureSpace())return;this.pm||this.initPackageManager();let t=new $;t.start("Cleaning build artifacts...");try{this.pm.run("clean"),t.stop("\u2714 Clean complete!");}catch{t.stopWithError("\u2718 Clean failed!"),process.exit(1);}}startMain(t){if(this.buildSpaceBool(true))try{let e=this.findBuiltMainFile();e||(o.showError(`Could not find built entry point.
27
+ Expected to find dist/main.js or dist/index.js after build.`),process.exit(1));let r=[];if(t?.dynamicArgs&&Array.isArray(t.dynamicArgs)&&r.push(...t.dynamicArgs),t?.dynamicOptions&&typeof t.dynamicOptions=="object")for(let[a,i]of Object.entries(t.dynamicOptions))r.push(`--${a}`),i!==!0&&i!==!1&&r.push(String(i));r.length>0;let s=child_process.spawnSync("bun",[e,...r],{stdio:"inherit",cwd:process.cwd()});s.error&&(o.showError("Failed to start process",s.error),process.exit(1)),s.status!==0&&s.status!==null&&(console.error(`
28
+ \u2718 Process exited with error`),process.exit(s.status));}catch(e){o.showError("Failed to start",e),process.exit(1);}}findBuiltMainFile(){let t=["dist/main.js","dist/index.js","dist/app.js"];for(let e of t)if(u__namespace.existsSync(T__namespace.join(process.cwd(),e)))return e;try{let e=T__namespace.join(process.cwd(),"package.json");if(u__namespace.existsSync(e)){let r=JSON.parse(u__namespace.readFileSync(e,"utf-8"));if(r.main&&u__namespace.existsSync(r.main))return r.main}}catch{}return null}async publish(t){if(this.buildSpaceBool(true))try{let e=this.spaceManager.loadSpaceConfig();if(!e){o.showError("Could not load space configuration");return}let r=e.repo.org?`@${e.repo.org}/${e.repo.name}`:e.repo.name,s=t.options.tag,a=t.options.access;if(!s&&!a){let n=await o.promptPublish(r);if(!n.confirm){o.showInfo("Publish cancelled");return}s=n.tag,a=n.access;}let i=new $;i.start("Publishing package..."),this.pm.publish({tag:s,access:a},i);}catch(e){o.showError("Publish failed",e),process.exit(1);}}};var W=M.create({name:"Space",version:"0.0.1",desc:"Build flexible spaces for any platform"});W.run();//# sourceMappingURL=main.cjs.map
29
+ //# sourceMappingURL=main.cjs.map